Share the problems encountered in the development of WeChat QR code and solutions-with the Ecshop WeChat payment plug-in, problems encountered ecshop

Source: Internet
Author: User

Problems encountered in the development of shared scan code payment and solutions-attached Ecshop payment plug-in, problems encountered ecshop

Recently, it was relatively easy to help a friend's ecshop-based shopping mall to add the scanning and payment function. I thought it was very simple-download the official sdk or development help documentation, it's okay to follow the steps in it. Who knows that it takes two or three days to get it done? I also found a lot of technical articles on the Internet with questions in the middle, however, I found that it was just a rough description of how they developed and accessed it, and it did not solve my problems ..., alas, sometimes you really feel that you can only rely on yourself '.

This article is intended to write out the problems and solutions you have encountered, so that developers can help you with this aspect!

Before development, check the official development document scan payment. Scan payment is divided into the following two modes:

  △ Mode 1:

Problem: the first scan of the QR code can still be normal scan, the next scan will prompt: OK or request the merchant information timeout HttpCode is not 200 -- this problem cannot be solved by any means. Here, I hope some friends can answer it. Thank you!

  △ Mode 2:

Note: you cannot directly use the order number of the mall as the transaction order number (out_trade_no). Otherwise, when the QR code is generated again, the interface will prompt that the merchant's order number is repeated and cannot be regenerated.

How can I set the transaction order number to ensure that the corresponding order information in the merchant's platform can be queried or reconciliation can be realized through the interface later? The feasible method is: the unified order interface before scanning the code, out_trade_no should not be passed into the Order Number of the mall order system, but re-generate a new unique flow; add another table corresponding to the order number and the payment order number (out_trade_no), as shown below:

In the above table, there is a serial_is_paid field: used to mark whether the transaction has been completed, that is, in the callback processing of the successful payment notification, the payment status is updated based on the out_trade_no returned; as to how to query the order payment status, you should have known it too...

Well, if you haven't written a technical blog for a long time, you may not be able to find the feeling. You may write it roughly. If you have any questions, you can pay attention to and communicate with others!

Payment callback page for payment V3 is everywhere

According to the last time there was a lot of trouble to pay for V3, many garden friends finally jumped to the friendly payment interface after being abused for thousands of times, but they did not know how to deal with it after entering the password for payment, next, complete the payment process.

1. the html page jumps to the relevant page based on the feedback after the front-end payment.

If (res. err_msg = "get_brand_wcpay_request: OK") {// message: "Payment successful! ", Window. location. replace (" @ Url. Content ("~ /WxPay/Success? Ordercode = @ (Model. order_no) ");} else if (res. err_msg =" get_brand_wcpay_request: cancel ") {// message:" Payment canceled! "}

2. Download the payment interface document and demo(public account No. ).zip in the payment development tutorial (merchant platform edition ).

For the returned parameters, see section 4.2. Common notification interfaces in the interface documentation.

The notification URL is the parameter yy_url submitted in section 4.1. After the payment is complete, the related and user information will be sent to the URL, and the Merchant needs to receive the processing information.

// Payment callback page public ActionResult notice_url () {string resultFromWx = getPostStr (); // set the payment parameter RequestHandler paySignReqHandler = new RequestHandler (null ); writeLog ("micropayment notice resultFromWx =" + resultFromWx); var res = XDocument. parse (resultFromWx); // if (res. element ("xml "). element ("return_code "). value = "SUCCESS") {if (res. element ("xml "). element ("result_code "). value = "SUCCESS") {// successful transaction paySignReqHandler. setParameter ("return_code", "SUCCESS"); paySignReqHandler. setParameter ("return_msg", "OK"); string ordecode = res. element ("xml "). element ("out_trade_no "). value; BLL. orders Bll = new BLL. orders (); try {if (Bll. update (ordecode) {WriteLog ("micro-payment transaction success =" + ordecode);} else {WriteLog ("micro-payment transaction failed =" + ordecode );}} catch (Exception ex) {WriteLog (ex, "micro-payment transaction Exception =" + ordecode) ;}} else {paySignReqHandler. setParameter ("return_code", "FAIL"); paySignReqHandler. setParameter ("return_msg", "transaction failed") ;}} else {paySignReqHandler. setParameter ("return_code", "FAIL"); paySignReqHandler. setParameter ("return_msg", "signature failed");} string data = paySignReqHandler. parseXML (); var result = tenpayv3.uniiedorder (data); WriteLog ("micropayment notice result =" + result); return View ();}

Note:

Therefore, after receiving a successful payment, you must return the red part of the code to remind the server that the payment has been processed. Otherwise, you will receive feedback from the server.

GetPostStr () method:

// Obtain the Post data public string getPostStr () {Int32 intLen = Convert. toInt32 (Request. inputStream. length); byte [] B = new byte [intLen]; Request. inputStream. read (B, 0, intLen); return System. text. encoding. UTF8.GetString (B );}

Now the front and back of the platform are connected. We need to debug it patiently and wish you good luck ~

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.