This article introduces the implementation of the delivery notification function in WeChat payment.
1. Shipping Notification
In order to better track the order status, a third party needs to call the shipping notification API to notify WeChat after receiving the final payment notification. The delivery status of the order in the background.
Delivery time limit: within 24 hours for virtual and service products, and within 72 hours for physical products.
After receiving the payment notification, please deliver the goods on time and use the delivery notification interface to synchronize relevant information to the WeChat backend. If the platform does not receive it within the specified time, it will be treated as a delivery overtime.
The URL of the delivery notification API is:
https://api.weixin.qq.com/pay/delivernotify?access_token=xxxxxx
The parameters in the URL are only Contains the current WeChat public platform credential access_token, and the real data of the shipping notice is placed in PostData, with 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 description of the above content parameters is shown in Table 6-12.
Parameter Description |
##appid |
openid | |
transid | ## Transaction number;|
##out_trade_no | Third-party order number; |
deliver_timestamp | Delivery timestamp, here refers to Is the Linux timestamp; |
deliver_status | delivery status, 1 indicates success, 0 indicates failure, when failure You need to fill in the failure reason in deliver_msg; |
deliver_msg | delivery status information. You can fill in UTF8 when it fails. Encoded error message, such as "This product has been refunded"; |
app_signature | According to the payment signature (paySign) generated by the signature method mentioned in the generation method, the participating signature fields are: appid, appkey, openid, transid, out_trade_no, deliver_timestamp, deliver_status, deliver_msg; |
sign_method |
Signature method (not counted in signature generation); |
Table 6-12 Shipping notification parameter description After verifying ok, the WeChat public platform will return data to indicate whether the notification is successful, for example: {"errcode":0,"errmsg":"ok"}if If there is an exception, it will be described in errcode and errmsg. If successful, errcode will be 0. |
<?php include_once("WxPayHelper.php"); //1. 获取access token $appid = "wx0000000000000000"; $appsecret = "e76050733ce76050733ce76050733cdd"; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret"; $result = https_request($url); $jsoninfo = json_decode($result, true); $access_token = $jsoninfo["access_token"]; //2.准备参数 $deliver_timestamp = time(); //2.1构造最麻烦的app_signature $obj['appid'] = $appid; $obj['appkey'] = "8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6k"; $obj['openid'] = "o0pk9uIVnlY-fJkzFKEbQ6LJ4cFc"; $obj['transid'] = "1218614901201405273313473135"; $obj['out_trade_no'] = "JfuKdiBig4zZnE4n"; $obj['deliver_timestamp'] = $deliver_timestamp; $obj['deliver_status'] = "1"; $obj['deliver_msg'] = "ok"; $WxPayHelper = new WxPayHelper(); //get_biz_sign函数受保护,需要先取消一下,否则会报错 $app_signature = $WxPayHelper->get_biz_sign($obj); //3. 将构造的json提交给微信服务器,查询 $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['deliver_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, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; }Result returned after running
string(27) "{"errcode":0,"errmsg":"ok"}"
For more WeChat payment development and delivery notices, please pay attention to the PHP Chinese website for related articles!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
