Ver Fonte

add:oppo全量推送;

Wang Chen há 4 anos atrás
pai
commit
21432955d4

+ 32 - 3
app/Libs/Push/OPPOPush/OPPOPushCommon.php

@@ -41,12 +41,13 @@ class OPPOPushCommon
     /**
      * 全部推送
      * @param $messageId
+     * @param $tag
      * @return mixed
      * @throws GuzzleException
      */
-    public function broadCastAll($messageId)
+    public function broadCastAll($messageId, $tag)
     {
-        return $this->broadCast(1, $messageId);
+        return $this->broadCast(6, $messageId, $tag);
     }
 
     /**
@@ -278,10 +279,11 @@ class OPPOPushCommon
      * 广播推送-通知栏消息
      * @param       $targetType
      * @param       $messageId
+     * @param       $tag
      * @return mixed
      * @throws GuzzleException
      */
-    private function broadCast($targetType, $messageId)
+    private function broadCast($targetType, $messageId, $tag = '')
     {
         $param = [
             'auth_token'  => $this->_authToken,
@@ -294,6 +296,11 @@ class OPPOPushCommon
             $param['target_value'] = implode(';', $this->_reg_arr);
         }
 
+        // 按标签推送
+        if ((int)$targetType === 6 && $tag) {
+            $param['target_value'] = $this->buildTag($tag);
+        }
+
         // 请求数据
         $data = [
             'form_params' => $param
@@ -309,6 +316,28 @@ class OPPOPushCommon
         return $result;
     }
 
+    /**
+     * 标签表达式
+     *
+     * @param [type] $tag
+     * @return void
+     */
+    private function buildTag($tag)
+    {
+
+        $data = [
+            'or'  => [],
+            'and' => [],
+            'not' => []
+        ];
+
+        if ($tag) {
+            $data['or'][] = $tag;
+        }
+
+        return json_encode($data);
+    }
+
     private function logPush($className, $message, $data = [])
     {
         var_dump('[' . $className . '] ' . $message, $data);

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

@@ -92,6 +92,14 @@ class PushService
                 $client = new HwPushCommon($pushAppId, getProp($pushApp, 'app_secret'));
                 $client->subscribeTopic(PushConst::TOPIC_ALL, [$regId]);
             }
+
+            // 针对OPPO用户需要主动订阅topic,方便后续全量推送
+            if ($provider === PushConst::PROVIDER_OPPO) {
+                $appKey       = getProp($pushApp, 'app_key');
+                $masterSecret = getProp($pushApp, 'master_secret');
+                $client       = new OPPOPushCommon($appKey, $masterSecret);
+                $client->subscribeTags($regId, PushConst::TOPIC_ALL);
+            }
         }
 
         // 更新用户数据库中reg_id
@@ -211,7 +219,7 @@ class PushService
             try {
                 // 针对渠道做不同处理
                 switch ($provider) {
-                        // 华为
+                    // 华为
                     case PushConst::PROVIDER_HW:
                         // 开发状态还是生产状态
                         $target = env('APP_ENV') === 'production' ? 2 : 1;
@@ -225,18 +233,18 @@ class PushService
                         // 推送
                         $result = $client->sendPushMessage($title, $content, $url);
                         break;
-                        // 小米
+                    // 小米
                     case PushConst::PROVIDER_MI:
                         $client = new MiPushCommon($package, $appSecret);
                         $result = $client->sendMessageToAll($title, $content, $url);
                         break;
-                        // OPPO
+                    // OPPO
                     case PushConst::PROVIDER_OPPO:
                         $client    = new OPPOPushCommon($appKey, $masterSecret);
                         $messageId = $client->getMessageId($title, $content, $url);
-                        $result    = $client->broadCastAll($messageId);
+                        $result    = $client->broadCastAll($messageId, $topic);
                         break;
-                        // VIVO
+                    // VIVO
                     case PushConst::PROVIDER_VIVO:
                         $client = new VPush($appId, $appKey, $appSecret);
                         $client->setPushData($title, $content, $url);