Wang Chen 5 年之前
父節點
當前提交
1533309aa7

+ 3 - 2
app/Console/Commands/Push/PushTest.php

@@ -62,8 +62,8 @@ class PushTest extends Command
         var_dump('app_key:' . $appKey);
         var_dump('app_key:' . $appKey);
         var_dump('master_secret:' . $masterSecret);
         var_dump('master_secret:' . $masterSecret);
 
 
-        $title   = '这是' . $name . '标题';
-        $content = '这是' . $name . '内容,创建于' . date('Y-m-d H:i:s');
+        $title   = 'this title';
+        $content = 'this content ' . date('Y-m-d H:i:s');
         $url     = '/views/Reader?send_order_id=1643289&bid=vdqY7p15xnZQzK4VzzgmMD6wG2yr8BNX&chapter_id=4774851';
         $url     = '/views/Reader?send_order_id=1643289&bid=vdqY7p15xnZQzK4VzzgmMD6wG2yr8BNX&chapter_id=4774851';
         var_dump('uid:' . $uid);
         var_dump('uid:' . $uid);
         var_dump('title:' . $title);
         var_dump('title:' . $title);
@@ -81,6 +81,7 @@ class PushTest extends Command
 
 
                     // 循环推送
                     // 循环推送
                     $client->setToken($regIdList);
                     $client->setToken($regIdList);
+                    $client->setFastAppTarget(1);
                     $result = $client->sendPushMessage($title, $content, $url);
                     $result = $client->sendPushMessage($title, $content, $url);
                     break;
                     break;
                 // 小米
                 // 小米

+ 15 - 14
app/Libs/Push/HuaWei/Admin/PushLogConfig.php

@@ -24,19 +24,19 @@ class PushLogConfig
 
 
     private function __construct()
     private function __construct()
     {
     {
-        $this->LogFile = @fopen(Constants::HW_PUSH_LOG_FILE_NAME, 'a+');
-        if (! is_resource($this->LogFile)) {
-            throw new Exception(Constants::HW_PUSH_LOG_FILE_NAME . 'invalid file Stream');
-        }
+//        $this->LogFile = @fopen(Constants::HW_PUSH_LOG_FILE_NAME, 'a+');
+//        if (!is_resource($this->LogFile)) {
+//            throw new Exception(Constants::HW_PUSH_LOG_FILE_NAME . 'invalid file Stream');
+//        }
 
 
-        fwrite($this->LogFile, $this->logBanner);
+//        fwrite($this->LogFile, $this->logBanner);
 
 
         $pushConfig = PushConfig::getSingleInstance();
         $pushConfig = PushConfig::getSingleInstance();
 
 
-        $this->default_log_level = $pushConfig->HW_DEFAULT_LOG_LEVEL;
-        if (empty($this->default_log_level)){
-            $this->default_log_level = Constants::HW_PUSH_LOG_INFO_LEVEL;
-        }
+//        $this->default_log_level = $pushConfig->HW_DEFAULT_LOG_LEVEL;
+//        if (empty($this->default_log_level)) {
+//            $this->default_log_level = Constants::HW_PUSH_LOG_INFO_LEVEL;
+//        }
     }
     }
 
 
     /**
     /**
@@ -45,7 +45,7 @@ class PushLogConfig
     public static function getSingleInstance()
     public static function getSingleInstance()
     {
     {
         static $obj;
         static $obj;
-        if (! isset($obj)) {
+        if (!isset($obj)) {
             $obj = new PushLogConfig();
             $obj = new PushLogConfig();
         }
         }
         return $obj;
         return $obj;
@@ -56,6 +56,7 @@ class PushLogConfig
      */
      */
     public function LogMessage($msg, $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL, $module = null, $timeZone = 'Asia/shanghai', $timeFormat = "%Y-%m-%d %H:%M:%S")
     public function LogMessage($msg, $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL, $module = null, $timeZone = 'Asia/shanghai', $timeFormat = "%Y-%m-%d %H:%M:%S")
     {
     {
+        return;
         if (empty($logLevel)) {
         if (empty($logLevel)) {
             $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL;
             $logLevel = Constants::HW_PUSH_LOG_INFO_LEVEL;
         }
         }
@@ -64,12 +65,12 @@ class PushLogConfig
             return;
             return;
         }
         }
         date_default_timezone_set($timeZone);
         date_default_timezone_set($timeZone);
-        $time = strftime($timeFormat, time());
-        $msg = str_replace("\t", '', $msg);
-        $msg = str_replace("\n", '', $msg);
+        $time        = strftime($timeFormat, time());
+        $msg         = str_replace("\t", '', $msg);
+        $msg         = str_replace("\n", '', $msg);
         $strLogLevel = $this->levelToString($logLevel);
         $strLogLevel = $this->levelToString($logLevel);
         if (isset($module)) {
         if (isset($module)) {
-            $module = '[' . str_pad(str_replace(array(
+            $module  = '[' . str_pad(str_replace(array(
                     "\n",
                     "\n",
                     "\t"
                     "\t"
                 ), array(
                 ), array(

+ 4 - 4
app/Libs/Push/HuaWei/HwPushCommon.php

@@ -185,7 +185,7 @@ class HwPushCommon
         $instanceAppPushBody->title($title);
         $instanceAppPushBody->title($title);
         $instanceAppPushBody->description($desc);
         $instanceAppPushBody->description($desc);
         $instanceAppPushBody->page($pageUrl);
         $instanceAppPushBody->page($pageUrl);
-        $instanceAppPushBody->params($params);
+        $instanceAppPushBody->params((object)[]);
 
 
         // 设置是否震动和显示呼吸灯
         // 设置是否震动和显示呼吸灯
         $instanceAppRingTone = new InstanceAppRingTone();
         $instanceAppRingTone = new InstanceAppRingTone();
@@ -208,9 +208,9 @@ class HwPushCommon
     private function createAndroidConfig(): AndroidConfig
     private function createAndroidConfig(): AndroidConfig
     {
     {
         $android_config = new AndroidConfig();
         $android_config = new AndroidConfig();
-        $android_config->collapse_key(-1);
-        $android_config->urgency(AndroidConfigDeliveryPriority::PRIORITY_HIGH);
-        $android_config->bi_tag('app');
+//        $android_config->collapse_key(-1);
+//        $android_config->urgency(AndroidConfigDeliveryPriority::PRIORITY_HIGH);
+//        $android_config->bi_tag('app');
         $android_config->fast_app_target($this->_fast_app_target);
         $android_config->fast_app_target($this->_fast_app_target);
         $android_config->buildFields();
         $android_config->buildFields();
         return $android_config;
         return $android_config;

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

@@ -4,6 +4,7 @@
 namespace App\Modules\Push\Services;
 namespace App\Modules\Push\Services;
 
 
 
 
+use App\Cache\Lock\LockCache;
 use Exception;
 use Exception;
 use App\Cache\PushCache;
 use App\Cache\PushCache;
 use App\Consts\PushConst;
 use App\Consts\PushConst;
@@ -44,6 +45,13 @@ class PushService
             return true;
             return true;
         }
         }
 
 
+        // 加锁
+        $token = md5($provider . ':' . $regId);
+        $lock  = LockCache::getLock($token, 3);
+        if (!$lock) {
+            return false;
+        }
+
         // 获取包信息
         // 获取包信息
         $packageInfo = QappPackage::getPackageByPackage($package);
         $packageInfo = QappPackage::getPackageByPackage($package);
         $packageId   = getProp($packageInfo, 'id');
         $packageId   = getProp($packageInfo, 'id');
@@ -90,6 +98,9 @@ class PushService
             PushCache::setUserPushRegId($uid, $regId);
             PushCache::setUserPushRegId($uid, $regId);
         }
         }
 
 
+        // 释放锁
+        LockCache::releaseLock($token);
+
         return $result;
         return $result;
     }
     }