wupengfei 3 anos atrás
pai
commit
4b74cd0484

+ 1 - 0
addons/expressquery/.addonrc

@@ -0,0 +1 @@
+{"license":"regular","licenseto":"50893","licensekey":"R36onwrJ2OeCj7SB GRVyNtOt9c\/X6jW+WUy4Fngp01yHyVlCjenZKRrmC7A=","menus":["expressquery","expressquery\/index"],"files":["application\/admin\/lang\/zh-cn\/expressquery.php","application\/admin\/model\/ExpressqueryConfig.php","application\/admin\/view\/expressquery\/index.html","application\/admin\/controller\/Expressquery.php","public\/assets\/js\/backend\/expressquery.js"]}

+ 61 - 0
addons/expressquery/Expressquery.php

@@ -0,0 +1,61 @@
+<?php
+
+namespace addons\expressquery;
+
+use app\common\library\Menu;
+use think\exception\PDOException;
+use think\Addons;
+use think\Db;
+
+/**
+ * 物流信息接口插件
+ */
+class Expressquery extends Addons
+{
+    /**
+     * 插件安装方法
+     * @return bool
+     */
+    public function install()
+    {
+        $menu = [
+            [
+                'name'    => 'expressquery',
+                'title'   => '物流接口配置',
+                'icon'    => 'fa fa-truck',
+                'remark'  => '集成快递鸟、快递100、阿里云3大物流信息查询接口',
+                'sublist' => [
+                    ['name' => 'expressquery/index', 'title' => '接口配置'],
+                ]
+            ]
+        ];
+        Menu::create($menu);
+        return true;
+    }
+
+    /**
+     * 插件卸载方法
+     * @return bool
+     */
+    public function uninstall()
+    {
+        Menu::delete('expressquery');
+        return true;
+    }
+    
+    /**
+     * 插件启用方法
+     */
+    public function enable()
+    {
+        Menu::enable('expressquery');
+    }
+
+    /**
+     * 插件禁用方法
+     */
+    public function disable()
+    {
+        Menu::disable('expressquery');
+    }
+}

+ 5 - 0
addons/expressquery/config.php

@@ -0,0 +1,5 @@
+<?php
+
+return [
+    
+];

+ 15 - 0
addons/expressquery/controller/Index.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace addons\expressquery\controller;
+
+use think\addons\Controller;
+
+class Index extends Controller
+{
+
+    public function index()
+    {
+        $this->error("当前插件暂无前台页面");
+    }
+
+}

+ 10 - 0
addons/expressquery/info.ini

@@ -0,0 +1,10 @@
+name = expressquery
+title = 物流信息接口
+intro = 集成快递鸟、快递100、阿里云3大物流信息查询接口
+author = Xing6
+website = https://www.fastadmin.net
+version = 1.0.0
+state = 1
+url = /addons/expressquery
+license = regular
+licenseto = 50893

+ 146 - 0
addons/expressquery/install.sql

@@ -0,0 +1,146 @@
+SET FOREIGN_KEY_CHECKS=0;
+
+-- ----------------------------
+-- Table structure for __PREFIX__expressquery
+-- ----------------------------
+CREATE TABLE IF NOT EXISTS `__PREFIX__expressquery` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `name` varchar(50) DEFAULT '',
+  `express` varchar(50) DEFAULT '',
+  `coding` varchar(10) NOT NULL DEFAULT '',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8 COMMENT='快递公司表';
+
+-- ----------------------------
+-- Records of __PREFIX__expressquery
+-- ----------------------------
+INSERT INTO `__PREFIX__expressquery` VALUES ('1', '顺丰', 'shunfeng', 'SF');
+INSERT INTO `__PREFIX__expressquery` VALUES ('2', '申通', 'shentong', 'STO');
+INSERT INTO `__PREFIX__expressquery` VALUES ('3', '韵达快运', 'yunda', 'YD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('4', '天天快递', 'tiantian', 'HHTT');
+INSERT INTO `__PREFIX__expressquery` VALUES ('5', '圆通速递', 'yuantong', 'YTO');
+INSERT INTO `__PREFIX__expressquery` VALUES ('6', '中通速递', 'zhongtong', 'ZTO');
+INSERT INTO `__PREFIX__expressquery` VALUES ('7', 'ems快递', 'ems', 'EMS');
+INSERT INTO `__PREFIX__expressquery` VALUES ('8', '百世快递', 'huitongkuaidi', 'HTKY');
+INSERT INTO `__PREFIX__expressquery` VALUES ('9', '全峰快递', 'quanfengkuaidi', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('10', '宅急送', 'zhaijisong', 'ZJS');
+INSERT INTO `__PREFIX__expressquery` VALUES ('11', 'aae全球专递', 'aae', 'AAE');
+INSERT INTO `__PREFIX__expressquery` VALUES ('12', '安捷快递', 'anjie', 'AJ');
+INSERT INTO `__PREFIX__expressquery` VALUES ('13', '安信达快递', 'anxindakuaixi', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('14', '彪记快递', 'biaojikuaidi', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('15', 'bht', 'bht', 'BHT');
+INSERT INTO `__PREFIX__expressquery` VALUES ('16', '百福东方国际物流', 'baifudongfang', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('17', '中国东方(COE)', 'coe', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('18', '长宇物流', 'changyuwuliu', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('19', '大田物流', 'datianwuliu', 'DTWL');
+INSERT INTO `__PREFIX__expressquery` VALUES ('20', '德邦物流', 'debangwuliu', 'DBL');
+INSERT INTO `__PREFIX__expressquery` VALUES ('21', 'dhl', 'dhl', 'DHL');
+INSERT INTO `__PREFIX__expressquery` VALUES ('22', 'dpex', 'dpex', 'DPEX');
+INSERT INTO `__PREFIX__expressquery` VALUES ('23', 'd速快递', 'dsukuaidi', 'DSWL');
+INSERT INTO `__PREFIX__expressquery` VALUES ('24', '递四方', 'disifang', 'D4PX');
+INSERT INTO `__PREFIX__expressquery` VALUES ('25', 'fedex(国外)', 'fedex', 'FEDEX_GJ');
+INSERT INTO `__PREFIX__expressquery` VALUES ('26', '飞康达物流', 'feikangda', 'FKD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('27', '凤凰快递', 'fenghuangkuaidi', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('28', '飞快达', 'feikuaida', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('29', '国通快递', 'guotongkuaidi', 'GTO');
+INSERT INTO `__PREFIX__expressquery` VALUES ('30', '港中能达物流', 'ganzhongnengda', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('31', '广东邮政物流', 'guangdongyouzhengwuliu', 'GDEMS');
+INSERT INTO `__PREFIX__expressquery` VALUES ('32', '共速达', 'gongsuda', 'GSD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('33', '恒路物流', 'hengluwuliu', 'HLWL');
+INSERT INTO `__PREFIX__expressquery` VALUES ('34', '华夏龙物流', 'huaxialongwuliu', 'HXLWL');
+INSERT INTO `__PREFIX__expressquery` VALUES ('35', '海红', 'haihongwangsong', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('36', '海外环球', 'haiwaihuanqiu', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('37', '佳怡物流', 'jiayiwuliu', 'JYWL');
+INSERT INTO `__PREFIX__expressquery` VALUES ('38', '京广速递', 'jinguangsudikuaijian', 'JGSD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('39', '急先达', 'jixianda', 'JXD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('40', '佳吉物流', 'jiajiwuliu', 'CNEX');
+INSERT INTO `__PREFIX__expressquery` VALUES ('41', '加运美物流', 'jymwl', 'JYM');
+INSERT INTO `__PREFIX__expressquery` VALUES ('42', '金大物流', 'jindawuliu', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('43', '嘉里大通', 'jialidatong', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('44', '晋越快递', 'jykd', 'JYKD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('45', '快捷速递', 'kuaijiesudi', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('46', '联邦快递(国内)', 'lianb', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('47', '联昊通物流', 'lianhaowuliu', 'LHT');
+INSERT INTO `__PREFIX__expressquery` VALUES ('48', '龙邦物流', 'longbanwuliu', 'LB');
+INSERT INTO `__PREFIX__expressquery` VALUES ('49', '立即送', 'lijisong', 'LJSKD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('50', '乐捷递', 'lejiedi', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('51', '民航快递', 'minghangkuaidi', 'MHKD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('52', '美国快递', 'meiguokuaidi', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('53', '门对门', 'menduimen', 'MDM');
+INSERT INTO `__PREFIX__expressquery` VALUES ('54', 'OCS', 'ocs', 'OCS');
+INSERT INTO `__PREFIX__expressquery` VALUES ('55', '配思货运', 'peisihuoyunkuaidi', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('56', '全晨快递', 'quanchenkuaidi', 'QCKD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('57', '全际通物流', 'quanjitong', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('58', '全日通快递', 'quanritongkuaidi', 'QRT');
+INSERT INTO `__PREFIX__expressquery` VALUES ('59', '全一快递', 'quanyikuaidi', 'UAPEX');
+INSERT INTO `__PREFIX__expressquery` VALUES ('60', '如风达', 'rufengda', 'RFD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('61', '三态速递', 'santaisudi', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('62', '盛辉物流', 'shenghuiwuliu', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('63', '速尔物流', 'suer', 'SURE');
+INSERT INTO `__PREFIX__expressquery` VALUES ('64', '盛丰物流', 'shengfeng', 'SFWL');
+INSERT INTO `__PREFIX__expressquery` VALUES ('65', '赛澳递', 'saiaodi', 'SAD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('66', '天地华宇', 'tiandihuayu', 'HOAU');
+INSERT INTO `__PREFIX__expressquery` VALUES ('67', 'tnt', 'tnt', 'TNT');
+INSERT INTO `__PREFIX__expressquery` VALUES ('68', 'ups', 'ups', 'UPS');
+INSERT INTO `__PREFIX__expressquery` VALUES ('69', '万家物流', 'wanjiawuliu', 'WJWL');
+INSERT INTO `__PREFIX__expressquery` VALUES ('70', '文捷航空速递', 'wenjiesudi', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('71', '伍圆', 'wuyuan', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('72', '万象物流', 'wxwl', 'WXWL');
+INSERT INTO `__PREFIX__expressquery` VALUES ('73', '新邦物流', 'xinbangwuliu', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('74', '信丰物流', 'xinfengwuliu', 'XFEX');
+INSERT INTO `__PREFIX__expressquery` VALUES ('75', '亚风速递', 'yafengsudi', 'YFSD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('76', '一邦速递', 'yibangwuliu', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('77', '优速物流', 'youshuwuliu', 'UC');
+INSERT INTO `__PREFIX__expressquery` VALUES ('78', '邮政快递包裹', 'youzhengguonei', 'YZBK');
+INSERT INTO `__PREFIX__expressquery` VALUES ('79', '邮政国际包裹挂号信', 'youzhengguoji', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('80', '远成物流', 'yuanchengwuliu', 'YCWL');
+INSERT INTO `__PREFIX__expressquery` VALUES ('81', '源伟丰快递', 'yuanweifeng', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('82', '元智捷诚快递', 'yuanzhijiecheng', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('83', '运通快递', 'yuntongkuaidi', 'YTKD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('84', '越丰物流', 'yuefengwuliu', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('85', '源安达', 'yad', 'YADEX');
+INSERT INTO `__PREFIX__expressquery` VALUES ('86', '银捷速递', 'yinjiesudi', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('87', '中铁快运', 'zhongtiekuaiyun', 'ZTKY');
+INSERT INTO `__PREFIX__expressquery` VALUES ('88', '中邮物流', 'zhongyouwuliu', 'ZYKD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('89', '忠信达', 'zhongxinda', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('90', '芝麻开门', 'zhimakaimen', '');
+INSERT INTO `__PREFIX__expressquery` VALUES ('91', '安能物流', 'annengwuliu', 'ANE');
+INSERT INTO `__PREFIX__expressquery` VALUES ('92', '京东快递', 'jd', 'JD');
+INSERT INTO `__PREFIX__expressquery` VALUES ('93', '微特派', 'weitepai', 'WTP');
+INSERT INTO `__PREFIX__expressquery` VALUES ('94', '九曳供应链', 'jiuyescm', 'JIUYE');
+INSERT INTO `__PREFIX__expressquery` VALUES ('95', '跨越速运', 'kuayue', 'KYSY');
+
+-- ----------------------------
+-- Table structure for __PREFIX__expressquery_cache
+-- ----------------------------
+CREATE TABLE IF NOT EXISTS `__PREFIX__expressquery_cache` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `expresssn` varchar(50) DEFAULT NULL,
+  `express` varchar(50) DEFAULT NULL,
+  `lasttime` int(11) NOT NULL,
+  `datas` text,
+  PRIMARY KEY (`id`),
+  KEY `idx_expresssn` (`expresssn`),
+  KEY `idx_express` (`express`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='查询缓存表';
+
+-- ----------------------------
+-- Records of __PREFIX__expressquery_cache
+-- ----------------------------
+
+-- ----------------------------
+-- Table structure for __PREFIX__expressquery_config
+-- ----------------------------
+CREATE TABLE IF NOT EXISTS `__PREFIX__expressquery_config` (
+  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
+  `express_type` enum('kuaidiniao','kuaidi100','ali') NOT NULL DEFAULT 'kuaidiniao' COMMENT '类型选择',
+  `express_bird_userid` varchar(100) DEFAULT NULL COMMENT '用户ID',
+  `express_bird_apikey` varchar(100) DEFAULT NULL COMMENT 'API key',
+  `express_bird_customer_name` varchar(100) DEFAULT NULL COMMENT '京东商家编码',
+  `express_bird_cache` int(10) unsigned DEFAULT '0' COMMENT '缓存时长(分钟)',
+  `kuaidi100_type` enum('free','company') NOT NULL DEFAULT 'free' COMMENT '接口类型',
+  `apikey` varchar(100) DEFAULT NULL COMMENT '授权密匙(Key)',
+  `customer` varchar(100) DEFAULT NULL COMMENT '公司编号(Customer)',
+  `aliappcode` varchar(100) DEFAULT NULL COMMENT '阿里云APPCODE',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='物流接口配置表';

+ 365 - 0
addons/expressquery/library/Expressquery.php

@@ -0,0 +1,365 @@
+<?php
+
+namespace addons\expressquery\library;
+
+use think\Db;
+use think\Exception;
+use Throwable;
+
+class Expressquery
+{
+    /**
+     * 实现查询快递信息的钩子方法
+     *
+     * @param 类型 array 参数一的说明 [$express,$expresssn,$mobile]
+     * @return array 返回类型
+     * @example 示例  hook('get_express_list', [快递公司编码, 快递单号, 手机号])
+     * @author Created by Xing <464401240@qq.com>
+     */
+    public function getExpressList($express, $expresssn, $mobile = '')
+    {
+       
+        $list = ['code' => 0, 'msg' => '配置参数错误', 'data' => ''];
+        if ($express && $expresssn) {
+            $express_set = \app\admin\model\ExpressqueryConfig::all();
+            $express_set = $express_set[0];
+
+            $express = $express == 'jymwl' ? 'jiayunmeiwuliu' : $express;
+            $express = $express == 'TTKD' ? 'tiantian' : $express;
+            $express = $express == 'jjwl' ? 'jiajiwuliu' : $express;
+            $express = $express == 'zhongtiekuaiyun' ? 'ztky' : $express;
+            
+            if ($express_set['express_type'] == 'kuaidiniao') {
+               
+                $list = $this->getExpressBird($express, $expresssn, $express_set, $mobile);
+            } elseif ($express_set['express_type'] == 'kuaidi100') {
+          
+                $list = $this->getExpressOneHundred($express, $expresssn, $express_set, $mobile);
+            } else {
+                if ($express_set['express_type'] == 'ali') {
+                    $list = $this->getExpressAli($express, $expresssn, $express_set, $mobile);
+                }
+            }
+        }
+        return $list;
+    }
+
+    /**
+     * 快递鸟
+     * @param $express
+     * @param $expresssn
+     * @param string $mobile
+     * @param $express_set
+     * @return array|bool
+     */
+    private function getExpressBird($express, $expresssn, $express_set, $mobile = '')
+    {
+        if (empty($express_set['express_bird_userid']) || empty($express_set['express_bird_apikey'])) {
+            return ['code' => 0, 'msg' => '配置参数错误', 'data' => ''];
+        }
+
+        if (!empty($express_set['express_bird_cache']) && 0 < $express_set['express_bird_cache']) {
+            $cache_time = $express_set['express_bird_cache'] * 60;
+            $cache = Db::name('expressquery_cache')->where(['express' => $express, 'expresssn' => $expresssn])->find();
+            if (time() <= $cache['lasttime'] + $cache_time && !empty($cache['datas'])) {
+                return ['code' => 1, 'msg' => '获取缓存数据成功', 'data' => json_decode($cache['datas'], true)];
+            }
+        }
+
+        $url = 'http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx';
+       
+        $expressInfo = Db::name('expressquery')->where(['coding' => $express])->find();
+
+        if (empty($expressInfo)) {
+            return ['code' => 0, 'msg' => '没有找到快递公司编码', 'data' => ''];
+        }
+
+        $expressEncoding = $expressInfo['coding'];
+        $requestData = array('ShipperCode' => $expressEncoding, 'LogisticCode' => $expresssn);
+
+        if ($expressEncoding == 'SF') {
+            $cunstomername = substr($mobile, -4);
+            $requestData['CustomerName'] = $cunstomername;
+        }
+
+        if ($expressEncoding == 'JGSD') {
+            $requestData['CustomerName'] = $express_set['express_bird_customer_name'];
+        }
+
+        $requestData = json_encode($requestData);
+        $datas = array(
+            'EBusinessID' => $express_set['express_bird_userid'],
+            'RequestType' => '1002',
+            'RequestData' => urlencode($requestData),
+            'DataType' => '2'
+        );
+        $datas['DataSign'] = urlencode(base64_encode(md5($requestData . $express_set['express_bird_apikey'])));
+        $response = $this->httpPost($url, $datas);
+        $expressData = json_decode($response, true);
+
+        if ($expressData['Success'] == false) {
+            //重试一次
+            $datas = array(
+                'EBusinessID' => $express_set['express_bird_userid'],
+                'RequestType' => '8001',
+                'RequestData' => urlencode($requestData),
+                'DataType' => '2'
+            );
+            $datas['DataSign'] = urlencode(base64_encode(md5($requestData . $express_set['express_bird_apikey'])));
+            $response = $this->httpPost($url, $datas);
+            $expressData = json_decode($response, true);
+        }
+
+        $list = array();
+        if (!empty($expressData['Traces']) && is_array($expressData['Traces'])) {
+            foreach ($expressData['Traces'] as $index => $data) {
+                $list[] = array('time' => trim($data['AcceptTime']), 'step' => trim($data['AcceptStation']));
+            }
+            $list = array_reverse($list);
+        } else {
+            return ['code' => 0, 'msg' => $expressData['Reason'], 'data' => $expressData];
+        }
+
+        if (0 < $express_set['express_bird_cache'] && !empty($list)) {
+            if (empty($cache)) {
+                Db::name('expressquery_cache')->insert(
+                    [
+                        'expresssn' => $expresssn,
+                        'express'   => $express,
+                        'lasttime'  => time(),
+                        'datas'     => json_encode($list)
+                    ]
+                );
+            } else {
+                Db::name('expressquery_cache')->where(['id' => $cache['id']])->update(
+                    [
+                        'lasttime' => time(),
+                        'datas'    => json_encode($list)
+                    ]
+                );
+            }
+        }
+
+        return ['code' => 1, 'msg' => 'success', 'data' => $list];
+    }
+
+    /**
+     * 快递100
+     * @param $express
+     * @param $expresssn
+     * @param string $mobile
+     * @param $express_set
+     * @return array
+     */
+    private function getExpressOneHundred($express, $expresssn, $express_set, $mobile = '')
+    {
+        if (empty($express_set['apikey'])) {
+            return ['code' => 0, 'msg' => '配置参数错误', 'data' => ''];
+        }
+
+        if (!empty($express_set['express_bird_cache']) && 0 < $express_set['express_bird_cache']) {
+            $cache_time = $express_set['express_bird_cache'] * 60;
+            $cache = Db::name('expressquery_cache')->where(['express' => $express, 'expresssn' => $expresssn])->find();
+            if (time() <= $cache['lasttime'] + $cache_time && !empty($cache['datas'])) {
+                return ['code' => 1, 'msg' => '获取缓存数据成功', 'data' => json_decode($cache['datas'], true)];
+            }
+        }
+
+        $expressInfo = Db::name('expressquery')->where(['express' => $express])->find();
+        if (empty($expressInfo)) {
+            return ['code' => 0, 'msg' => '没有找到快递公司编码', 'data' => ''];
+        }
+
+        if ($express_set['kuaidi100_type'] == 'free') {
+            $url = 'http://api.kuaidi100.com/api?id=' . $express_set['apikey'] . '&com=' . $express . '&num=' . $expresssn;
+            $params = array();
+        } else {
+            $url = 'http://poll.kuaidi100.com/poll/query.do';
+            $params = array(
+                'customer' => $express_set['customer'],
+                'param' => json_encode(array('com' => $express, 'num' => $expresssn))
+            );
+            $params['sign'] = md5($params['param'] . $express_set['apikey'] . $params['customer']);
+            $params['sign'] = strtoupper($params['sign']);
+            $params['phone'] = $mobile;
+        }
+
+        $content = $this->httpPost($url, $params);
+        $info = json_decode($content, true);
+        $info['request_url'] = $url;
+
+        if (!isset($info) || empty($info['data']) || !is_array($info['data'])) {
+            $useapi = false;
+        } else {
+            $useapi = true;
+        }
+
+        $list = array();
+        if (!empty($info['data']) && is_array($info['data'])) {
+            foreach ($info['data'] as $index => $data) {
+                if ($data['context'] == '查无结果') {
+                    continue;
+                }
+                $list[] = array('time' => trim($data['time']), 'step' => trim($data['context']));
+            }
+        } else {
+            return ['code' => 0, 'msg' => $info['message'], 'data' => $info];
+        }
+
+        if ($useapi && 0 < $express_set['express_bird_cache'] && !empty($list)) {
+            if (empty($cache)) {
+                Db::name('expressquery_cache')->insert(
+                    [
+                        'expresssn' => $expresssn,
+                        'express'   => $express,
+                        'lasttime'  => time(),
+                        'datas'     => json_encode($list)
+                    ]
+                );
+            } else {
+                Db::name('expressquery_cache')->where(['id' => $cache['id']])->update(
+                    [
+                        'lasttime' => time(),
+                        'datas'    => json_encode($list)
+                    ]
+                );
+            }
+        }
+
+        return ['code' => 1, 'msg' => 'success', 'data' => $list];
+    }
+
+    /**
+     * 阿里云
+     * @param $express
+     * @param $expresssn
+     * @param string $mobile
+     * @param $express_set
+     * @return array
+     */
+    private function getExpressAli($express, $expresssn, $express_set, $mobile = '')
+    {
+        $appcode = $express_set['aliappcode'];
+        if (!$appcode) {
+            return ['code' => 0, 'msg' => '配置参数错误', 'data' => ''];
+        }
+        //读取缓存数据
+        if (!empty($express_set['express_bird_cache']) && 0 < $express_set['express_bird_cache']) {
+            $cache_time = $express_set['express_bird_cache'] * 60;
+            $cache = Db::name('expressquery_cache')->where(['express' => $express, 'expresssn' => $expresssn])->find();
+            if (time() <= $cache['lasttime'] + $cache_time && !empty($cache['datas'])) {
+                return ['code' => 1, 'msg' => '获取缓存数据成功', 'data' => json_decode($cache['datas'], true)];
+            }
+        }
+
+        $url = 'https://wdexpress.market.alicloudapi.com/gxali';
+        $method = 'GET';
+        $expressInfo = Db::name('expressquery')->where(['express' => $express])->find();
+        if (empty($expressInfo)) {
+            return ['code' => 0, 'msg' => '没有找到快递公司编码', 'data' => ''];
+        }
+
+        $expressEncoding = $expressInfo['coding'];
+        $headers = array();
+        array_push($headers, 'Authorization:APPCODE ' . $appcode);
+
+        if ($expressEncoding == 'SF') {
+            $cunstomername = substr($mobile, -4);
+            $querys = 'n=' . $expresssn . ':' . $cunstomername . '&t=' . $expressEncoding;
+        } else {
+            $querys = 'n=' . $expresssn . '&t=' . $expressEncoding;
+        }
+
+        $url = $url . '?' . $querys;
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($curl, CURLOPT_FAILONERROR, false);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($curl, CURLOPT_HEADER, false);
+        //curl_setopt($curl, CURLOPT_HEADER, true); 如不输出json, 请打开这行代码,打印调试头部状态码。
+        //状态码: 200 正常;400 URL无效;401 appCode错误; 403 次数用完; 500 API网管错误
+        if (1 == strpos("$".$url, "https://")) {
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
+        }
+        $out_put = curl_exec($curl);
+
+
+        $expressData = json_decode($out_put, true);
+        $list = array();
+        if (!empty($expressData['Traces']) && is_array($expressData['Traces'])) {
+            foreach ($expressData['Traces'] as $index => $data) {
+                $list[] = array('time' => trim($data['AcceptTime']), 'step' => trim($data['AcceptStation']));
+            }
+            $list = array_reverse($list);
+        } else {
+            $expressData['querys'] = $querys;
+            return ['code' => 0, 'msg' => 'error', 'data' => $expressData];
+        }
+
+        if (0 < $express_set['express_bird_cache'] && !empty($list)) {
+            if (empty($cache)) {
+                Db::name('expressquery_cache')->insert(
+                    [
+                        'expresssn' => $expresssn,
+                        'express'   => $express,
+                        'lasttime'  => time(),
+                        'datas'     => json_encode($list)
+                    ]
+                );
+            } else {
+                Db::name('expressquery_cache')->where(['id' => $cache['id']])->update(
+                    [
+                        'lasttime' => time(),
+                        'datas'    => json_encode($list)
+                    ]
+                );
+            }
+        }
+
+        return ['code' => 1, 'msg' => 'success', 'data' => $list];
+    }
+
+
+    /**
+     * Post提交数据
+     *
+     * @param string $url 请求的Url
+     * @param array $datas 提交的数据
+     * @return string 响应返回的html
+     * @author Created by Xing <464401240@qq.com>
+     */
+    private function httpPost($url, $datas)
+    {
+        $temps = array();
+        foreach ($datas as $key => $value) {
+            $temps[] = sprintf('%s=%s', $key, $value);
+        }
+        $post_data = implode('&', $temps);
+        $url_info = parse_url($url);
+        if (empty($url_info['port'])) {
+            $url_info['port'] = 80;
+        }
+        $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
+        $httpheader .= "Host:" . $url_info['host'] . "\r\n";
+        $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";
+        $httpheader .= "Content-Length:" . strlen($post_data) . "\r\n";
+        $httpheader .= "Connection:close\r\n\r\n";
+        $httpheader .= $post_data;
+        $fd = fsockopen($url_info['host'], $url_info['port']);
+        fwrite($fd, $httpheader);
+        $gets = "";
+        while (!feof($fd)) {
+            if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) {
+                break;
+            }
+        }
+        while (!feof($fd)) {
+            $gets .= fread($fd, 128);
+        }
+        fclose($fd);
+        return $gets;
+    }
+}

+ 9 - 0
addons/shopro/model/OrderExpress.php

@@ -4,6 +4,7 @@ namespace addons\shopro\model;
 
 use think\Model;
 use addons\shopro\exception\Exception;
+use addons\expressquery\library\Expressquery;
 use think\Db;
 
 /**
@@ -49,6 +50,14 @@ class OrderExpress extends Model
             return $query->where('order_id', $order_id);
         }])->where('user_id', $user->id)->where('order_id', $order_id)->where('id', $id)->find();
 
+
+        $expModle = new Expressquery();
+
+
+        $list = $expModle->getExpressList($detail->express_code, $detail->express_no);
+
+
+        $detail->log=$list['data'];
         return $detail;
     }