瀏覽代碼

Merge branch 'kuaiyingyong' into quickapp_fly

fly 4 年之前
父節點
當前提交
227ebf080d

+ 7 - 4
app/Console/Commands/Push/PushTest.php

@@ -20,7 +20,7 @@ class PushTest extends Command
      *
      * @var string
      */
-    protected $signature = 'push:test {uid}';
+    protected $signature = 'push:test {uid} {url}';
 
     /**
      * The console command description.
@@ -36,6 +36,7 @@ class PushTest extends Command
     {
         // 用户Uid
         $uid = $this->argument('uid');
+        $url = $this->argument('url');
 
         // 获取用户push信息
         $pushUser  = QappPushUser::getPushUserByUid($uid);
@@ -64,11 +65,13 @@ class PushTest extends Command
 
         $title   = '这是' . $name . '标题';
         $content = '这是' . $name . '内容,创建于' . date('Y-m-d H:i:s');
-        $url     = 'hap://app/com.app.kyy.xnyd/views/Reader?send_order_id=1643289&bid=vdqY7p15xnZQzK4VzzgmMD6wG2yr8BNX&chapter_id=4774851';
+        $url     = $url ?: '/views/Reader';
+        $params  = ['send_order_id' => 1643289, 'bid' => 'vdqY7p15xnZQzK4VzzgmMD6wG2yr8BNX', 'chapter_id' => 4774851];
         var_dump('uid:' . $uid);
         var_dump('title:' . $title);
         var_dump('content:' . $content);
         var_dump('url:' . $url);
+        var_dump('params:' . json_encode($params));
         var_dump('reg id:' . $regId);
 
         $result = [];
@@ -81,7 +84,7 @@ class PushTest extends Command
 
                     // 循环推送
                     $client->setToken($regIdList);
-                    $result = $client->sendPushMessage($title, $content, $url);
+                    $result = $client->sendPushMessage($title, $content, $url, $params);
                     break;
                 // 小米
                 case PushConst::PROVIDER_MI:
@@ -96,7 +99,7 @@ class PushTest extends Command
                 case PushConst::PROVIDER_OPPO:
                     // 初始化oppo推送
                     $client    = new OPPOPushCommon($appKey, $masterSecret);
-                    $messageId = $client->getMessageId($title, $content, $url);
+                    $messageId = $client->getMessageId($title, $content, $url, $params);
 
                     // 循环推送
                     $client->setRegArr($regIdList);

+ 10 - 2
app/Http/Controllers/QuickApp/Book/ChapterController.php

@@ -26,6 +26,8 @@ use App\Modules\UserTask\Services\UserTaskService;
 class ChapterController extends BaseController
 {
 
+    private $book_info;
+
     /**
      * @apiDefine Chapter 章节
      */
@@ -260,6 +262,7 @@ class ChapterController extends BaseController
         $book_info  = BookConfigService::getBookById($bid);
         if (empty($book_info))
             return response()->error('QAPP_SYS_ERROR');
+        $this->book_info = $book_info;
         //获取章节信息
         $chapter = ChapterService::getChapterNameById($cid, $bid);
         if (!$chapter) {
@@ -693,10 +696,15 @@ class ChapterController extends BaseController
         if(!$send_order_id) return $force_add_desk_type;
         $send_order_info = SendOrderService::getById($send_order_id);
         if(!$send_order_info)  return $force_add_desk_type;
-        if($send_order_info->book_id == $bid && $send_order_info->force_add_desk_type && $send_order_info->force_add_desk_seq){
-            if($sequence >= $send_order_info->force_add_desk_seq){
+        if($send_order_info->book_id == $bid){
+            if($send_order_info->force_add_desk_type == 1 && $send_order_info->force_add_desk_type){
                 $force_add_desk_type = $send_order_info->force_add_desk_type;
             }
+            if($send_order_info->force_add_desk_type == 2){
+                if($sequence >= $this->book_info->force_subscribe_chapter_seq && $sequence<= $this->book_info->force_subscribe_chapter_seq+3){
+                    $force_add_desk_type = $send_order_info->force_add_desk_type;
+                }
+            }
         }
         return $force_add_desk_type;
     }

+ 7 - 6
app/Libs/Push/HuaWei/HwPushCommon.php

@@ -71,15 +71,16 @@ class HwPushCommon
 
     /**
      * 发送通知消息
-     * @param $title
-     * @param $desc
-     * @param $pageUrl
-     * @return mixed|null
+     * @param       $title
+     * @param       $desc
+     * @param       $pageUrl
+     * @param array $params
+     * @return bool|mixed|string|null
      */
-    public function sendPushMessage($title, $desc, $pageUrl)
+    public function sendPushMessage($title, $desc, $pageUrl, $params = [])
     {
         // 组装发送数据
-        $data    = $this->createFastAppConfigNotificationData($title, $desc, $pageUrl);
+        $data    = $this->createFastAppConfigNotificationData($title, $desc, $pageUrl, 0, $params);
         $message = $this->createFastAppMsg($data->getFields());
 
         # 创建app

+ 12 - 8
app/Libs/Push/OPPOPush/OPPOPushCommon.php

@@ -46,7 +46,7 @@ class OPPOPushCommon
      */
     public function broadCastAll($messageId)
     {
-        return $this->broadCast('all', $messageId);
+        return $this->broadCast(1, $messageId);
     }
 
     /**
@@ -62,21 +62,25 @@ class OPPOPushCommon
 
     /**
      * 保存通知栏消息内容体
-     * @param $title
-     * @param $content
-     * @param $url
+     * @param       $title
+     * @param       $content
+     * @param       $url
+     * @param array $params
      * @return mixed|string
      * @throws GuzzleException
      */
-    public function getMessageId($title, $content, $url)
+    public function getMessageId($title, $content, $url, $params = [])
     {
         // 组装数据
         $pushMessage = new PushMessage();
-        $pushMessage->style(1);
+        $pushMessage->style(1); // 通知栏样式,1. 标准样式
         $pushMessage->title($title);
         $pushMessage->content($content);
-        $pushMessage->click_action_type(1);
-        $pushMessage->click_action_activity($url);
+        $pushMessage->click_action_type(1); // 点击动作类型0,启动应用;1,打开应用内页
+        $pushMessage->click_action_activity('com.nearme.instant.action.PUSH');
+        $pushMessage->action_parameters(json_encode([
+            'page' => $url,
+        ]));
         $pushMessage->channel_id('OPPO PUSH');
         $pushMessage->auth_token($this->_authToken);
         $fields = $pushMessage->getData();

+ 1 - 0
app/Libs/Push/XMPush/MiPushCommon.php

@@ -77,6 +77,7 @@ class MiPushCommon
         $message->extra(Builder::intentUri, $url); // 此处设置预定义点击行为,1为打开app
         $message->extra(Builder::notifyEffect, 2); // 此处设置预定义点击行为,1为打开app 2通知栏点击后打开app的任一Activity
         $message->extra(Builder::notifyForeground, 1); // 应用在前台是否展示通知,如果不希望应用在前台时候弹出通知,则设置这个参数为0
+        $message->extra(Builder::flowControl, 3000); // 设置平滑推送, 推送速度3000每秒(qps=3000)
         $message->notifyId(2); // 通知类型。最多支持0-4 5个取值范围,同样的类型的通知会互相覆盖,不同类型可以在通知栏并存
         $message->build();
         return $message;

+ 23 - 3
app/Modules/Push/Services/PushService.php

@@ -30,14 +30,14 @@ class PushService
      */
     public static function setUserRegId($uid, string $regId, string $provider, string $package): bool
     {
-        myLog('push')->info('setUserRegId', compact('uid', 'regId', 'provider', 'package'));
-
         // push服务商(转小写)
         $provider = strtolower($provider);
-        if (empty($uid) || empty($regId) || empty($package) || empty($provider)) {
+        if (empty($uid) || empty($regId) || empty($package) || empty($provider) || $package !== 'com.app.kyy.xnyd') {
             return false;
         }
 
+        myLog('push')->info('setUserRegId', compact('uid', 'regId', 'provider', 'package'));
+
         // 获取缓存
         $userCacheRegId = PushCache::getUserPushRegId($uid);
         if ($regId === $userCacheRegId) {
@@ -288,9 +288,16 @@ class PushService
                         $client = new HwPushCommon($appId, $appSecret);
 
                         // 循环推送
+                        $i = 0;
                         foreach ($regIdArr as $regIdList) {
                             $client->setToken($regIdList);
                             $result = $client->sendPushMessage($title, $content, $url);
+
+                            // 一般的应用默认消息流控是针对单个应用3000QPS(每秒不能超过3000个token数)
+                            $i++;
+                            if ($i % 3 === 0) {
+                                sleep(1);
+                            }
                         }
                         break;
                     // 小米
@@ -299,9 +306,16 @@ class PushService
                         $client = new MiPushCommon($package, $appSecret);
 
                         // 循环推送
+                        $i = 0;
                         foreach ($regIdArr as $regIdList) {
                             $client->setRegArr($regIdList);
                             $result = $client->sendMessage($title, $content, $url);
+
+                            // 一般的应用默认消息流控是针对单个应用3000QPS(每秒不能超过3000个token数)
+                            $i++;
+                            if ($i % 3 === 0) {
+                                sleep(1);
+                            }
                         }
                         break;
                     // OPPO
@@ -311,9 +325,15 @@ class PushService
                         $messageId = $client->getMessageId($title, $content, $url);
 
                         // 循环推送
+                        $i = 0;
                         foreach ($regIdArr as $regIdList) {
                             $client->setRegArr($regIdList);
                             $result = $client->broadCastRegIds($messageId);
+                            // 一般的应用默认消息流控是针对单个应用3000QPS(每秒不能超过3000个token数)
+                            $i++;
+                            if ($i % 3 === 0) {
+                                sleep(1);
+                            }
                         }
                         break;
                 }