林琦海 5 years ago
parent
commit
cc742a9584

+ 45 - 0
app-ghs/controllers/NoticeController.php

@@ -2,6 +2,7 @@
 
 namespace ghs\controllers;
 
+use biz\express\classes\ExpressShanClass;
 use bizGhs\express\services\DadaExpressServices;
 use bizGhs\order\classes\OrderClass;
 use bizGhs\order\classes\OrderExpressClass;
@@ -9,6 +10,7 @@ use bizGhs\order\classes\OrderSendClass;
 use bizGhs\order\services\OrderService;
 use common\components\dict;
 use common\components\payUtil;
+use common\components\shans\shans;
 use Yii;
 use common\components\util;
 use biz\recharge\classes\RechargeClass;
@@ -221,4 +223,47 @@ class NoticeController extends PublicController
         echo "success";
         util::end();
     }
+
+    //闪送授权
+    public function shansAuth()
+    {
+        $get = Yii::$app->request->get();
+        $token = $get['token']??'';
+        if($token !== 'hhb-shans'){
+            util::end();
+        }
+        $url = shans::getAuthUrl(1);
+        $this->redirect($url);
+    }
+
+    //闪送开放者授权跳转
+    public function shansRedirect()
+    {
+        $get = Yii::$app->request->get();
+        Yii::info("get info". json_encode($get));
+        $code = $get['code']??'';
+        $thirdStoreId = $get['thirdStoreId']??0;
+        $state = $get['state']??0; //shopId
+        $data =[
+            'shopId'=>$state,
+            'thirdStoreId'=>$thirdStoreId
+        ];
+        if($code){
+            //获取token
+            $res = shans::getAccessToken($code);
+            $res = json_decode($res,true);
+            if(is_array($res) && $res['status']==200){
+                $accessToken = $res['data']['access_token']??'';
+                $refreshToken = $res['data']['refresh_token']??'';
+                $expiresIn = $res['data']['expires_in']??0;
+                $expiresIn = date('Y-m-d H:i:s',strtotime("+$expiresIn seconds"));
+                $data['accessToken'] = $accessToken;
+                $data['refreshToken'] = $refreshToken;
+                $data['expiresIn '] = $expiresIn;
+                ExpressShanClass::add($data);
+            }
+        }
+    }
+
+
 }

+ 37 - 0
biz/express/classes/ExpressShanClass.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace biz\express\classes;
+
+use biz\base\classes\BaseClass;
+use common\components\util;
+
+class ExpressShanClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\express\models\ExpressShan';
+
+    public static function getExpressAll($select='*',$where=[])
+    {
+        return self::getAllList($select,$where,'id asc','');
+    }
+
+    public static function getExpressInfo($id)
+    {
+        $data = self::checkExist($id);
+        if($data['status']!=1){
+            util::fail("快递已停用");
+        }
+        return $data;
+
+    }
+
+    public static function checkExist($id)
+    {
+        $res = self::getById($id);
+        if(!$res) {
+            util::fail('快递不存在');
+        }
+        return $res;
+    }
+
+}

+ 16 - 0
biz/express/models/ExpressShan.php

@@ -0,0 +1,16 @@
+<?php
+/**
+ * User: admin
+ * Date Time: 2021/6/2 21:44
+ */
+
+namespace biz\express\models;
+use biz\base\models\Base;
+//闪送
+class ExpressShan  extends Base
+{
+    public static function tableName()
+    {
+        return 'xhExpressShan';
+    }
+}

+ 68 - 0
common/components/shans/shans.php

@@ -0,0 +1,68 @@
+<?php
+/**
+ * User: admin
+ * Date Time: 2021/6/2 20:14
+ */
+
+namespace common\components\shans;
+
+use Yii;
+use linslin\yii2\curl;
+//闪送
+class shans
+{
+
+    public static function getAccessToken($code)
+    {
+        $url = self::getUrl();
+        $path = '/openapi/oauth/token';
+        $url = $url.$path;
+        $data = [
+            'clientId'=>self::getAppId(),
+            'code'=>$code,
+        ];
+        $res = self::request($data,$url);
+        return $res;
+    }
+
+    //获取授权跳转url
+    public static function getAuthUrl($shopId,$shansShopId = 751839)
+    {
+        $redirectUri = Yii::$app->params['ghsHost'].'/notice/shans-redirect';
+        $url = self::getUrl();
+        $path = '/auth?response_type=code&client_id='.self::getAppId().'&state='.$shopId;
+        $path = $path.'&scope=shop_open_api&thirdStoreId='.$shansShopId.'&&redirect_uri='.$redirectUri;
+        $url = $url.$path;
+        return $url;
+    }
+
+    public static function request($data,$url)
+    {
+        Yii::info("闪送请求:data ".json_encode($data). " url: " .$url);
+        $curl = new curl\Curl();
+        $curl->setOptions([
+            CURLOPT_TIMEOUT => 2,
+            CURLOPT_CONNECTTIMEOUT => 2,
+        ]);
+        $res = $curl->setOption(CURLOPT_POSTFIELDS, http_build_query($data))->post($url);
+        Yii::info("闪送请求:res ",$res);
+        return $res;
+    }
+
+    public static function getUrl()
+    {
+        return Yii::$app->params['expressShanUrl'];
+    }
+
+    public static function getAppId()
+    {
+        return Yii::$app->params['shanAppId'];
+    }
+
+    public static function getAppSecret()
+    {
+        return Yii::$app->params['shanAppSecret'];
+    }
+
+
+}

+ 11 - 0
common/config/params.php

@@ -54,6 +54,10 @@ $config = [
     'baiduAipAppKey' => 'WLp9xP7GG1FFSz6UNGaNeuSv',
     'baiduAipAppSecret' => '7gxpGeWzI2dpBVWbe8ffb11lvbtGfLOC',
 
+    //闪送开放者配置
+    'shanAppId'=>'sswoXlqJvk7Be9GN3',
+    'shanAppSecret'=>'mUa1uLQkybm6cGaUa4AW4krn4i5QROpD',
+
 ];
 
 $prefixHttp = 'http://';
@@ -93,6 +97,7 @@ if (getenv('YII_ENV') == 'local') {
 
     $config['ossBucket'] = 'pic-hhb-cs';
 
+    $config['expressShanUrl'] = 'http://open.s.bingex.com';
 }
 if (getenv('YII_ENV') == 'test') {
     $config['hdHost'] = $prefixHttp . 'api.shop.huaml.com';
@@ -115,6 +120,8 @@ if (getenv('YII_ENV') == 'test') {
 
     $config['ossBucket'] = 'pic-hhb-cs';
 
+    $config['expressShanUrl'] = 'http://open.s.bingex.com';
+
 }
 if (getenv('YII_ENV') == 'dev') {
     $config['hdHost'] = $prefixHttp . 'api.shop.huaml.com';
@@ -137,6 +144,8 @@ if (getenv('YII_ENV') == 'dev') {
 
     $config['ossBucket'] = 'pic-hhb-cs';
 
+    $config['expressShanUrl'] = 'http://open.s.bingex.com';
+
 }
 if (getenv('YII_ENV') == 'production') {
     $config['hdHost'] = $prefixHttp . 'api.shop.huahb.cn';
@@ -159,6 +168,8 @@ if (getenv('YII_ENV') == 'production') {
 
     $config['ossBucket'] = 'pic-hhb-online';
 
+    $config['expressShanUrl'] = 'http://open.ishansong.com';
+
 }
 
 return $config;