This article introduces delivery notification for payment development. This article introduces the implementation of the delivery notification function for payment.
I. delivery notice
In order to better track the order situation, the third party must call the delivery notification API to inform the background of the delivery status of the order after receiving the final payment notification.
Delivery time limit: Within 24 hours for virtual and Service services, and within 72 hours for real objects.
After receiving the payment notification, Please deliver the goods on time and use the delivery notification interface to synchronize the relevant information to the background. If the platform does not receive the message within the specified time, it will be treated as a delivery timeout.
The shipping notification api url is:
Https://api.weixin.qq.com/pay/delivernotify? Access_token = xxxxxx
The URL parameter only contains the current public platform credential access_token, and the real data of the shipping notification is placed in PostData, in the following format:
{ "appid" : "wwwwb4f85f3a797777", "openid" : "oX99MDgNcgwnz3zFN3DNmo8uwa-w", "transid" : "111112222233333", "out_trade_no" : "555666uuu", "deliver_timestamp" : "1369745073", "deliver_status" : "1", "deliver_msg" : "ok", "app_signature" : "53cca9d47b883bd4a5c85a9300df3da0cb48565c", "sign_method" : "sha1"}
The preceding parameters are described in Table 6-12.
Parameters |
Description |
Appid |
AppId of the public platform account; |
Openid |
The OpenId of the buyer, which has been placed in the PostData of the final payment result notification; |
Transid |
Transaction ticket number; |
Out_trade_no |
Third-party order number; |
Deliver_timestamp |
Delivery timestamp, which refers to the Linux timestamp; |
Deliver_status |
Delivery Status, 1 indicates success, 0 indicates failure, and the cause of failure needs to be filled in deliver_msg; |
Deliver_msg |
The shipping status information. if the product fails, you can enter the UTF8 encoding error message, such as "the product has been refunded "; |
App_signature |
Generated based on the signature method described in the paySign generation method. the signature fields include appid, appkey, openid, transid, out_trade_no, deliver_timestamp, deliver_status, and deliver_msg; |
Sign_method |
Signature Method (not included in signature generation ); |
Table 6-12 delivery notification parameters
After the public platform verifies OK, it returns data indicating whether the notification is successful. for example, {"errcode": 0, "errmsg": "OK"} if an exception occurs, it is described in errcode and errmsg. if errcode is successful, it is 0.
II. program implementation
Some parameters in the program are from the payment development data before this blog. For more information, see run
Get_biz_sign ($ obj); // 3. submit the constructed json file to the server and query $ jsonmenu = '{"appid ":"'. $ obj ['appid ']. '"," openid ":"'. $ obj ['openid']. '"," transid ":"'. $ obj ['transid ']. '"," out_trade_no ":"'. $ obj ['out _ trade_no ']. '"," deliver_timestamp ":"'. $ deliver_timestamp. '"," deliver_status ":"'. $ obj ['deliver _ status']. '"," deliver_msg ":"'. $ obj ['delimiter_msg ']. '"," app_signature ":"'. $ app_signature. '"," sign_method ":" sha1 "}'; $ url =" https://api.weixin.qq.com/pay/delivernotify?access_token= ". $ Access_token; $ result = https_request ($ url, $ jsonmenu); var_dump ($ result); function https_request ($ url, $ data = null) {$ curl = curl_init (); curl_setopt ($ curl, CURLOPT_URL, $ url); curl_setopt ($ curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt ($ curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (! Empty ($ data) {curl_setopt ($ curl, CURLOPT_POST, 1); curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data);} curl_setopt ($ curl, expires, 1 ); $ output = curl_exec ($ curl); curl_close ($ curl); return $ output ;}
Result returned after running
string(27) "{"errcode":0,"errmsg":"ok"}"
For more articles related to payment development and delivery notifications, please follow the PHP Chinese network!