IOSNotification.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. require_once(APP_ROOT_PATH. 'system/umeng/notification/UmengNotification.php');
  3. abstract class IOSNotification extends UmengNotification {
  4. // The array for payload, please see API doc for more information
  5. protected $iosPayload = array(
  6. "aps" => array(
  7. "alert" => NULL
  8. //"badge" => xx,
  9. //"sound" => "xx",
  10. //"content-available" => xx
  11. ),
  12. "room_id" => NULL,
  13. "type" => NULL,
  14. //"key1" => "value1",
  15. //"key2" => "value2"
  16. );
  17. // Keys can be set in the aps level
  18. protected $APS_KEYS = array("alert", "badge", "sound", "content-available");
  19. function __construct() {
  20. parent::__construct();
  21. $this->data["payload"] = $this->iosPayload;
  22. }
  23. // Set key/value for $data array, for the keys which can be set please see $DATA_KEYS, $PAYLOAD_KEYS, $BODY_KEYS, $POLICY_KEYS
  24. function setPredefinedKeyValue($key, $value) {
  25. if (!is_string($key))
  26. throw new Exception("key should be a string!");
  27. if (in_array($key, $this->DATA_KEYS)) {
  28. $this->data[$key] = $value;
  29. } else if (in_array($key, $this->APS_KEYS)) {
  30. $this->data["payload"]["aps"][$key] = $value;
  31. } else if (in_array($key, $this->POLICY_KEYS)) {
  32. $this->data["policy"][$key] = $value;
  33. } else {
  34. if ($key == "payload" || $key == "policy" || $key == "aps") {
  35. throw new Exception("You don't need to set value for ${key} , just set values for the sub keys in it.");
  36. } else {
  37. throw new Exception("Unknown key: ${key}");
  38. }
  39. }
  40. }
  41. // Set extra key/value for Android notification
  42. function setCustomizedField($key, $value) {
  43. if (!is_string($key))
  44. throw new Exception("key should be a string!");
  45. $this->data["payload"][$key] = $value;
  46. }
  47. }