You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
1.9 KiB

  1. <?php
  2. namespace JPush;
  3. use InvalidArgumentException;
  4. class ReportPayload {
  5. private static $EFFECTIVE_TIME_UNIT = array('HOUR', 'DAY', 'MONTH');
  6. const REPORT_URL = 'https://report.jpush.cn/v3/received';
  7. const MESSAGES_URL = 'https://report.jpush.cn/v3/messages';
  8. const USERS_URL = 'https://report.jpush.cn/v3/users';
  9. private $client;
  10. /**
  11. * ReportPayload constructor.
  12. * @param $client JPush
  13. */
  14. public function __construct($client)
  15. {
  16. $this->client = $client;
  17. }
  18. public function getReceived($msgIds) {
  19. $queryParams = '?msg_ids=';
  20. if (is_array($msgIds) && !empty($msgIds)) {
  21. $msgIdsStr = implode(',', $msgIds);
  22. $queryParams .= $msgIdsStr;
  23. } elseif (is_string($msgIds)) {
  24. $queryParams .= $msgIds;
  25. } else {
  26. throw new InvalidArgumentException("Invalid msg_ids");
  27. }
  28. $url = ReportPayload::REPORT_URL . $queryParams;
  29. return Http::get($this->client, $url);
  30. }
  31. public function getMessages($msgIds) {
  32. $queryParams = '?msg_ids=';
  33. if (is_array($msgIds) && !empty($msgIds)) {
  34. $msgIdsStr = implode(',', $msgIds);
  35. $queryParams .= $msgIdsStr;
  36. } elseif (is_string($msgIds)) {
  37. $queryParams .= $msgIds;
  38. } else {
  39. throw new InvalidArgumentException("Invalid msg_ids");
  40. }
  41. $url = ReportPayload::MESSAGES_URL . $queryParams;
  42. return Http::get($this->client, $url);
  43. }
  44. public function getUsers($time_unit, $start, $duration) {
  45. $time_unit = strtoupper($time_unit);
  46. if (!in_array($time_unit, self::$EFFECTIVE_TIME_UNIT)) {
  47. throw new InvalidArgumentException('Invalid time unit');
  48. }
  49. $url = ReportPayload::USERS_URL . '?time_unit=' . $time_unit . '&start=' . $start . '&duration=' . $duration;
  50. return Http::get($this->client, $url);
  51. }
  52. }