WeChat JSAPI payment callback, message JSAPI payment callback

Source: Internet
Author: User
Tags openid

JSAPI payment callback, message JSAPI payment callback

In the payment process, after the user successfully pays, the relevant payment result and user information will be sent to the merchant, the merchant needs to receive the processing and return a response.

After successfully completing all the JSAPI payment pitfalls (JSAPI payment and the pitfalls encountered), the payment interface was easily called, seeing the dear payment page, after successful payment, I found that I forgot to handle the callback, and my heart was running in the dark.

First:

Check whether the notification address is correct when the unified order is placed.

The callback address for receiving asynchronous notifications is also required:The notification url must be a directly accessible url and cannot contain parameters.. Example: notify_url: "https://pay.weixin.qq.com/wxpay/pay.action"

In payment development, payment result general notification description page → https://pay.weixin.qq.com/wiki/doc/api/app/app.php? Chapter = 9_7 & index = 3.

Note: after the payment is complete, the relevant payment results and user information will be sent to the merchant, the merchant needs to receive and handle the request, and return a response.

At first, I was overwhelmed. I don't know whether to use a page or a general handler. After the callback is back, I updated the payment status and then responded, what should I do ?? What ??

In addition, if the response received by the merchant is not successful or timed out, the notification is deemed to fail, and the notification will be re-initiated on a regular basis through a certain policy to improve the success rate of the notification as much as possible, but the notification is not guaranteed to succeed. (The Notification frequency is 15/15/30/180/1800/1800/1800/1800/3600, in seconds)

This means that the payment may be successful, and the notification cannot be successful.

If I do not respond, I will initiate a new notification and call back the successful payment page.

Another pitfall is:Note: The same notification may be sent to the merchant system multiple times. The merchant system must be able to correctly handle duplicate notifications.

Therefore, during the callback, you must determine whether the order has been called back and succeeded.

The address of this callback page cannot be disclosed. It prevents malicious and false callbacks and "fake notifications", resulting in financial losses.

 

After reading the official documents and various searches, I started to process the payment callback.

(1) Create An aspx page in the payment authorization directory as the callback page.

(2) Code

String returnResutStr = ""; try {Logger. info ("Payment callback entry page"); # The ResponseHandler resHandler = new ResponseHandler (null); string result_code = resHandler is parsed as needed. getParameter ("result_code"); // business result string return_code = resHandler. getParameter ("return_code"); // returns the status string out_trade_no = resHandler. getParameter ("out_trade_no"); // Merchant Order Number string WEXIN_OPENID = resHandler. getParameter ("openid"); // openid string transaction_id = resHandler. getParameter ("transaction_id"); // Payment Order Number # endregion if (result_code = "SUCCESS" & return_code = "SUCCESS ") // verify whether callback is performed {# region log processing Logger. info ("Payment callback, Verification Successful, order number:" + orderno); # endregion # logic processing of successful region Verification
If (// determine whether it is a real order ){
// Update the payment status if (fals) // the payment status is successfully updated {# region log processing Logger. info ("Payment callback updates order payment status, order payment status updated successfully, order number:" + orderno); # endregion returnResutStr = "<xml> <return_code> <! [CDATA [SUCCESS]> </return_code> <return_msg> <! [CDATA [OK]> </return_msg> </xml> ";} else // failed to update the payment status {# region log processing Logger. info ("Payment callback updates order payment status, update order payment status failed, order number:" + orderno); # endregion returnResutStr = "<xml> <return_code> <! [CDATA [FAIL]> </return_code> <return_msg> <! [CDATA [error]> </return_msg> </xml> ";}} else {Logger. info ("Payment callback updates order payment status, check this order, order number:" + out_trade_no) ;}# endregion} else // callback failed {# region log processing Logger. error ("Payment callback updates order payment status, Verification Failed, callback parameter is invalid"); # endregion returnResutStr = "<xml> <return_code> <! [CDATA [FAIL]> </return_code> <return_msg> <! [CDATA [error]> </return_msg> </xml> ";}} catch (Exception exception) {# add error log Logger to region. error ("Payment callback updates the order payment status, with an exception:" + exception. message + ", Stack:" + exception. stackTrace); # endregion returnResutStr = "<xml> <return_code> <! [CDATA [FAIL]> </return_code> <return_msg> <! [CDATA [error]> </return_msg> </xml> ";} Response. Write (returnResutStr );

ReturnResutStr is the response returned.

 

At the beginning, after the payment is successful, check the callback address carefully. However, the callback page has not been accessed, and the log has not recorded a callback interface.

Later, we found that the callback page inherits the base class and blocks the callback address. I am so stupid.

 

Refer:

General notification of payment results in development documents:

Https://pay.weixin.qq.com/wiki/doc/api/app/app.php? Chapter = 9_7 & index = 3

 

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.