Home >Backend Development >PHP Tutorial >Payment verification signature payment failed? —— WeChat Pay app payment
Situation description:
1. Call the same order interface and get the prepay_id equivalent value!
2. Before submitting data to the app, there is a secondary signature. I signed it according to the rules! //Please check if the code I wrote is correct
3. Why does this problem occur?
4. I beg God for guidance!
This is my secondary signature code:
............ //Set parameters, etc.
$wx_result = $wechatAppPay->unifiedOrder( $params );//调用同一下单接口,并成功返回结果 //开始生成二次签名 $sign_array = array();//第二次签名需要的参数 $sign_array['appid'] = $wx_result['appid']; $sign_array['mch_id'] = $wx_result['mch_id']; $sign_array['prepay_id'] = $wx_result['prepay_id']; $sign_array['nonce_str'] = $wx_result['nonce_str']; $sign_array['timeStamp'] = time(); $sign_array['package'] = $wx_result['Sign=WXPay']; $sign_two = $wechatAppPay->MakeSign($sign_array);//调用签名生成函数
The following is my function code to generate signatures:
/** * 生成签名 * @return 签名 */ public function MakeSign( $params ){ //签名步骤一:按字典序排序数组参数 ksort($params); $string = $this->ToUrlParams($params);//调用拼接函数 //签名步骤二:在string后加入KEY $string = $string . "&key=".$this->key; //签名步骤三:MD5加密 $string = md5($string); //签名步骤四:所有字符转为大写 $result = strtoupper($string); return $result; } /** * 将参数拼接为url: key=value&key=value * @param $params * @return string */ public function ToUrlParams( $params ){ $string = ''; if( !empty($params) ){ $array = array(); foreach( $params as $key => $value ){ $array[] = $key.'='.$value; } $string = implode("&",$array); } return $string; }
This question has been resolved Solved, the reason is that the parameter name in the second signature is wrong.
//////////////////////////////Update/////////////////// ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// /////////////////////////////////
But I don’t know how to write the callback! !
But I can’t receive the value (I can’t receive the general notification of payment results from WeChat), and I don’t know what’s going on
Receive WeChat payment asynchronous notification callback address:
$notify_url = 'http://www.XXXXXX.com/index.php/apps/cart/wxResult';
//微信支付回调函数 public function wxResult() { $data = array(); $data = $this->wechatAppPay->getNotifyData();//调用获取数据函数 ////////********逻辑处理********////////// $data2 = $this->wechatAppPay->replyNotify();//接收通知成功后应答输出XML数据 $this->jsonmsg($data); }
Function to get notification data:
/** * * 获取支付结果通知数据 * return array */ public function getNotifyData(){ //获取通知的数据 $xml = $GLOBALS['HTTP_RAW_POST_DATA']; $data = array(); if( empty($xml) ){ return false; } $data = $this->xml_to_data( $xml ); if( !empty($data['return_code']) ){ if( $data['return_code'] == 'FAIL' ){ return false; } } return $data; }
Response output XML data function after successfully receiving notification:
/** * 接收通知成功后应答输出XML数据 * @param string $xml */ public function replyNotify(){ $data['return_code'] = 'SUCCESS'; $data['return_msg'] = 'OK'; $xml = $this->data_to_xml( $data ); echo $xml; die(); }
** Solved
///////Updated/////////////////Merchant system for payment result notification Signature verification of the content /////////////////////////////////**
is working on the content of the payment result notification from the merchant system How to do signature verification?
What is it? What is the logical idea?
Reply content:
Payment interface document
Fields specified in the document
appid
partnerid
prepayid
package
noncestr
timestamp
sign
Please do not change the case of parameter names, also Don't add Underline or something. I have encountered this problem before and it has been solved.
Hello, I also encountered the same problem. I wonder if you have solved it?
Is the parameter name involved in the md5 calculation?
The timestamp of the secondary signature is the timestamp when pre_payid was generated