From 5c5dd1e343963079f016716e87d7c28388e3344a Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 10 Jul 2017 14:47:40 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E5=A2=9E=E5=8A=A0kuaidi100?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=94=AF=E6=8C=81=EF=BC=8CCURL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/controller/Index.php | 10 ++++ extend/service/ExpressService.php | 78 -------------------------- extend/service/ToolsService.php | 20 +++++++ 3 files changed, 30 insertions(+), 78 deletions(-) delete mode 100644 extend/service/ExpressService.php diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index 1b40c0bfd..77bb04dc2 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -14,8 +14,12 @@ namespace app\index\controller; +use service\HttpService; +use service\ToolsService; use think\Controller; use think\Db; +use think\Request; +use Wechat\Lib\Tools; /** * 网站入口控制器 @@ -44,4 +48,10 @@ class Index extends Controller } } + public function wuliu() + { + $order = '1202247993797'; + dump(ToolsService::express($order)); + } + } diff --git a/extend/service/ExpressService.php b/extend/service/ExpressService.php deleted file mode 100644 index e75c16b62..000000000 --- a/extend/service/ExpressService.php +++ /dev/null @@ -1,78 +0,0 @@ - - * @date 2017/03/15 15:17 - */ -class ExpressService -{ - - const APPID = '1232779'; - const APPKEY = 'ac45f461-8c1a-4518-87b1-bb8e835a2f9d'; - const APIURI = 'http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx'; - - /** - * @brief 获取物流轨迹线路 - * @param $ShipperCode string 物流公司代号 - * @param $LogisticCode string 物流单号 - * @return string array 轨迹数据 - */ - public static function line($ShipperCode, $LogisticCode) - { - $sendData = json_encode(['ShipperCode' => $ShipperCode, 'LogisticCode' => $LogisticCode], JSON_UNESCAPED_UNICODE); - $data = [ - 'RequestData' => $sendData, - 'EBusinessID' => self::APPID, - 'RequestType' => '1002', - 'DataType' => 2, - 'DataSign' => base64_encode(md5($sendData . self::APPKEY)), - ]; - $result = HttpService::post(self::APIURI, $data); - !($resultJson = json_decode($result, true)) && die(var_export($result)); - return self::response($resultJson); - } - - /** - * 处理返回数据统一数据格式 - * @param $result 结果处理 - * @return array 通用的结果集 array('result' => 'success或者fail','data' => array( array('time' => '时间','info' => '地点'),......),'reason' => '失败原因') - */ - public static function response($result) - { - $status = "fail"; - $data = []; - $message = "此单号无跟踪记录"; - if (isset($result['Message'])) { - $message = $result['Message']; - } elseif (isset($result['Reason'])) { - $message = $result['Reason']; - } - if (isset($result['Traces']) && $result['Traces']) { - foreach ($result['Traces'] as $key => $val) { - $data[$key]['time'] = $val['AcceptTime']; - $data[$key]['info'] = $val['AcceptStation']; - } - $status = "success"; - $message = '此订单号有' . count($data) . '条跟踪记录'; - } - return ['result' => $status, 'data' => $data, 'message' => $message]; - } - -} diff --git a/extend/service/ToolsService.php b/extend/service/ToolsService.php index 7e2ebc9ef..c378cf828 100644 --- a/extend/service/ToolsService.php +++ b/extend/service/ToolsService.php @@ -14,6 +14,8 @@ namespace service; +use think\Request; + /** * 系统工具服务 * Class ToolsService @@ -154,4 +156,22 @@ class ToolsService return $ids; } + /** + * 物流单查询 + * @param $code + * @return array + */ + public static function express($code) + { + $result = []; + $autoResult = HttpService::get("http://www.kuaidi100.com/autonumber/autoComNum?text={$code}"); + foreach (json_decode($autoResult)->auto as $vo) { + $microtime = microtime(true); + $url = "http://www.kuaidi100.com/query?type={$vo->comCode}&postid={$code}&id=1&valicode=&temp={$microtime}"; + $client_ip = Request::instance()->ip(); + $header = ['Host' => 'www.kuaidi100.com', 'CLIENT-IP' => $client_ip, 'X-FORWARDED-FOR' => $client_ip]; + $result[$vo->comCode] = json_decode(HttpService::get($url, [], 30, $header), true); + } + return $result; + } }