PushTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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\VPush\VPush;
  7. use App\Libs\Push\XMPush\MiPushCommon;
  8. use App\Modules\Push\Models\QappPushApp;
  9. use App\Modules\Push\Models\QappPushUser;
  10. use Exception;
  11. use Illuminate\Console\Command;
  12. class PushTest extends Command
  13. {
  14. /**
  15. * The name and signature of the console command.
  16. *
  17. * @var string
  18. */
  19. protected $signature = 'push:test {uid} {url}';
  20. /**
  21. * The console command description.
  22. *
  23. * @var string
  24. */
  25. protected $description = 'test push';
  26. /**
  27. * @throws \GuzzleHttp\Exception\GuzzleException
  28. */
  29. public function handle()
  30. {
  31. // 用户Uid
  32. $uid = $this->argument('uid');
  33. $newUrl = $this->argument('url');
  34. // 获取用户push信息
  35. $pushUser = QappPushUser::getPushUserByUid($uid);
  36. $regId = getProp($pushUser, 'reg_id');
  37. $regIdList = [$regId];
  38. // 获取push app信息
  39. $pushAppId = getProp($pushUser, 'app_id');
  40. $pushApp = QappPushApp::getPushAppByAppId($pushAppId);
  41. $package = getProp($pushApp, 'package');
  42. $appId = getProp($pushApp, 'app_id');
  43. $name = getProp($pushApp, 'name');
  44. $provider = getProp($pushApp, 'provider');
  45. $appSecret = getProp($pushApp, 'app_secret');
  46. $appKey = getProp($pushApp, 'app_key');
  47. $masterSecret = getProp($pushApp, 'master_secret');
  48. // 打印
  49. // var_dump('name:' . $name);
  50. // var_dump('package:' . $package);
  51. // var_dump('provider:' . $provider);
  52. // var_dump('app_id:' . $appId);
  53. // var_dump('app_secret:' . $appSecret);
  54. // var_dump('app_key:' . $appKey);
  55. // var_dump('master_secret:' . $masterSecret);
  56. $title = 'this title';
  57. $content = 'this content ' . date('Y-m-d H:i:s');
  58. $url = '/views/Reader?send_order_id=1643289&bid=vdqY7p15xnZQzK4VzzgmMD6wG2yr8BNX&chapter_id=4774851';
  59. if (strlen($newUrl) > 5) {
  60. $url = $newUrl;
  61. }
  62. // var_dump('uid:' . $uid);
  63. // var_dump('title:' . $title);
  64. // var_dump('content:' . $content);
  65. // var_dump('url:' . $url);
  66. // var_dump('reg id:' . $regId);
  67. $result = [];
  68. try {
  69. switch ($provider) {
  70. // 华为
  71. case PushConst::PROVIDER_HW:
  72. // 初始化huawei推送
  73. $client = new HwPushCommon($appId, $appSecret);
  74. // 循环推送
  75. $client->setToken($regIdList);
  76. $client->setFastAppTarget(1);
  77. $result = $client->sendPushMessage($title, $content, $url);
  78. break;
  79. // 小米
  80. case PushConst::PROVIDER_MI:
  81. // 初始化小米推送
  82. $client = new MiPushCommon($package, $appSecret);
  83. // 循环推送
  84. $client->setRegArr($regIdList);
  85. $result = $client->sendMessage($title, $content, $url);
  86. break;
  87. // OPPO
  88. case PushConst::PROVIDER_OPPO:
  89. // 初始化oppo推送
  90. $client = new OPPOPushCommon($appKey, $masterSecret);
  91. $messageId = $client->getMessageId($title, $content, $url);
  92. // 循环推送
  93. $client->setRegArr($regIdList);
  94. $result = $client->broadCastRegIds($messageId);
  95. break;
  96. // VIVO
  97. case PushConst::PROVIDER_VIVO:
  98. // 初始化oppo推送
  99. $client = new VPush($appId, $appKey, $appSecret);
  100. // 设置相关推送数据,保存消息内容(批量推送至少需要两个用户,故写死一个reg_id)
  101. $regIdList[] = '16004127020450881896432';
  102. $client->setPushData($title, $content, $url, $regIdList);
  103. $client->saveListPayload();
  104. // 循环推送
  105. $result = $client->sendMessage();
  106. break;
  107. }
  108. } catch (Exception $e) {
  109. // var_dump($e->getFile());
  110. // var_dump($e->getLine());
  111. // var_dump($e->getMessage());
  112. // var_dump($e->getTraceAsString());
  113. }
  114. dd($result);
  115. }
  116. }