mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-09-11 06:39:46 +08:00
55 lines
2.2 KiB
PHP
55 lines
2.2 KiB
PHP
<?php
|
||
|
||
// +----------------------------------------------------------------------
|
||
// | Library for ThinkAdmin
|
||
// +----------------------------------------------------------------------
|
||
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||
// +----------------------------------------------------------------------
|
||
// | 官方网站: http://library.thinkadmin.top
|
||
// +----------------------------------------------------------------------
|
||
// | 开源协议 ( https://mit-license.org )
|
||
// +----------------------------------------------------------------------
|
||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace library\tools;
|
||
|
||
/**
|
||
* 快递100查询接口
|
||
* Class Express
|
||
* @package library\tools
|
||
*/
|
||
class Express
|
||
{
|
||
/**
|
||
* 通用物流单查询
|
||
* @param string $code 快递物流编号
|
||
* @return array
|
||
*/
|
||
public static function auto($code)
|
||
{
|
||
list($result, $client_ip) = [[], request()->ip()];
|
||
$header = ['Host' => 'www.kuaidi100.com', 'CLIENT-IP' => $client_ip, 'X-FORWARDED-FOR' => $client_ip];
|
||
$autoResult = Http::get("http://www.kuaidi100.com/autonumber/autoComNum?text={$code}", [], ['header' => $header, 'timeout' => 30]);
|
||
foreach (json_decode($autoResult)->auto as $vo) {
|
||
$item = self::query($vo->comCode, $code);
|
||
if (!empty($item) && $item['message'] === 'ok') $result[$vo->comCode] = $item;
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
/**
|
||
* 查询物流信息
|
||
* @param string $expressCode 快递公司编辑
|
||
* @param string $expressNo 快递物流编号
|
||
* @return array
|
||
*/
|
||
public static function query($expressCode, $expressNo)
|
||
{
|
||
list($microtime, $clientIp) = [microtime(true), request()->ip()];
|
||
$header = ['Host' => 'www.kuaidi100.com', 'CLIENT-IP' => $clientIp, 'X-FORWARDED-FOR' => $clientIp];
|
||
$location = "http://www.kuaidi100.com/query?type={$expressCode}&postid={$expressNo}&phone=&temp={$microtime}";
|
||
return json_decode(Http::get($location, [], ['header' => $header, 'timeout' => 30]), true);
|
||
}
|
||
|
||
} |