Default Changelist
This commit is contained in:
+80
-81
@@ -10,107 +10,106 @@ namespace wchat\qq;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Kiri\Client;
|
use Kiri\Client;
|
||||||
use wchat\common\HttpClient;
|
|
||||||
use wchat\common\Result;
|
use wchat\common\Result;
|
||||||
use wchat\common\Help;
|
use wchat\common\Help;
|
||||||
|
|
||||||
class Recharge extends SmallProgram
|
class Recharge extends SmallProgram
|
||||||
{
|
{
|
||||||
private $money = 0;
|
private float $money = 0;
|
||||||
|
|
||||||
private $orderNo;
|
private string $orderNo;
|
||||||
|
|
||||||
private $data = [];
|
private array $data = [];
|
||||||
|
|
||||||
private $spill_create_ip = '';
|
private string $spill_create_ip = '';
|
||||||
|
|
||||||
private $uniformer = 'https://qpay.qq.com/cgi-bin/pay/qpay_unified_order.cgi';
|
private string $uniformer = '/cgi-bin/pay/qpay_unified_order.cgi';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param $value
|
||||||
*/
|
*/
|
||||||
public function setSpillCreateIp($value)
|
public function setSpillCreateIp($value)
|
||||||
{
|
{
|
||||||
$this->spill_create_ip = $value;
|
$this->spill_create_ip = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $money
|
* @param int $money
|
||||||
* @param string $orderNo
|
* @param string $orderNo
|
||||||
* @param string $openId
|
* @param string $openId
|
||||||
* @return Result
|
* @return Result
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
public function recharge(int $money, string $orderNo, string $openId = ''): Result
|
public function recharge(int $money, string $orderNo, string $openId = ''): Result
|
||||||
{
|
{
|
||||||
if ($money < 0) {
|
if ($money < 0) {
|
||||||
return new Result(code: 500, message: '充值金额不能小于0.');
|
return new Result(code: 500, message: '充值金额不能小于0.');
|
||||||
}
|
}
|
||||||
$this->money = $money;
|
$this->money = $money;
|
||||||
$this->orderNo = $orderNo;
|
$this->orderNo = $orderNo;
|
||||||
$this->data['openid'] = $openId;
|
$this->data['openid'] = $openId;
|
||||||
|
|
||||||
$client = new Client('qpay.qq.com', 443, true);
|
$client = new Client('qpay.qq.com', 443, true);
|
||||||
$client->withHeader(['Content-Type' => 'application/xml']);
|
$client->withHeader(['Content-Type' => 'application/xml']);
|
||||||
$client->withBody($this->builder());
|
$client->withBody($this->builder());
|
||||||
$client->post($this->uniformer);
|
$client->post($this->uniformer);
|
||||||
$client->close();
|
$client->close();
|
||||||
|
|
||||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||||
return new Result(code: 505, message: 'network error.');
|
return new Result(code: 505, message: 'network error.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = Help::toArray($client->getBody());
|
$data = Help::toArray($client->getBody());
|
||||||
if (isset($data['return_code']) && $data['return_code'] != 'SUCCESS') {
|
if (isset($data['return_code']) && $data['return_code'] != 'SUCCESS') {
|
||||||
return new Result(code: 503, message: $data['return_msg']);
|
return new Result(code: 503, message: $data['return_msg']);
|
||||||
}
|
}
|
||||||
if ($data['result_code'] != 'SUCCESS') {
|
if ($data['result_code'] != 'SUCCESS') {
|
||||||
return new Result(code: 504, message: $data['err_code_des']);
|
return new Result(code: 504, message: $data['err_code_des']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Result(code: 0, data: $this->reception($data['prepayid']));
|
return new Result(code: 0, data: $this->reception($data['prepayid']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $prepay_id
|
* @param string $prepay_id
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function reception(string $prepay_id): string
|
public function reception(string $prepay_id): string
|
||||||
{
|
{
|
||||||
return Help::sign([
|
return Help::sign([
|
||||||
'signType' => $this->config->getSignType(),
|
'signType' => $this->config->getSignType(),
|
||||||
'package' => 'prepay_id=' . $prepay_id,
|
'package' => 'prepay_id=' . $prepay_id,
|
||||||
'nonceStr' => Help::random(32),
|
'nonceStr' => Help::random(32),
|
||||||
'timestamp' => time()
|
'timestamp' => time()
|
||||||
], $this->getConfig()->getKey(), $this->getConfig()->getSignType());
|
], $this->getConfig()->getKey(), $this->getConfig()->getSignType());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function builder(): string
|
protected function builder(): string
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'appid' => $this->config->getAppid(),
|
'appid' => $this->config->getAppid(),
|
||||||
'mch_id' => $this->config->getMchId(),
|
'mch_id' => $this->config->getMchId(),
|
||||||
'nonce_str' => Help::random(32),
|
'nonce_str' => Help::random(32),
|
||||||
'body' => $this->config->getBody(),
|
'body' => $this->config->getBody(),
|
||||||
'out_trade_no' => $this->orderNo,
|
'out_trade_no' => $this->orderNo,
|
||||||
'total_fee' => $this->money,
|
'total_fee' => $this->money,
|
||||||
'spbill_create_ip' => $this->spill_create_ip,
|
'spbill_create_ip' => $this->spill_create_ip,
|
||||||
'notify_url' => $this->config->getNotifyUrl(),
|
'notify_url' => $this->config->getNotifyUrl(),
|
||||||
'trade_type' => $this->config->getTradeType(),
|
'trade_type' => $this->config->getTradeType(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->data = array_merge($data, $this->data);
|
$this->data = array_merge($data, $this->data);
|
||||||
|
|
||||||
$key = $this->config->getKey();
|
$key = $this->config->getKey();
|
||||||
$sign_type = $this->config->getSignType();
|
$sign_type = $this->config->getSignType();
|
||||||
|
|
||||||
$this->data['sign_type'] = $this->config->getSignType();
|
$this->data['sign_type'] = $this->config->getSignType();
|
||||||
$this->data['sign'] = Help::sign($this->data, $key, $sign_type);
|
$this->data['sign'] = Help::sign($this->data, $key, $sign_type);
|
||||||
|
|
||||||
return Help::toXml($this->data);
|
return Help::toXml($this->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -431,7 +431,7 @@ class Redhat extends SmallProgram
|
|||||||
*/
|
*/
|
||||||
public function redEnvelopes(): Result
|
public function redEnvelopes(): Result
|
||||||
{
|
{
|
||||||
$client = new Client('qpay.qq.com', 443, true);
|
$client = new Client('api.qpay.qq.com', 443, true);
|
||||||
$client->withHeader(['Content-Type' => 'application/json']);
|
$client->withHeader(['Content-Type' => 'application/json']);
|
||||||
$client->post($this->sendUrl, $this->generate());
|
$client->post($this->sendUrl, $this->generate());
|
||||||
$client->close();
|
$client->close();
|
||||||
|
|||||||
Reference in New Issue
Block a user