OppoPushTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands\Push;
  3. use App\Consts\PushConst;
  4. use App\Libs\Push\OPPOPush\OPPOPushCommon;
  5. use Illuminate\Console\Command;
  6. use GuzzleHttp\Exception\GuzzleException;
  7. class OppoPushTest extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'push:oppo:test';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command description';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * @throws GuzzleException
  32. */
  33. public function handle()
  34. {
  35. // 配置
  36. $regId = 'CN_83427bab875a0a40e4da3eeb2055f331';
  37. [$appKey, $masterSecret] = ['354f2fba4c834e94a206fca247f132a0', 'ba2d9968c45b489da75e6bde7147b32a'];
  38. // 初始化
  39. $instance = new OPPOPushCommon($appKey, $masterSecret);
  40. // 查询APP当天发送量的状态
  41. $res = $instance->fetchPushPermit();
  42. dd($res);
  43. // 标签相关
  44. $tag = PushConst::TOPIC_ALL;
  45. $res1 = $instance->addTags($tag, '全部用户');
  46. $res2 = $instance->subscribeTags($regId, $tag);
  47. $res3 = $instance->getAllTags($regId);
  48. dd($res1, $res2, $res3);
  49. // 发送消息
  50. $messageId = $instance->getMessageId('我是标题11', '我是内容11', '/');
  51. $res4 = $instance->broadCastRegIds($messageId, [$regId]);
  52. dd($messageId, $res4);
  53. }
  54. }