luck-draw/app/service/Kd100.php

80 lines
2.4 KiB
PHP

<?php
namespace app\service;
class Kd100
{
private static $url = 'http://poll.kuaidi100.com/poll/query.do'; //实时查询请求地址
private static $key = 'bRIlFitN9883';//客户授权key
private static $customer = '03A67821933221AAE6CBACBCA7E565F2';//查询公司编号
public static function query(string $com, string $num, $returnArray = false)
{
$param = [
'com' => $com, //快递公司编码, 一律用小写字母
'num' => $num, //快递单号
// 'phone' => '', //手机号
// 'from' => '', //出发地城市
// 'to' => '', //目的地城市
// 'resultv2' => '1' //开启行政区域解析
];
//请求参数
$post_data = [];
$post_data["customer"] = self::$customer;
$post_data["param"] = json_encode($param);
$sign = md5($post_data["param"].self::$key.$post_data["customer"]);
$post_data["sign"] = strtoupper($sign);
$params = "";
foreach ($post_data as $k => $v) {
$params .= "$k=".urlencode($v)."&"; //默认UTF-8编码格式
}
$post_data = substr($params, 0, -1);
//发送post请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, self::$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
return json_decode($result, $returnArray);
}
/**
* 状态
*
* @return string[]
*/
public static function state(): array
{
return [
0 => '在途',
1 => '揽收',
2 => '疑难',
3 => '签收',
4 => '退签',
5 => '派件',
6 => '退回',
7 => '转单',
10 => '待清关',
11 => '清关中',
12 => '已清关',
13 => '清关异常',
14 => '收件人拒签',
];
}
/**
* 不在继续查询的配送状态
* @return int[]
*/
public static function unSearchState(): array
{
return [3,4,12];
}
}