Ver código fonte

fix yii2 bug: in console, not exist getAbsoluteUrl function

shizhongqi 4 anos atrás
pai
commit
3f7a108cd7

+ 1 - 75
common/components/pushNotice.php

@@ -28,9 +28,6 @@ class pushNotice
     const appId = 'YjALucIHmI7DylcjlMZEx2';
     const masterSecret = 'zSbdBLOQrxAa5IcDNqIne7';
 
-    //版本2:个推开放平台接口前缀(BaseUrl): https://restapi.getui.com/v2/$appId
-    const baseUrl = 'https://restapi.getui.com/v2';
-
     public static function push($adminId, $cId, $title, $body)
     {
         $notify = new GTNotification();
@@ -168,7 +165,7 @@ class pushNotice
         $push->setPushChannel($pushChannel);
 
 
-        //创建API,APPID等配置参考 环境要求 进行获取
+        //创建API,APPID等配置
         $api = new GTClient(self::domainUrl, self::appKey, self::appId, self::masterSecret);
         //处理返回结果
         $result = $api->pushApi()->pushToSingleByCid($push);
@@ -181,75 +178,4 @@ class pushNotice
         $time = ($sec . substr($usec, 2, 3));
         return $time;
     }
-
-    // 执行cid单推
-    public static function newPush($cId, $title, $body)
-    {
-        $bodyArr['title'] = $title;
-        $bodyArr['body'] = $body;
-        $bodyArr['click_type'] = 'startapp';
-
-        $token = Yii::$app->redis->executeCommand('GET', ['getui_token']);
-
-        if (empty($token)) {
-            $token = self::getToken();
-            if ($token == "") {
-                Yii::error('generate getui token fail');
-                return;
-            }
-            Yii::$app->redis->executeCommand('SET', ['getui_token', $token, 'EX', 86400]);
-        }
-
-        $client = new Client([
-            'base_uri' => self::baseUrl,
-            'timeout'  => 5.0,
-        ]);
-
-        try {
-            $response = $client->request('POST', self::baseUrl . '/push/single/cid', [
-                'form_params' => [
-                    'request_id' => time(),
-                    'settings' => ['ttl' => 86400000],
-                    'audience' => [
-                        'cid' => $cId,
-                    ],
-                    'push_message' => [
-                        'notification' => $bodyArr
-                    ],
-                    'headers' => [
-                        'token' => $token
-                    ]
-                ]
-            ]);
-        } catch (GuzzleException $e) {
-            Yii::error('push/single/cid: ' . $e->getMessage());
-        }
-
-        // 失败,则生重新获取 token ,再发送
-    }
-
-    public static function getToken()
-    {
-        $i = 0;
-        do{
-            $client = new Client([
-                'base_uri' => self::baseUrl,
-                'timeout' => 5.0
-            ]);
-            $response = $client->request('POST', self::baseUrl . '/auth', [
-                'form_params' => [
-                    "sign" => hash('sha256', self::appKey . time() . self::masterSecret),
-                    "timestamp" => round(microtime(true) * 1000),
-                    "appkey" => self::appKey
-                ]
-            ]);
-            $data = json_decode($response, true);
-        }while(!isset($data['data']['token']) && $i++ < 3);
-
-        if ($i > 3) {
-            return "";
-        }
-
-        return $data['data']['token'];
-    }
 }

+ 2 - 2
console/controllers/ItemController.php

@@ -474,7 +474,7 @@ class ItemController extends Controller
     public function actionTestGt()
     {
         Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs'); //指定当前环境为批发商
-        pushNotice::nPush('07307c3fd79969d983db648de9b3bb11', '新客户加入', '测试内容体111');
-        pushNotice::nPush('114c4e00a2ccdb60080c270d14ad3705', '新客户加入', '测试内容体222');
+        pushNotice::gtPush('07307c3fd79969d983db648de9b3bb11', '新客户加入', '测试内容体111');
+        pushNotice::gtPush('114c4e00a2ccdb60080c270d14ad3705', '新客户加入', '测试内容体222');
     }
 }

+ 17 - 7
vendor/yiisoft/yii2-debug/LogTarget.php

@@ -157,16 +157,26 @@ class LogTarget extends Target
 
         $request = Yii::$app->getRequest();
         $response = Yii::$app->getResponse();
-        $summary = [
+
+        // are we working from the console?
+        if (! method_exists($request, "getAbsoluteUrl")) {
+            $summary = [
             'tag' => $this->tag,
-            'url' => $request->getAbsoluteUrl(),
-            'ajax' => (int) $request->getIsAjax(),
-            'method' => $request->getMethod(),
-            'ip' => $request->getUserIP(),
             'time' => $_SERVER['REQUEST_TIME_FLOAT'],
-            'statusCode' => $response->statusCode,
             'sqlCount' => $this->getSqlTotalCount(),
-        ];
+            ];
+        } else {
+            $summary = [
+                'tag' => $this->tag,
+                'url' => $request->getAbsoluteUrl(),
+                'ajax' => (int) $request->getIsAjax(),
+                'method' => $request->getMethod(),
+                'ip' => $request->getUserIP(),
+                'time' => $_SERVER['REQUEST_TIME_FLOAT'],
+                'statusCode' => $response->statusCode,
+                'sqlCount' => $this->getSqlTotalCount(),
+            ];
+        }
 
         if (isset($this->module->panels['mail'])) {
             $summary['mailCount'] = count($this->module->panels['mail']->getMessages());