123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- require_once(BASE_DATA_PATH . '/api/notification/android/AndroidCustomizedcast.php');
- require_once(BASE_DATA_PATH . '/api/notification/ios/IOSCustomizedcast.php');
- class push_sender
- {
- protected $appkey = NULL;
- protected $appMasterSecret = NULL;
- protected $timestamp = NULL;
- protected $validation_token = NULL;
- protected $android_alias_type = 'LRLZ';
- protected $androd_appkey = '5631efd4e0f55a8770000027';
- protected $androd_appmastersecret = 'r6w2a8z9x8zonh7qmk8ds2fvypu02wpj';
- protected $ios_alias_type = 'kPandaMakeUpAlias';
- protected $ios_appkey = '568b6727e0f55a06580011e7';
- protected $ios_appmastersecret = 'q9rmi5zjvfpvkwauenbgvhnmdsqdjeso';
- function __construct()
- {
- $this->timestamp = strval(time());
- }
- private function sendAndroidCustomizedcast(array $pushinfo)
- {
- $customizedcast = new AndroidCustomizedcast();
- $customizedcast->setAppMasterSecret($this->androd_appmastersecret);
- $customizedcast->setPredefinedKeyValue("appkey", $this->androd_appkey);
- $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
- $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
- $customizedcast->setPredefinedKeyValue("alias_type", $this->android_alias_type);
- $customizedcast->setPredefinedKeyValue("ticker", $pushinfo['text']);
- $customizedcast->setPredefinedKeyValue("title", $pushinfo['text']);
- $customizedcast->setPredefinedKeyValue("text", $pushinfo['text']);
- $customizedcast->setPredefinedKeyValue("after_open", "go_app");
- $customizedcast->setExtraField("go_type", $pushinfo['go_type']);
- return $customizedcast->send();
- }
- private function sendIOSCustomizedcast(array $pushinfo)
- {
- $customizedcast = new IOSCustomizedcast();
- $customizedcast->setAppMasterSecret($this->ios_appmastersecret);
- $customizedcast->setPredefinedKeyValue("appkey", $this->ios_appkey);
- $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
- $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
- $customizedcast->setPredefinedKeyValue("alias_type", $this->ios_alias_type);
- $customizedcast->setPredefinedKeyValue("alert", $pushinfo['text']);
- $customizedcast->setPredefinedKeyValue("badge", 0);
- $customizedcast->setPredefinedKeyValue("sound", "chime");
- $customizedcast->setPredefinedKeyValue("production_mode", "true");
- $customizedcast->setCustomizedField("go_type", $pushinfo['go_type']);
- return $customizedcast->send();
- }
- private function sendAndroidCustomizedcastMessage(array $pushinfo)
- {
- $customizedcast = new AndroidCustomizedcast();
- $customizedcast->setAppMasterSecret($this->androd_appmastersecret);
- $customizedcast->setPredefinedKeyValue("appkey", $this->androd_appkey);
- $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
- $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
- $customizedcast->setPredefinedKeyValue("alias_type", $this->android_alias_type);
- $customizedcast->setPredefinedKeyValue("display_type", 'message');
- $customizedcast->setPredefinedKeyValue("production_mode", "true");
- $customizedcast->setPredefinedKeyValue("custom", json_encode($pushinfo['custom']));
- return $customizedcast->send();
- }
- private function sendIOSCustomizedcastMessage(array $pushinfo)
- {
- $customizedcast = new IOSCustomizedcast();
- $customizedcast->setAppMasterSecret($this->ios_appmastersecret);
- $customizedcast->setPredefinedKeyValue("appkey", $this->ios_appkey);
- $customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);
- $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
- $customizedcast->setPredefinedKeyValue("alias_type", $this->ios_alias_type);
- $customizedcast->setPredefinedKeyValue("alert", $pushinfo['text']);
- $customizedcast->setPredefinedKeyValue("badge", 1);
- $customizedcast->setPredefinedKeyValue("production_mode", "false");
- $customizedcast->setCustomizedField("custom", json_encode($pushinfo['custom']));
- return $customizedcast->send();
- }
- public function send(array $info)
- {
- try
- {
- $ret = $this->sendAndroidCustomizedcast($info);
- $data = json_decode($ret,true);
- if(strtoupper($data['ret']) == 'SUCCESS') {
- return true;
- }
- }
- catch (Exception $ex) {
- Log::record("push_app sendAndroid error",Log::ERR);
- }
- try
- {
- $ret = $this->sendIOSCustomizedcast($info);
- $data = json_decode($ret,true);
- if(strtoupper($data['ret']) == 'SUCCESS') {
- return true;
- }
- }
- catch (Exception $ex) {
- Log::record("push_app sendAndroid error",Log::ERR);
- }
- return false;
- }
- public function send_message(array $info)
- {
- try
- {
- $ret = $this->sendAndroidCustomizedcastMessage($info);
- $data = json_decode($ret,true);
- if(strtoupper($data['ret']) == 'SUCCESS') {
- return true;
- }
- }
- catch (Exception $ex) {
- Log::record("push_app sendAndroid error",Log::ERR);
- }
- try
- {
- $ret = $this->sendIOSCustomizedcastMessage($info);
- $data = json_decode($ret,true);
- if(strtoupper($data['ret']) == 'SUCCESS') {
- return true;
- }
- }
- catch (Exception $ex) {
- Log::record("push_app sendAndroid error",Log::ERR);
- }
- return false;
- }
- }
|