fly vor 4 Jahren
Ursprung
Commit
4f745d1d72

+ 0 - 1
app/Modules/Push/Models/QappNewUserPushTaskLog.php

@@ -11,7 +11,6 @@ class QappNewUserPushTaskLog extends Model
     protected $table = 'qapp_new_user_push_task_logs';
     protected $fillable = [
         'task_id',
-        'app_id',
         'uid',
         'status',
         'push_time',

+ 20 - 12
app/Modules/Push/Services/PushService.php

@@ -102,7 +102,7 @@ class PushService
         }
 
         // 释放锁
-//        LockCache::releaseLock($token);
+        //        LockCache::releaseLock($token);
 
         return $result;
     }
@@ -121,9 +121,11 @@ class PushService
 
         // 获取任务数据,判断任务状态及发送时间
         $pushTask = QappPushTask::getPushTaskById($taskId);
-        if ((int)getProp($pushTask, 'status') !== PushConst::STATUS_TODO ||
+        if (
+            (int)getProp($pushTask, 'status') !== PushConst::STATUS_TODO ||
             (int)getProp($pushTask, 'select_user_status') !== PushConst::SELECT_USER_OK ||
-            getProp($pushTask, 'push_time') > date('Y-m-d H:i:s')) {
+            getProp($pushTask, 'push_time') > date('Y-m-d H:i:s')
+        ) {
             return false;
         }
 
@@ -199,6 +201,7 @@ class PushService
             $masterSecret = getProp($pushApp, 'master_secret');
             $topic        = PushConst::TOPIC_ALL;
 
+            $content = self::contentFormat($content, $provider);
             // 更新开始状态
             QappPushTaskLogs::updateSubTaskStatus($subTaskId, PushConst::STATUS_DOING);
 
@@ -206,7 +209,7 @@ class PushService
             try {
                 // 针对渠道做不同处理
                 switch ($provider) {
-                    // 华为
+                        // 华为
                     case PushConst::PROVIDER_HW:
                         // 开发状态还是生产状态
                         $target = env('APP_ENV') === 'production' ? 2 : 1;
@@ -220,18 +223,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);
                         break;
-                    // VIVO
+                        // VIVO
                     case PushConst::PROVIDER_VIVO:
                         $client = new VPush($appId, $appKey, $appSecret);
                         $client->setPushData($title, $content, $url);
@@ -295,6 +298,7 @@ class PushService
             $appKey       = getProp($pushApp, 'app_key');
             $masterSecret = getProp($pushApp, 'master_secret');
 
+            $content = self::contentFormat($content, $provider);
             // 更新开始状态
             QappPushTaskLogs::updateSubTaskStatus($subTaskId, PushConst::STATUS_DOING);
 
@@ -303,7 +307,7 @@ class PushService
             $regIdArr = array_chunk($regIds, 1000);
             try {
                 switch ($provider) {
-                    // 华为
+                        // 华为
                     case PushConst::PROVIDER_HW:
                         // 初始化huawei推送
                         $client = new HwPushCommon($appId, $appSecret);
@@ -321,7 +325,7 @@ class PushService
                             }
                         }
                         break;
-                    // 小米
+                        // 小米
                     case PushConst::PROVIDER_MI:
                         // 初始化小米推送
                         $client = new MiPushCommon($package, $appSecret);
@@ -339,7 +343,7 @@ class PushService
                             }
                         }
                         break;
-                    // OPPO
+                        // OPPO
                     case PushConst::PROVIDER_OPPO:
                         // 初始化oppo推送
                         $client    = new OPPOPushCommon($appKey, $masterSecret);
@@ -357,7 +361,7 @@ class PushService
                             }
                         }
                         break;
-                    // VIVO
+                        // VIVO
                     case PushConst::PROVIDER_VIVO:
                         // 初始化oppo推送
                         $client = new VPush($appId, $appKey, $appSecret);
@@ -393,4 +397,8 @@ class PushService
         return $pushResult;
     }
 
-}
+    private static function contentFormat(string $content, string $provider): string
+    {
+        return str_replace('{device}', PushMessageService::providers[$provider], $content);
+    }
+}