H5 payment is a kind of non-internal browser payment method developed based on the public account (you need to apply for the payment permission separately), which can meet the needs of overseas mobile phone H5 page payment .. This article introduces the implementation process of H5 payment under payment.
I. INTRODUCTION
H5 payment is a kind of non-internal browser payment method developed based on the public account (you need to apply for the payment permission separately), which can meet the needs of overseas mobile phone H5 page payment ..
Test address
Http://wxpay.weixin.qq.com/pub_v2/pay/wap.v2.php
Http://wxpay.weixin.qq.com/mch/pay/h5.v2.php
II. product information preparation
It mainly defines the product name and price, and the transaction number. The code is as follows.
Include_once (".. /WxPayPubHelper. php "); // use the unified payment interface $ unifiedOrder = new UnifiedOrder_pub (); // set the parameters of the unified payment interface // set the required parameter // appid is filled in, the merchant does not need to fill in the/mch_id field repeatedly, the merchant does not need to fill in the/noncestr field repeatedly, the merchant does not need to fill in the/spbill_create_ip field repeatedly, and the merchant does not need to fill in the/sign field repeatedly, the merchant does not need to repeat $ unifiedOrder-> setParameter ("body", "H5 payment test"); // product description $ timeStamp = time (); $ out_trade_no = WxPayConf_pub: APPID. "$ timeStamp"; $ unifiedOrder-> setParameter ("out_trade_no", "$ out_trade_no"); // merchant Order No. $ unifiedOrder-> setParameter ("total_fee", "1 "); // Total amount // $ unifiedOrder-> setParameter ("yy_url", WxPayConf_pub: yy_url); // notification address $ unifiedOrder-> setParameter ("trade_type", "WAP "); // transaction type // optional parameter. the merchant can select $ unifiedOrder-> setParameter ("device_info", "100001") based on the actual situation; // device number
The preceding parameters are eventually encapsulated as XML parameters similar to the following:
H5支付测试
100001_1433009089
1
//
http://www.php.cn/
WAP
100001
wx1d065b0628e21103
1237905502
61.129.47.79
gwpdlnn0zlfih21gipjj5z53i7vea8e8
C5A1E210F9B4402D8254F731882F41AC
2. call the unified payment request
Send the preceding XML to the unified payment interface
https://api.mch.weixin.qq.com/pay/unifiedorder
Get the following XML data:
SUCCESS
OK
wx1d065b0628e21103
1237905502
100001
6u8ovTtFupTagsiY
E84D8BC2331766DD685591F908367FF1
SUCCESS
wx20150531020450bb586eb2f70717331240
WAP
In this way, a prepayid is obtained.
II. DeepLink
The merchant server calls the unified order interface to request orders. for details about the api, refer to the public api [unified order] (trade_type must be defined as WAP in the interface) and returns the prepayid to the merchant. the merchant generates the deeplink in a fixed format, you can click deeplink to make the payment.
Deeplink format:
weixin://wap/pay?appid%3Dwxf5b5e87a6a0fde94%26noncestr%3D123%26package%3D123%26prepayid%3Dwx20141203201153d7bac0d2e10889028866%26sign%3D6AF4B69CCC30926F85770F900D098D64%26timestamp%3D1417511263
To generate deeplink, follow these steps:
Step 1: assemble parameters in URL format and perform URL encoding for $ value to generate string1:
String1: key1 = Urlencode ($ value1) & key2 = Urlencode ($ value2 ,&...
Step 2: Urlencode string1 to generate string2:
String2 = Urlencode (string1 );
Step 3: splice the prefix to generate the final deeplink
Example:
String1:
appid=wxf5b5e87a6a0fde94&noncestr=123&package=WAP&prepayid=wx201412101630480281750c890475924233&sign=53D411FB74FE0B0C79CC94F2AB0E2333×tamp=1417511263
Then URLEncode the entire string1
String2:
appid%3Dwxf5b5e87a6a0fde94%26noncestr%3D123%26package%3DWAP%26prepayid%3Dwx201412101630480281750c890475924233%26sign%3D53D411FB74FE0B0C79CC94F2AB0E2333%26timestamp%3D1417511263
Plus the header weixin: // wap/pay? Get the final deeplink
weixin://wap/pay?appid%3Dwxf5b5e87a6a0fde94%26noncestr%3D123%26package%3DWAP%26prepayid%3Dwx201412101630480281750c890475924233%26sign%3D53D411FB74FE0B0C79CC94F2AB0E2333%26timestamp%3D1417511263
| Field name |
Variable name |
Required |
Type |
Sample value |
Description |
| Public Account ID |
Appid |
Yes |
String (32) |
Wx88888888888888 |
Assigned public account ID |
| Random string |
Noncestr |
Yes |
String (32) |
5k8rjiltkch16cq2502si8znmtm67vs |
A random string of no more than 32 characters. Recommendation random number generation algorithm |
| Order details extension string |
Package |
Yes |
String (32) |
WAP |
Extended Field, fixed to WAP |
| Pre-payment fair statement ID |
Prepayid |
Yes |
String (64) |
Wx201272009395522657a690389285100 |
The pre-payment return ID returned by the unified order interface for subsequent interface calls. The value is valid for 2 hours. |
| Signature |
Sign |
Yes |
String (32) |
C380BEC2BFD727A4B6845133519F3AD6 |
Signature. for details, refer to the signature generation algorithm. |
| Timestamp |
Timestamp |
Yes |
String (32) |
1414561699 |
The current time. For more information, see timestamp rules. |
Development documentation: https://pay.weixin.qq.com/wiki/doc/api/wap.php? Chapter = 15_1
3. new version process
1. the user places an order at the merchant side and uses the payment method for payment.
2. the merchant's background initiates an order request to pay (call the unified order interface) Note: transaction type trade_type = MWEB
3. verify Merchant permissions for payment
4. the unified order interface returns the payment-related parameters to the merchant's background, such as the payment jump url (the parameter name is "mweb_url", that is, the Transit page address in the flowchart)
5. the merchant's background receives the parameters returned by the unified order interface and returns the mweb_url to the front-end
6. the merchant accesses the transfer page mweb_url through the front-end page (the payment in this step will verify the refer to determine whether the request source is valid)
7. the transfer page mweb_url actively calls the payment cashier
8. the payment cashier is aroused and the mweb_url transfer page is closed.
9. the user completes the payment at the cashier
For more information about H5 payment, see PHP!