push_sender.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. require_once(BASE_DATA_PATH . '/api/notification/android/AndroidCustomizedcast.php');
  3. require_once(BASE_DATA_PATH . '/api/notification/ios/IOSCustomizedcast.php');
  4. class push_sender
  5. {
  6. protected $appkey = NULL;
  7. protected $appMasterSecret = NULL;
  8. protected $timestamp = NULL;
  9. protected $validation_token = NULL;
  10. protected $android_alias_type = 'LRLZ';
  11. protected $androd_appkey = '5631efd4e0f55a8770000027';
  12. protected $androd_appmastersecret = 'r6w2a8z9x8zonh7qmk8ds2fvypu02wpj';
  13. protected $ios_alias_type = 'kPandaMakeUpAlias';
  14. protected $ios_appkey = '568b6727e0f55a06580011e7';
  15. protected $ios_appmastersecret = 'q9rmi5zjvfpvkwauenbgvhnmdsqdjeso';
  16. function __construct()
  17. {
  18. $this->timestamp = strval(time());
  19. }
  20. private function sendAndroidCustomizedcast(array $pushinfo)
  21. {
  22. $customizedcast = new AndroidCustomizedcast();
  23. $customizedcast->setAppMasterSecret($this->androd_appmastersecret);
  24. $customizedcast->setPredefinedKeyValue("appkey", $this->androd_appkey);
  25. $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
  26. $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
  27. $customizedcast->setPredefinedKeyValue("alias_type", $this->android_alias_type);
  28. $customizedcast->setPredefinedKeyValue("ticker", $pushinfo['text']);
  29. $customizedcast->setPredefinedKeyValue("title", $pushinfo['text']);
  30. $customizedcast->setPredefinedKeyValue("text", $pushinfo['text']);
  31. $customizedcast->setPredefinedKeyValue("after_open", "go_app");
  32. $customizedcast->setExtraField("go_type", $pushinfo['go_type']);
  33. return $customizedcast->send();
  34. }
  35. private function sendIOSCustomizedcast(array $pushinfo)
  36. {
  37. $customizedcast = new IOSCustomizedcast();
  38. $customizedcast->setAppMasterSecret($this->ios_appmastersecret);
  39. $customizedcast->setPredefinedKeyValue("appkey", $this->ios_appkey);
  40. $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
  41. $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
  42. $customizedcast->setPredefinedKeyValue("alias_type", $this->ios_alias_type);
  43. $customizedcast->setPredefinedKeyValue("alert", $pushinfo['text']);
  44. $customizedcast->setPredefinedKeyValue("badge", 0);
  45. $customizedcast->setPredefinedKeyValue("sound", "chime");
  46. $customizedcast->setPredefinedKeyValue("production_mode", "true");
  47. $customizedcast->setCustomizedField("go_type", $pushinfo['go_type']);
  48. return $customizedcast->send();
  49. }
  50. private function sendAndroidCustomizedcastMessage(array $pushinfo)
  51. {
  52. $customizedcast = new AndroidCustomizedcast();
  53. $customizedcast->setAppMasterSecret($this->androd_appmastersecret);
  54. $customizedcast->setPredefinedKeyValue("appkey", $this->androd_appkey);
  55. $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
  56. $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
  57. $customizedcast->setPredefinedKeyValue("alias_type", $this->android_alias_type);
  58. $customizedcast->setPredefinedKeyValue("display_type", 'message');
  59. $customizedcast->setPredefinedKeyValue("production_mode", "true");
  60. $customizedcast->setPredefinedKeyValue("custom", json_encode($pushinfo['custom']));
  61. return $customizedcast->send();
  62. }
  63. private function sendIOSCustomizedcastMessage(array $pushinfo)
  64. {
  65. $customizedcast = new IOSCustomizedcast();
  66. $customizedcast->setAppMasterSecret($this->ios_appmastersecret);
  67. $customizedcast->setPredefinedKeyValue("appkey", $this->ios_appkey);
  68. $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
  69. $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
  70. $customizedcast->setPredefinedKeyValue("alias_type", $this->ios_alias_type);
  71. $customizedcast->setPredefinedKeyValue("alert", $pushinfo['text']);
  72. $customizedcast->setPredefinedKeyValue("badge", 1);
  73. $customizedcast->setPredefinedKeyValue("production_mode", "false");
  74. $customizedcast->setCustomizedField("custom", json_encode($pushinfo['custom']));
  75. return $customizedcast->send();
  76. }
  77. public function send(array $info)
  78. {
  79. try
  80. {
  81. $ret = $this->sendAndroidCustomizedcast($info);
  82. $data = json_decode($ret,true);
  83. if(strtoupper($data['ret']) == 'SUCCESS') {
  84. return true;
  85. }
  86. }
  87. catch (Exception $ex) {
  88. Log::record("push_app sendAndroid error",Log::ERR);
  89. }
  90. try
  91. {
  92. $ret = $this->sendIOSCustomizedcast($info);
  93. $data = json_decode($ret,true);
  94. if(strtoupper($data['ret']) == 'SUCCESS') {
  95. return true;
  96. }
  97. }
  98. catch (Exception $ex) {
  99. Log::record("push_app sendAndroid error",Log::ERR);
  100. }
  101. return false;
  102. }
  103. public function send_message(array $info)
  104. {
  105. try
  106. {
  107. $ret = $this->sendAndroidCustomizedcastMessage($info);
  108. $data = json_decode($ret,true);
  109. if(strtoupper($data['ret']) == 'SUCCESS') {
  110. return true;
  111. }
  112. }
  113. catch (Exception $ex) {
  114. Log::record("push_app sendAndroid error",Log::ERR);
  115. }
  116. try
  117. {
  118. $ret = $this->sendIOSCustomizedcastMessage($info);
  119. $data = json_decode($ret,true);
  120. if(strtoupper($data['ret']) == 'SUCCESS') {
  121. return true;
  122. }
  123. }
  124. catch (Exception $ex) {
  125. Log::record("push_app sendAndroid error",Log::ERR);
  126. }
  127. return false;
  128. }
  129. }