|
@@ -7,8 +7,8 @@ Dever::apply('sdk/xg', 'message');
|
|
|
|
|
|
class Push
|
|
class Push
|
|
{
|
|
{
|
|
- private $prefix = 'dever_';
|
|
|
|
- public function send($id, $uid, $name, $content, $param)
|
|
|
|
|
|
+ private $prefix = 'dever_';
|
|
|
|
+ public function send($id, $uid, $name, $content, $param)
|
|
{
|
|
{
|
|
$this->config = Dever::db('message/push')->one($id);
|
|
$this->config = Dever::db('message/push')->one($id);
|
|
if ($this->config) {
|
|
if ($this->config) {
|
|
@@ -24,11 +24,11 @@ class Push
|
|
# 发单条
|
|
# 发单条
|
|
$result = $this->sendOne($uid[0], $name, $content, $param);
|
|
$result = $this->sendOne($uid[0], $name, $content, $param);
|
|
} elseif ($total <= $num) {
|
|
} elseif ($total <= $num) {
|
|
- # 发多条
|
|
|
|
|
|
+ # 发多条
|
|
$result = $this->sendList($uid, $name, $content, $param);
|
|
$result = $this->sendList($uid, $name, $content, $param);
|
|
} else {
|
|
} else {
|
|
- # 批量发送
|
|
|
|
- $result = $this->sendMul($uid, $name, $content, $param);
|
|
|
|
|
|
+ # 批量发送
|
|
|
|
+ $result = $this->sendMul($uid, $name, $content, $param);
|
|
}
|
|
}
|
|
return $result;
|
|
return $result;
|
|
}
|
|
}
|
|
@@ -39,48 +39,48 @@ class Push
|
|
|
|
|
|
private function sendAction($source_type, $type, $account, $name, $content, $param)
|
|
private function sendAction($source_type, $type, $account, $name, $content, $param)
|
|
{
|
|
{
|
|
- $result = array();
|
|
|
|
- $method = $source_type . '_message';
|
|
|
|
- if ($param && is_array($param)) {
|
|
|
|
- if ($source_type == 'android' && isset($param[0])) {
|
|
|
|
- $param = $param[0];
|
|
|
|
|
|
+ $result = array();
|
|
|
|
+ $method = $source_type . '_message';
|
|
|
|
+ if ($param && is_array($param)) {
|
|
|
|
+ if ($source_type == 'ios' && isset($param[0])) {
|
|
|
|
+ $param = $param[0];
|
|
|
|
+ }
|
|
|
|
+ if ($source_type == 'android' && isset($param[1])) {
|
|
|
|
+ $param = $param[1];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $message = $this->$method($name, $content, $param);
|
|
|
|
+
|
|
|
|
+ $push = $this->get($source_type);
|
|
|
|
+ if ($type == 1) {
|
|
|
|
+ $method = 'PushAllDevices';
|
|
|
|
+ $send = array(0, $message);
|
|
|
|
+ } elseif ($type == 2) {
|
|
|
|
+ $method = 'PushSingleAccount';
|
|
|
|
+ $send = array(0, $account, $message);
|
|
|
|
+ } elseif ($type == 3) {
|
|
|
|
+ $method = 'PushAccountList';
|
|
|
|
+ $send = array(0, $account, $message);
|
|
}
|
|
}
|
|
- if ($source_type == 'ios' && isset($param[1])) {
|
|
|
|
- $param = $param[1];
|
|
|
|
|
|
+
|
|
|
|
+ if ($source_type == 'ios') {
|
|
|
|
+ $send[] = \XingeApp::IOSENV_DEV;
|
|
}
|
|
}
|
|
- }
|
|
|
|
- $message = $this->$method($name, $content, $param);
|
|
|
|
-
|
|
|
|
- $push = $this->get($source_type);
|
|
|
|
- if ($type == 1) {
|
|
|
|
- $method = 'PushAllDevices';
|
|
|
|
- $send = array(0, $message);
|
|
|
|
- } elseif ($type == 2) {
|
|
|
|
- $method = 'PushSingleAccount';
|
|
|
|
- $send = array(0, $account, $message);
|
|
|
|
- } elseif ($type == 3) {
|
|
|
|
- $method = 'PushAccountList';
|
|
|
|
- $send = array(0, $account, $message);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ($source_type == 'ios') {
|
|
|
|
- $send[] = \XingeApp::IOSENV_DEV;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $result[$source_type]['send'] = $send;
|
|
|
|
- $result[$source_type]['message'] = array($name, $content, $param);
|
|
|
|
- $result[$source_type]['result'] = call_user_func_array(array($push, $method), $send);
|
|
|
|
-
|
|
|
|
- $log = Dever::json_encode($result[$source_type]);
|
|
|
|
- Dever::log($log, 'message_app_push');
|
|
|
|
-
|
|
|
|
- return $result;
|
|
|
|
|
|
+
|
|
|
|
+ $result[$source_type]['send'] = $send;
|
|
|
|
+ $result[$source_type]['message'] = array($name, $content, $param);
|
|
|
|
+ $result[$source_type]['result'] = call_user_func_array(array($push, $method), $send);
|
|
|
|
+
|
|
|
|
+ $log = Dever::json_encode($result[$source_type]);
|
|
|
|
+ Dever::log($log, 'message_app_push');
|
|
|
|
+
|
|
|
|
+ return $result;
|
|
}
|
|
}
|
|
|
|
|
|
private function sendMul($account, $name, $content, $param)
|
|
private function sendMul($account, $name, $content, $param)
|
|
{
|
|
{
|
|
- return $this->sendList($account, $name, $content, $param);
|
|
|
|
- # 大批量发送
|
|
|
|
|
|
+ return $this->sendList($account, $name, $content, $param);
|
|
|
|
+ # 大批量发送
|
|
$result = $push->CreateMultipush($mess, \XingeApp::IOSENV_DEV);
|
|
$result = $push->CreateMultipush($mess, \XingeApp::IOSENV_DEV);
|
|
if (!($result['ret_code'] === 0)) {
|
|
if (!($result['ret_code'] === 0)) {
|
|
|
|
|
|
@@ -100,68 +100,68 @@ class Push
|
|
}
|
|
}
|
|
|
|
|
|
private function sendList($account, $name, $content, $param)
|
|
private function sendList($account, $name, $content, $param)
|
|
- {
|
|
|
|
- $result = array();
|
|
|
|
- list($android, $ios) = $this->getUser($account);
|
|
|
|
-
|
|
|
|
- if ($android) {
|
|
|
|
- $result += $this->sendAction('android', 1, $android, $name, $content, $param);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ($ios) {
|
|
|
|
- $result += $this->sendAction('ios', 1, $ios, $name, $content, $param);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return $result;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private function sendOne($account, $name, $content, $param)
|
|
|
|
- {
|
|
|
|
- $result = array();
|
|
|
|
- $info = Dever::db('passport/app')->one(array('uid' => $account));
|
|
|
|
- if (!$info || ($info && !$info['source_type'])) {
|
|
|
|
- $info = Dever::db('passport/user')->one(array('id' => $account));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //$info['source_type'] = 'ios';
|
|
|
|
- if ($info && $info['source_type'] && ($info['source_type'] == 'ios' || $info['source_type'] == 'android')) {
|
|
|
|
- $result = $this->sendAction($info['source_type'], 2, $this->prefix . $account, $name, $content, $param);
|
|
|
|
- } else {
|
|
|
|
- $result = '没有账户信息';
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return $result;
|
|
|
|
- }
|
|
|
|
|
|
+ {
|
|
|
|
+ $result = array();
|
|
|
|
+ list($android, $ios) = $this->getUser($account);
|
|
|
|
+
|
|
|
|
+ if ($android) {
|
|
|
|
+ $result += $this->sendAction('android', 1, $android, $name, $content, $param);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ($ios) {
|
|
|
|
+ $result += $this->sendAction('ios', 1, $ios, $name, $content, $param);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function sendOne($account, $name, $content, $param)
|
|
|
|
+ {
|
|
|
|
+ $result = array();
|
|
|
|
+ $info = Dever::db('passport/app')->one(array('uid' => $account));
|
|
|
|
+ if (!$info || ($info && !$info['source_type'])) {
|
|
|
|
+ $info = Dever::db('passport/user')->one(array('id' => $account));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //$info['source_type'] = 'ios';
|
|
|
|
+ if ($info && $info['source_type'] && ($info['source_type'] == 'ios' || $info['source_type'] == 'android')) {
|
|
|
|
+ $result = $this->sendAction($info['source_type'], 2, $this->prefix . $account, $name, $content, $param);
|
|
|
|
+ } else {
|
|
|
|
+ $result = '没有账户信息';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $result;
|
|
|
|
+ }
|
|
|
|
|
|
private function sendAll($name, $content, $param)
|
|
private function sendAll($name, $content, $param)
|
|
- {
|
|
|
|
- $result = array();
|
|
|
|
- $result += $this->sendAction('android', 1, false, $name, $content, $param);
|
|
|
|
- $result += $this->sendAction('ios', 1, false, $name, $content, $param);
|
|
|
|
- return $result;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private function getUser($account)
|
|
|
|
- {
|
|
|
|
- $android = array();
|
|
|
|
- $ios = array();
|
|
|
|
- $info = Dever::db('passport/app')->getAllByUids(array('uid' => $account));
|
|
|
|
- if ($info) {
|
|
|
|
- foreach ($info as $k => $v) {
|
|
|
|
- if ($v['source_type'] == 'android') {
|
|
|
|
- $android[] = $this->prefix . $v['uid'];
|
|
|
|
- } elseif ($v['source_type'] == 'ios') {
|
|
|
|
- $ios[] = $this->prefix . $v['uid'];
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return array($android, $ios);
|
|
|
|
- }
|
|
|
|
|
|
+ {
|
|
|
|
+ $result = array();
|
|
|
|
+ $result += $this->sendAction('android', 1, false, $name, $content, $param);
|
|
|
|
+ $result += $this->sendAction('ios', 1, false, $name, $content, $param);
|
|
|
|
+ return $result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function getUser($account)
|
|
|
|
+ {
|
|
|
|
+ $android = array();
|
|
|
|
+ $ios = array();
|
|
|
|
+ $info = Dever::db('passport/app')->getAllByUids(array('uid' => $account));
|
|
|
|
+ if ($info) {
|
|
|
|
+ foreach ($info as $k => $v) {
|
|
|
|
+ if ($v['source_type'] == 'android') {
|
|
|
|
+ $android[] = $this->prefix . $v['uid'];
|
|
|
|
+ } elseif ($v['source_type'] == 'ios') {
|
|
|
|
+ $ios[] = $this->prefix . $v['uid'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return array($android, $ios);
|
|
|
|
+ }
|
|
|
|
|
|
private function android_message($name, $content, $param, $type = 1)
|
|
private function android_message($name, $content, $param, $type = 1)
|
|
{
|
|
{
|
|
- $message = new \Message();
|
|
|
|
|
|
+ $message = new \Message();
|
|
$message->setExpireTime(86400);
|
|
$message->setExpireTime(86400);
|
|
$message->setTitle($name);
|
|
$message->setTitle($name);
|
|
$message->setContent($content);
|
|
$message->setContent($content);
|
|
@@ -178,25 +178,25 @@ class Push
|
|
|
|
|
|
private function ios_message($name, $content, $param, $type = 1)
|
|
private function ios_message($name, $content, $param, $type = 1)
|
|
{
|
|
{
|
|
- $message = new \MessageIOS();
|
|
|
|
- $message->setExpireTime(86400);
|
|
|
|
- $message->setAlert(array('title' => $name, 'content' => $content));
|
|
|
|
- $message->setBadge(-2);
|
|
|
|
- //$mess->setSound("beep.wav");
|
|
|
|
- $custom = Dever::json_decode($param);
|
|
|
|
- $message->setCustom($custom);
|
|
|
|
- //$message->setRaw($param);
|
|
|
|
- $time = new \TimeInterval(0, 0, 23, 59);
|
|
|
|
- $message->addAcceptTime($time);
|
|
|
|
|
|
+ $message = new \MessageIOS();
|
|
|
|
+ $message->setExpireTime(86400);
|
|
|
|
+ $message->setAlert(array('title' => $name, 'content' => $content));
|
|
|
|
+ $message->setBadge(-2);
|
|
|
|
+ //$mess->setSound("beep.wav");
|
|
|
|
+ $custom = Dever::json_decode($param);
|
|
|
|
+ $message->setCustom($custom);
|
|
|
|
+ //$message->setRaw($param);
|
|
|
|
+ $time = new \TimeInterval(0, 0, 23, 59);
|
|
|
|
+ $message->addAcceptTime($time);
|
|
|
|
|
|
return $message;
|
|
return $message;
|
|
}
|
|
}
|
|
|
|
|
|
- private function get($type = 'android')
|
|
|
|
- {
|
|
|
|
- if (!isset($this->push[$type])) {
|
|
|
|
- $this->push[$type] = new \XingeApp($this->config[$type . '_appid'], $this->config[$type . '_appsecret']);
|
|
|
|
- }
|
|
|
|
- return $this->push[$type];
|
|
|
|
- }
|
|
|
|
|
|
+ private function get($type = 'android')
|
|
|
|
+ {
|
|
|
|
+ if (!isset($this->push[$type])) {
|
|
|
|
+ $this->push[$type] = new \XingeApp($this->config[$type . '_appid'], $this->config[$type . '_appsecret']);
|
|
|
|
+ }
|
|
|
|
+ return $this->push[$type];
|
|
|
|
+ }
|
|
}
|
|
}
|