Преглед на файлове

add:oppo用户绑定tag;

Wang Chen преди 4 години
родител
ревизия
9b15b6af58

+ 106 - 0
app/Console/Commands/Push/PushTagBind.php

@@ -0,0 +1,106 @@
+<?php
+
+namespace App\Console\Commands\Push;
+
+
+use App\Consts\PushConst;
+use App\Libs\Push\HuaWei\HwPushCommon;
+use App\Libs\Push\OPPOPush\OPPOPushCommon;
+use App\Libs\Push\VPush\VPush;
+use App\Libs\Push\XMPush\MiPushCommon;
+use App\Modules\Push\Models\QappPushApp;
+use App\Modules\Push\Models\QappPushUser;
+use App\Modules\Push\Services\PushAppService;
+use Illuminate\Console\Command;
+use phpDocumentor\Reflection\Types\True_;
+
+class PushTagBind extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'push:tag:bind';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '推送标签绑定';
+
+    /**
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public function handle()
+    {
+        # 标签
+        $tag      = PushConst::TOPIC_ALL;
+        $provider = 'oppo';
+
+        # 获取所有oppo app,初始化推送
+        $apps    = PushAppService::getAppsByProvider($provider);
+        $clients = $this->initCients($apps);
+
+        # 查询所有oppo用户
+        $id = 0;
+        while (True) {
+            var_dump('last id:'.$id);
+
+            # 获取用户列表
+            $users = PushAppService::getAppUsersByProvider($provider, $id);
+            if (empty($users)) {
+                break;
+            }
+
+            # 循环绑定tag
+            foreach($users as $user) {
+                $regId  = getProp($user, 'reg_id');
+                $appId  = getProp($user, 'app_id');
+                $client = getProp($clients, $appId);
+                if (empty($client)) {
+                    continue;
+                }
+
+                // $client->subscribeTags($regId, $tag);
+                var_dump(getProp($user, 'uid'), $regId, getProp($user, 'provider'));
+            }
+
+            # 分页id
+            $len = count($users);
+            $id  = $users[$len - 1]['id'];
+            var_dump('next id:'.$id);
+
+            break;
+        }
+    }
+
+    /**
+     * 初始化推送实例
+     *
+     * @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;
+    }
+
+    private function buildOppoPushTag($regId)
+    {
+        # code...
+    }
+}

+ 2 - 0
app/Console/Kernel.php

@@ -5,6 +5,7 @@ namespace App\Console;
 
 use App\Console\Commands\Push\PushStats;
 use App\Console\Commands\Push\PushTag;
+use App\Console\Commands\Push\PushTagBind;
 use App\Console\Commands\Push\PushTask;
 use App\Console\Commands\Push\PushTest;
 use Illuminate\Console\Scheduling\Schedule;
@@ -22,6 +23,7 @@ class Kernel extends ConsoleKernel
         PushTest::class,
         PushTask::class,
         PushTag::class,
+        PushTagBind::class,
         Commands\Activity\ActivityStats::class,
         Commands\BookAdjust::class,
         Commands\BookAdjustOne::class,

+ 14 - 0
app/Modules/Push/Models/QappPushApp.php

@@ -77,4 +77,18 @@ class QappPushApp extends Model
         $result = self::whereIn('app_id', $appIds)->where('status', PushConst::APP_WORKING)->get();
         return $result ? $result->toArray() : [];
     }
+
+    /**
+     * @param $provider
+     * @return array
+     */
+    public static function getPushAppsByProvider($provider): array
+    {
+        if (empty($provider)) {
+            return [];
+        }
+
+        $result = self::where('provider', $provider)->get();
+        return $result ? $result->toArray() : [];
+    }
 }

+ 10 - 0
app/Modules/Push/Models/QappPushUser.php

@@ -38,6 +38,16 @@ class QappPushUser extends Model
         return $result ? $result->toArray() : [];
     }
 
+    public static function getPushUsersByProvider($provider, $id = 0): array
+    {
+        if (empty($provider)) {
+            return [];
+        }
+
+        $result = self::where('id', '>', $id)->where('provider', $provider)->orderBy('id', 'asc')->limit(5000)->get();
+        return $result ? $result->toArray() : [];
+    }
+
     /**
      * @param $uid
      * @param $regId

+ 34 - 0
app/Modules/Push/Services/PushAppService.php

@@ -0,0 +1,34 @@
+<?php
+
+
+namespace App\Modules\Push\Services;
+
+
+use App\Modules\Push\Models\QappPushApp;
+use App\Modules\Push\Models\QappPushUser;
+
+class PushAppService
+{
+    /**
+     * 获取apps
+     * @param $provider
+     * @return array
+     */
+    public static function getAppsByProvider($provider): array
+    {
+        if (empty($provider)) {
+            return [];
+        }
+
+        return QappPushApp::getPushAppsByProvider($provider);
+    }
+
+    public static function getAppUsersByProvider($provider, $id = 0)
+    {
+        if (empty($provider)) {
+            return [];
+        }
+
+        return QappPushUser::getPushUsersByProvider($provider, $id);
+    }
+}