WeChat Pay Development Shipping Notice

高洛峰
Release: 2017-02-24 16:28:07
Original
1868 people have browsed it

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"
}
Copy after login

The description of the above content parameters is shown in Table 6-12.

AppId of the public platform account;The OpenId of the purchasing user has been placed in the PostData of the final payment result notification; ## Transaction number;

Parameter Description

##appid

openid

transid

##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.
2. Program Implementation

Some parameters in the program come from the WeChat payment development data earlier in this blog. Readers please refer to Run

 <?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[&#39;appid&#39;]               = $appid; $obj[&#39;appkey&#39;]              = "8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6kxCRvdJENpWpw8mruTNOGeX8OVUlIYxIyw6k"; $obj[&#39;openid&#39;]              = "o0pk9uIVnlY-fJkzFKEbQ6LJ4cFc"; $obj[&#39;transid&#39;]             = "1218614901201405273313473135"; $obj[&#39;out_trade_no&#39;]        = "JfuKdiBig4zZnE4n"; $obj[&#39;deliver_timestamp&#39;]   = $deliver_timestamp; $obj[&#39;deliver_status&#39;]      = "1"; $obj[&#39;deliver_msg&#39;]         = "ok"; $WxPayHelper = new WxPayHelper(); //get_biz_sign函数受保护,需要先取消一下,否则会报错
 $app_signature  = $WxPayHelper->get_biz_sign($obj); //3. 将构造的json提交给微信服务器,查询
 $jsonmenu = &#39;
 {
     "appid" : "&#39;.$obj[&#39;appid&#39;].&#39;",
     "openid" : "&#39;.$obj[&#39;openid&#39;].&#39;",
     "transid" : "&#39;.$obj[&#39;transid&#39;].&#39;",
     "out_trade_no" : "&#39;.$obj[&#39;out_trade_no&#39;].&#39;",
     "deliver_timestamp" : "&#39;.$deliver_timestamp.&#39;",
     "deliver_status" : "&#39;.$obj[&#39;deliver_status&#39;].&#39;",
     "deliver_msg" : "&#39;.$obj[&#39;deliver_msg&#39;].&#39;",
     "app_signature" : "&#39;.$app_signature.&#39;",
     "sign_method" : "sha1"
 }&#39;; $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;
 }
Copy after login

Result returned after running

string(27) "{"errcode":0,"errmsg":"ok"}"
Copy after login

For more WeChat payment development and delivery notices, please pay attention to the PHP Chinese website for related articles!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!