Section 7. Practical implementation of project payment function - scheduled task checking, order closing, deposit withdrawal (refund)

Summary

In the previous section, the active payment and scheduled task callback functions were completed. Although the payment can be basically completed in this way, it is not perfect. Especially when the merchant is unable to receive notifications from the WeChat platform, the status of the order cannot be updated, and the user never knows whether the payment was successful. Therefore, in order to avoid problems caused by network abnormalities, we adopt the following solutions to compensate:

The scheduled task starts every 30 seconds, finds the orders that were created in the last 10 minutes and have not been paid, and calls the "WeChat Payment Order Checking Interface" to verify the order status. The system records the number of order inquiries. If the status is still not paid successfully after 10 inquiries, it will stop subsequent inquiries and call the "Close Order Interface" to close the order. (Merchants can flexibly set the polling interval and number of times according to their own business scenarios)

Timed task check list

Scheduled tasks use lightweight springtask. Springtask does not require a separate jar package. Its API is encapsulated into the spring-context package, as shown in the figure below:
Insert image description here
It is relatively simple to use and is very suitable for the scenario of timing order processing. In the plan, we mentioned: start every 30 seconds to find out the orders that were created and unpaid in the last 10 minutes . First, let’s create a scheduled task. The main content of the scheduled task mainly includes the following items:
(1) Query the order table records to obtain orders created within 10 minutes and unpaid. This can be based on business changes. I changed it here to obtain orders created 5 minutes ago every 10 seconds. , and unprocessed orders, the principle is actually the same, the purpose is to check the status of unprocessed orders.
(2࿰

Guess you like

Origin blog.csdn.net/superzhang6666/article/details/135342482