dever 6 years ago
parent
commit
8ee1c30a64
5 changed files with 206 additions and 172 deletions
  1. 9 0
      database/inbox.php
  2. 9 0
      database/outbox.php
  3. 58 43
      lib/Data.php
  4. 15 14
      lib/Manage.php
  5. 115 115
      lib/Push.php

+ 9 - 0
database/inbox.php

@@ -143,6 +143,15 @@ return array
 			'list'		=> true,
 			'list'		=> true,
 		),
 		),
 
 
+		'param'		=> array
+		(
+			'type' 		=> 'varchar-800',
+			'name' 		=> '传入参数-一般为json格式数据',
+			'default' 	=> '',
+			'desc' 		=> '传入参数',
+			'match' 	=> 'is_string',
+		),
+
 		'status'		=> array
 		'status'		=> array
 		(
 		(
 			'type' 		=> 'tinyint-1',
 			'type' 		=> 'tinyint-1',

+ 9 - 0
database/outbox.php

@@ -123,6 +123,15 @@ return array
 			'control'	=> 'scope',
 			'control'	=> 'scope',
 		),
 		),
 
 
+		'param'		=> array
+		(
+			'type' 		=> 'varchar-800',
+			'name' 		=> '传入参数-一般为json格式数据',
+			'default' 	=> '',
+			'desc' 		=> '传入参数',
+			'match' 	=> 'is_string',
+		),
+
 		'to_uid'		=> array
 		'to_uid'		=> array
 		(
 		(
 			'type' 		=> 'text-255',
 			'type' 		=> 'text-255',

+ 58 - 43
lib/Data.php

@@ -8,53 +8,54 @@ use Dever;
 
 
 class Data
 class Data
 {
 {
-	public function __construct()
-	{
+    public function __construct()
+    {
         # 获取用户信息
         # 获取用户信息
         //$user = new User();
         //$user = new User();
         //$this->user = $user->data();
         //$this->user = $user->data();
-	}
+    }
 
 
-	/**
+    /**
      * 获取我的消息
      * 获取我的消息
      * 
      * 
      * @return mixed
      * @return mixed
      */
      */
-	public function read($uid, $type = false, $update = false, $status = false, $project = 1)
-	{
+    public function read($uid, $type = false, $update = false, $status = false, $project = 1)
+    {
         if (!$uid) {
         if (!$uid) {
             Dever::alert('错误的用户信息');
             Dever::alert('错误的用户信息');
         }
         }
-		$prefix = defined('DEVER_PROJECT') && DEVER_PROJECT != 'default' ? DEVER_PROJECT . '_' : '';
-		$outbox = $prefix . 'message_outbox';
-		$inbox = $prefix . 'message_inbox';
+        $prefix = defined('DEVER_PROJECT') && DEVER_PROJECT != 'default' ? DEVER_PROJECT . '_' : '';
+        $outbox = $prefix . 'message_outbox';
+        $inbox = $prefix . 'message_inbox';
 
 
-		$where = ' and a.state = 1 and a.project_id = ' . $project;
+        $where = ' and a.state = 1 and a.project_id = ' . $project;
         # 去掉a.type判断
         # 去掉a.type判断
         $where .= ' and a.scope = 2';
         $where .= ' and a.scope = 2';
         # 这个是兼容历史版本
         # 这个是兼容历史版本
         //$where .= ' (and a.type <= 10 || a.scope = 2)';
         //$where .= ' (and a.type <= 10 || a.scope = 2)';
-		# 读取outbox里的数据
-		$sql = 'select a.name,a.content,a.id,a.type,a.uid,a.project_id,a.scope from '.$outbox.' as a where not exists(select oid from '.$inbox.' where a.id = oid and uid = '.$uid.')' . $where . ' ';
+        # 读取outbox里的数据
+        $sql = 'select a.name,a.content,a.id,a.type,a.uid,a.project_id,a.scope,a.param from '.$outbox.' as a where not exists(select oid from '.$inbox.' where a.id = oid and uid = '.$uid.')' . $where . ' ';
 
 
         $state = Dever::db('message/inbox')->query($sql);
         $state = Dever::db('message/inbox')->query($sql);
-		$outbox = $state->fetchAll();
+        $outbox = $state->fetchAll();
 
 
-		if ($outbox) {
-			foreach ($outbox as $k => $v) {
+        if ($outbox) {
+            foreach ($outbox as $k => $v) {
                 $insert['add_uid'] = $uid;
                 $insert['add_uid'] = $uid;
                 $insert['add_oid'] = $v['id'];
                 $insert['add_oid'] = $v['id'];
                 $insert['add_status'] = 1;
                 $insert['add_status'] = 1;
                 $insert['add_project_id'] = $v['project_id'];
                 $insert['add_project_id'] = $v['project_id'];
                 $insert['add_type'] = $v['type'];
                 $insert['add_type'] = $v['type'];
-				//$insert['add_site'] = $v['site'];
-				$insert['add_from_uid'] = $v['uid'];
-				$insert['add_name'] = $v['name'];
+                //$insert['add_site'] = $v['site'];
+                $insert['add_from_uid'] = $v['uid'];
+                $insert['add_name'] = $v['name'];
                 $insert['add_scope'] = $v['scope'];
                 $insert['add_scope'] = $v['scope'];
-				$insert['add_content'] = $v['content'];
+                $insert['add_content'] = $v['content'];
+                $insert['add_param'] = $v['param'];
                 Dever::load('message/inbox-insert', $insert);
                 Dever::load('message/inbox-insert', $insert);
             }
             }
-		}
+        }
         if ($project) {
         if ($project) {
             $param['option_project_id'] = $project;
             $param['option_project_id'] = $project;
         }
         }
@@ -66,7 +67,7 @@ class Data
             $param['option_status'] = $status;
             $param['option_status'] = $status;
             return Dever::load('message/inbox-total', $param);
             return Dever::load('message/inbox-total', $param);
         }
         }
-		$data = Dever::load('message/inbox-getAll', $param);
+        $data = Dever::load('message/inbox-getAll', $param);
 
 
         if ($update) {
         if ($update) {
             foreach ($data as $k => $v) {
             foreach ($data as $k => $v) {
@@ -74,8 +75,8 @@ class Data
             }
             }
         }
         }
 
 
-		return $data;
-	}
+        return $data;
+    }
 
 
     /**
     /**
      * 查看我的新消息
      * 查看我的新消息
@@ -87,26 +88,26 @@ class Data
         return $this->read($uid, false, false, 1, $project);
         return $this->read($uid, false, false, 1, $project);
     }
     }
 
 
-	/**
+    /**
      * 查看我的消息
      * 查看我的消息
      * 
      * 
      * @return mixed
      * @return mixed
      */
      */
-	public function view($uid, $id)
-	{
-		if ($id > 0) {
-			$info = Dever::load('message/inbox-one', array('option_uid' => $uid, 'option_id' => $id));
-			if ($info) {
-				Dever::load('message/inbox-update', array('where_id' => $id, 'set_status' => 2));
+    public function view($uid, $id)
+    {
+        if ($id > 0) {
+            $info = Dever::load('message/inbox-one', array('option_uid' => $uid, 'option_id' => $id));
+            if ($info) {
+                Dever::load('message/inbox-update', array('where_id' => $id, 'set_status' => 2));
 
 
-				$data = Dever::load('message/inbox-one', $id);
+                $data = Dever::load('message/inbox-one', $id);
 
 
-				return $data;
-			}
-		}
+                return $data;
+            }
+        }
 
 
-		Dever::alert('错误的消息信息');
-	}
+        Dever::alert('错误的消息信息');
+    }
 
 
     public function test_api()
     public function test_api()
     {
     {
@@ -129,13 +130,13 @@ class Data
         return $result;
         return $result;
     }
     }
 
 
-	/**
+    /**
      * 推送消息
      * 推送消息
      * 
      * 
      * @return mixed
      * @return mixed
      */
      */
-	public function push($uid, $to_uid, $name, $content, $type = 11, $project = 1, $scope = false, $push = false, $id = -1)
-	{
+    public function push($uid, $to_uid, $name, $content, $type = 11, $project = 1, $scope = false, $param = false, $id = -1)
+    {
         if (!is_numeric($type)) {
         if (!is_numeric($type)) {
             Dever::alert('错误的消息类型');
             Dever::alert('错误的消息类型');
         }
         }
@@ -164,6 +165,14 @@ class Data
             $uid = -1;
             $uid = -1;
         }
         }
 
 
+        if ($param) {
+            if (is_array($param) && isset($param[0])) {
+                $add_param = $param[0];
+            } elseif (is_string($param)) {
+                $add_param = $param;
+            }
+        }
+
         if (is_numeric($uid)) {
         if (is_numeric($uid)) {
             if ($id <= 0) {
             if ($id <= 0) {
                 $data['add_uid'] = $uid;
                 $data['add_uid'] = $uid;
@@ -172,11 +181,14 @@ class Data
                 $data['add_type'] = $type;
                 $data['add_type'] = $type;
                 $data['add_scope'] = $scope;
                 $data['add_scope'] = $scope;
                 $data['add_project_id'] = $project;
                 $data['add_project_id'] = $project;
+                if (isset($add_param)) {
+                    $data['add_param'] = $add_param;
+                }
                 $id = Dever::load('message/outbox-insert', $data);
                 $id = Dever::load('message/outbox-insert', $data);
             }
             }
 
 
             if ($id > 0) {
             if ($id > 0) {
-            	if ($to_uid) {
+                if ($to_uid) {
                     if (strstr($to_uid, ',')) {
                     if (strstr($to_uid, ',')) {
                         $to_uid = explode(',', $to_uid);
                         $to_uid = explode(',', $to_uid);
                     } else {
                     } else {
@@ -184,7 +196,7 @@ class Data
                     }
                     }
                     
                     
                     foreach ($to_uid as $k => $v) {
                     foreach ($to_uid as $k => $v) {
-                    	$insert['add_uid'] = $v;
+                        $insert['add_uid'] = $v;
                         $insert['add_oid'] = $id;
                         $insert['add_oid'] = $id;
                         $insert['add_status'] = 1;
                         $insert['add_status'] = 1;
                         $insert['add_type'] = $type;
                         $insert['add_type'] = $type;
@@ -194,6 +206,9 @@ class Data
                         $insert['add_name'] = $name;
                         $insert['add_name'] = $name;
                         $insert['add_content'] = $content;
                         $insert['add_content'] = $content;
                         //$insert['add_origin'] = $origin;
                         //$insert['add_origin'] = $origin;
+                        if (isset($add_param)) {
+                            $insert['add_param'] = $add_param;
+                        }
                         Dever::load('message/inbox-insert', $insert);
                         Dever::load('message/inbox-insert', $insert);
                     }
                     }
                 }
                 }
@@ -204,10 +219,10 @@ class Data
                         # 发送全部
                         # 发送全部
                         $to_uid = array();
                         $to_uid = array();
                     }
                     }
-                    return Dever::load('message/lib/push')->send($config['push'], $to_uid, $name, $content, $push);
+                    return Dever::load('message/lib/push')->send($config['push'], $to_uid, $name, $content, $param);
                     //Dever::daemon('lib/push.send?', 'message');
                     //Dever::daemon('lib/push.send?', 'message');
                 }
                 }
             }
             }
         }
         }
-	}
+    }
 }
 }

+ 15 - 14
lib/Manage.php

@@ -6,22 +6,23 @@ use Dever;
 
 
 class Manage
 class Manage
 {
 {
-	# 发送消息
+    # 发送消息
     public function send($id, $name, $param)
     public function send($id, $name, $param)
     {
     {
-    	$uid = Dever::param('uid', $param);
-    	$to_uid = Dever::param('to_uid', $param);
-    	$name = Dever::param('name', $param);
-    	$content = Dever::param('content', $param);
-    	$project_id = Dever::param('project_id', $param);
-    	$type = Dever::param('type', $param);
-    	$scope = Dever::param('scope', $param);
+        $uid = Dever::param('uid', $param);
+        $to_uid = Dever::param('to_uid', $param);
+        $name = Dever::param('name', $param);
+        $content = Dever::param('content', $param);
+        $project_id = Dever::param('project_id', $param);
+        $type = Dever::param('type', $param);
+        $scope = Dever::param('scope', $param);
 
 
-    	if (!$uid) {
-    		$uid = -1;
-    	}
-    	if ($to_uid && $name && $content) {
-    		Dever::load('message/lib/data')->push($uid, $to_uid, $name, $content, $type, $project_id, $scope, $id);
-    	}
+        if (!$uid) {
+            $uid = -1;
+        }
+        if ($to_uid && $name && $content) {
+            $push = '';
+            Dever::load('message/lib/data')->push($uid, $to_uid, $name, $content, $type, $project_id, $scope, $id, $push);
+        }
     }
     }
 }
 }

+ 115 - 115
lib/Push.php

@@ -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];
+   }
 }
 }