WeChat JSAPI unified payment order (. net background), jsapi.net

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.