//微信小程序后台发货同步
require 'wxsendno.php';
$user = $db->get_one("SELECT openid,push FROM {$TT}wxsmall_user WHERE username='$td[buyer]'");
$openid=$user['openid'];
$data =array(
'order_key' => array(
'order_number_type' => 2,
// 'mchid'=>"",//商户号
// 'out_trade_no' => $itemid//商户订单号
'transaction_id'=>$td[' transaction_id']
),
'logistics_type' => 1,//物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
'delivery_mode' => 1,
'shipping_list' => array(
array(
'tracking_no' => $send_no,
'express_company' => $td['fee_name'],
'item_desc' => $td['title']
),
),
'upload_time' => date('Y-m-d\TH:i:sP', time()),
'payer' => array(
'openid' => $openid
)
);
$iswxsend=sendDelivery($data);
if($iswxsend['errcode']){
$wxsend="微信小程序官方后台发货错误".$iswxsend['errmsg']."请注意手动处理,订单号".$itemid;
}else{
$wxsend="微信小程序官方后台同步发货成功!";
}
wxsendno.php
<?php
//test($access_token);
function http_get($url) {
$rec = dcurl($url);
$arr = json_decode($rec, true);
return $arr ? $arr : array();
}
function get_token() {
$access_token=isset($access_token)?$access_token:null;
if(!$access_token) {
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
$arr = http_get($url);
$access_token = isset($arr['access_token']) ? $arr['access_token'] : null;
// if($access_token) $this->dc->set($this->appid.'_weixinsmall_access_token', $access_token, 7000);
}
return $access_token;
}
//获取发货订单信息
function getWxSendOrderStatus($itemid,$access_token)
{
$url = "https://api.weixin.qq.com/wxa/sec/order/get_order?access_token=" . $access_token;
$data = array(
'transaction_id' => $itemid
);
$data = json_encode($data);
//test($data);
$result = mycurl($url, $data);
$result = json_decode($result, true);
// test($result);
}
//设置微信发货后,消息跳转地址,不设置为默认
function set_jump_path()
{
$access_token = $this->$access_token;
$url = "https://api.weixin.qq.com/wxa/sec/order/set_msg_jump_path?access_token=" . $access_token;
$data = array(
'path' => 'pages/order/index'
);
$data = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
dcurl($url, $data);
}
//发货 物流10天自动确认,虚拟商品隔天自动确认
function sendDelivery($data)
{
$token = get_token();
$urlss = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=" . $token;
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
// test($data);
$results = dcurl($urlss, $data);
$results = json_decode($results, true);
return $results;
}
?>