123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
- require_once(BASE_DATA_PATH . '/api/notification/android/AndroidCustomizedcast.php');
- require_once(BASE_DATA_PATH . '/api/notification/ios/IOSCustomizedcast.php');
- require_once(BASE_DATA_PATH . '/api/notification/ios/IOSGroupcast.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_type", $this->android_alias_type);
- $customizedcast->setPredefinedKeyValue("after_open", "go_app");
- $pre_keys = ['alias','title','text','img'];
- foreach ($pushinfo as $key => $value)
- {
- if(in_array($key,$pre_keys))
- {
- $customizedcast->setPredefinedKeyValue($key,$value);
- if($key == 'title') {
- $customizedcast->setPredefinedKeyValue('ticker',$value);
- }
- }
- elseif( $key == 'extra')
- {
- if(empty($value) || is_array($value) == false) continue;
- foreach ($value as $skey => $sval) {
- $customizedcast->setExtraField($skey, $sval);
- }
- }
- }
- 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_type", $this->ios_alias_type);
- $customizedcast->setPredefinedKeyValue("badge", 0);
- $customizedcast->setPredefinedKeyValue("sound", "chime");
- if(is_publish()) {
- $customizedcast->setPredefinedKeyValue("production_mode", "true");
- } else {
- $customizedcast->setPredefinedKeyValue("production_mode", "false");
- }
- $pre_keys = ['alias','text'];
- foreach ($pushinfo as $key => $value)
- {
- if(in_array($key,$pre_keys))
- {
- if($key == 'text') {
- $customizedcast->setPredefinedKeyValue('alert',$value);
- } else {
- $customizedcast->setPredefinedKeyValue($key,$value);
- }
- }
- elseif( $key == 'extra')
- {
- if(empty($value) || is_array($value) == false) continue;
- foreach ($value as $skey => $sval) {
- $customizedcast->setCustomizedField($skey, $sval);
- }
- }
- else {
- continue;
- }
- }
- 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_type", $this->android_alias_type);
- $customizedcast->setPredefinedKeyValue("display_type", 'message');
- if(is_publish()) {
- $customizedcast->setPredefinedKeyValue("production_mode", "true");
- } else {
- $customizedcast->setPredefinedKeyValue("production_mode", "false");
- }
- $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
- $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_type", $this->ios_alias_type);
- $customizedcast->setPredefinedKeyValue("badge", 1);
- if(is_publish()) {
- $customizedcast->setPredefinedKeyValue("production_mode", "true");
- } else {
- $customizedcast->setPredefinedKeyValue("production_mode", "false");
- }
- $customizedcast->setPredefinedKeyValue("alias", $pushinfo['member_id']);
- $customizedcast->setPredefinedKeyValue("alert", $pushinfo['text']);
- $customizedcast->setCustomizedField("custom", json_encode($pushinfo['custom']));
- return $customizedcast->send();
- }
- public function send(array $info,$client_type = 0)
- {
- $fAndroid = false;
- $fIos = false;
- try
- {
- if($client_type == 0 || $client_type == session_helper::device_android)
- {
- $ret = $this->sendAndroidCustomizedcast($info);
- $data = json_decode($ret,true);
- if(strtoupper($data['ret']) == 'SUCCESS') {
- $fAndroid = true;
- }
- }
- }
- catch (Exception $ex) {
- Log::record("push_app send Android error",Log::DEBUG);
- }
- try
- {
- if($client_type == 0 || $client_type == session_helper::device_ios)
- {
- $ret = $this->sendIOSCustomizedcast($info);
- $data = json_decode($ret,true);
- if(strtoupper($data['ret']) == 'SUCCESS') {
- $fIos = true;
- }
- }
- }
- catch (Exception $ex) {
- Log::record("push_app send IOS error",Log::ERR);
- }
- return ($fAndroid | $fIos);
- }
- public function send_message(array $info,$client_type = 0)
- {
- $fAndroid = false;
- $fIos = false;
- try
- {
- if($client_type == 0 || $client_type == session_helper::device_android)
- {
- $ret = $this->sendAndroidCustomizedcastMessage($info);
- $data = json_decode($ret,true);
- if(strtoupper($data['ret']) == 'SUCCESS') {
- $fAndroid = true;
- }
- }
- }
- catch (Exception $ex) {
- Log::record("push_app sendAndroid error",Log::ERR);
- }
- try
- {
- if($client_type == 0 || $client_type == session_helper::device_ios)
- {
- $ret = $this->sendIOSCustomizedcastMessage($info);
- $data = json_decode($ret,true);
- if(strtoupper($data['ret']) == 'SUCCESS') {
- $fIos = true;
- }
- }
- }
- catch (Exception $ex) {
- Log::record("push_app sendAndroid error",Log::ERR);
- }
- return ($fAndroid || $fIos);
- }
- }
|