一、发货通知
为了更好地跟踪订单的情况,需要第三方在收到最终支付通知之后,调用发货通知API告知微信后台该订单的发货状态。
发货时间限制:虚拟、服务类24小时内,实物类72小时内。
请在收到支付通知后,按时发货,并使用发货通知接口将相关信息同步到微信后台。若平台在规定时间内没有收到,将视作发货超时处理。
发货通知API的URL为:
https://api.weixin.qq.com/pay/delivernotify?access_token=xxxxxx
URL中的参数只包含目前微信公众平台凭证access_token,而发货通知的真正的数据是放在PostData中的,
格式如下:
上述内容参数说明如下表所示:
二、程序实现
程序中的一些参数来自本博客前面的微信支付开发数据。读者请参照运行
//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;
}
运行后返回结果
以上就是对开发微信支付发货通知的资料整理,希望能帮到开发微支付的朋友。
原文链接:https://www.f2er.com/php/19391.html