push_app.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/android/AndroidCustomizedcast.php');
  3. require_once(dirname(dirname(__FILE__)) . '/data/api/' . 'notification/ios/IOSCustomizedcast.php');
  4. class push_app
  5. {
  6. protected $appkey = NULL;
  7. protected $appMasterSecret = NULL;
  8. protected $timestamp = NULL;
  9. protected $validation_token = NULL;
  10. protected $alias_type = 'LRLZ';
  11. protected $ios_alias_type = 'kPandaMakeUpAlias';
  12. protected $androd_appkey = '5631efd4e0f55a8770000027';
  13. protected $androd_appmastersecret = 'r6w2a8z9x8zonh7qmk8ds2fvypu02wpj';
  14. protected $ios_appkey = '568b6727e0f55a06580011e7';
  15. protected $ios_appmastersecret = 'q9rmi5zjvfpvkwauenbgvhnmdsqdjeso';
  16. function __construct()
  17. {
  18. $this->timestamp = strval(time());
  19. }
  20. public function setAliasType($value)
  21. {
  22. if (!empty($value)) {
  23. $this->alias_type = $value;
  24. }
  25. }
  26. function sendAndroidCustomizedcast(array $pushinfo)
  27. {
  28. $customizedcast = new AndroidCustomizedcast();
  29. $customizedcast->setAppMasterSecret($this->androd_appmastersecret);
  30. $customizedcast->setPredefinedKeyValue("appkey", $this->androd_appkey);
  31. $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
  32. // Set your alias here, and use comma to split them if there are multiple alias.
  33. // And if you have many alias, you can also upload a file containing these alias, then
  34. // use file_id to send customized notification.
  35. $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
  36. // Set your alias_type here
  37. $customizedcast->setPredefinedKeyValue("alias_type", $this->alias_type);
  38. $customizedcast->setPredefinedKeyValue("ticker", $pushinfo['text']);
  39. $customizedcast->setPredefinedKeyValue("title", $pushinfo['text']);
  40. $customizedcast->setPredefinedKeyValue("text", $pushinfo['text']);
  41. $customizedcast->setPredefinedKeyValue("after_open", "go_app");
  42. return $customizedcast->send();
  43. }
  44. function sendIOSCustomizedcast(array $pushinfo)
  45. {
  46. try {
  47. $customizedcast = new IOSCustomizedcast();
  48. $customizedcast->setAppMasterSecret($this->ios_appmastersecret);
  49. $customizedcast->setPredefinedKeyValue("appkey", $this->ios_appkey);
  50. $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
  51. // Set your alias here, and use comma to split them if there are multiple alias.
  52. // And if you have many alias, you can also upload a file containing these alias, then
  53. // use file_id to send customized notification.
  54. $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
  55. // Set your alias_type here
  56. $customizedcast->setPredefinedKeyValue("alias_type", $this->ios_alias_type);
  57. $customizedcast->setPredefinedKeyValue("alert", $pushinfo['text']);
  58. $customizedcast->setPredefinedKeyValue("badge", 0);
  59. $customizedcast->setPredefinedKeyValue("sound", "chime");
  60. // Set 'production_mode' to 'true' if your app is under production mode
  61. $customizedcast->setPredefinedKeyValue("production_mode", "false");
  62. return $customizedcast->send();
  63. } catch (Exception $e) {
  64. print("Caught exception: " . $e->getMessage());
  65. }
  66. }
  67. }
  68. // Set your appkey and master secret here
  69. $demo = new push_app();
  70. $demo->sendIOSCustomizedcast(array('member_id' => '36485', 'text' => 'ddddddddd'));