|
@@ -456,29 +456,31 @@ class WechatService extends BaseService
|
|
|
if (empty($openid) || empty($orderNo) || empty($totalFee)) {
|
|
if (empty($openid) || empty($orderNo) || empty($totalFee)) {
|
|
|
return ['code' => 'error', 'message' => '参数错误'];
|
|
return ['code' => 'error', 'message' => '参数错误'];
|
|
|
}
|
|
}
|
|
|
- $nonceStr = WechatService::createNonceStr();
|
|
|
|
|
|
|
+
|
|
|
$unified = array(
|
|
$unified = array(
|
|
|
- 'appid' => $appId,
|
|
|
|
|
|
|
+ 'sp_appid' => $spAppId,
|
|
|
|
|
+ 'sub_appid' => $appId,
|
|
|
'attach' => 'pay', //商家数据包,原样返回,如果填写中文,请注意转换为utf-8
|
|
'attach' => 'pay', //商家数据包,原样返回,如果填写中文,请注意转换为utf-8
|
|
|
'description' => isset($order['body']) ? trim($order['body']) : '订单支付',
|
|
'description' => isset($order['body']) ? trim($order['body']) : '订单支付',
|
|
|
- 'mchid' => $mchId,
|
|
|
|
|
- 'nonce_str' => $nonceStr,
|
|
|
|
|
|
|
+ 'sp_mchid' => $spMchId,
|
|
|
|
|
+ 'sub_mchid' => $mchId,
|
|
|
'notify_url' => $notifyUrl,
|
|
'notify_url' => $notifyUrl,
|
|
|
'payer'=> [
|
|
'payer'=> [
|
|
|
- 'openid' => $openid, //rade_type=JSAPI,此参数必传
|
|
|
|
|
|
|
+ 'sub_openid' => $openid, //子商户此参数必传
|
|
|
],
|
|
],
|
|
|
'out_trade_no' => $orderNo,
|
|
'out_trade_no' => $orderNo,
|
|
|
- 'spbill_create_ip' => get_client_ip(),
|
|
|
|
|
'amount' => [
|
|
'amount' => [
|
|
|
'total'=> intval($totalFee * 100),
|
|
'total'=> intval($totalFee * 100),
|
|
|
'currency'=> 'CNY'
|
|
'currency'=> 'CNY'
|
|
|
], //单位 转为分
|
|
], //单位 转为分
|
|
|
- 'trade_type' => 'JSAPI',
|
|
|
|
|
|
|
+ 'scene_info' => [
|
|
|
|
|
+ 'payer_client_ip'=> get_client_ip()
|
|
|
|
|
+ ],
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
$body = json_encode($unified);
|
|
$body = json_encode($unified);
|
|
|
$url = !empty(self::$apiUrl['unifiedorderV3']) ? trim(self::$apiUrl['unifiedorderV3']) : 'https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi';
|
|
$url = !empty(self::$apiUrl['unifiedorderV3']) ? trim(self::$apiUrl['unifiedorderV3']) : 'https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi';
|
|
|
- $token = WechatService::getSignToken(['url'=> $url, 'method'=> 'POST', 'body'=> $body,'nonceStr'=> $nonceStr]);
|
|
|
|
|
|
|
+ $token = WechatService::getSignToken(['url'=> $url, 'method'=> 'POST','mchid'=> $spMchId, 'body'=> $body]);
|
|
|
RedisService::set('caches:orders:'.$scene.':'.$openid.':unifiedSign', ['data'=>$unified,'token'=> $token], 600);
|
|
RedisService::set('caches:orders:'.$scene.':'.$openid.':unifiedSign', ['data'=>$unified,'token'=> $token], 600);
|
|
|
$headers = ["Authorization: {$token}","Content-Type: application/json","Accept: application/json","User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"];
|
|
$headers = ["Authorization: {$token}","Content-Type: application/json","Accept: application/json","User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"];
|
|
|
RedisService::set('caches:orders:'.$scene.':'.$openid.':unifiedRequest', ['data'=> $unified,'headers'=> $headers], 600);
|
|
RedisService::set('caches:orders:'.$scene.':'.$openid.':unifiedRequest', ['data'=> $unified,'headers'=> $headers], 600);
|
|
@@ -486,8 +488,6 @@ class WechatService extends BaseService
|
|
|
$response = $response? json_decode($response, true) : $response;
|
|
$response = $response? json_decode($response, true) : $response;
|
|
|
//禁止引用外部xml实体
|
|
//禁止引用外部xml实体
|
|
|
RedisService::set('caches:orders:'.$scene.':'.$openid.':unifiedResult', ['data'=> $response], 600);
|
|
RedisService::set('caches:orders:'.$scene.':'.$openid.':unifiedResult', ['data'=> $response], 600);
|
|
|
- var_dump($response);
|
|
|
|
|
- //$response['prepay_id'] = 'sdfdsilofhewfjkwehfkuhwe';
|
|
|
|
|
$prepayId = isset($response['prepay_id'])? $response['prepay_id'] : '';
|
|
$prepayId = isset($response['prepay_id'])? $response['prepay_id'] : '';
|
|
|
$code = isset($response['code'])? $response['code'] : '';
|
|
$code = isset($response['code'])? $response['code'] : '';
|
|
|
if (!$prepayId) {
|
|
if (!$prepayId) {
|
|
@@ -512,8 +512,6 @@ class WechatService extends BaseService
|
|
|
public static function jsapiUnifiedorderV2($order, $scene = 'jsapiPay')
|
|
public static function jsapiUnifiedorderV2($order, $scene = 'jsapiPay')
|
|
|
{
|
|
{
|
|
|
$appId = WechatService::getConfigs('wx_appid');
|
|
$appId = WechatService::getConfigs('wx_appid');
|
|
|
- $spAppId = WechatService::getConfigs('wx_sp_appid');
|
|
|
|
|
- $spMchId = WechatService::getConfigs('wx_sp_mchid');
|
|
|
|
|
$mchId = WechatService::getConfigs('wx_mch_id');
|
|
$mchId = WechatService::getConfigs('wx_mch_id');
|
|
|
$notifyUrls = WechatService::getConfigs('notify');
|
|
$notifyUrls = WechatService::getConfigs('notify');
|
|
|
$notifyUrl = isset($notifyUrls[$scene]) ? url()->formatRoot('http://').$notifyUrls[$scene] : url()->formatRoot('http://').'/api/notify/pay/index';
|
|
$notifyUrl = isset($notifyUrls[$scene]) ? url()->formatRoot('http://').$notifyUrls[$scene] : url()->formatRoot('http://').'/api/notify/pay/index';
|
|
@@ -530,23 +528,16 @@ class WechatService extends BaseService
|
|
|
return ['code' => 'error', 'message' => '参数错误'];
|
|
return ['code' => 'error', 'message' => '参数错误'];
|
|
|
}
|
|
}
|
|
|
$unified = array(
|
|
$unified = array(
|
|
|
- 'sp_appid' => $spAppId,
|
|
|
|
|
- 'sub_appid' => $appId,
|
|
|
|
|
|
|
+ 'appid' => $appId,
|
|
|
'attach' => 'pay', //商家数据包,原样返回,如果填写中文,请注意转换为utf-8
|
|
'attach' => 'pay', //商家数据包,原样返回,如果填写中文,请注意转换为utf-8
|
|
|
- 'description' => isset($order['body']) ? trim($order['body']) : '订单支付',
|
|
|
|
|
- 'sp_mchid' => $spMchId,
|
|
|
|
|
- 'mchid' => $mchId,
|
|
|
|
|
|
|
+ 'body' => isset($order['body']) ? trim($order['body']) : '订单支付',
|
|
|
|
|
+ 'mch_id' => $mchId,
|
|
|
'nonce_str' => WechatService::createNonceStr(),
|
|
'nonce_str' => WechatService::createNonceStr(),
|
|
|
'notify_url' => $notifyUrl,
|
|
'notify_url' => $notifyUrl,
|
|
|
- 'payer'=> [
|
|
|
|
|
- 'openid' => $openid, //rade_type=JSAPI,此参数必传
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ 'openid'=> $openid,
|
|
|
'out_trade_no' => $orderNo,
|
|
'out_trade_no' => $orderNo,
|
|
|
'spbill_create_ip' => get_client_ip(),
|
|
'spbill_create_ip' => get_client_ip(),
|
|
|
- 'amount' => [
|
|
|
|
|
- 'total'=> intval($totalFee * 100),
|
|
|
|
|
- 'currency'=> 'CNY'
|
|
|
|
|
- ], //单位 转为分
|
|
|
|
|
|
|
+ 'total_fee' => intval($totalFee * 100), //单位 转为分
|
|
|
'trade_type' => 'JSAPI',
|
|
'trade_type' => 'JSAPI',
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -1272,7 +1263,7 @@ class WechatService extends BaseService
|
|
|
$url = $params['url'];
|
|
$url = $params['url'];
|
|
|
$url_parts = parse_url($url);
|
|
$url_parts = parse_url($url);
|
|
|
$canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : ""));
|
|
$canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : ""));
|
|
|
- $nonce = $params['nonceStr']? $params['nonceStr'] : WechatService::createNonceStr(32);
|
|
|
|
|
|
|
+ $nonce = WechatService::createNonceStr(32);
|
|
|
$timestamp = time();
|
|
$timestamp = time();
|
|
|
$body = isset($params['body'])? $params['body'] : '';
|
|
$body = isset($params['body'])? $params['body'] : '';
|
|
|
$method = isset($params['method'])? $params['method'] : 'POST';
|
|
$method = isset($params['method'])? $params['method'] : 'POST';
|
|
@@ -1283,16 +1274,15 @@ class WechatService extends BaseService
|
|
|
if($body){
|
|
if($body){
|
|
|
$message .= $body."\n";
|
|
$message .= $body."\n";
|
|
|
}
|
|
}
|
|
|
-var_dump($message);
|
|
|
|
|
|
|
+
|
|
|
$mch_private_key = openssl_get_privatekey(file_get_contents(self::$certPaths['key_path']));
|
|
$mch_private_key = openssl_get_privatekey(file_get_contents(self::$certPaths['key_path']));
|
|
|
openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
|
|
openssl_sign($message, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
|
|
|
$sign = base64_encode($raw_sign);
|
|
$sign = base64_encode($raw_sign);
|
|
|
|
|
|
|
|
$schema = 'WECHATPAY2-SHA256-RSA2048';
|
|
$schema = 'WECHATPAY2-SHA256-RSA2048';
|
|
|
$serial_no = WechatService::getConfigs('wx_mch_cert_no');
|
|
$serial_no = WechatService::getConfigs('wx_mch_cert_no');
|
|
|
- $mchId = WechatService::getConfigs('wx_mch_id');
|
|
|
|
|
- $token = sprintf('%s mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', $schema, $mchId, $nonce, $timestamp, $serial_no, $sign);
|
|
|
|
|
-var_dump($token);
|
|
|
|
|
|
|
+ $mchId = isset($params['mchid'])? $params['mchid'] : WechatService::getConfigs('wx_mchid');
|
|
|
|
|
+ $token = sprintf('%s mchid="%s",nonce_str="%s",timestamp="%d",signature="%s",serial_no="%s"', $schema, $mchId, $nonce, $timestamp, $sign, $serial_no);
|
|
|
return $token;
|
|
return $token;
|
|
|
}
|
|
}
|
|
|
|
|
|