Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problems encountered in the development of sharing Wechat scanning payment

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to solve the problems encountered in the development of sharing Wechat code scanning payment". The content of the article is simple and clear, and it is easy to learn and understand. let's study and learn "how to solve the problems encountered in sharing Wechat code scanning payment development"!

Before development, check the official [Code scan payment] development documentation. Code scan payment is divided into the following two modes:

△ mode 1:

Problems encountered: the first scan of the QR code can also be scanned normally, and re-scanning without payment will prompt: ok or request for merchant information timeout HttpCode is not 200-this problem has failed to try to find a solution through various ways, here I hope that friends can give me an answer, thank you!

△ mode II:

Note: you cannot directly use the mall's order number as the transaction order number (out_trade_no), otherwise, when the Wechat scanning code is generated again, the API will prompt: the merchant's order number is duplicated and cannot be regenerated.

So the purple question comes, how should we set the transaction order number and ensure that we can query the corresponding order information in Wechat merchant platform or achieve reconciliation through the interface? The feasible way is to use the unified API for issuing orders before scanning the code. Instead of passing the order number of the mall order system into the out_trade_no, a new unique pipeline is generated, and a corresponding table of order number and WeChat Pay transaction order number (out_trade_no) is added as follows:

There is a serial_is_paid field in the above table: it is used to mark whether the transaction has been completed, that is, in the callback process of the payment success notification, the payment status is updated according to the returned out_trade_no; as for how to query the payment status of the order, you must also know.

Well, I haven't written a technical blog for a long time. I can't find the feeling. It may be rough. Friends who are not clear can pay attention to it and communicate.

The WeChat Pay callback page of WeChat Pay V3 is everywhere.

According to WeChat Pay V3, who was full of holes everywhere last time, after being abused thousands of times, many gardeners finally jumped to the friendly WeChat Pay interface, but after entering the password to pay, they didn't know how to deal with it, and then made up the processing flow after payment.

1. In html, jump to the relevant page based on the feedback after payment at the front desk.

If (res.err_msg = = "get_brand_wcpay_request:ok") {/ / message: "WeChat Pay succeeded!", _ window.location.replace ("@ Url.Content (" ~ / WxPay/Success?ordercode=@ (Model.order_no) ");} else if (res.err_msg = =" get_brand_wcpay_request:cancel ") {/ / message:" WeChat Pay has been cancelled! "}

two。 Download WeChat Pay interface document and demo (public account) from the payment development tutorial (Wechat merchant platform version). Zip

The returned parameters refer to 4. 2 in the API documentation. General Notification Interface section.

Notification URL is the parameter notify_url submitted in Section 4.1. after the payment is completed, Wechat will send relevant and user information to the URL, and merchants need to receive processing information.

/ / payment callback page public ActionResult notice_url () {string resultFromWx= getPostStr (); / / set payment parameters RequestHandler paySignReqHandler = new RequestHandler (null); WriteLog ("micro-payment 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") {/ / transaction success 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 ("micropayment transaction success =" + ordecode) } else {WriteLog ("micropayment transaction failure =" + ordecode);}} catch (Exception ex) {WriteLog (ex, "micropayment 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.Unifiedorder (data); WriteLog ("micro-payment notice result=" + result); return View ();}

Note:

Therefore, after receiving a successful payment, you need to return the red part of the code to remind the Wechat server that it has been processed, otherwise you will continue to receive feedback from the Wechat server.

GetPostStr () method:

/ / get the data from Post 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) } Thank you for your reading. The above is the content of "how to solve the problems encountered in the development of sharing Wechat code scanning payments". After the study of this article, I believe you have a deeper understanding of how to solve the problems encountered in the development of sharing Wechat code scanning payments, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report