微信支付开发发货通知实例

前端之家收集整理的这篇文章主要介绍了微信支付开发发货通知实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、发货通知

为了更好地跟踪订单的情况,需要第三方在收到最终支付通知之后,调用发货通知API告知微信后台该订单的发货状态。

发货时间限制:虚拟、服务类24小时内,实物类72小时内。

请在收到支付通知后,按时发货,并使用发货通知接口将相关信息同步到微信后台。若平台在规定时间内没有收到,将视作发货超时处理。

发货通知API的URL为:

https://api.weixin.qq.com/pay/delivernotify?access_token=xxxxxx

URL中的参数只包含目前微信公众平台凭证access_token,而发货通知的真正的数据是放在PostData中的,

格式如下:

PHP;"> { "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" }

上述内容参数说明如下表所示:

用户的OpenId,这个已经放在最终支付结果通知的PostData里了;提示信息,比如“该商品已退款”;生成方法中所讲的签名方式生成的,参加签名字段为:appid、appkey、openid、transid、out_trade_no、deliver_timestamp、deliver_status、deliver_msg;方法(不计入签名生成); 微信公众平台在校验ok之后,会返回数据表明是否通知成功,例如:{"errcode":0,"errmsg":"ok"}如果有异常,会在errcode和errmsg描述出来,如果成功errcode就为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;
}

运行后返回结果

PHP;"> string(27) "{"errcode":0,"errmsg":"ok"}"

以上就是对开发微信支付发货通知的资料整理,希望能帮到开发微支付的朋友。

原文链接:https://www.f2er.com/php/19391.html

猜你在找的PHP相关文章