Преглед изворни кода

Merge branch 'kuaiyingyong' of iqiyoo:zhuishuyun_wap into kuaiyingyong

zz пре 4 година
родитељ
комит
b241c4a3be

+ 106 - 0
app/Console/Commands/Push/PushTag.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 Illuminate\Console\Command;
+
+class PushTag extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'push:tag {uid}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '推送标签';
+
+    /**
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public function handle()
+    {
+        // 用户Uid
+        $uid = $this->argument('uid');
+        
+        // 获取用户push信息
+        $pushUser     = QappPushUser::getPushUserByUid($uid);
+        $regId        = getProp($pushUser, 'reg_id');
+        $pushAppId    = getProp($pushUser, 'app_id');
+        $pushApp      = QappPushApp::getPushAppByAppId($pushAppId);
+        $package      = getProp($pushApp, 'package');
+        $appId        = getProp($pushApp, 'app_id');
+        $provider     = getProp($pushApp, 'provider');
+        $appSecret    = getProp($pushApp, 'app_secret');
+        $appKey       = getProp($pushApp, 'app_key');
+        $masterSecret = getProp($pushApp, 'master_secret');
+
+        switch ($provider) {
+            // 华为
+            case PushConst::PROVIDER_HW:
+                // 初始化huawei推送
+                $client = new HwPushCommon($appId, $appSecret);
+
+                // 循环推送
+                // $client->setToken($regIdList);
+                // $client->setFastAppTarget(1);
+                // $result = $client->sendPushMessage($title, $content, $url);
+                break;
+            // 小米
+            case PushConst::PROVIDER_MI:
+                // 初始化小米推送
+                $client = new MiPushCommon($package, $appSecret);
+
+                // 循环推送
+                // $client->setRegArr($regIdList);
+                // $result = $client->sendMessage($title, $content, $url);
+                break;
+            // OPPO
+            case PushConst::PROVIDER_OPPO:
+                // 初始化oppo推送
+                $client = new OPPOPushCommon($appKey, $masterSecret);
+
+                # 获取全部tag
+                $tags   = $client->getAllTags($regId);
+
+                // # 创建tag
+                $tag = PushConst::TOPIC_ALL;
+                // $client->addTags(PushConst::TOPIC_ALL, '全部用户');
+
+                $client->subscribeTags($regId, $tag);
+
+                // # 获取全部tag
+                $tags2 = $client->getAllTags($regId);
+
+                dd($tags, $tags2);
+                break;
+            // VIVO
+            case PushConst::PROVIDER_VIVO:
+                // 初始化oppo推送
+                $client = new VPush($appId, $appKey, $appSecret);
+
+                // 设置相关推送数据,保存消息内容(批量推送至少需要两个用户,故写死一个reg_id)
+                // $regIdList[] = '16004127020450881896432';
+                // $client->setPushData($title, $content, $url, $regIdList);
+                // $client->saveListPayload();
+
+                // // 循环推送
+                // $result = $client->sendMessage();
+                break;
+        }
+    }
+}

+ 3 - 3
app/Console/Kernel.php

@@ -2,10 +2,9 @@
 
 namespace App\Console;
 
-use App\Console\Commands\Push\HwPushTest;
-use App\Console\Commands\Push\MiPushTest;
-use App\Console\Commands\Push\OppoPushTest;
+
 use App\Console\Commands\Push\PushStats;
+use App\Console\Commands\Push\PushTag;
 use App\Console\Commands\Push\PushTask;
 use App\Console\Commands\Push\PushTest;
 use Illuminate\Console\Scheduling\Schedule;
@@ -22,6 +21,7 @@ class Kernel extends ConsoleKernel
         PushStats::class,
         PushTest::class,
         PushTask::class,
+        PushTag::class,
         Commands\Activity\ActivityStats::class,
         Commands\BookAdjust::class,
         Commands\BookAdjustOne::class,

+ 5 - 0
app/Consts/PushConst.php

@@ -27,6 +27,11 @@ class PushConst
     const FILTER_ALL_USERS = 'all';
 
     /**
+     * 全量用户
+     */
+    const FILTER_ALL_SUB_USERS = 'sub-all';
+
+    /**
      * 华为服务商
      */
     const PROVIDER_HW = 'huawei';

+ 5 - 1
app/Modules/Push/Services/PushService.php

@@ -150,7 +150,8 @@ class PushService
         QappPushTask::updateMainTaskStatus($taskId, PushConst::STATUS_DOING, '无有效推送APP');
 
         // 全量发送走标签,否则走批量
-        if (getProp($pushTask, 'push_filter') === PushConst::FILTER_ALL_USERS) {
+        $pushFilter = getProp($pushTask, 'push_filter');
+        if (in_array($pushFilter, [PushConst::FILTER_ALL_USERS, PushConst::FILTER_ALL_SUB_USERS])) {
             $result = self::pushMessageToAll($pushTask, $subTasks, $pushApps);
         } else {
             $result = self::pushMessageToUsers($pushTask, $subTasks, $pushApps);
@@ -182,6 +183,7 @@ class PushService
         $title      = getProp($pushTask, 'title');
         $content    = getProp($pushTask, 'content');
         $url        = getProp($pushTask, 'url');
+        myLog('push')->info('1', compact('title', 'content'));
 
         // 循环群发
         foreach ($subTasks as $subTask) {
@@ -242,6 +244,8 @@ class PushService
                         break;
                 }
             } catch (Exception $e) {
+                myLog('push')->info('pushMessageToAll', [$provider, $result, $e->getMessage()]);
+
                 // 最终结果
                 $pushResult = 0 && $pushResult;