PushTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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}';
  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. // 获取用户push信息
  33. $pushUser = QappPushUser::getPushUserByUid($uid);
  34. $regId = getProp($pushUser, 'reg_id');
  35. $regIdList = [$regId];
  36. // 获取push app信息
  37. $pushAppId = getProp($pushUser, 'app_id');
  38. $pushApp = QappPushApp::getPushAppByAppId($pushAppId);
  39. $package = getProp($pushApp, 'package');
  40. $appId = getProp($pushApp, 'app_id');
  41. $name = getProp($pushApp, 'name');
  42. $provider = getProp($pushApp, 'provider');
  43. $appSecret = getProp($pushApp, 'app_secret');
  44. $appKey = getProp($pushApp, 'app_key');
  45. $masterSecret = getProp($pushApp, 'master_secret');
  46. // 打印
  47. var_dump('name:' . $name);
  48. var_dump('package:' . $package);
  49. var_dump('provider:' . $provider);
  50. var_dump('app_id:' . $appId);
  51. var_dump('app_secret:' . $appSecret);
  52. var_dump('app_key:' . $appKey);
  53. var_dump('master_secret:' . $masterSecret);
  54. $title = 'this title';
  55. $content = 'this content ' . date('Y-m-d H:i:s');
  56. $url = '/views/Reader?send_order_id=1643289&bid=vdqY7p15xnZQzK4VzzgmMD6wG2yr8BNX&chapter_id=4774851';
  57. var_dump('uid:' . $uid);
  58. var_dump('title:' . $title);
  59. var_dump('content:' . $content);
  60. var_dump('url:' . $url);
  61. var_dump('reg id:' . $regId);
  62. $result = [];
  63. try {
  64. switch ($provider) {
  65. // 华为
  66. case PushConst::PROVIDER_HW:
  67. // 初始化huawei推送
  68. $client = new HwPushCommon($appId, $appSecret);
  69. // 循环推送
  70. $client->setToken($regIdList);
  71. $client->setFastAppTarget(1);
  72. $result = $client->sendPushMessage($title, $content, $url);
  73. break;
  74. // 小米
  75. case PushConst::PROVIDER_MI:
  76. // 初始化小米推送
  77. $client = new MiPushCommon($package, $appSecret);
  78. // 循环推送
  79. $client->setRegArr($regIdList);
  80. $result = $client->sendMessage($title, $content, $url);
  81. break;
  82. // OPPO
  83. case PushConst::PROVIDER_OPPO:
  84. // 初始化oppo推送
  85. $client = new OPPOPushCommon($appKey, $masterSecret);
  86. $messageId = $client->getMessageId($title, $content, $url);
  87. // 循环推送
  88. $client->setRegArr($regIdList);
  89. $result = $client->broadCastRegIds($messageId);
  90. break;
  91. }
  92. } catch (Exception $e) {
  93. var_dump($e->getMessage());
  94. }
  95. dd($result);
  96. }
  97. }