eee
This commit is contained in:
@@ -14,6 +14,11 @@ class AppConfig
|
||||
public string $appId = '';
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $host = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -217,5 +222,20 @@ class AppConfig
|
||||
$this->signType = $signType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHost(): string
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $host
|
||||
*/
|
||||
public function setHost(string $host): void
|
||||
{
|
||||
$this->host = $host;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,9 @@ abstract class Multiprogramming implements Progaram
|
||||
protected string $errorMsg = '';
|
||||
|
||||
|
||||
protected string $host = 'api.weixin.qq.com';
|
||||
|
||||
|
||||
/**
|
||||
* @var AppConfig
|
||||
*/
|
||||
@@ -136,11 +139,12 @@ abstract class Multiprogramming implements Progaram
|
||||
/**
|
||||
* @param string $requestUrl
|
||||
* @param mixed $body
|
||||
* @param string $contentType
|
||||
* @return Result
|
||||
*/
|
||||
protected function post(string $requestUrl, mixed $body): Result
|
||||
protected function post(string $requestUrl, mixed $body, string $contentType = 'application/application'): Result
|
||||
{
|
||||
return $this->request('post', $requestUrl, $body);
|
||||
return $this->request('post', $requestUrl, $body, $contentType);
|
||||
}
|
||||
|
||||
|
||||
@@ -149,9 +153,9 @@ abstract class Multiprogramming implements Progaram
|
||||
* @param mixed $body
|
||||
* @return Result
|
||||
*/
|
||||
protected function get(string $requestUrl, mixed $body): Result
|
||||
protected function get(string $requestUrl, mixed $body, string $contentType = 'application/application'): Result
|
||||
{
|
||||
return $this->request('get', $requestUrl, $body);
|
||||
return $this->request('get', $requestUrl, $body, $contentType);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,22 +174,24 @@ abstract class Multiprogramming implements Progaram
|
||||
* @param string $method
|
||||
* @param string $requestUrl
|
||||
* @param $body
|
||||
* @param string $contentType
|
||||
* @return Result
|
||||
*/
|
||||
private function request(string $method, string $requestUrl, $body): Result
|
||||
private function request(string $method, string $requestUrl, $body, string $contentType = 'application/application'): Result
|
||||
{
|
||||
$client = new Client('api.weixin.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client = new Client($this->host, 443, true);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
if ($method == 'post') {
|
||||
$client->withHeader(['Content-Type' => $contentType]);
|
||||
$client->post($requestUrl, $body);
|
||||
} else if ($method == 'upload') {
|
||||
$client->upload($requestUrl, $body);
|
||||
} else {
|
||||
$client->withHeader(['Content-Type' => $contentType]);
|
||||
$client->get($requestUrl, $body);
|
||||
}
|
||||
$client->close();
|
||||
|
||||
+3
-15
@@ -20,24 +20,12 @@ class Account extends SmallProgram
|
||||
*/
|
||||
public function login(string $code): Result
|
||||
{
|
||||
$param['appid'] = $this->config->getAppid();
|
||||
$param['secret'] = $this->config->getAppsecret();
|
||||
$param['appid'] = $this->payConfig->appId;
|
||||
$param['secret'] = $this->payConfig->appSecret;
|
||||
$param['js_code'] = $code;
|
||||
$param['grant_type'] = 'authorization_code';
|
||||
|
||||
$client = new Client('api.q.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->get('sns/jscode2session', $param);
|
||||
$client->close();
|
||||
|
||||
return Result::init($client);
|
||||
return $this->get('/sns/jscode2session', $param);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -73,8 +73,8 @@ class Notify extends SmallProgram
|
||||
$sign = $params['sign'];
|
||||
unset($params['sign']);
|
||||
|
||||
$signType = $this->config->getSignType();
|
||||
$privateKey = $this->config->getKey();
|
||||
$signType = $this->payConfig->getSignType();
|
||||
$privateKey = $this->payConfig->getKey();
|
||||
$nowSign = Help::sign($params, $privateKey, $signType);
|
||||
if ($sign === $nowSign) {
|
||||
return true;
|
||||
|
||||
+13
-39
@@ -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
|
||||
*/
|
||||
@@ -49,32 +51,7 @@ class Recharge extends SmallProgram
|
||||
$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());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,23 +75,20 @@ class Recharge extends SmallProgram
|
||||
protected function builder(): string
|
||||
{
|
||||
$data = [
|
||||
'appid' => $this->config->getAppid(),
|
||||
'mch_id' => $this->config->getMchId(),
|
||||
'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();
|
||||
$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);
|
||||
|
||||
+9
-10
@@ -265,9 +265,9 @@ class Redhat extends SmallProgram
|
||||
$requestParam['charset'] = $this->getCharset();
|
||||
$requestParam['nonce_str'] = Help::random(30);
|
||||
$requestParam['mch_billno'] = $this->getMchBillno();
|
||||
$requestParam['mch_id'] = $this->config->getMchId();
|
||||
$requestParam['mch_id'] = $this->payConfig->pay->qq->mchId;
|
||||
$requestParam['mch_name'] = $this->getMchName();
|
||||
$requestParam['qqappid'] = $this->config->getAppid();
|
||||
$requestParam['qqappid'] = $this->payConfig->appId;
|
||||
$requestParam['re_openid'] = $this->getReOpenid();
|
||||
$requestParam['total_amount'] = $this->getTotalAmount() * 100;
|
||||
$requestParam['min_value'] = $this->getMinValue() * 100;
|
||||
@@ -276,8 +276,7 @@ class Redhat extends SmallProgram
|
||||
$requestParam['wishing'] = $this->getWishing();
|
||||
$requestParam['act_name'] = $this->getActName();
|
||||
$requestParam['icon_id'] = $this->getIconId();
|
||||
$requestParam['notify_url'] = $this->config->getNotifyUrl();
|
||||
|
||||
$requestParam['notify_url'] = $this->payConfig->getNotifyUrl();
|
||||
$requestParam['sign'] = $this->builderSign($requestParam);
|
||||
|
||||
return $requestParam;
|
||||
@@ -290,7 +289,7 @@ class Redhat extends SmallProgram
|
||||
*/
|
||||
private function builderSign($requestParam): string
|
||||
{
|
||||
return Help::sign($requestParam, $this->config->getKey(), $this->config->getSignType());
|
||||
return Help::sign($requestParam, $this->payConfig->pay->qq->mchSecret, $this->payConfig->getSignType());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,9 +299,9 @@ class Redhat extends SmallProgram
|
||||
{
|
||||
$client = new Client('api.qpay.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/x-www-form-urlencoded']);
|
||||
$client->withSslKeyFile($this->config->getSslKey());
|
||||
$client->withSslCertFile($this->config->getSslCert());
|
||||
$client->withCa($this->config->getSslCa());
|
||||
$client->withSslKeyFile($this->payConfig->getSslKey());
|
||||
$client->withSslCertFile($this->payConfig->getSslCert());
|
||||
$client->withCa($this->payConfig->getSslCa());
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
@@ -333,19 +332,19 @@ class Redhat extends SmallProgram
|
||||
public function searchByOrderNo($listid, $orderNo = null): Result
|
||||
{
|
||||
$requestParam['nonce_str'] = Help::random(31);
|
||||
$requestParam['mch_id'] = $this->config->getMchId();
|
||||
$requestParam['mch_id'] = $this->payConfig->getMchId();
|
||||
$requestParam['listid'] = $listid;
|
||||
if (!empty($orderNo)) {
|
||||
$requestParam['mch_billno'] = $orderNo;
|
||||
}
|
||||
$requestParam['sign'] = $this->builderSign($requestParam);
|
||||
$client = new Client('qpay.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->post($this->searchUrl, $requestParam);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
|
||||
+4
-39
@@ -30,29 +30,12 @@ class SecCheck extends SmallProgram
|
||||
|
||||
$real_path = new \CURLFile($path);
|
||||
$data = [
|
||||
'appid' => $this->config->getAppid(),
|
||||
'appid' => $this->payConfig->appId,
|
||||
'media' => $real_path,
|
||||
'form-data[filename]' => $path,
|
||||
'form-data[content-type]' => $real_path->getMimeType()
|
||||
];
|
||||
$client = new Client('api.q.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'multipart/form-data']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->upload($path, $data);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errCode']) && $body['errCode'] != 0) {
|
||||
return new Result(code: $body['errCode'], message: $body['errMsg']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $body);
|
||||
}
|
||||
return $this->upload($path, $data);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,27 +48,9 @@ class SecCheck extends SmallProgram
|
||||
if (empty($content)) {
|
||||
return $this->sendError('文件不存在', 404);
|
||||
}
|
||||
$url = '/' . ltrim($this->_url, '/') . $this->config->getAccessToken();
|
||||
$url = '/' . ltrim($this->_url, '/') . $this->payConfig->getAccessToken();
|
||||
|
||||
$client = new Client('api.q.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($url, ['appid' => $this->config->getAppid(), 'content' => $content]);
|
||||
$client->close();
|
||||
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errCode']) && $body['errCode'] != 0) {
|
||||
return new Result(code: $body['errCode'], message: $body['errMsg']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $body);
|
||||
}
|
||||
return $this->post($url, ['appid' => $this->payConfig->appId, 'content' => $content]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,9 +4,39 @@
|
||||
namespace wchat\qq;
|
||||
|
||||
|
||||
use Kiri\Client;
|
||||
use wchat\common\Multiprogramming;
|
||||
|
||||
class SmallProgram extends Multiprogramming
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected string $host = 'api.q.qq.com';
|
||||
|
||||
|
||||
/**
|
||||
* @param string $url
|
||||
* @param mixed $data
|
||||
* @return Client
|
||||
*/
|
||||
protected function createClient(string $url, mixed $data): Client
|
||||
{
|
||||
$client = new Client('api.qpay.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->withSslCertFile($this->payConfig->pay->qq->mchCert);
|
||||
$client->withSslKeyFile($this->payConfig->pay->qq->mchKey);
|
||||
$client->withCa($this->payConfig->pay->qq->mchCa);
|
||||
$proxyHost = $this->payConfig->getProxyHost();
|
||||
$proxyPort = $this->payConfig->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->post($url, $data);
|
||||
$client->close();
|
||||
return $client;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-20
@@ -17,27 +17,10 @@ class Token extends SmallProgram
|
||||
{
|
||||
$query = [
|
||||
'grant_type' => 'client_credential',
|
||||
'appid' => $this->config->getAppid(),
|
||||
'secret' => $this->config->getAppsecret()
|
||||
'appid' => $this->payConfig->appId,
|
||||
'secret' => $this->payConfig->appSecret
|
||||
];
|
||||
$client = new Client('api.q.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
$client->get('/api/getToken', $query);
|
||||
$client->close();
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
$body = json_decode($client->getBody(), true);
|
||||
if (isset($body['errcode']) && $body['errcode'] != 0) {
|
||||
return new Result(code: $body['errcode'], message: $body['errmsg']);
|
||||
} else {
|
||||
return new Result(code: 0, data: $body);
|
||||
}
|
||||
return $this->get('/api/getToken', $query);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-26
@@ -5,11 +5,9 @@ namespace wchat\qq\pay;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Kiri\Client;
|
||||
use wchat\common\Help;
|
||||
use wchat\common\HttpClient;
|
||||
use wchat\common\Result;
|
||||
use wchat\wx\SmallProgram;
|
||||
use wchat\qq\SmallProgram;
|
||||
|
||||
/**
|
||||
* Class Cash_Bonus
|
||||
@@ -86,20 +84,7 @@ class Cash_Bonus extends SmallProgram
|
||||
*/
|
||||
public function mch_send($mch_billno, $openId, $price): Result
|
||||
{
|
||||
$client = new Client('api.qpay.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->withSslCertFile($this->getConfig()->getSslCert());
|
||||
$client->withSslKeyFile($this->getConfig()->getSslKey());
|
||||
$client->withCa($this->getConfig()->getSslCa());
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->post($this->_cash, $this->orderConfig($mch_billno, $openId, $price));
|
||||
$client->close();
|
||||
$client = $this->createClient($this->_cash, $this->orderConfig($mch_billno, $openId, $price));
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
@@ -128,21 +113,18 @@ class Cash_Bonus extends SmallProgram
|
||||
$requestParam['charset'] = 1;
|
||||
$requestParam['nonce_str'] = Help::random(32);
|
||||
$requestParam['mch_billno'] = $mch_billno;
|
||||
$requestParam['mch_id'] = $this->getConfig()->getMchId();
|
||||
$requestParam['qqappid'] = $this->getConfig()->getAppid();
|
||||
$requestParam['mch_id'] = $this->payConfig->pay->qq->mchId;
|
||||
$requestParam['qqappid'] = $this->payConfig->appId;
|
||||
$requestParam['re_openid'] = $openId;
|
||||
$requestParam['total_amount'] = $price * 100;
|
||||
$requestParam['min_value'] = $price * 100;
|
||||
$requestParam['max_value'] = $price * 100;
|
||||
$requestParam['total_num'] = 1;
|
||||
$requestParam['notify_url'] = $this->getConfig()->getNotifyUrl();
|
||||
|
||||
$requestParam['notify_url'] = $this->payConfig->getNotifyUrl();
|
||||
if (!empty($this->_requestParams)) {
|
||||
$requestParam = array_merge($requestParam, $this->_requestParams);
|
||||
}
|
||||
|
||||
$requestParam['sign'] = Help::sign($requestParam, $this->getConfig()->getKey(), 'MD5');
|
||||
|
||||
$requestParam['sign'] = Help::sign($requestParam, $this->payConfig->pay->qq->mchSecret, 'MD5');
|
||||
return $requestParam;
|
||||
}
|
||||
|
||||
@@ -154,7 +136,7 @@ class Cash_Bonus extends SmallProgram
|
||||
public function mchOrderNo(): string
|
||||
{
|
||||
return implode([
|
||||
$this->getConfig()->getMchId(),
|
||||
$this->payConfig->pay->qq->mchId,
|
||||
date('Ymd'),
|
||||
random_int(11, 99),
|
||||
date('His'),
|
||||
@@ -171,7 +153,7 @@ class Cash_Bonus extends SmallProgram
|
||||
{
|
||||
$notifySign = $requestParams['sign'];
|
||||
unset($requestParams['sign']);
|
||||
$sign = Help::sign($requestParams, $this->getConfig()->getKey(), 'MD5');
|
||||
$sign = Help::sign($requestParams, $this->payConfig->pay->qq->mchSecret, 'MD5');
|
||||
|
||||
if ($sign !== $notifySign) {
|
||||
return false;
|
||||
|
||||
@@ -5,9 +5,7 @@ namespace wchat\qq\pay;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Kiri\Client;
|
||||
use wchat\common\Help;
|
||||
use wchat\common\HttpClient;
|
||||
use wchat\common\Result;
|
||||
use wchat\qq\SmallProgram;
|
||||
|
||||
@@ -67,25 +65,12 @@ class Enterprise_payment extends SmallProgram
|
||||
* @param $mch_billno
|
||||
* @param $openId
|
||||
* @param $price
|
||||
* @return mixed
|
||||
* @return Result
|
||||
* @throws Exception
|
||||
*/
|
||||
public function mch_send($mch_billno, $openId, $price)
|
||||
public function mch_send($mch_billno, $openId, $price): Result
|
||||
{
|
||||
$client = new Client('api.qpay.qq.com', 443, true);
|
||||
$client->withHeader(['Content-Type' => 'application/json']);
|
||||
$client->withSslCertFile($this->getConfig()->getSslCert());
|
||||
$client->withSslKeyFile($this->getConfig()->getSslKey());
|
||||
$client->withCa($this->getConfig()->getSslCa());
|
||||
|
||||
$proxyHost = $this->getConfig()->getProxyHost();
|
||||
$proxyPort = $this->getConfig()->getProxyPort();
|
||||
if (!empty($proxyHost) && $proxyPort > 0) {
|
||||
$client->withProxyHost($proxyHost)->withProxyPort($proxyPort);
|
||||
}
|
||||
|
||||
$client->post($this->_cash, $this->orderConfig($mch_billno, $openId, $price));
|
||||
$client->close();
|
||||
$client = $this->createClient($this->_cash, $this->orderConfig($mch_billno, $openId, $price));
|
||||
if (!in_array($client->getStatusCode(), [101, 200, 201])) {
|
||||
return new Result(code: 505, message: $client->getBody());
|
||||
}
|
||||
@@ -110,21 +95,18 @@ class Enterprise_payment extends SmallProgram
|
||||
$requestParam['input_charset'] = 'UTF-8';
|
||||
$requestParam['nonce_str'] = Help::random(32);
|
||||
$requestParam['out_trade_no'] = $mch_billno;
|
||||
$requestParam['mch_id'] = $this->getConfig()->getMchId();
|
||||
$requestParam['appid'] = $this->getConfig()->getAppid();
|
||||
$requestParam['mch_id'] = $this->payConfig->pay->qq->mchId;
|
||||
$requestParam['appid'] = $this->payConfig->pay->qq->mchSecret;
|
||||
$requestParam['openid'] = $openId;
|
||||
$requestParam['fee_type'] = 'CNY';
|
||||
$requestParam['total_fee'] = $price * 100;
|
||||
$requestParam['memo'] = $this->getConfig()->getBody();
|
||||
$requestParam['notify_url'] = $this->getConfig()->getNotifyUrl();
|
||||
$requestParam['spbill_create_ip'] = $this->getConfig()->getNotifyUrl();
|
||||
|
||||
$requestParam['memo'] = $this->payConfig->getBody();
|
||||
$requestParam['notify_url'] = $this->payConfig->getNotifyUrl();
|
||||
$requestParam['spbill_create_ip'] = $this->payConfig->getNotifyUrl();
|
||||
if (!empty($this->_requestParams) && is_array($this->_requestParams)) {
|
||||
$requestParam = array_merge($requestParam, $this->_requestParams);
|
||||
}
|
||||
|
||||
$requestParam['sign'] = Help::sign($requestParam, $this->getConfig()->getKey(), 'MD5');
|
||||
|
||||
$requestParam['sign'] = Help::sign($requestParam, $this->payConfig->pay->qq->mchSecret, 'MD5');
|
||||
return $requestParam;
|
||||
}
|
||||
|
||||
@@ -136,7 +118,7 @@ class Enterprise_payment extends SmallProgram
|
||||
public function mchOrderNo(): string
|
||||
{
|
||||
return implode([
|
||||
$this->getConfig()->getMchId(),
|
||||
$this->payConfig->pay->qq->mchId,
|
||||
date('Ymd'),
|
||||
random_int(11, 99),
|
||||
date('His'),
|
||||
@@ -153,7 +135,7 @@ class Enterprise_payment extends SmallProgram
|
||||
{
|
||||
$notifySign = $requestParams['sign'];
|
||||
unset($requestParams['sign']);
|
||||
$sign = Help::sign($requestParams, $this->getConfig()->getKey(), 'MD5');
|
||||
$sign = Help::sign($requestParams, $this->payConfig->pay->qq->mchSecret, 'MD5');
|
||||
|
||||
if ($sign !== $notifySign) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user