Explorar el Código

修改保存安卓clientId

shish hace 4 años
padre
commit
f216a61ca0

+ 13 - 0
app-ghs/controllers/AdminController.php

@@ -16,6 +16,19 @@ class AdminController extends BaseController
 
     public $guestAccess = ['recent-shop', 'mini-full-info', 'mini-mobile', 'login-detail'];
 
+    //修改保存安卓clientId
+    public function actionReplaceClientId()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? '';
+        if (empty($id)) {
+            util::success(['returnStatus' => 'FAILURE']);
+        }
+        $this->admin->clientId = $id;
+        $this->admin->save();
+        util::complete();
+    }
+
     //修改密码 shish 20220106
     public function actionModifyPassword()
     {

+ 40 - 0
common/components/pushNotice.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace common\components;
+
+class pushNotice
+{
+
+    const domainUrl = 'https://restapi.getui.com';
+    const appKey = 'uC5ZdrWSV48cLRBJWMSId9';
+    const appId = 'YjALucIHmI7DylcjlMZEx2';
+    const masterSecret = 'zSbdBLOQrxAa5IcDNqIne7';
+
+    public static function push($cId, $title, $body)
+    {
+        //创建API,APPID等配置参考 环境要求 进行获取
+        $api = new \GTClient(self::domainUrl, self::appKey, self::appId, self::masterSecret);
+        //设置推送参数
+        $push = new \GTPushRequest();
+        $push->setRequestId("1100000000000049");
+        $message = new \GTPushMessage();
+        $notify = new \GTNotification();
+        $notify->setTitle($title);
+        $notify->setBody($body);
+        //点击通知后续动作,目前支持以下后续动作:
+        //1、intent:打开应用内特定页面url:打开网页地址。2、payload:自定义消息内容启动应用。3、payload_custom:自定义消息内容不启动应用。4、startapp:打开应用首页。5、none:纯通知,无后续动作
+        $notify->setClickType("startapp");
+
+        //保证有振动
+        $notify->setChannelId('channelId1');
+        $notify->setChannelName('channelName1');
+        $notify->setChannelLevel(4);
+
+        $message->setNotification($notify);
+        $push->setPushMessage($message);
+        //客户ID
+        $push->setCid($cId);
+        $api->pushApi()->pushToSingleByCid($push);
+    }
+
+}

+ 30 - 2
vendor/getuilaboratory/getui-pushapi-php-client-v2/GTClient.php

@@ -92,7 +92,7 @@ class GTClient
         try {
             $this->auth();
         } catch (Exception $e) {
-            echo  $e->getMessage();
+            echo $e->getMessage();
         }
     }
 
@@ -139,6 +139,23 @@ class GTClient
 
     public function auth()
     {
+        $ptStyle = Yii::$app->params['ptStyle'];
+        if (is_numeric($ptStyle) == false) {
+            \common\components\util::fail('个推所属平台未明确');
+        }
+        $open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => $ptStyle], true);
+        if (empty($open)) {
+            \common\components\util::fail('个推所属平台没有找到');
+        }
+        $expireDate = $open->gtTokenDeadTime ?? '';
+        $current = date("Y-m-d H:i:s");
+        if ($current < $expireDate) {
+            $token = $open->gtToken ?? '';
+            $this->authToken = $token;
+            \common\components\noticeUtil::push("从数据库获取个推token", '15280215347');
+            return true;
+        }
+
         $auth = new GTAuthRequest();
         $auth->setAppkey($this->appkey);
         $timeStamp = $this->getMicroTime();
@@ -147,7 +164,18 @@ class GTClient
         $auth->setTimestamp($timeStamp);
         $rep = $this->userApi()->auth($auth);
         if ($rep["code"] == 0) {
-            $this->authToken = $rep["data"]["token"];
+            $token = $rep["data"]["token"] ?? '';
+            $expireTime = $rep["data"]["expire_time"] ?? '';
+            $expireTime = bcdiv($expireTime, 1000);
+            $expireTime = bcsub($expireTime, 3600);
+            $expireDate = date("Y-m-d H:i:s", $expireTime);
+            $open->gtToken = $token;
+            $open->gtTokenDeadTime = $expireDate;
+            $open->save();
+
+            \common\components\noticeUtil::push("从接口获取个推token", '15280215347');
+
+            $this->authToken = $token;
             return true;
         }
         return false;