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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)
