eee
This commit is contained in:
+18
-44
@@ -25,6 +25,8 @@ class Recharge extends SmallProgram
|
||||
|
||||
private string $uniformer = '/cgi-bin/pay/qpay_unified_order.cgi';
|
||||
|
||||
protected string $host = 'qpay.qq.com';
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
*/
|
||||
@@ -45,36 +47,11 @@ class Recharge extends SmallProgram
|
||||
if ($money < 0) {
|
||||
return new Result(code: 500, message: '充值金额不能小于0.');
|
||||
}
|
||||
$this->money = $money;
|
||||
$this->orderNo = $orderNo;
|
||||
$this->money = $money;
|
||||
$this->orderNo = $orderNo;
|
||||
$this->data['openid'] = $openId;
|
||||
|
||||
$client = new Client('qpay.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/xml']);
|
||||
$client->withBody($this->builder());
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->post($this->uniformer);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
|
||||
$data = Help::toArray($client->getBody());
|
||||
if (isset($data['return_code']) && $data['return_code'] != 'SUCCESS') {
|
||||
return new Result(code: 503, message: $data['return_msg']);
|
||||
}
|
||||
if ($data['result_code'] != 'SUCCESS') {
|
||||
return new Result(code: 504, message: $data['err_code_des']);
|
||||
}
|
||||
|
||||
return new Result(code: 0, data: $this->reception($data['prepayid']));
|
||||
return $this->post($this->uniformer, $this->builder(), 'application/xml');
|
||||
}
|
||||
|
||||
|
||||
@@ -85,11 +62,11 @@ class Recharge extends SmallProgram
|
||||
public function reception(string $prepay_id): string
|
||||
{
|
||||
return Help::sign([
|
||||
'signType' => $this->config->getSignType(),
|
||||
'signType' => $this->payConfig->getSignType(),
|
||||
'package' => 'prepay_id=' . $prepay_id,
|
||||
'nonceStr' => Help::random(32),
|
||||
'timestamp' => time()
|
||||
], $this->getConfig()->getKey(), $this->getConfig()->getSignType());
|
||||
], $this->payConfig->pay->qq->mchSecret, $this->payConfig->getSignType());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,25 +74,22 @@ class Recharge extends SmallProgram
|
||||
*/
|
||||
protected function builder(): string
|
||||
{
|
||||
$data = [
|
||||
'appid' => $this->config->getAppid(),
|
||||
'mch_id' => $this->config->getMchId(),
|
||||
$data = [
|
||||
'appid' => $this->payConfig->appId,
|
||||
'mch_id' => $this->payConfig->pay->qq->mchId,
|
||||
'nonce_str' => Help::random(32),
|
||||
'body' => $this->config->getBody(),
|
||||
'body' => $this->payConfig->getBody(),
|
||||
'out_trade_no' => $this->orderNo,
|
||||
'total_fee' => $this->money,
|
||||
'spbill_create_ip' => $this->spill_create_ip,
|
||||
'notify_url' => $this->config->getNotifyUrl(),
|
||||
'trade_type' => $this->config->getTradeType(),
|
||||
'notify_url' => $this->payConfig->getNotifyUrl(),
|
||||
'trade_type' => $this->payConfig->getTradeType(),
|
||||
];
|
||||
|
||||
$this->data = array_merge($data, $this->data);
|
||||
|
||||
$key = $this->config->getKey();
|
||||
$sign_type = $this->config->getSignType();
|
||||
|
||||
$this->data['sign_type'] = $this->config->getSignType();
|
||||
$this->data['sign'] = Help::sign($this->data, $key, $sign_type);
|
||||
$this->data = array_merge($data, $this->data);
|
||||
$key = $this->payConfig->pay->qq->mchSecret;
|
||||
$sign_type = $this->payConfig->getSignType();
|
||||
$this->data['sign_type'] = $this->payConfig->getSignType();
|
||||
$this->data['sign'] = Help::sign($this->data, $key, $sign_type);
|
||||
|
||||
return Help::toXml($this->data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user