You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
3.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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;
}
}