|
|
@@ -64,6 +64,12 @@ class Wechat
|
|
|
'token' => 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s',
|
|
|
];
|
|
|
|
|
|
+ // 支付证书
|
|
|
+ protected static $certPaths = [
|
|
|
+ 'cert_path'=> CMF_DATA.'cert/pay_cert.pem',
|
|
|
+ 'key_path'=> CMF_DATA.'cert/pay_key.pem',
|
|
|
+ ];
|
|
|
+
|
|
|
/**
|
|
|
* 授权地址校验
|
|
|
*/
|
|
|
@@ -644,10 +650,10 @@ class Wechat
|
|
|
if ($unifiedOrder === false) {
|
|
|
return ['code' => 'exception', 'message' => 'parase xml error'];
|
|
|
}
|
|
|
- if ($unifiedOrder['return_code'] != 'SUCCESS') {
|
|
|
+ if (isset($unifiedOrder['return_code']) && $unifiedOrder['return_code'] != 'SUCCESS') {
|
|
|
return ['code' => 'error', 'message' => $unifiedOrder['return_msg']];
|
|
|
}
|
|
|
- if ($unifiedOrder['result_code'] != 'SUCCESS') {
|
|
|
+ if (isset($unifiedOrder['result_code']) && $unifiedOrder['result_code'] != 'SUCCESS') {
|
|
|
return ['code' => 'error', 'message' => $unifiedOrder['err_code']];
|
|
|
}
|
|
|
|
|
|
@@ -681,6 +687,7 @@ class Wechat
|
|
|
// 'mch_appid' => 'ww80960cfd3748a47f',
|
|
|
'mch_appid' => $appId,
|
|
|
'mchid' => trim($mchId),
|
|
|
+ 'device_info' => uniqid(),
|
|
|
'nonce_str' => Wechat::createNonceStr(),
|
|
|
'partner_trade_no' => $orderNo,
|
|
|
'openid' => $openid,
|
|
|
@@ -699,11 +706,11 @@ var_dump($unified);
|
|
|
$unified['sign'] = Wechat::getPaySign($unified);
|
|
|
var_dump($unified);
|
|
|
PRedis::set('orders:'.$scene.':'.$openid.':unifiedSign', $unified, 600);
|
|
|
- $url = !empty(self::$apiUrl['unifiedorder']) ? trim(self::$apiUrl['unifiedorder']) : 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
|
|
|
+ $url = !empty(self::$apiUrl['transfers']) ? trim(self::$apiUrl['transfers']) : 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
|
|
|
$data = Wechat::arrayToXml($unified);
|
|
|
var_dump($data);
|
|
|
PRedis::set('orders:'.$scene.':'.$openid.':unifiedXml', ['data'=> $unified,'result'=> $data], 600);
|
|
|
- $responseXml = Wechat::curlPost($url, trim($data));
|
|
|
+ $responseXml = Wechat::curlPost($url, $data, [], self::$certPaths);
|
|
|
//禁止引用外部xml实体
|
|
|
libxml_disable_entity_loader(true);
|
|
|
$result = simplexml_load_string($responseXml, 'SimpleXMLElement', LIBXML_NOCDATA);
|
|
|
@@ -712,10 +719,10 @@ var_dump($unified);
|
|
|
if ($result === false) {
|
|
|
return ['code' => 'exception', 'message' => 'parase xml error'];
|
|
|
}
|
|
|
- if ($result['return_code'] != 'SUCCESS') {
|
|
|
+ if (isset($result['return_code']) && $result['return_code'] != 'SUCCESS') {
|
|
|
return ['code' => 'error', 'message' => $result['return_msg'],'type'=>'return_code'];
|
|
|
}
|
|
|
- if ($result['result_code'] != 'SUCCESS') {
|
|
|
+ if (isset($result['result_code']) && $result['result_code'] != 'SUCCESS') {
|
|
|
return ['code' => 'error', 'message' => $result['err_code'],'type'=>'result_code'];
|
|
|
}
|
|
|
|
|
|
@@ -864,12 +871,12 @@ var_dump($unified);
|
|
|
* @param array $options
|
|
|
* @return mixed
|
|
|
*/
|
|
|
- public static function curlPost($url = '', $postData = '', $options = array())
|
|
|
+ public static function curlPost($url = '', $postData = '', $options = array(), $cert=[])
|
|
|
{
|
|
|
if (is_array($postData)) {
|
|
|
- echo 666;
|
|
|
$postData = http_build_query($postData);
|
|
|
}
|
|
|
+
|
|
|
$ch = curl_init();
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
@@ -879,6 +886,17 @@ var_dump($unified);
|
|
|
if (!empty($options)) {
|
|
|
curl_setopt_array($ch, $options);
|
|
|
}
|
|
|
+ var_dump($cert);
|
|
|
+ if($cert){
|
|
|
+ if(isset($cert['cert_path']) && $cert['cert_path']){
|
|
|
+ curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
|
|
|
+ curl_setopt($ch,CURLOPT_SSLCERT, $cert['cert_path']);
|
|
|
+ }
|
|
|
+ if(isset($cert['key_path']) && $cert['key_path']) {
|
|
|
+ curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
|
|
|
+ curl_setopt($ch, CURLOPT_SSLKEY, $cert['key_path']);
|
|
|
+ }
|
|
|
+ }
|
|
|
//https请求 不验证证书和host
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|