Quellcode durchsuchen

add:vivo用户绑定tag;

Wang Chen vor 4 Jahren
Ursprung
Commit
8036ab384f
2 geänderte Dateien mit 21 neuen und 36 gelöschten Zeilen
  1. 20 35
      app/Console/Commands/Push/PushTagBind.php
  2. 1 1
      app/Modules/Push/Models/QappPushUser.php

+ 20 - 35
app/Console/Commands/Push/PushTagBind.php

@@ -4,6 +4,7 @@ namespace App\Console\Commands\Push;
 
 
 use App\Consts\PushConst;
+use App\Libs\Push\VPush\VPush;
 use App\Libs\Push\OPPOPush\OPPOPushCommon;
 use App\Modules\Push\Services\PushAppService;
 use Illuminate\Console\Command;
@@ -15,7 +16,7 @@ class PushTagBind extends Command
      *
      * @var string
      */
-    protected $signature = 'push:tag:bind';
+    protected $signature = 'push:tag:bind {provider} {last_id}';
 
     /**
      * The console command description.
@@ -31,13 +32,13 @@ class PushTagBind extends Command
     {
         # 标签
         $tag      = PushConst::TOPIC_ALL;
-        $provider = 'oppo';
+        $provider = $this->argument('provider');
+        $id       = (int)$this->argument('last_id');
 
         # 获取所有oppo app,初始化推送
-        $apps    = PushAppService::getAppsByProvider($provider);
+        $apps = PushAppService::getAppsByProvider($provider);
 
         # 查询所有oppo用户
-        $id = 1991477;
         while (True) {
             var_dump('last id:'.$id);
 
@@ -49,20 +50,27 @@ class PushTagBind extends Command
 
             $groupUsers = collect($users)->groupBy('app_id')->all();
             foreach($groupUsers as $appId => $userList) {
-                $regIds = collect($userList)->pluck('reg_id')->all();
-                $app    = collect($apps)->firstWhere('app_id', $appId);
+                $regIds  = collect($userList)->pluck('reg_id')->all();
+                $pushApp = collect($apps)->firstWhere('app_id', $appId);
                 var_dump($appId, count($regIds));
 
                 // 初始化
-                $appKey       = getProp($app, 'app_key');
-                $masterSecret = getProp($app, 'master_secret');
-                $client       = new OPPOPushCommon($appKey, $masterSecret);
+                $appId        = getProp($pushApp, 'app_id');
+                $appSecret    = getProp($pushApp, 'app_secret');
+                $appKey       = getProp($pushApp, 'app_key');
+                $masterSecret = getProp($pushApp, 'master_secret');
 
                 // 循环绑定
-                if ($regIds && $client) {
-                    foreach($regIds as $regId) {
-                        $client->subscribeTags($regId, $tag);
+                if ($provider === PushConst::PROVIDER_OPPO) {
+                    $client = new OPPOPushCommon($appKey, $masterSecret);
+                    if ($regIds && $client) {
+                        foreach($regIds as $regId) {
+                            $client->subscribeTags($regId, $tag);
+                        }
                     }
+                }elseif ($provider === PushConst::PROVIDER_VIVO) {
+                    $client = new VPush($appId, $appKey, $appSecret);
+                    $client->addTagForUsers($tag, $regIds);
                 }
             }
 
@@ -73,27 +81,4 @@ class PushTagBind extends Command
         }
     }
 
-    /**
-     * 初始化推送实例
-     *
-     * @param [type] $apps
-     * @return void
-     */
-    private function initCients($apps)
-    {
-        if(empty($apps)) {
-            return [];
-        }
-
-        $clients = [];
-        foreach($apps as $app) {
-            $appId           = getProp($app, 'app_id');
-            $appKey          = getProp($app, 'app_key');
-            $masterSecret    = getProp($app, 'master_secret');
-            $clients[$appId] = new OPPOPushCommon($appKey, $masterSecret);
-        }
-
-        return $clients;
-    }
-
 }

+ 1 - 1
app/Modules/Push/Models/QappPushUser.php

@@ -44,7 +44,7 @@ class QappPushUser extends Model
             return [];
         }
 
-        $result = self::where('id', '<', $id)->where('provider', $provider)->orderBy('id', 'desc')->limit(5000)->get();
+        $result = self::where('id', '<', $id)->where('provider', $provider)->orderBy('id', 'desc')->limit(1000)->get();
         return $result ? $result->toArray() : [];
     }