Home > Article > WeChat Applet > WeChat Mini Program Payment Process
Payment step logic:
1. The mini program initiates a request for prepayment
2. The server calls the interface to initiate prepayment information
3. The WeChat applet calls up the payment to complete the payment
1. The mini program initiates a request for prepayment
2. The server calls the interface to initiate prepayment information
After the server receives the request, it calls WeChat's api interface. If the call is successful, a prepay_id will be obtained. This is equivalent to the prepayment id process of the mini program. A signature will be generated. Just generate it according to the instance parameters in the official document. If it is not required, you can choose not to fill it in, and then send an xml
<xml> <appid>wx2421b1c4370ec43b</appid> <attach>支付测试</attach> <body>JSAPI支付测试</body> <mch_id>10000100</mch_id> <detail><![CDATA[{ "goods_detail":[ { "goods_id":"iphone6s_16G", "wxpay_goods_id":"1001", "goods_name":"iPhone6s 16G", "quantity":1, "price":528800, "goods_category":"123456", "body":"苹果手机" }, { "goods_id":"iphone6s_32G", "wxpay_goods_id":"1002", "goods_name":"iPhone6s 32G", "quantity":1, "price":608800, "goods_category":"123789", "body":"苹果手机" } ] }]]></detail> <nonce_str>1add1a30ac87aa2db72f57a2375d8fec</nonce_str> <notify_url>[url]http://wxpay.wxutil.com/pub_v2/pay/notify.v2.php</notify_url>[/url] <openid>oUpF8uMuAJO_M2pxb1Q9zNjWeS6o</openid> <out_trade_no>1415659990</out_trade_no> <spbill_create_ip>14.23.150.211</spbill_create_ip> <total_fee>1</total_fee> <trade_type>JSAPI</trade_type> <sign>0CB01533B8C1EF103065174F50BCA001</sign> </xml>
##
/** * 生成签名 * @return 签名,本函数不覆盖sign成员变量,如要设置签名需要调用SetSign方法赋值 */ public function MakeSign() { //签名步骤一:按字典序排序参数 ksort($this->_prepay); $string = $this->ToUrlParams(); //签名步骤二:在string后加入KEY $string = $string . "&key=".WxPayConfig::KEY; //签名步骤三:MD5加密 $string = md5($string); //签名步骤四:所有字符转为大写 $result = strtoupper($string); return $result; } /** * 格式化参数格式化成url参数 */ public function ToUrlParams() { $buff = ""; foreach ($this->values as $k => $v) { if($k != "sign" && $v != "" && !is_array($v)){ $buff .= $k . "=" . $v . "&"; } } $buff = trim($buff, "&"); return $buff; }
/** * 统一下单调取返回值 * @return mixed * $output['return_code'] 状态码 SUCCESS/FAIL * $output['return_msg'] 返回信息,如非空,为错误原因 签名失败 参数格式校验错误 * $output['time'] 当前时间戳 * $output['nonceStr'] 随机字符串 * $output['prepay_id'] 预支付id * $output['sign'] 签名 * */ public function pay_place_order() { $xml = '<xml> <appid>'.$this->_prepay['appid'].'</appid> <body>'.$this->_prepay['body'].'</body> <mch_id>'.$this->_prepay['mch_id'].'</mch_id> <nonce_str>'.$this->_prepay['nonce_str'].'</nonce_str> <notify_url>'.$this->_prepay['notify_url'].'</notify_url> <openid>'.$this->_prepay['openid'].'</openid> <out_trade_no>'.$this->_prepay['out_trade_no'].'</out_trade_no> <spbill_create_ip>'.$this->_prepay['spbill_create_ip'].'</spbill_create_ip> <total_fee>'.$this->_prepay['total_fee'].'</total_fee> <trade_type>'.$this->_prepay['trade_type'].'</trade_type> <sign>'.$this->MakeSign().'</sign> </xml>'; //调用api,自定义对参数进行处理,改请求方式是自定义方式 $xml_result = post_request_https('https://api.mch.weixin.qq.com/pay/unifiedorder', $xml);
Note: The fields that generate the name of the returned applet signature and participate in the generated signature are as shown below. Remember to splice the key and use the value returned by calling the api
3. WeChat applet calls up payment and completes payment
Note: WeChat callback notification signature verification after successful payment , the required parameters are all returned parameter fields except the sign field, and the generated signature = sign (signature) in the returned field
#
The above is the detailed content of WeChat Mini Program Payment Process. For more information, please follow other related articles on the PHP Chinese website!