JSAPI unified payment order (. net background), jsapi.net
Exchange QQ Group ASP. NET e group 460845632.
We need to make a payment. After configuring the merchant and payment configuration, we should first checkHttps://pay.weixin.qq.com/wiki/doc/api/app/app.php? Chapter = 9_1 #
This is the unified order parameter. I made this parameter into a data model.
After completing the data model, take a closer look at the parameters that are required. Pay attentionMinuteTo compute
Next, we need to generate a signature. I have written a class to generate a signature and return the submitted value.
Note: here we sign the signature, and then splice the signature into the Order Parameters and sort the signature. The following code can be used directly.
Next is the code
Public string OrderSign (WXOrder order)
{
Dictionary <string, string> dic = ClassToObject. ClassToType. Test (order );
Dic = dic. OrderBy (m => m. Key). ToDictionary (m => m. Key, m => m. Value );
StringBuilder sb = new StringBuilder ();
StringBuilder sbXml = new StringBuilder ();
SbXml. Append ("<xml> ");
Foreach (var item in dic)
{
SbXml. Append ("<" + item. Key + ">" + item. Value + "</" + item. Key + "> ");
Sb. Append (item. Key + "=" + item. Value + "&");
}
Sb. Append ("key =" + WXConfig. Config. KEY );
String str = sb. ToString (). Replace ("","");
String sign = Common. Tool. GetMD5 (str );
SbXml. Append ("<sign>" + sign + "</sign> </xml> ");
Return sbXml. ToString (). Replace ("","");
}
The next step is to unify the order request,
The above method returns an xml post request to the https://api.mch.weixin.qq.com/pay/unifiedorder
After the request, if the correct return value is an XML Parser method, as follows:
After the xml parsing, a key-value pair set is returned. I only extract the four required values. Note that prepay_id is the information of the order after the unified order. jsapi obtains the payment information through this method.
Jsapi will be used to initiate payment laterIf you have not done jsapi, please check my blog and give a very detailed explanation.
Let's take a look at how jsapi initiates a payment.
I used the background of the ajax request to get the above data, and the returned json is paid by jsapi.
If you don't know anything, add my QQ Group ASP. NET e group 460845632.