Home  >  Article  >  WeChat Applet  >  WeChat Pay Development Shipping Notice

WeChat Pay Development Shipping Notice

高洛峰
高洛峰Original
2017-02-24 16:28:071908browse

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.

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

 4962cee6a46084ce6f0c22bffc606e31get_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!

Statement:
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