user = $user->data(); } /** * 获取我的消息 * * @return mixed */ public function read($uid, $type = false, $update = false, $status = false, $project = 1) { if (!$uid) { Dever::alert('错误的用户信息'); } $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; # 去掉a.type判断 $where .= ' and 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 . ' '; $state = Dever::db('message/inbox')->query($sql); $outbox = $state->fetchAll(); if ($outbox) { foreach ($outbox as $k => $v) { $insert['add_uid'] = $uid; $insert['add_oid'] = $v['id']; $insert['add_status'] = 1; $insert['add_project_id'] = $v['project_id']; $insert['add_type'] = $v['type']; //$insert['add_site'] = $v['site']; $insert['add_from_uid'] = $v['uid']; $insert['add_name'] = $v['name']; $insert['add_scope'] = $v['scope']; $insert['add_content'] = $v['content']; Dever::load('message/inbox-insert', $insert); } } if ($project) { $param['option_project_id'] = $project; } if ($type) { $param['option_type'] = $type; } $param['option_uid'] = $uid; if ($status > 0) { $param['option_status'] = $status; return Dever::load('message/inbox-total', $param); } $data = Dever::load('message/inbox-getAll', $param); if ($update) { foreach ($data as $k => $v) { Dever::load('message/inbox-update', array('where_id' => $v['id'], 'set_status' => 2)); } } return $data; } /** * 查看我的新消息 * * @return mixed */ public function num($uid, $project = 1) { return $this->read($uid, false, false, 1, $project); } /** * 查看我的消息 * * @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)); $data = Dever::load('message/inbox-one', $id); return $data; } } Dever::alert('错误的消息信息'); } /** * 推送消息 * * @return mixed */ public function push($uid, $to_uid, $name, $content, $type = 11, $project = 1, $scope = false, $id = -1) { if (!is_numeric($type)) { Dever::alert('错误的消息类型'); } $config = Dever::load('message/type-one', $type); if (!$config) { Dever::alert('错误的消息类型'); } if (!$content) { Dever::alert('错误的消息内容'); } if (!$scope) { $scope = $config['scope']; } if ($scope == 1 && !$uid) { Dever::alert('错误的发件人id'); } if ($scope == 1 && !$to_uid) { Dever::alert('错误的收件人id'); } if ($scope == 2) { $uid = -1; } if (is_numeric($uid)) { if ($id <= 0) { $data['add_uid'] = $uid; $data['add_name'] = $name; $data['add_content'] = $content; $data['add_type'] = $type; $data['add_scope'] = $scope; $data['add_project_id'] = $project; $id = Dever::load('message/outbox-insert', $data); } if ($id > 0) { if ($to_uid) { $to_uid = explode(',', $to_uid); foreach ($to_uid as $k => $v) { $insert['add_uid'] = $v; $insert['add_oid'] = $id; $insert['add_status'] = 1; $insert['add_type'] = $type; $insert['add_scope'] = $scope; $insert['add_project_id'] = $project; $insert['add_from_uid'] = $uid; $insert['add_name'] = $name; $insert['add_content'] = $content; //$insert['add_origin'] = $origin; Dever::load('message/inbox-insert', $insert); } } //这里可以设置发送push if (isset($config['push']) && $config['push'] > 0) { if ($scope == 2) { # 发送全部 $to_uid = -1; } $this->push($config['push'], $to_uid, $name, $content); } } } } private function push($id, $uid, $name, $content) { $config = Dever::db('message/push')->one($id); if ($config) { # 现在就是腾讯信鸽 if ($config['type'] == 1) { $push = new \XingeApp($config['appid'], $config['appsecret']); $mess = new \Message(); $mess->setExpireTime(86400); $mess->setTitle($name); $mess->setContent($content); $mess->setType(\Message::TYPE_MESSAGE); $uid = explode(',', $uid); $accountList = array_walk( $uid, function(&$value, $key, $prefix){$value = $prefix.$value;}, 'dever_' ); $ret = $push->PushAccountList(0, $accountList, $mess); return ($ret); } } } function DemoPushSingleAccountIOS() { $push = new XingeApp(000, 'secret_key'); $mess = new MessageIOS(); $mess->setExpireTime(86400); $mess->setAlert("ios test"); //$mess->setAlert(array('key1'=>'value1')); $mess->setBadge(1); $mess->setSound("beep.wav"); $custom = array('key1'=>'value1', 'key2'=>'value2'); $mess->setCustom($custom); $acceptTime1 = new TimeInterval(0, 0, 23, 59); $mess->addAcceptTime($acceptTime1); $ret = $push->PushSingleAccount(0, 'joelliu', $mess, XingeApp::IOSENV_DEV); return $ret; } }