PushTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Console\Commands\Push;
  3. use App\Consts\PushConst;
  4. use App\Libs\Push\HuaWei\HwPushCommon;
  5. use App\Libs\Push\OPPOPush\OPPOPushCommon;
  6. use App\Libs\Push\XMPush\MiPushCommon;
  7. use App\Modules\Push\Models\QappPushApp;
  8. use App\Modules\Push\Models\QappPushUser;
  9. use Exception;
  10. use Illuminate\Console\Command;
  11. class PushTest extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'push:test {uid} {url}';
  19. /**
  20. * The console command description.
  21. *
  22. * @var string
  23. */
  24. protected $description = 'test push';
  25. /**
  26. * @throws \GuzzleHttp\Exception\GuzzleException
  27. */
  28. public function handle()
  29. {
  30. // 用户Uid
  31. $uid = $this->argument('uid');
  32. $newUrl = $this->argument('url');
  33. // 获取用户push信息
  34. $pushUser = QappPushUser::getPushUserByUid($uid);
  35. $regId = getProp($pushUser, 'reg_id');
  36. $regIdList = [$regId];
  37. // 获取push app信息
  38. $pushAppId = getProp($pushUser, 'app_id');
  39. $pushApp = QappPushApp::getPushAppByAppId($pushAppId);
  40. $package = getProp($pushApp, 'package');
  41. $appId = getProp($pushApp, 'app_id');
  42. $name = getProp($pushApp, 'name');
  43. $provider = getProp($pushApp, 'provider');
  44. $appSecret = getProp($pushApp, 'app_secret');
  45. $appKey = getProp($pushApp, 'app_key');
  46. $masterSecret = getProp($pushApp, 'master_secret');
  47. // 打印
  48. var_dump('name:' . $name);
  49. var_dump('package:' . $package);
  50. var_dump('provider:' . $provider);
  51. var_dump('app_id:' . $appId);
  52. var_dump('app_secret:' . $appSecret);
  53. var_dump('app_key:' . $appKey);
  54. var_dump('master_secret:' . $masterSecret);
  55. $title = 'this title';
  56. $content = 'this content ' . date('Y-m-d H:i:s');
  57. $url = '/views/Reader?send_order_id=1643289&bid=vdqY7p15xnZQzK4VzzgmMD6wG2yr8BNX&chapter_id=4774851';
  58. if (strlen($newUrl) > 5) {
  59. $url = $newUrl;
  60. }
  61. var_dump('uid:' . $uid);
  62. var_dump('title:' . $title);
  63. var_dump('content:' . $content);
  64. var_dump('url:' . $url);
  65. var_dump('reg id:' . $regId);
  66. $result = [];
  67. try {
  68. switch ($provider) {
  69. // 华为
  70. case PushConst::PROVIDER_HW:
  71. // 初始化huawei推送
  72. $client = new HwPushCommon($appId, $appSecret);
  73. // 循环推送
  74. $client->setToken($regIdList);
  75. $client->setFastAppTarget(1);
  76. $result = $client->sendPushMessage($title, $content, $url);
  77. break;
  78. // 小米
  79. case PushConst::PROVIDER_MI:
  80. // 初始化小米推送
  81. $client = new MiPushCommon($package, $appSecret);
  82. // 循环推送
  83. $client->setRegArr($regIdList);
  84. $result = $client->sendMessage($title, $content, $url);
  85. break;
  86. // OPPO
  87. case PushConst::PROVIDER_OPPO:
  88. // 初始化oppo推送
  89. $client = new OPPOPushCommon($appKey, $masterSecret);
  90. $messageId = $client->getMessageId($title, $content, $url);
  91. // 循环推送
  92. $client->setRegArr($regIdList);
  93. $result = $client->broadCastRegIds($messageId);
  94. break;
  95. }
  96. } catch (Exception $e) {
  97. var_dump($e->getMessage());
  98. }
  99. dd($result);
  100. }
  101. }