Browse Source

修复vivo添加标签用户报错

zqwang 2 years ago
parent
commit
9422360672
2 changed files with 23 additions and 15 deletions
  1. 3 1
      app/Http/Controllers/QuickApp/HuaWeiController.php
  2. 20 14
      app/Libs/Push/VPush/VPush.php

+ 3 - 1
app/Http/Controllers/QuickApp/HuaWeiController.php

@@ -12,6 +12,8 @@ namespace App\Http\Controllers\QuickApp;
 
 use App\Http\Controllers\Controller;
 
+use App\Libs\Push\VPush\VPush;
+use App\Modules\Push\Models\QappPushApp;
 use App\Modules\Subscribe\Services\ChapterOrderService;
 use App\Modules\User\Services\ReadRecordService;
 use Illuminate\Support\Facades\DB;
@@ -21,7 +23,7 @@ class HuaWeiController extends  Controller
 
     public function index(){
 
-
+ 
 
     }
 

+ 20 - 14
app/Libs/Push/VPush/VPush.php

@@ -229,7 +229,9 @@ class VPush
         if (empty($tag) || empty($regIds)) {
             return false;
         }
-
+        if (!is_array($regIds)){
+            $regIds = [$regIds];
+        }
         // token授权
         $this->getAccessToken();
 
@@ -335,20 +337,24 @@ class VPush
         // 组装请求数据
         $authToken = $this->_accessToken;
         $option    = ['json' => $sendData];
-
-        // 请求
-        $client = new Client(['timeout' => 5.0, 'headers' => ['authToken' => $authToken]]);
-        if ($method === 'POST') {
-            $response = $client->request('POST', $url, $option);
-        } else {
-            $response = $client->request('GET', $url);
+        try {
+
+            // 请求
+            $client = new Client(['timeout' => 5.0, 'headers' => ['authToken' => $authToken]]);
+            if ($method === 'POST') {
+                $response = $client->request('POST', $url, $option);
+            } else {
+                $response = $client->request('GET', $url);
+            }
+
+            $body   = $response->getBody()->__toString();
+            $result = json_decode($body, true);
+            myLog('push')->info('[VIVO] getDataByInfo', compact('url', 'option', 'authToken', 'result'));
+            return $result;
+        }catch (\Exception $exception){
+            myLog('vivo-push-erro')->info('[VIVO] getDataByInfo', compact('url', 'option', 'authToken', 'result'));
+            return [];
         }
-
-        $body   = $response->getBody()->__toString();
-        $result = json_decode($body, true);
-
-        myLog('push')->info('[VIVO] getDataByInfo', compact('url', 'option', 'authToken', 'result'));
-        return $result;
     }
 }