mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-09-15 00:00:03 +08:00
61 lines
2.5 KiB
PHP
61 lines
2.5 KiB
PHP
<?php
|
||
|
||
// +----------------------------------------------------------------------
|
||
// | ThinkAdmin
|
||
// +----------------------------------------------------------------------
|
||
// | 版权所有 2014~2020 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||
// +----------------------------------------------------------------------
|
||
// | 官方网站: https://gitee.com/zoujingli/ThinkLibrary
|
||
// +----------------------------------------------------------------------
|
||
// | 开源协议 ( https://mit-license.org )
|
||
// +----------------------------------------------------------------------
|
||
// | gitee 代码仓库:https://gitee.com/zoujingli/ThinkLibrary
|
||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace think\admin\service;
|
||
|
||
use think\admin\Service;
|
||
|
||
/**
|
||
* 百度快递100物流查询
|
||
* Class ExpressService
|
||
* @package think\admin\service
|
||
*/
|
||
class ExpressService extends Service
|
||
{
|
||
/**
|
||
* 通过百度快递100应用查询物流信息
|
||
* @param string $code 快递公司编辑
|
||
* @param string $number 快递物流编号
|
||
* @return array
|
||
*/
|
||
public function express($code, $number)
|
||
{
|
||
$list = [];
|
||
for ($i = 0; $i < 6; $i++) if (is_array($result = $this->doExpress($code, $number))) {
|
||
if (!empty($result['data']['info']['context'])) {
|
||
foreach ($result['data']['info']['context'] as $vo) $list[] = [
|
||
'time' => date('Y-m-d H:i:s', $vo['time']), 'context' => $vo['desc'],
|
||
];
|
||
return ['message' => 'ok', 'com' => $code, 'nu' => $number, 'data' => $list];
|
||
}
|
||
}
|
||
return ['message' => 'ok', 'com' => $code, 'nu' => $number, 'data' => $list];
|
||
}
|
||
|
||
/**
|
||
* 执行百度快递100应用查询请求
|
||
* @param string $code 快递公司编号
|
||
* @param string $number 快递单单号
|
||
* @return mixed
|
||
*/
|
||
private function doExpress($code, $number)
|
||
{
|
||
list($microtime, $clientIp) = [time(), $this->app->request->ip()];
|
||
$url = "https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?cb=callback&appid=4001&com={$code}&nu={$number}&vcode=&token=&_={$microtime}";
|
||
$options = ['cookie_file' => $this->app->getRuntimePath() . 'express_cookie.txt', 'headers' => ['Host' => 'www.kuaidi100.com', 'CLIENT-IP' => $clientIp, 'X-FORWARDED-FOR' => $clientIp],];
|
||
return json_decode(str_replace('/**/callback(', '', trim(http_get($url, [], $options), ')')), true);
|
||
}
|
||
|
||
} |