Wang Chen 4 년 전
부모
커밋
9710112a6a

+ 1 - 1
app/Console/Kernel.php

@@ -55,6 +55,6 @@ class Kernel extends ConsoleKernel
         });
 
         // 推送任务每分钟执行
-        $schedule->command('push:task')->everyMinute()->sendOutputTo(storage_path('push-' . date('Y-m-d')));
+        $schedule->command('push:task')->everyMinute()->sendOutputTo(storage_path('pushCommand-' . date('Y-m-d')));
     }
 }

+ 2 - 2
app/Libs/Push/HuaWei/Admin/Application.php

@@ -88,7 +88,7 @@ class Application
     private function logPush($className, $message, $data = [])
     {
         var_dump('[' . $className . '] ' . $message, $data);
-        myLog('push')->info('[' . $className . '] ' . $message, $data);
+        myLog('push')->info('[HuaWei] [' . $className . '] ' . $message, $data);
     }
 
     private function is_token_expired()
@@ -296,7 +296,7 @@ class Application
 
         return $result;
     }
-    
+
     private function curl_https_post($url, $data = [], $header = [])
     {
         $this->logPush(__FUNCTION__, 'curl_https_post:', compact('url', 'data'));

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

@@ -96,7 +96,7 @@ class OPPOPushCommon
             throw new Exception('保存通知栏消息内容体失败');
         }
 
-        myLog('push')->info(__FUNCTION__, compact('data', 'messageId'));
+        $this->logPush(__FUNCTION__, 'result', compact('data', 'messageId'));
         return $messageId;
     }
 
@@ -125,7 +125,7 @@ class OPPOPushCommon
         $body     = $response->getBody();
         $result   = json_decode($body, true);
 
-        myLog('push')->info(__FUNCTION__, compact('data', 'result'));
+        $this->logPush(__FUNCTION__, 'result', compact('data', 'result'));
         return $result;
     }
 
@@ -154,7 +154,7 @@ class OPPOPushCommon
         $body     = $response->getBody();
         $result   = json_decode($body, true);
 
-        myLog('push')->info(__FUNCTION__, compact('data', 'result'));
+        $this->logPush(__FUNCTION__, 'result', compact('data', 'result'));
         return $result;
     }
 
@@ -183,7 +183,7 @@ class OPPOPushCommon
         $body     = $response->getBody();
         $result   = json_decode($body, true);
 
-        myLog('push')->info(__FUNCTION__, compact('data', 'result'));
+        $this->logPush(__FUNCTION__, 'result', compact('data', 'result'));
         return $result;
     }
 
@@ -210,7 +210,7 @@ class OPPOPushCommon
         $body     = $response->getBody();
         $result   = json_decode($body, true);
 
-        myLog('push')->info(__FUNCTION__, compact('data', 'result'));
+        $this->logPush(__FUNCTION__, 'result', compact('data', 'result'));
         return $result;
     }
 
@@ -233,7 +233,7 @@ class OPPOPushCommon
         $body     = $response->getBody();
         $result   = json_decode($body, true);
 
-        myLog('push')->info(__FUNCTION__, compact('data', 'result'));
+        $this->logPush(__FUNCTION__, 'result', compact('data', 'result'));
         return $result;
     }
 
@@ -266,7 +266,7 @@ class OPPOPushCommon
             throw new Exception('获取auth token失败');
         }
 
-        myLog('push')->info(__FUNCTION__, compact('authToken'));
+        $this->logPush(__FUNCTION__, 'result', compact('authToken'));
         return $authToken;
     }
 
@@ -301,8 +301,13 @@ class OPPOPushCommon
         $body     = $response->getBody();
         $result   = json_decode($body, true);
 
-        myLog('push')->info(__FUNCTION__, compact('targetType', 'messageId', 'result'));
+        $this->logPush(__FUNCTION__, 'result', compact('targetType', 'messageId', 'result'));
         return $result;
     }
 
+    private function logPush($className, $message, $data = [])
+    {
+        var_dump('[' . $className . '] ' . $message, $data);
+        myLog('push')->info('[OPPO] [' . $className . '] ' . $message, $data);
+    }
 }

+ 19 - 2
app/Libs/Push/XMPush/MiPushCommon.php

@@ -36,7 +36,10 @@ class MiPushCommon
     {
         $sender  = new Sender();
         $message = $this->buildMessage($title, $desc, $url);
-        return $sender->sendToIds($message, $this->_reg_arr)->getRaw();
+        $result  = $sender->sendToIds($message, $this->_reg_arr)->getRaw();
+
+        $this->logPush(__FUNCTION__, 'result', compact('result'));
+        return $result;
     }
 
     /**
@@ -50,7 +53,10 @@ class MiPushCommon
     {
         $sender  = new Sender();
         $message = $this->buildMessage($title, $desc, $url);
-        return $sender->broadcastAll($message)->getRaw();
+        $result  = $sender->broadcastAll($message)->getRaw();
+
+        $this->logPush(__FUNCTION__, 'result', compact('result'));
+        return $result;
     }
 
     /**
@@ -75,4 +81,15 @@ class MiPushCommon
         $message->build();
         return $message;
     }
+
+    /**
+     * @param       $className
+     * @param       $message
+     * @param array $data
+     */
+    private function logPush($className, $message, $data = [])
+    {
+        var_dump('[' . $className . '] ' . $message, $data);
+        myLog('push')->info('[XiaoMi] [' . $className . '] ' . $message, $data);
+    }
 }

+ 15 - 11
app/Modules/Push/Services/PushService.php

@@ -41,7 +41,6 @@ class PushService
         // 获取缓存
         $userCacheRegId = PushCache::getUserPushRegId($uid);
         if ($regId === $userCacheRegId) {
-            myLog('push')->info('setUserRegId', ['cache' => 'match']);
             return true;
         }
 
@@ -162,7 +161,11 @@ class PushService
             return false;
         }
 
+        // 推送结果、推送内容
         $pushResult = true;
+        $title      = getProp($pushTask, 'title');
+        $content    = getProp($pushTask, 'content');
+        $url        = getProp($pushTask, 'url');
 
         // 循环群发
         foreach ($subTasks as $subTask) {
@@ -174,10 +177,7 @@ class PushService
             }
 
             // push app相关
-            $title        = getProp($pushTask, 'title');
-            $content      = getProp($pushTask, 'content');
-            $url          = getProp($pushTask, 'url');
-            $provider     = strtolower(getProp($pushApp, 'provider'));
+            $provider     = getProp($pushApp, 'provider');
             $package      = getProp($pushApp, 'package');
             $appId        = getProp($pushApp, 'app_id');
             $appSecret    = getProp($pushApp, 'app_secret');
@@ -192,6 +192,7 @@ class PushService
             try {
                 // 针对渠道做不同处理
                 switch ($provider) {
+                    // 华为
                     case PushConst::PROVIDER_HW:
                         // 开发状态还是生产状态
                         $target = env('APP_ENV') === 'production' ? 2 : 1;
@@ -201,14 +202,17 @@ class PushService
                         $client->setFastAppTarget($target);
                         $client->setTopic($topic);
                         $client->setBigTag('Task_' . getProp($pushTask, 'id'));
+
+                        // 推送
                         $result = $client->sendPushMessage($title, $content, $url);
                         break;
+                    // 小米
                     case PushConst::PROVIDER_MI:
                         $client = new MiPushCommon($package, $appSecret);
                         $result = $client->sendMessageToAll($title, $content, $url);
                         break;
+                    // OPPO
                     case PushConst::PROVIDER_OPPO:
-                        // 实例化OPPO
                         $client    = new OPPOPushCommon($appKey, $masterSecret);
                         $messageId = $client->getMessageId($title, $content, $url);
                         $result    = $client->broadCastAll($messageId);
@@ -248,8 +252,11 @@ class PushService
             return false;
         }
 
-        // 推送结果
+        // 推送结果、推送内容
         $pushResult = true;
+        $title      = getProp($pushTask, 'title');
+        $content    = getProp($pushTask, 'content');
+        $url        = getProp($pushTask, 'url');
 
         // 推送
         foreach ($subTasks as $subTask) {
@@ -261,15 +268,12 @@ class PushService
             $regIds    = array_column($users, 'reg_id');
 
             // push app相关
-            $provider     = strtolower(getProp($pushApp, 'provider'));
+            $provider     = getProp($pushApp, 'provider');
             $package      = getProp($pushApp, 'package');
             $appId        = getProp($pushApp, 'app_id');
             $appSecret    = getProp($pushApp, 'app_secret');
             $appKey       = getProp($pushApp, 'app_key');
             $masterSecret = getProp($pushApp, 'master_secret');
-            $title        = getProp($pushTask, 'title');
-            $content      = getProp($pushTask, 'content');
-            $url          = getProp($pushTask, 'url');
 
             // 更新开始状态
             QappPushTaskLogs::updateSubTaskStatus($subTaskId, PushConst::STATUS_DOING);