|
|
<?php
|
|
|
|
|
|
namespace kdniao;
|
|
|
|
|
|
class Logistics extends Base
|
|
|
{
|
|
|
/**
|
|
|
* 查询物流
|
|
|
* @param string $deliver_number 物流单号
|
|
|
* @param string $deliver_code 快递公司编码
|
|
|
* @param string $order_number 订单编号
|
|
|
* @param string $customer_name ShipperCode 为JD,必填,对应京东的青龙配送编码,也叫商家编码,格式:数字+字母+数字,9 位数字加一个字母,共10 位,举例:001K123450;
|
|
|
* ShipperCode 为SF,且快递单号非快递鸟渠道返回时,必填,对应收件人/寄件人手机号后四位;
|
|
|
* ShipperCode 为SF,且快递单号为快递鸟渠道返回时,不填;
|
|
|
* ShipperCode 为其他快递时,不填
|
|
|
* @param string $request_type 1002为免费版 8001为在途监控付费版
|
|
|
* @date 2021-12-24
|
|
|
*/
|
|
|
function getLogistics($deliver_number, $deliver_code, $order_number = '', $customer_name = '', $request_type = 1002)
|
|
|
{
|
|
|
// 请求内容
|
|
|
$request_data = [
|
|
|
// 订单编号 非必填
|
|
|
'OrderCode' => $order_number,
|
|
|
// 快递公司编码
|
|
|
'ShipperCode' => $deliver_code,
|
|
|
// 物流单号
|
|
|
'LogisticCode' => $deliver_number
|
|
|
];
|
|
|
|
|
|
// JD或SF有部分情况需要填写客户信息
|
|
|
if (!empty($customer_name)) {
|
|
|
$request_data['CustomerName'] = $customer_name;
|
|
|
}
|
|
|
|
|
|
// 请求内容转JSON
|
|
|
$request_data = json_encode($request_data);
|
|
|
|
|
|
$data = [
|
|
|
// 请求内容需进行URL(utf-8)编码。请求内容JSON格式,须和DataType一致
|
|
|
'RequestData' => urlencode($request_data),
|
|
|
// 商户ID
|
|
|
'EBusinessID' => $this->config['user_id'],
|
|
|
// 请求指令类型:1002
|
|
|
'RequestType' => (string)$request_type,
|
|
|
// 请求、返回数据类型:2-json
|
|
|
'DataType' => '2',
|
|
|
];
|
|
|
// 数据内容签名
|
|
|
$data['DataSign'] = $this->encrypt($request_data, $this->config['api_key']);
|
|
|
|
|
|
// 发送请求
|
|
|
$result = http_data_post($this->url . 'Ebusiness/EbusinessOrderHandle.aspx', $data, 3, 1, [
|
|
|
'Content-type:application/x-www-form-urlencoded'
|
|
|
]);
|
|
|
|
|
|
if ($result['Success'] == 'true') {
|
|
|
switch ($result['State']) {
|
|
|
case 2:
|
|
|
$result['logistics_text'] = '运输中';
|
|
|
break;
|
|
|
case 3:
|
|
|
$result['logistics_text'] = '已签收';
|
|
|
break;
|
|
|
case 4:
|
|
|
$result['logistics_text'] = '问题件';
|
|
|
break;
|
|
|
default:
|
|
|
$result['logistics_text'] = '';
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 记录日志
|
|
|
$uid = defined('UID') ? UID : '';
|
|
|
platformLog($data, $result, 'kdniao_get_logistics_uid_' . $uid);
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|