Home >Backend Development >PHP Tutorial >PHP analysis of the difference between return_url and notify_url in Alipay development, Alipay notifyurl_PHP tutorial
This article analyzes the difference between return_url and notify_url in Alipay development using PHP. Share it with everyone for your reference. The specific analysis is as follows:
What statuses are returned by return_url and notify_url in Alipay processing business? If we want to do some processing based on it, we must understand the difference between return_url and notify_url. Let me introduce it to you below.
Problem description:
I had such a problem when dealing with Alipay business. After the payment was completed, when Alipay jumped to the merchant's designated page, the order status had been updated. Through debugging, it was found that Alipay notified notify_url first and completed the order status.
Alipay return_url and notify_url notification order issues:
The order is not necessarily certain, please do not judge based on the order. How to judge specifically is based on comparing the status in your current database with the status just obtained from Alipay to determine whether it has been processed.
Regarding the difference between Alipay return_url and notify_url, the synchronization notification page feature (return_url feature):
(1) After the payment is successful, the buyer will see an Alipay page prompting that the transaction is successful. The page will stay for a few seconds, and then automatically jump back to the synchronization notification page specified by the merchant (parameter return_url);
(2) To obtain parameters on this page, you need to use the GET method, such as request.QueryString("out_trade_no"), $_GET['out_trade_no'];
(3) This method only automatically jumps after the buyer completes payment, so it will only be done once;
(4) This method is not that Alipay actively calls the merchant page, but that Alipay's program uses the page automatic jump function to automatically jump to the user's current page;
(5) Based on the reason (4), debugging can be done locally instead of only on the server;
(6) The return URL is only valid for one minute. If it exceeds one minute, the link address will become invalid and the verification will fail;
(7) When setting the path of the page jump synchronization notification page (return_url), do not add custom parameters after the page file. For example:
Incorrect writing:
Correct writing:
Server asynchronous notification page feature (notify_url feature):
(1) It must be ensured that there are no characters on the server’s asynchronous notification page (notify_url), such as spaces, HTML tags, exception prompts thrown by the development system, etc.;
(2) Alipay uses POST to send notification information, so the parameters are obtained in this page, such as:
request.Form("out_trade_no"), $_POST['out_trade_no'].
(3) This method will be enabled only if Alipay actively initiates notification;
(4) Only if the transaction exists in Alipay's transaction management and the transaction status changes, Alipay will initiate a server notification through this method (the transaction status in the immediate account is "Waiting for buyer payment" Status will not send notifications by default);
(5) Interaction between servers, unlike page jump synchronization notifications that can be displayed on the page, this interaction method is invisible;
(6) When the transaction status changes for the first time (in instant payment, the transaction status is transaction completed), not only the page jump synchronous notification page will be enabled, but the server asynchronous notification page will also receive the notification from Alipay Notification of processing results;
(7) After the program is executed, "success" must be printed out (without quotation marks). If the characters fed back to Alipay by the merchant are not the 7 characters of success, the Alipay server will continue to resend the notification until it exceeds 24 hours and 22 minutes.
Under normal circumstances, 8 notifications are completed within 25 hours (the interval frequency of notifications is generally: 2m, 10m, 10m, 1h, 2h, 6h, 15h);
(8) After the program execution is completed, page jump cannot be performed on this page. If a page jump is executed, Alipay will not receive the success character, and the Alipay server will determine that the page program is running abnormally, and will resend the processing result notification;
(9) Cookies, sessions, etc. will be invalid on this page, that is, these data cannot be obtained;
(10) The debugging and operation of this method must be on the server, that is, accessible on the Internet;
(11) The main function of this method is to prevent order loss, that is, the page jump synchronization notification does not process the order update, but it will handle it;
(12) The notification ID (parameter notify_id) is only valid for one minute. If it exceeds one minute, the notification will fail to be verified. Once the verification is successful, the next verification will be invalid.
I hope this article will be helpful to everyone’s PHP programming design.