|
@@ -22,34 +22,28 @@ namespace 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 快递物流编号
|
|
|
+ * @param string $code 快递公司编辑
|
|
|
+ * @param string $number 快递物流编号
|
|
|
* @return array
|
|
|
*/
|
|
|
- public static function query($expressCode, $expressNo)
|
|
|
+ public static function query($code, $number)
|
|
|
{
|
|
|
- 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);
|
|
|
+ if (in_array($code, ['debangkuaidi'])) $code = 'debangwuliu';
|
|
|
+ list($microtime, $clientIp, $list) = [time(), request()->ip(), []];
|
|
|
+ $options = ['header' => ['Host' => 'www.kuaidi100.com', 'CLIENT-IP' => $clientIp, 'X-FORWARDED-FOR' => $clientIp], 'cookie_file' => env('runtime_path') . 'temp/cookie'];
|
|
|
+ $location = "https://sp0.baidu.com/9_Q4sjW91Qh3otqbppnN2DJv/pae/channel/data/asyncqury?cb=callback&appid=4001&com={$code}&nu={$number}&vcode=&token=&_={$microtime}";
|
|
|
+ $result = json_decode(str_replace('/**/callback(', '', trim(http_get($location, [], $options), ')')), true);
|
|
|
+ if (empty($result['data']['info']['context'])) { // 第一次可能失败,这里尝试第二次查询
|
|
|
+ $result = json_decode(str_replace('/**/callback(', '', trim(http_get($location, [], $options), ')')), true);
|
|
|
+ if (empty($result['data']['info']['context'])) {
|
|
|
+ return ['message' => 'ok', 'com' => $code, 'nu' => $number, 'data' => $list];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ foreach ($result['data']['info']['context'] as $vo) $list[] = [
|
|
|
+ 'time' => date('Y-m-d H:i:s', $vo['time']), 'ftime' => date('Y-m-d H:i:s', $vo['time']), 'context' => $vo['desc'],
|
|
|
+ ];
|
|
|
+ return ['message' => 'ok', 'com' => $code, 'nu' => $number, 'data' => $list];
|
|
|
}
|
|
|
|
|
|
}
|