12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace logistics;
- use GuzzleHttp\Client;
- use think\Env;
- class Kd100 extends QueryInterface{
- protected $key;
- protected $customer;
- public function __construct()
- {
- $this->key=Env::get('logistics.kd100_key','fVczXhfg8960');
- $this->customer=Env::get('logistics.kd100_customer','B20CCD1C0BAFDD7E69CC986A1A0C57E0');
- }
- public function query()
- {
- //====================================
- // 实时查询示例代码
- // 授权信息可通过链接查看:https://api.kuaidi100.com/manager/v2/myinfo/enterprise
- //====================================
- //参数设置
- $key = $this->key; // 客户授权key
- $customer = $this->customer; // 查询公司编号
- $param = array (
- 'com' => $this->getLogistics('code_kd100'), // 快递公司编码
- 'num' => $this->getNo(), // 快递单号
- 'phone' => $this->getPhone(), // 手机号
- 'from' => '', // 出发地城市
- 'to' => '', // 目的地城市
- 'resultv2' => '1', // 开启行政区域解析
- 'show' => '0', // 返回格式:0:json格式(默认),1:xml,2:html,3:text
- 'order' => 'desc' // 返回结果排序:desc降序(默认),asc 升序
- );
- //请求参数
- $post_data = array();
- $post_data['customer'] = $customer;
- $post_data['param'] = json_encode($param, JSON_UNESCAPED_UNICODE);
- $sign = md5($post_data['param'].$key.$post_data['customer']);
- $post_data['sign'] = strtoupper($sign);
- $url = 'https://poll.kuaidi100.com/poll/query.do'; // 实时查询请求地址
- $str=(new Client)->post($url,[
- 'form_params'=>$post_data,
- ]);
- $arr=json_decode($str,true);
- return $arr['data']??[];
- }
- }
|