Nenhuma Descrição

Builder.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * (android)消息体.
  4. * @author wangkuiwei
  5. * @name Builder
  6. * @desc 构建发送给Android设备的Message对象。
  7. *
  8. */
  9. namespace xmpush;
  10. class Builder extends Message {
  11. const soundUri = 'sound_uri';
  12. const notifyForeground = 'notify_foreground';
  13. const notifyEffect = 'notify_effect';
  14. const intentUri = 'intent_uri';
  15. const webUri = 'web_uri';
  16. const flowControl = 'flow_control';
  17. const callback = 'callback';
  18. public function __construct() {
  19. $this->notify_id = 0;
  20. $this->notify_type = -1;
  21. $this->payload = '';
  22. $this->restricted_package_name = Constants::$packageName;
  23. parent::__construct();
  24. }
  25. public function payload($payload) {
  26. $this->payload = $payload;
  27. }
  28. public function title($title) {
  29. $this->title = $title;
  30. }
  31. public function description($description) {
  32. $this->description = $description;
  33. }
  34. public function passThrough($passThrough) {
  35. $this->pass_through = $passThrough;
  36. }
  37. public function notifyType($type) {
  38. $this->notify_type = $type;
  39. }
  40. public function restrictedPackageNames($packageNameList) {
  41. $jointPackageNames = '';
  42. foreach ($packageNameList as $packageName) {
  43. if (isset($packageName)) {
  44. $jointPackageNames .= $packageName . Constants::$comma;
  45. }
  46. }
  47. $this->restricted_package_name = $jointPackageNames;
  48. }
  49. public function timeToLive($ttl) {
  50. $this->time_to_live = $ttl;
  51. }
  52. public function timeToSend($timeToSend) {
  53. $this->time_to_send = $timeToSend;
  54. }
  55. public function notifyId($notifyId) {
  56. $this->notify_id = $notifyId;
  57. }
  58. public function extra($key, $value) {
  59. $this->extra[$key] = $value;
  60. }
  61. public function build() {
  62. $keys = array(
  63. 'payload', 'title', 'description', 'pass_through', 'notify_type',
  64. 'restricted_package_name', 'time_to_live', 'time_to_send', 'notify_id'
  65. );
  66. foreach ($keys as $key) {
  67. if (isset($this->$key)) {
  68. $this->fields[$key] = $this->$key;
  69. $this->json_infos[$key] = $this->$key;
  70. }
  71. }
  72. //单独处理extra
  73. $JsonExtra = array();
  74. if (count($this->extra) > 0) {
  75. foreach ($this->extra as $extraKey => $extraValue) {
  76. $this->fields[Message::EXTRA_PREFIX . $extraKey] = $extraValue;
  77. $JsonExtra[$extraKey] = $extraValue;
  78. }
  79. }
  80. $this->json_infos['extra'] = $JsonExtra;
  81. }
  82. }
  83. ?>