Explorar o código

Merge remote-tracking branch 'origin/master'

zhangdehua hai 1 ano
pai
achega
c5243fec00

+ 18 - 1
app/api/controller/Kuaidi.php

@@ -7,6 +7,7 @@ use app\common\enum\Setting as SettingEnum;
 use app\common\library\express\Kuaidi100;
 use app\api\model\Kuaidi as KuaidiModel;
 use app\common\model\store\Setting as SettingModel;
+use think\facade\Log;
 
 /**
  * 快递100接口
@@ -28,7 +29,22 @@ class Kuaidi extends Controller
         // 实例化快递100类
         $Kuaidi100 = new Kuaidi100($config['kuaidi100']);
         // 请求订阅接口
-        $list = $Kuaidi100->subscribe($arg['number']);
+        $list = $Kuaidi100->subscribe($arg['number'],$arg['type'] ?? 1,$arg['company']);
+        return $this->renderSuccess(compact('list'));
+    }
+
+    public function dynamic(){
+        $arg = $this->request->param();
+        // 获取快递100配置项
+        // 实例化快递100类
+        $config = SettingModel::getItem(SettingEnum::DELIVERY);
+        if (empty($config['kuaidi100']['customer']) || empty($config['kuaidi100']['key'])) {
+            throwError('请先到后台-设置-配送方式 补充物流查询API配置');
+        }
+        // 实例化快递100类
+        $Kuaidi100 = new \app\common\model\Express($config['kuaidi100']);
+        // 请求订阅接口
+        $list = $Kuaidi100->dynamic($arg['name'],$arg['code'] ?? 1,$arg['no'],$arg['phone'] ?? '');
         return $this->renderSuccess(compact('list'));
     }
 
@@ -40,6 +56,7 @@ class Kuaidi extends Controller
      */
     public function callback(){
         $model = new KuaidiModel;
+        Log::info('callback:'.':'.json_encode($this->request->param()));
         if ($model->upd($this->request->param())) {
             return json([
                 "result"=>true,

+ 18 - 3
app/common/library/express/Kuaidi100.php

@@ -15,6 +15,7 @@ namespace app\common\library\express;
 use app\common\model\Kuaidi;
 use think\facade\Cache;
 use app\common\library\helper;
+use think\facade\Log;
 
 /**
  * 快递100API模块
@@ -45,27 +46,41 @@ class Kuaidi100
      * @param $expressNo
      * @return bool
      */
-    public function query($code, $expressNo)
+    public function query($code, $expressNo, $phone='')
     {
         // 缓存索引
         $cacheIndex = "express_{$code}_$expressNo";
         if ($data = Cache::instance()->get($cacheIndex)) {
             return $data;
         }
-        // 参数设置
+        $param = [
+            'resultv2' => '1',
+            'com' => $code,
+            'num' => $expressNo
+        ];
+        if (!empty($phone)){
+            $param['phone'] = $phone;
+        }
         $postData = [
             'customer' => $this->config['customer'],
+            'param' => helper::jsonEncode($param)
+        ];
+
+        // 参数设置
+/*        $postData = [
+            'customer' => $this->config['customer'],
             'param' => helper::jsonEncode([
                 'resultv2' => '1',
                 'com' => $code,
                 'num' => $expressNo
             ])
-        ];
+        ];*/
         $postData['sign'] = strtoupper(md5($postData['param'] . $this->config['key'] . $postData['customer']));
         // 请求快递100 api
         $url = 'http://poll.kuaidi100.com/poll/query.do';
         $result = curl_post($url, http_build_query($postData));
         $express = helper::jsonDecode($result);
+        Log::info('query:'.$expressNo.':'.json_encode($express));
         // 记录错误信息
         if (isset($express['returnCode']) || !isset($express['data'])) {
             $this->error = isset($express['message']) ? $express['message'] : '查询失败';

+ 4 - 2
app/common/model/Express.php

@@ -12,6 +12,7 @@ declare (strict_types = 1);
 
 namespace app\common\model;
 
+use app\api\controller\points\Log;
 use app\common\library\express\Kuaidi100;
 use app\common\model\store\Setting as SettingModel;
 use app\common\enum\Setting as SettingEnum;
@@ -96,7 +97,7 @@ class Express extends BaseModel
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function dynamic(string $expressName, string $expressCode, string $expressNo)
+    public function dynamic(string $expressName, string $expressCode, string $expressNo, $phone = '')
     {
         $data = [
             'express_name' => $expressName,
@@ -107,7 +108,7 @@ class Express extends BaseModel
         // 实例化快递100类
         $Kuaidi100 = new Kuaidi100($config);
         // 请求查询接口
-        $data['list'] = $Kuaidi100->query($expressCode, $expressNo);
+        $data['list'] = $Kuaidi100->query($expressCode, $expressNo,$phone);
         if ($data['list'] === false) {
             $this->error = $Kuaidi100->getError();
             return false;
@@ -140,6 +141,7 @@ class Express extends BaseModel
         $Kuaidi100 = new Kuaidi100($config);
         // 请求查询接口
         $data = $Kuaidi100->deliverylist($expressNo, $delivery_time, $type);
+        \think\facade\Log::info('delivery:'.$expressNo.':'.json_encode($data));
         if ($data === false) {
             $this->error = $Kuaidi100->getError();
             return false;