batch_push_example.php 870 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. // 这只是使用样例,不应该直接用于实际生产环境中 !!
  3. require 'config.php';
  4. $singlePayloads = array(
  5. array(
  6. 'platform' => 'all',
  7. 'target' => 'regid1',
  8. 'notification' => array(
  9. 'alert' => 'NotificationAlert1'
  10. )
  11. ),
  12. array(
  13. 'platform' => 'all',
  14. 'target' => 'regid2',
  15. 'notification' => array(
  16. 'alert' => 'NotificationAlert2'
  17. )
  18. )
  19. );
  20. $push_payload = $client -> push();
  21. try {
  22. $response = $push_payload -> batchPushByRegid($singlePayloads);
  23. print_r($response);
  24. $response = $push_payload -> batchPushByAlias($singlePayloads);
  25. print_r($response);
  26. } catch (\JPush\Exceptions\APIConnectionException $e) {
  27. // try something here
  28. print $e;
  29. } catch (\JPush\Exceptions\APIRequestException $e) {
  30. // try something here
  31. print $e;
  32. }