Kd100.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace logistics;
  3. use GuzzleHttp\Client;
  4. use think\Env;
  5. class Kd100 extends QueryInterface{
  6. protected $key;
  7. protected $customer;
  8. public function __construct()
  9. {
  10. $this->key=Env::get('logistics.kd100_key','fVczXhfg8960');
  11. $this->customer=Env::get('logistics.kd100_customer','B20CCD1C0BAFDD7E69CC986A1A0C57E0');
  12. }
  13. public function query()
  14. {
  15. //====================================
  16. // 实时查询示例代码
  17. // 授权信息可通过链接查看:https://api.kuaidi100.com/manager/v2/myinfo/enterprise
  18. //====================================
  19. //参数设置
  20. $key = $this->key; // 客户授权key
  21. $customer = $this->customer; // 查询公司编号
  22. $param = array (
  23. 'com' => $this->getLogistics('code_kd100'), // 快递公司编码
  24. 'num' => $this->getNo(), // 快递单号
  25. 'phone' => $this->getPhone(), // 手机号
  26. 'from' => '', // 出发地城市
  27. 'to' => '', // 目的地城市
  28. 'resultv2' => '1', // 开启行政区域解析
  29. 'show' => '0', // 返回格式:0:json格式(默认),1:xml,2:html,3:text
  30. 'order' => 'desc' // 返回结果排序:desc降序(默认),asc 升序
  31. );
  32. //请求参数
  33. $post_data = array();
  34. $post_data['customer'] = $customer;
  35. $post_data['param'] = json_encode($param, JSON_UNESCAPED_UNICODE);
  36. $sign = md5($post_data['param'].$key.$post_data['customer']);
  37. $post_data['sign'] = strtoupper($sign);
  38. $url = 'https://poll.kuaidi100.com/poll/query.do'; // 实时查询请求地址
  39. $makeRequest=(new Client)->post($url,[
  40. 'form_params'=>$post_data,
  41. ]);
  42. $arr=json_decode($makeRequest->getBody()->getContents(),true);
  43. $content=$arr['data']??[];
  44. $flow=[];
  45. foreach ($content as $item){
  46. $flow[]=[
  47. 'time'=>$item['time'],
  48. 'content'=>$item['context'],
  49. ];
  50. }
  51. return $flow;
  52. }
  53. }