Recently, the development of micro-credit program into the payment phase, has been engaged in app development, so the payment process is to memorize the heart. But the micro-credit program to pay a little bit strange, the application of the creation of the public number, but the introduction of the document in the public number can not find a direct entrance, very puzzled, and the small program of the teacher in the end is the public number payment category or app Payment category also become a question. The following is the entry for the small program payment document (nested in the Applet API):
Https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_3&index=1
Small program Payment steps:
1, Advance payment
2, according to the pre-payment data + signature--> initiated payment
3, Payment callback
Here's a brief description of these 3 steps:
1, Advance payment. the interface submits the required information (order number, price, etc.) to the developer server through the front-end, and the developer server submits the micro-letter, then returns some information that the real front end needs to pay; Eg:
Pre-payment interface for developer server:
https://() htm?total_fee=100&cid=6001&ordercodes=2016120119
{"
sign": "A2****************a6", "
timestamp": "14****************68", "
Package": "Sign=wxpay",
"Partnerid": "14****************02", "
AppID": "Wx****************ab", "
noncestr": "9f****************37",
"Prepayid": "wx************* "
}
2, to initiate payment (note that initiating payment is not required to upload AppID,
But the signature paysign need to be appid and put in the first one.
Wx.requestpayment ({
nonceStr:res.data.nonceStr,
package: "Prepay_id=" +res.data.prepayid,
signtype: ' MD5 ',
timeStamp:res.data.timestamp,
paysign:sign,//<strong><span style= "color: #ff0000;" > Five fields to participate in signatures (case-sensitive): Appid,noncestr,package,signtype,timestamp (note that the order of the 5 parameter signatures is sorted according to the ASCII dictionary order) </span> </strong>
success:function (res) {
Console.log ("pay success");
},
fail:function () {
},
Complete:function () {
}
})
Generate Signature Sign
https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=7_3&index=1&t=20161122
Micro-Letter Applet MD5 encryption tool download address: Https://code.csdn.net/snippets/2019875/master/download
var md5util = require ('.. /.. /.. /utils/md5.js ');
var sign = ';
<strong><span style= "color: #ff0000;" > order is sorted by ASCII dictionary order </span></strong>
var signa = "appid=" +app.appid+ "&noncestr=" + res.data.noncestr+ "&package=prepay_id=" +res.data.prepayid+ "&signtype=md5×tamp=" + Res.data.timestamp;
var signb = signa+ "&key=" +app.key;
Sign = MD5UTIL.MD5 (SIGNB). toUpperCase ();
Build signature above is my code, not very clear, listed below the official document detailed description:
Suppose the parameters of the transfer are as follows:
APPID:WXD930EA5D5A258F4F (Note that AppID is not uploading in wx.requestpayment ({}), but it needs to be signed)
mch_id:10000100
Device_ info:1000
body:test
Nonce_str:ibuaivckdprxkhja
The first step is to follow the parameters in Key=value format and sort by the ASCII dictionary of parameter names as follows:
Stringa= "appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str= Ibuaivckdprxkhja ";
Step two: Stitching API key:
stringsigntemp= "stringa&key=192006250b4c09247ec02edce69f6a2d"
sign=md5 (stringsigntemp). ToUpperCase () = " 9a0a8659f005d6984697e2ca0a9cf3b7 "
At this point the sign is used for wx.requestpayment upload parameter paysign.
Finally get the final data sent:
<xml>
<appid>wxd930ea5d5a258f4f</appid>
<mch_id>10000100</mch_id>
<device_info>1000<device_info>
<body>test</body>
<nonce_str> ibuaivckdprxkhja</nonce_str>
<sign>9A0A8659F005D6984697E2CA0A9CF3B7</sign>
<xml >
The above is a small set to introduce the micro-credit procedures for micro-letter payment steps, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!