/** * sso token校验 * @method POST */ public function token() { if ($this->get_method() != 'POST') { $this->send_response(405, NULL, '请求的方法不存在'); } $post = $this->get_data(); $appid = $post['appid'] ? intval($post['appid']) : 0; $appkey = $post['appkey'] ? trim($post['appkey']) : ''; $token = $post['token'] ? trim($post['token']) : ''; if (empty($appid)) { $this->send_response(400, NULL, '40011:appid为空'); } if (empty($appkey)) { $this->send_response(400, NULL, '40012:appkey为空'); } //检查app合法性 if (!$this->model->check_app_valid($appid, $appkey)) { $this->send_response(400, NULL, $this->model->getResponseMsg()); } //require_once MODPATH.'filesystem/include/Core.php'; //$auth_token = Core::authcode($token,'DECODE','sdfjk2348*&21234(*3xx'); //if($auth_token) { $result = $this->model->get_token_info($token); if ($token && $result) { $user_info = sns::getuser($result['ost_usa_id_ref']); $this->send_response(200, array('uid' => $user_info['uid'], 'zone_code' => $user_info['zone_code'], 'mobile' => $user_info['mobile'], 'status' => $user_info['status'])); } //} $this->send_response(400, NULL, '40022:非法用户'); }
/** * 添加赞 */ public function create() { $post = $this->get_data(); $statuses_id = $post['statuses_id']; if (empty($statuses_id)) { $this->send_response(400, NULL, '对象id为空'); } $feed = new Feed_Model(); $doc = $feed->findFeed($statuses_id); if (!$doc) { $this->send_response(404, NULL, '该动态不存在'); } $owner = $doc['owner_uid']; $had_praise = 0; foreach ($doc['like_list'] as $key => $var) { $uid = $var['uid'] ? $var['uid'] : $var['id']; if ((int) $uid == (int) $this->uid) { $had_praise = 1; break; } } $group_member = array(); if ($doc['group_type'] > 0) { $grade = Group_Model::instance()->getMemberGrade($doc['group_id'], $this->uid); if ($grade < 1) { $this->send_response(400, NULL, '400:你不是该群成员,无权限赞'); } $group_member = Group_Model::instance()->getGroupAllMember($doc['group_id']); } $is_bubble = $owner == Kohana::config('uap.xiaomo') ? false : true; if ($doc['last_updated'] && $had_praise == 0) { if (count($group_member) > 0) { foreach ($group_member as $member) { if ($member['uid'] != $this->uid) { if (!$feed->addAboutme($member['uid'], $this->uid, $doc['typeid'], 0, '', array(), $statuses_id, 4)) { $this->send_response(400, NULL, $feed->get_error_msg()); } } } } elseif ($owner != $this->uid) { if (!$feed->addAboutme($owner, $this->uid, $doc['typeid'], 0, '', array(), $statuses_id, 4)) { $this->send_response(400, NULL, $feed->get_error_msg()); } } $feed->addLike($this->uid, sns::getrealname($this->uid), $statuses_id, $is_bubble); if ($doc['group_type'] == 1 && $doc['group_id']) { Tab_Model::instance()->lastModify($this->uid, 1, $doc['group_id']); } $this->send_response(200); } $this->send_response(400, NULL, '赞失败,你已经赞过'); }
public static function getwho($uid = NULL) { if ($uid == NULL) { $uid = sns::getuid(); return Kohana::lang('global.me'); } //当前用户的情况下 // if ($uid == sns::getuid() && !preg_match('|user/[\d]+|', url::current())) return Kohana::lang('global.me'); if ($uid == sns::getuid()) { return Kohana::lang('global.me'); } $data = sns::getuser($uid); return $data['sex'] == '2' ? Kohana::lang('global.her') : Kohana::lang('global.his'); }
private function _user($uid, $avatar_size = 130) { //外部应用不需获取用户信息 if ($this->is_app_standalone) { return array('id' => $uid, 'name' => '', 'avatar' => ''); } if (!$uid) { return array('id' => 0, 'name' => '', 'avatar' => '', 'nick' => array(), 'mobile' => '', 'zone_code' => ''); } if (!$this->_cache_users[$uid]) { $user_info = sns::getuser($uid); $nicks = Friend_Model::instance()->get_contact_formatted_name($this->uid, $user_info['mobile'], $user_info['zone_code']); $mobile = $user_info['mobile']; $this->_cache_users[$uid] = array('id' => (int) $uid, 'name' => $user_info['realname'], 'avatar' => sns::getavatar($uid, $avatar_size), 'nick' => $nicks, 'mobile' => $mobile, 'zone_code' => $user_info['zone_code']); } return $this->_cache_users[$uid]; }
/** * 取得反馈 */ public function index() { if ($this->get_method() != 'POST') { $this->send_response(405, NULL, '请求的方法不存在'); } $data = $this->get_data(); $text = isset($data['text']) ? trim($data['text']) : ''; $contact = isset($data['contact']) ? trim($data['contact']) : ''; $kind = isset($data['kind']) ? trim($data['kind']) : ''; $source = $this->get_source(); if (empty($text)) { $this->send_response(400, NULL, '400901:反馈内容不能为空'); } if (empty($source)) { $this->send_response(400, NULL, '400902:客户端类型id不能为空'); } $this->user_id = $this->getUid(); $name = sns::getrealname($this->user_id); $text = html::specialchars($text); $array = array('uid' => $this->user_id, 'name' => $name, 'content' => $text, 'contact' => $contact, 'kind' => $kind, 'client_id' => $source, 'addtime' => time()); $return = $this->model->saveData($array); $this->send_response(200); }
/** * 创建活动 */ public function create() { if ($this->get_method() != 'POST') { $this->send_response(405, NULL, '请求的方法不存在'); } $data = $this->get_data(); if (!$data) { $this->send_response(400, NULL, '400505:活动信息非法'); } $post = new Validation($data); $post->add_rules('title', 'required', 'length[1, 30]'); $post->add_rules('start_at', 'required', 'numeric'); $post->add_rules('end_at', 'required', 'numeric'); $post->add_rules('spot', 'required', 'length[1, 30]'); $post->add_rules('type', 'required', 'numeric', array($this, '_check_type_validation')); $post->add_rules('is_allow_invite', 'required', 'numeric', array($this, '_check_allow_invite_validation')); $post->add_rules('content', 'length[0, 300]'); $post->add_rules('group_ids', array($this, '_check_group_ids_validation')); $post->add_callbacks(TRUE, array($this, '_check_time_validation')); if ($post->validate()) { $activity = array(); $form = $post->as_array(); $activity['creator_id'] = $this->user_id; $activity['title'] = $form['title']; $activity['start_time'] = $form['start_at']; $activity['end_time'] = $form['end_at']; $nowTime = time(); $activity['create_time'] = $nowTime; $activity['spot'] = $form['spot']; $activity['type'] = $form['type']; $activity['is_allow_invite'] = $form['is_allow_invite']; if (isset($form['content'])) { $activity['content'] = $form['content']; } $groupIds = array(); if (isset($form['group_ids'])) { $groupIds = $form['group_ids']; } $groupModel = new Group_Model(); $gidArray = array(); foreach ($groupIds as $id) { $id = floatval($id); if ($id != -1) { $groupInfo = $groupModel->getGroupInfo($id); if (!$groupInfo) { $this->send_response(400, NULL, '400506:活动发布到的群不存在'); } $grade = $groupModel->getMemberGrade($id, $this->user_id); if ($grade < 1) { $this->send_response(400, NULL, '400507:您不是活动指定发布到群的成员'); } } $gidArray[] = $id; } if (!$gidArray) { $activity['is_publish'] = 0; } else { $activity['is_publish'] = 1; } $activity_id = $this->model->add($activity); $activityMember = array('aid' => $activity_id, 'uid' => $this->user_id, 'apply_type' => Kohana::config('activity.apply_type.join'), 'apply_time' => $nowTime, 'grade' => Kohana::config('activity.grade.creator')); $result = $this->model->applyActivity($activityMember); $this->model->addActivityUser($activity_id, $this->user_id); $friendModel = new Friend_Model(); $fidList = $friendModel->getAllFriendIDs($this->user_id, false); //活动动态发送到指定momo成员 foreach ($gidArray as $gid) { $this->model->addActivityGroup($activity_id, $gid); if ($gid == -1) { $friendModel = new Friend_Model(); $fidList = $friendModel->getAllFriendIDs($this->user_id, false); foreach ($fidList as $fid) { $this->model->addActivityUser($activity_id, $fid); } } else { $this->model->addActivityGroup($activity_id, $gid); $members = $groupModel->getGroupAllMember($gid); foreach ($members as $value) { $this->model->addActivityUser($activity_id, $value['uid']); } } } $feedModel = new Feed_Model(); $title = array('uid' => $this->user_id, 'name' => sns::getrealname($this->user_id), 'id' => $activity_id, 'title' => $activity['title']); $messageModel = new Message_Model(); if ($activity['is_publish']) { $feedModel->addFeed($this->user_id, 'action_add', Kohana::config('uap.app.action'), $title, array(), $activity_id); } $this->send_response(200, array('id' => floatval($activity_id))); } $errors = $post->errors(); $this->send_response(400, NULL, '400505:活动信息非法'); }
/** * * 获取群组管理员 */ private function _get_group_manager($gid) { $gm_user = array(); $gm = $this->model->getGroupManager($gid); if ($gm) { foreach ($gm as $v) { $gm_user[] = array('id' => $v['uid'], 'name' => sns::getrealname($v['uid']), 'avatar' => sns::getavatar($v['uid'])); } } return $gm_user; }
public function sendfacefeed($pid, $album_id = 0, $img = "", $appid = 0) { $return = false; if ($pid) { $feed_flag = 1; if ($feed_flag == 1) { //发送好友动态 $data = $this->db->getRow("album_pic", "pic_width, pic_height", "pic_id={$pid}"); if ($data['pic_height'] >= 780 || $data['pic_width'] >= 780) { if ($height >= $width) { $height_780 = 780; $width_780 = intval($data['pic_width'] / ($data['pic_height'] / 780)); } else { $width_780 = 780; $height_780 = intval($data['pic_height'] / ($data['pic_width'] / 780)); } } else { $height_780 = $data['pic_height']; $width_780 = $data['pic_width']; } $this->feed = new Feed_Model(); if (!$img) { $img = Kohana::config('album.recordThumb') . 'thumb/' . $pid . '_120.jpg'; } $realname = sns::getrealname($this->uid); $feedkey = sns::getFeedUniqid('user_face_update'); $feed = array('title' => array('uid' => $this->uid, 'name' => sns::getrealname($this->uid), 'time' => time(), 'appid' => $appid), 'body' => array('uid' => $this->uid, 'image' => $img, 'name' => $realname, 'pid' => $pid, 'img_780' => Kohana::config('album.recordThumb') . 'thumb/' . $pid . '_780.jpg', 'aid' => $album_id, 'height_780' => $height_780, 'width_780' => $width_780)); $result = $this->feed->addFeed($this->uid, 'user_face_update', Kohana::config('uap.app.user'), $feed['title'], $feed['body'], $feedkey, '', '', array(), $appid); $return = $result['code'] == 200 ? true : false; } } return $return; }
/** * 获取关于我的动态,提供iphone,andriod使用 * @return <type> */ public function aboutme_alone() { $pos = $this->input->get('pagesize', 20); $start = $this->input->get('page', 1); $new = $this->input->get('new', 0); $pos = $pos > 100 ? 100 : $pos; $start = abs(($start - 1) * $pos); $arr = $this->feedModel->findAboutme($new, $pos, $start); $res = array(); if ($arr) { $i = 0; foreach ($arr as $row) { $res[$i]['id'] = $row['_id']; $res[$i]['statuses_id'] = $row['feed_id']; $res[$i]['kind'] = $row['kind']; $res[$i]['group'] = array('id' => $this->_st($row['group_id'], 0), 'name' => $this->_st($row['group_name'], '')); $res[$i]['text'] = $this->_st($this->feedModel->format_title($row['comment_content'], $this->source), ''); $res[$i]['source'] = $row['source'] == 0 ? '' : $this->get_source($row['source']); $res[$i]['user'] = array('id' => $this->_st($row['comment_uid'], 0), 'name' => $this->_st(sns::getrealname($row['comment_uid'])), 'avatar' => sns::getavatar($row['comment_uid'], 'small')); $res[$i]['new'] = $row['new'] == 1 ? true : false; $res[$i]['created_at'] = ceil($row['addtime'] / 10000); $aboutme_opt = array(); if ($row['kind'] == 6) { $content = $this->_st(strip_tags($row['reply_content']), ''); $aboutme_opt['reply_source'] = array('id' => $row['reply_id'], 'text' => $this->feedModel->format_title($content, $this->source), 'at' => $row['reply_at'], 'user' => array('id' => $row['reply_uid'], 'name' => $row['reply_name'], 'avatar' => sns::getavatar($row['reply_uid'], 'small'))); } elseif ($row['kind'] == 2) { $aboutme_opt['message'] = array('text' => $this->_st($this->feedModel->format_title($row['feed_content'], $this->source), ''), 'at' => $row['feed_at']); } else { $content = $this->_st(strip_tags($row['feed_content']), ''); $aboutme_opt['statuses'] = array('text' => $this->feedModel->format_title($content, $this->source), 'at' => $row['feed_at'], 'uid' => $this->_st($row['feed_uid'], 0), 'name' => $this->_st($row['feed_name'])); } if (in_array($row['kind'], array(1, 3, 6))) { $aboutme_opt['comment'] = array('id' => $row['comment_id'], 'text' => $this->_st($this->feedModel->format_title(str_replace(array('评论道:', '回复:'), '', $row['comment_content']), $this->source), ''), 'at' => $row['comment_at']); } $res[$i]['opt'] = $aboutme_opt; $i++; } $this->feedModel->updateAboutmeRead(); } $this->send_response(200, $res); }
/** * * 获取备份记录 * @param $user_id */ public function get_backup_history($user_id, $device_id = '', $num = 1) { $setters = array('uid' => $user_id); $result = $history = array(); $table = $this->get_table($user_id, 'backup_history'); $sql = "SELECT device_id,batch_number,phone_model,backup_total_sms,dateline FROM {$table} WHERE uid='{$user_id}' "; if ($device_id) { $sql .= " AND device_id='{$device_id}' "; } $sql .= "ORDER BY dateline DESC LIMIT {$num}"; $query = $this->db->query($sql); $result = $query->result_array(FALSE); if ($query->count() > 0) { foreach ($result as $key => $var) { $history[$key] = $var; $history[$key]['dateline_alias'] = sns::gettime($var['dateline']); $history[$key]['device_alias'] = Brand_Model::instance()->get_by_model($var['phone_model']); } } return array_values($history); }
/** * 获取用户参加的所有活动列表(确认参加与可能参加) * @param int $aid 活动id * @param int $apply_type 参与活动类型,默认为参加类型 * @param bool $now 活动是否正在进行(未结束状态) * @return array */ public function userAllJoinActivity($uid, $apply_type = 1, $now = false) { $aidList = array(); $activityList = array(); $join = Kohana::config('activity.apply_type.join'); $interest = Kohana::config('activity.apply_type.interest'); $query = $this->db->query("SELECT aid FROM action_member WHERE uid = {$uid} AND (apply_type = {$join} OR apply_type = {$interest}) ORDER BY apply_time DESC"); if ($query->count() != 0) { $aidList = $query->result_array(FALSE); } $nowtime = time(); foreach ($aidList as $value) { $activity = $this->getActivityInfo($value['aid'], false); $activity['creator_name'] = sns::getrealname($activity['creator_id']); if ($now && $nowtime > $activity['end_time'] + Kohana::config('activity.additional_time')) { continue; } if (date('Y', $activity['start_time']) != date('Y', $activity['end_time']) || date('Y') != date('Y', $activity['start_time'])) { $activity['start_time'] = date('Y年m月d日 H:i', $activity['start_time']); $activity['end_time'] = date('Y年m月d日 H:i', $activity['end_time']); } else { if (date('Y-m-d', $activity['start_time']) != date('Y-m-d', $activity['end_time'])) { $activity['start_time'] = date('m月d日 H:i', $activity['start_time']); $activity['end_time'] = date('m月d日 H:i', $activity['end_time']); } else { $activity['start_time'] = date('m月d日 H:i', $activity['start_time']); $activity['end_time'] = date('H:i', $activity['end_time']); } } $activityList[] = $activity; } return $activityList; }
private function bulid_user_hyperlinks(&$matches) { if ($matches[1] == sns::getrealname($matches[2]) || !$matches[2]) { $this->at2id[] = array('id' => $matches[2], 'name' => $matches[1]); return '[@' . (count($this->at2id) - 1) . ']'; } return $matches[0]; }
private function _transTime($time) { $year = substr($time, 0, 4); $month = substr($time, 4, 2); $day = substr($time, 6, 2); $hour = substr($time, 8, 2); $minute = substr($time, 10, 2); $second = substr($time, 12, 2); return sns::gettime(mktime($hour, $minute, $second, $month, $day, $year)); }
/** * 根据需求查询 * @param string $query 查询字符串 * @return array */ public function cypher($query) { $result = $this->_graph_query($query, 25); if ($result) { $cols = $result->getColumns(); $return = array(); foreach ($result as $i => $row) { /** @var Everyman\Neo4j\PropertyContainer[] $row */ foreach ($cols as $col) { if ($row[$col] instanceof Everyman\Neo4j\Node) { /** @var Everyman\Neo4j\Node[] $row */ $return[$i][$col]['meta']['id'] = $row[$col]->getId(); $return[$i][$col]['property'] = $row[$col]->getProperties(); if ($user_id = $row[$col]->getProperty('uid')) { $return[$i][$col]['property']['name'] = sns::getrealname($user_id); $return[$i][$col]['property']['avatar'] = sns::getavatar($user_id); } } elseif ($row[$col] instanceof Everyman\Neo4j\Relationship) { /** @var Everyman\Neo4j\Relationship[] $row */ $return[$i][$col]['meta']['id'] = $row[$col]->getId(); $return[$i][$col]['meta']['type'] = $row[$col]->getType(); $return[$i][$col]['meta']['start_node'] = $row[$col]->getStartNode()->getId(); $return[$i][$col]['meta']['end_node'] = $row[$col]->getEndNode()->getId(); $return[$i][$col]['property'] = $row[$col]->getProperties(); } elseif ($row[$col] instanceof Everyman\Neo4j\Query\Row) { foreach ($row[$col] as $j => $r) { if ($r instanceof Everyman\Neo4j\Node) { /** @var Everyman\Neo4j\Node[] $row */ $return[$i][$col][$j]['meta']['id'] = $r->getId(); $return[$i][$col][$j]['property'] = $r->getProperties(); if ($user_id = $r->getProperty('uid')) { $return[$i][$col][$j]['property']['name'] = sns::getrealname($user_id); $return[$i][$col][$j]['property']['avatar'] = sns::getavatar($user_id); } } elseif ($r instanceof Everyman\Neo4j\Relationship) { /** @var Everyman\Neo4j\Relationship[] $row */ $return[$i][$col][$j]['meta']['id'] = $row[$col]->getId(); $return[$i][$col][$j]['meta']['type'] = $row[$col]->getType(); $return[$i][$col][$j]['meta']['start_node'] = $row[$col]->getStartNode()->getId(); $return[$i][$col][$j]['meta']['end_node'] = $row[$col]->getEndNode()->getId(); $return[$i][$col][$j]['property'] = $r->getProperties(); } else { $return[$i][$col][$j] = $r; } } } else { $return[$i][$col] = $row[$col]; } } } return $return; } return false; }
/** * * @return none */ public function personal($id = NULL) { if ($this->get_method() != 'GET') { $this->send_response(405, NULL, '请求的方法不存在'); } $data = $this->get_data(); if (empty($id)) { $this->send_response(400, NULL, '401307:交易ID为空'); } $id = (int) $id; $user_info = sns::getuser($id); if (!$user_info) { $this->send_response(400, NULL, '401311:用户不存在'); } $stat = $this->model->stat($id); $deal_lists = $this->model->personal_lists($id, $this->user_id); $this->send_response(200, array('id' => (int) $id, 'name' => $user_info['realname'], 'avatar' => sns::getAvatar($id), 'deal_stat' => array('total' => (int) $stat['total'], 'success' => (int) $stat['success']), 'deal_lists' => $deal_lists, 'relationship' => 0, 'social_account' => array('sina_weibo' => '', 'qq_weibo' => ''))); }
/** * * 整理用户信息 * @param array $item * @param int $apply_type */ private function _arrange_user_item($item, $apply_type, $event_info) { $arranged_item = array(); if (!empty($item)) { $arranged_item['uid'] = $item['uid']; $arranged_item['pid'] = $item['pid']; $arranged_item['name'] = $item['name']; $arranged_item['avatar'] = sns::getavatar($item['uid']); if ($this->user_id == $event_info['organizer'] || $this->user_id == $item['uid'] || $this->user_id == $item['pid']) { $arranged_item['mobile'] = $item['mobile']; if ($apply_type == Kohana::config('event.apply_type.joined')) { $arranged_item['apply_doc'] = $this->model->getUserApplyDoc($item['eid'], $item['uid'], $item['pid'], '', $item['name']); } } } return $arranged_item; }
/** * 报名活动 */ public function create($id = 0) { $data = $this->get_data(); $aid = (int) $id; $apply_type = (int) $data['type']; $webRequest = (int) $data['web']; if ($webRequest != 2) { $webRequest = 0; } if ($this->get_method() != 'POST') { $this->send_response(405, NULL, '请求的方法不存在'); } if ($id == 0) { $this->send_response(400, NULL, '400501:活动id为空'); } if ($apply_type < Kohana::config('activity.apply_type.join') || $apply_type > Kohana::config('activity.apply_type.interest')) { $this->send_response(400, NULL, '400508:活动报名类型非法'); } $activity = $this->model->getActivityInfo($aid); if (!$activity) { $this->send_response(400, NULL, '400502:活动不存在'); } if ($activity['end_time'] < time()) { $this->send_response(400, NULL, '活动已结束'); } $permit = $this->_check_activity_view_permission($activity, $this->user_id); if (!$permit) { $this->send_response(400, NULL, '400510:无权限报名活动'); } if ($webRequest > 0) { $types = array_flip(Kohana::config('activity.type')); $typeId = $types[$activity['type']]; $typeNames = Kohana::config('activity.typeName'); $type = $typeNames[$typeId]; $view = new View('activity/details'); $view->webRequest = $webRequest; $view->type = $type; $user = array(); $user['id'] = floatval($activity['creator_id']); $userInfo = sns::getuser($activity['creator_id']); $user['name'] = $userInfo['realname']; $user['mobile'] = $userInfo['mobile']; $activity['user'] = $user; unset($user); $organizer = array(); $organizerList = $this->model->getActivityOrganizer($aid); $organizerIdList = array(); foreach ($organizerList as $value) { $user = array(); $user['id'] = floatval($value['uid']); $userInfo = sns::getuser($value['uid']); $user['name'] = $userInfo['realname']; $user['avatar'] = sns::getavatar($value['uid']); $user['mobile'] = $userInfo['mobile']; $organizer[] = $user; $organizerIdList[] = $user['id']; unset($userInfo); unset($user); } $activity['organizer'] = $organizer; $view->activity = $activity; $view->apply_type = $apply_type; } $userModel = new User_Model(); $nowTime = time(); $feedModel = new Feed_Model(); //获取用户是否已经参与了报名 $applyResult = $this->model->getActivityApplyType($aid, $this->user_id); if ($applyResult) { $tab = $userModel->getTag($this->user_id, 15, $aid); if ($applyResult == $apply_type) { if ($webRequest > 0) { $view->render(true); exit; } $this->send_response(200); } else { if ($applyResult == Kohana::config('activity.apply_type.not_join') && !$tab) { $userModel->insertTag($this->user_id, 15, $aid); } else { if ($apply_type == Kohana::config('activity.apply_type.not_join')) { //$userModel->deleteTag($this->user_id, 15, $aid); } } } $activityMember = array('apply_type' => $apply_type, 'apply_time' => $nowTime); $grade = $this->model->getMemberGrade($aid, $this->user_id); if ($grade == Kohana::config('activity.grade.manager') && $apply_type != Kohana::config('activity.apply_type.join')) { $activityMember['grade'] = Kohana::config('activity.group.normal'); } $result = $this->model->updateApplyActivity($aid, $this->user_id, $activityMember); $this->_add_feed_comment($activity, $applyResult, $apply_type, $this->user_id); $feedModel->addTab($aid, $activity['title'], 15, $this->user_id); if ($webRequest > 0) { $view->render(true); exit; } $this->send_response(200); } $activityMember['aid'] = $aid; $activityMember['uid'] = $this->user_id; $activityMember['apply_type'] = $apply_type; $activityMember['apply_time'] = $nowTime; $activityMember['grade'] = Kohana::config('activity.grade.normal'); $this->model->applyActivity($activityMember); $userModel->insertTag($this->user_id, 15, $aid); $messageModel = new Message_Model(); $appid = Kohana::config('uap.app.action'); $tplid = Kohana::config('noticetpl.actionInvite.id'); while (true) { $inviteMsg = $messageModel->getNoticeInfo(array('uid' => $this->user_id, 'appid' => $appid, 'tplid' => $tplid, 'objid' => $aid, 'status' => 0)); if ($inviteMsg) { //修改系统消息模板 $invite_uid = $inviteMsg['authorid']; $nid = $inviteMsg['id']; $messageModel->putChangeTplByid($this->user_id, $nid, $apply_type); $this->model->setInviteStatus($aid, $invite_uid, $this->user_id); } else { break; } } if ($apply_type == Kohana::config('activity.apply_type.not_join')) { if ($webRequest > 0) { $view->render(true); exit; } $this->send_response(200); } $this->_add_feed_comment($activity, 0, $apply_type, $this->user_id); $feedModel->addTab($aid, $activity['title'], 15, $this->user_id); if ($webRequest > 0) { $view->render(true); exit; } $this->send_response(200); }
/** * 根据用户权限获取好友信息 * @param int $user_id 当前用户ID * @param int $friend_user_id 获取用户ID * @return Contact */ public function get_user_info($user_id, $friend_user_id) { $user_model = User_Model::instance(); $result = $user_model->get_user_info($friend_user_id); if ($result !== FALSE) { $friend_country_code = $result['zone_code']; $data = $user_model->profile_assembly($result, $user_id); $data = array_merge($data, Contact_Helper::formatted_name_to_name($data['name'])); //根据权限获取好友信息 $user_country_code = $this->get_country_code($user_id); $prefix = ''; if ($user_country_code and $friend_country_code and $user_country_code != $friend_country_code) { $prefix = '+' . $friend_country_code; } $array = array(); foreach ($data as $key => $value) { if (in_array($key, array('family_name', 'given_name', 'nickname', 'department', 'title', 'birthday', 'organization'))) { $array[$key] = $value; } elseif ($key == 'tels') { if (!empty($value)) { foreach ($value as $val) { if ($prefix and strpos($val['value'], $prefix) !== 0) { $tel = $prefix . $val['value']; } else { $tel = $val['value']; } if (!empty($val['pref'])) { $array[$key][] = array('type' => $val['type'], 'value' => $tel, 'pref' => $val['pref']); } else { $array[$key][] = array('type' => $val['type'], 'value' => $tel); } } } } elseif (in_array($key, array('emails', 'ims', 'addresses', 'urls'))) { if (!empty($value)) { foreach ($value as $val) { $array[$key][] = $val; } } } } //获取好友头像 $array['avatar'] = sns::getavatar($friend_user_id, 130); return Contact_Helper::array_to_contact($array, $user_country_code); } return FALSE; }
public function saveComment($status_id, $content, $feed_uid, $client_id = 0, $reply_commentid = 0, $uid = 0, $group_member = array()) { $this->at2id = array(); $comment_at = array(); $isall = 0; if (strpos($content, '@全部成员(0)') !== false) { $isall = 1; } $addfeed = new Feed_Model(); $doc = $addfeed->findFeed($status_id); $this->group_id = (int) $doc['group_id']; $content = preg_replace_callback('#\\b(https?)://[-A-Z0-9+&\\#/%?=~_|!:,.;]*[-A-Z0-9+&\\#/%=~_|]#i', array($this, 'bulid_hyperlinks'), $content); $content = preg_replace_callback('/@([^@]+?)\\(([0-9]*)\\)/', array($this, 'bulid_user_hyperlinks'), $content); $comment_at = $this->at2id; $time = time(); $typeid = 4; $feed_uid = $doc['owner_uid']; $uid = $uid == 0 ? $this->uid : $uid; $content_link = $addfeed->atLink($content, $this->at2id); $m = new MongoClient(Kohana::config('uap.mongodb')); $comment_id = md5($status_id . '_' . $feed_uid . '_' . microtime()); $addTime = microtime(true) * 10000; $col = $this->m->selectCollection('im_user'); //右侧聊天窗口start $arr = $col->find(array('feedid' => $status_id)); if (!empty($arr)) { $source_name = api::get_source_name($client_id); $immsg = array("kind" => "im", "data" => array("id" => $comment_id, "statuses_id" => $status_id, "owner_uid" => $feed_uid, "user" => array('id' => $uid, 'name' => sns::getrealname($uid), 'avatar' => sns::getavatar($uid)), "datetime" => $addTime, "created_at" => sns::gettime($time), "source_name" => $source_name == 'MOMO网站' ? '' : $source_name, "text" => $content_link)); $uid_string = ''; foreach ($arr as $v) { if ($v['uid'] == $uid) { continue; } if (strlen($uid_string) > 200) { $this->mq_send(json_encode($immsg), substr($uid_string, 0, -1)); $uid_string = ''; } $uid_string .= $v['uid'] . '.'; } $this->mq_send(json_encode($immsg), substr($uid_string, 0, -1)); } //右侧聊天窗口end $client_id = $client_id ? $client_id : 0; $realname = sns::getrealname($uid); $array = array('id' => $comment_id, 'feedid' => $status_id, 'content' => $content, 'at' => $this->at2id, 'addtime' => $addTime, 'uid' => intval($uid), 'realname' => $realname, 'client_id' => intval($client_id), 'owner' => intval($feed_uid)); $this->comment->insert($array); if ($doc) { } $typeid = $doc['typeid']; $sended_uid = array(); //回复某人 if ($reply_commentid) { $reply_comment = $this->comment->findOne(array('id' => $reply_commentid)); $is_reply = false; if ($reply_comment['uid'] && count($this->at2id) > 0) { foreach ($this->at2id as $key => $var) { if ($var['id'] == $reply_comment['uid']) { $is_reply = true; $reply_key = key; continue; } } if ($is_reply) { $sended_uid[] = $reply_comment['uid']; unset($comment_at[$reply_key]); $addfeed->addAboutme($reply_comment['uid'], $this->uid, $typeid, $comment_id, $content, $this->at2id, $status_id, 6, $reply_comment); } } } //评论动态 if ($feed_uid != $this->uid && $reply_uid != $feed_uid) { if (!in_array($feed_uid, $sended_uid)) { $sended_uid[] = $feed_uid; $addfeed->addAboutme($feed_uid, $this->uid, $typeid, $comment_id, $content, $this->at2id, $status_id, 1); } } //群组评论动态 if (count($group_member) > 0) { foreach ($group_member as $member) { if (!in_array($member['uid'], $sended_uid) && $member['uid'] != $this->uid) { $sended_uid[] = $member['uid']; $addfeed->addAboutme($member['uid'], $this->uid, $typeid, $comment_id, $content, $this->at2id, $status_id, 1); } } } //动态中@某人 if (!empty($comment_at) && count($comment_at) > 0) { foreach ($comment_at as $key => $var) { if ($var['id'] != $feed_uid && !in_array($var['id'], $sended_uid) && !$var['group_id']) { $sended_uid[] = $var['id']; $addfeed->addAboutme($var['id'], $this->uid, $typeid, $comment_id, $content, $this->at2id, $status_id, 3); } } } $comment_list = array('id' => $comment_id, 'uid' => intval($uid), 'name' => $realname, 'created_at' => intval($time), 'text' => $content, 'at' => $this->at2id, 'source' => $client_id, 'im' => 0); $isbubble = $feed_uid == Kohana::config('uap.xiaomo') ? false : true; $addfeed->addFeedComment($status_id, $comment_list, $isbubble); $addfeed->updateFeed($status_id); $addfeed->delHidden($status_id); $addfeed->mo_sms('comment', $status_id, $comment_id, $this->at2mo); $return = array("success" => true, "data" => array("id" => $comment_id, "text" => $content_link)); return $return; }
/** * * 评论mo短信 * @param string $feedid * @param array $at */ private function mo_sms_comment($commentid, $feedid, $receiver_uid, $receiver_name, $moid = '', $auto) { $type = $this->format_type($typeid); $sender_uid = $this->uid; $sender_name = sns::getrealname($this->uid); //检查接收者是否在自己联系人中,并且接收者级别<3 if (Friend_Model::instance()->check_iscontact($sender_uid, $receiver_uid)) { $receiver_status = sns::getstatus($receiver_uid); if ($receiver_status >= 3 && $auto == true) { return false; } } else { return false; } //接收者的用户基本要<2x if (!$this->is_mo_sms_sent('comment', $feedid, $sender_uid, $receiver_uid, $moid)) { $receiver_info = sns::getuser($receiver_uid); $url_code = Url_Model::instance()->create('status', $sender_uid, $sender_name, $receiver_uid, $receiver_name, $receiver_info['mobile'], $receiver_info['zone_code'], $feedid); $short_url = MO_SMS_JUMP . $url_code; $comment_row = $this->comment_new->findOne(array('id' => $commentid)); if ($comment_row) { $content = str::cnSubstr($this->feed_at_format($comment_row['content'], $comment_row['at']), 0, 15) . '..'; $data = array(); $data['sender']['id'] = $sender_uid; $data['sender']['name'] = $sender_name; $data['receiver'][] = $receiver_uid; $data['timestamp'] = time(); $data['content']['text'] = $sender_name . '分享了:' . $content . ',点开互动: ' . $short_url; $mq_msg = array("kind" => "mobile_sms", "data" => $data); $this->mq_send(json_encode($mq_msg), $this->uid, 'momo_im'); $this->mo_sms_log('comment', $commentid, $feedid, $this->uid, $receiver_uid, $moid); if ($moid) { $this->update_my_mo($moid); } return true; } } }
/** * 获取机器人信息 * @param int $robot_id 机器人ID * @return array */ public function find_by_id($robot_id) { $query = $this->db->getwhere('app_robot', array('robot_id' => $robot_id)); $result = array(); if ($query->count()) { $res = $query->result_array(FALSE); $result = $res[0]; $result['avatar'] = sns::getavatar($robot_id); } return $result; }
/** * 管理员接受群组申请 * @return <type> */ public function agree_group_admin() { $data = $this->get_data(); $message_id = $data['id']; if (empty($message_id)) { $this->send_response(400, NULL, '400102:消息id非法'); } $result = $this->model->getNoticeInfo(array('id' => $message_id, 'uid' => $this->user_id), true); if (!$result) { $this->send_response(400, NULL, '400101:消息体不存在或已经被处理'); } $group_tmp = json_decode($result['title'], true); $gid = $group_tmp['group'][0]['id']; $gname = $group_tmp['group'][0]['name']; $group_info = $this->groupModel->getGroupInfo($gid); if (!$group_info) { $this->model->putChangeTplByid($this->user_id, $message_id, 6); $this->send_response(400, NULL, '400109:群不存在'); } $grade = $this->groupModel->getmembergrade($gid, $this->user_id); if ($grade < 2) { $this->model->putChangeTplByid($this->user_id, $message_id, 5); $this->send_response(400, NULL, '400111:你不是群组管理员,无权进行此操作'); } $req_uid = $result['authorid']; $apply = $this->groupModel->getUserApplyGroup($gid, $req_uid); if (!$apply) { $this->send_response(400, NULL, '400112:群申请记录不存在'); } if ($apply['status'] && $apply['manager_uid'] != $this->user_id) { $this->model->putChangeTplByid($this->user_id, $message_id, 3); $this->send_response(400, NULL, '400113:请求已被其他管理员处理'); } $gname = $group_info['gname']; $username = sns::getrealname($this->user_id); $title = array('uid' => $this->user_id, 'name' => $username, 'group' => array(array('id' => $gid, 'name' => $gname))); $grade = $this->groupModel->getmembergrade($gid, $req_uid); if ($grade > 0) { //已经是群成员 $this->model->putChangeTplByid($this->user_id, $message_id, 3); $this->send_response(400, NULL, '400108:已经是群成员'); } //查询群组成员总数是否超出最大限制(暂定100) $memberNum = $group_info['member_number']; if ($group_info['type'] == Kohana::config('group.type.public')) { $maxMemberNum = Kohana::config('group.maxMemberNum.public'); } else { $maxMemberNum = Kohana::config('group.maxMemberNum.private'); } if ($memberNum >= $maxMemberNum) { $this->model->putChangeTplByid($this->user_id, $message_id, 4); $this->send_response(400, NULL, '400114:群组成员人数已满'); } $ret = $this->groupModel->addGroupMember($gid, $req_uid, 1); $this->groupModel->addMemberNum($gid); $feedModel = new Feed_Model(); if ($group_info['type'] == Kohana::config('group.type.private')) { $dateline = time(); try { //添加群组通讯录联系人 $ret = $this->groupContactModel->addGroupContactByUserCard($gid, $req_uid, $dateline); } catch (Exception $exc) { $this->send_response(400, NULL, '400115:导入个人名片到群组通讯录联系人失败'); } $ginfo['modify_time'] = $dateline; $ret = $this->groupModel->modifyGroup($gid, $ginfo); } else { if ($group_info['type'] == Kohana::config('group.type.public')) { //发送加入公开群组动态 $application = array('id' => floatval($gid), 'title' => '查看群组', 'url' => 'group/' . $gid); $feedModel->addFeed($req_uid, 2, $text = '加入了群组:' . $group_info['gname'], $this->get_source(), $application, $at = array(), $images = array(), $sync = array(), $group_type = 0, $group_id = 0, $retweet_id = 0, $allow_rt = 0, $allow_comment = 1, $allow_praise = 1, $allow_del = 1, $allow_hide = 1); } } $commentModel = new Comment_Model(); if ($group_info['feed_id']) { $friendModel = Friend_Model::instance(); $isFriend = $friendModel->check_isfriend($req_uid, $group_info['creator_id']); if ($isFriend) { $commentModel->saveComment($group_info['feed_id'], '加入了本群', $group_info['creator_id'], 0, 0, $req_uid); } } if ($group_info['group_feed_id']) { $commentModel->saveComment($group_info['group_feed_id'], '加入了本群', $group_info['creator_id'], 0, 0, $req_uid); } //添加群到首页tab列表 $userModel = new User_Model(); $userModel->insertTag($req_uid, 7, $gid); $feedModel->addTab($gid, $group_info['gname'], 7, $req_uid); $appid = Kohana::config('uap.app.group'); // 添加通知 $this->model->putAddNotice($req_uid, $appid, 'agreeJoinGroup', $title); $this->model->putChangeTplByid($this->user_id, $message_id, 1); //更新申请加入群记录状态 $this->groupModel->dealApplyMember($gid, $req_uid, $this->user_id); $this->send_response(200); }
public function message_opt_friend_apply($data, $message_id, $mini) { $location = ''; $sex = 0; $together_count = 0; $same_friend = array(); $result = $this->getNoticeInfo(array('id' => $message_id, 'authorid' => $this->uid), true); if ($result) { $tmp = $result['body'] ? json_decode($result['body'], true) : array("explain" => ""); //取得共同好友 $friendModel = new Friend_Model(); $ffids = $friendModel->getAllFriendIDs($result['authorid'], false); $mfids = $friendModel->getAllFriendIDs($this->uid, false); $together = array_intersect($ffids, $mfids); $data = sns::getuser($result['authorid']); $tmp['reside'] = ''; if ($data['resideprovince'] || $data['residecity']) { $config = Kohana::config_load('cityarray'); //加载城市数组 $province = isset($data['resideprovince']) ? isset($config['province'][$data['resideprovince']]) ? $config['province'][$data['resideprovince']] : '' : ""; $city = isset($data['residecity']) ? isset($config['city'][$data['residecity']]) ? $config['city'][$data['residecity']] : '' : ""; $location = $province . " " . $city; } $sex = $data['sex'] == 1 ? "男" : "女"; $tmp['fid'] = $result['authorid']; $tmp['explain'] = $tmp['explain'] ? str::unhtmlspecialchars($tmp['explain']) : ''; unset($data, $ffids, $mfids, $config); $str = ""; $urlpre = url::base(); $avatar = sns::getavatar($result['authorid']); if (!empty($together)) { $together_count = count($together); $i = 0; foreach ($together as $val) { $item = array(); $item['id'] = $val; $item['name'] = sns::getrealname($val); $same_friend[] = $item; if (9 < ++$i) { break; } } } } return array('location' => $location, 'sex' => $sex, 'together_count' => $together_count, 'together' => $same_friend); }
public function search() { $friends = $this->friend_model->get_user_link_cache($this->user_id); $data = $this->get_data(); $mobiles = isset($data['mobiles']) ? $data['mobiles'] : array(); $result = array(); foreach ($mobiles as $mobile) { $res = international::check_mobile($mobile); if (!$res) { continue; } $user = $this->model->get_user_by_mobile($res['country_code'], $res['mobile']); if ($user) { $uuid = $this->user_id; $pos = array_search($user['id'], $friends); //已经是好友或者是登录者自己 if ($pos !== False || $user['id'] == $this->user_id) { continue; } $result[] = array('id' => $user['id'], 'name' => $user['username'], 'avatar' => sns::getavatar($user['id'])); } } $this->send_response(200, $result); }
public function __construct() { parent::__construct(); switch ($this->second) { case 'request_token': $this->oauth_server->requestToken(); exit; case 'authorize': if ($this->get_method() == 'POST' || !empty($_POST)) { if (!empty($_POST)) { $oauth_token = $_POST['oauth_token']; $account = $_POST['account']; $password = $_POST['password']; $oauth_callback = $_POST['oauth_callback']; } else { $data = $this->get_data(); $oauth_token = $data['oauth_token']; $account = isset($data['account']) ? $data['account'] : ''; $password = isset($data['password']) ? $data['password'] : ''; $oauth_callback = isset($data['oauth_callback']) ? $data['oauth_callback'] : ''; $this->is_mobile = true; } $to_post['account'] = $account; $to_post['password'] = $password; $result = $this->_uc_fopen(API_PATH . 'user/verify.json', 0, $this->to_postdata($to_post), 'POST'); $result_obj = json_decode($result['data']); if (isset($result_obj->error_code) && $result_obj->error_code == 400) { $this->error = $result_obj->error; if (empty($oauth_callback)) { $this->send_response(400, NULL, $result_obj->error); } } if (isset($result_obj->uid) && $result_obj->uid > 0) { $this->oauth_server->authorizeVerify($oauth_token, $oauth_callback, $this->is_mobile); $verifier = $this->oauth_server->authorizeFinish(true, $result_obj->uid, $oauth_token); if (!empty($verifier)) { if ($this->is_mobile) { $result = array(); $result['verifier'] = $verifier; $result['user_id'] = $result_obj->uid; $result['name'] = $result_obj->name; $result['avatar'] = sns::getavatar($result_obj->uid); $result['role'] = $result_obj->role; $this->send_response(200, $result); } $this->render_authorize_verifier($verifier); } } } try { $app_info = $this->oauth_server->authorizeVerify(); $this->assert_logged_in($app_info); } catch (OAuthException2 $e) { header('HTTP/1.1 400 Bad Request'); header('Content-Type: text/plain'); echo "Failed OAuth Request: " . $e->getMessage(); } exit; case 'access_token': $this->oauth_server->accessToken(); exit; default: header('HTTP/1.1 404 Not Found'); header('Content-Type: text/plain'); echo "Unknown request"; exit; } }
/** * 精确查找用户 * @method GET */ public function search() { if ($this->get_method() != 'GET') { $this->send_response(405, NULL, '请求的方法不存在'); } $name = $this->input->get("name"); $name = trim($name); if (empty($name)) { $this->send_response(400, NULL, "name不能为空"); } $page = (int) $this->input->get("page", 1); if ($page <= 0) { $this->send_response(400, NULL, "输入有误"); } $pos = (int) $this->input->get("pagesize", 20); if ($pos < 0 || $pos > self::MAX_PAGESIZE) { $this->send_response(400, NULL, "输入有误"); } $start = ($page - 1) * $pos; $total = $this->model->get_user_counts_byname($name); if (!$total) { $this->send_response(200, array("count" => $total, "start" => 0, "pos" => 0, "data" => array())); } $result = $this->model->get_users_byname($name, $start, $pos); $tmp = array(); $curYear = date('Y'); //@FIXME birthplace residence 现只处理了中国 $zipmap = (include Kohana::find_file('vendor', 'cityarray', true)); $residence = ""; foreach ($result as $key => $val) { //居住地 if (!empty($val["resideprovince"])) { $residence = isset($zipmap["province"][$val["resideprovince"]]) ? $zipmap["province"][$val["resideprovince"]] : ""; } if (!empty($val["residecity"])) { $residence .= isset($zipmap["city"][$val["residecity"]]) ? " " . $zipmap["city"][$val["residecity"]] : ""; } $tmp[$key]["id"] = (int) $val["uid"]; $tmp[$key]["name"] = $val["realname"]; $tmp[$key]["gender"] = (int) $val["sex"]; $tmp[$key]["age"] = (string) $val["birthyear"] > 0 ? $curYear - $val["birthyear"] : ''; $tmp[$key]["city"] = $residence; $tmp[$key]["company"] = $val["company"]; $tmp[$key]["school"] = $val["college"]; $tmp[$key]["zodiac"] = $val["astro"]; $tmp[$key]["sign"] = $val["sign"]; $tmp[$key]["avatar"] = sns::getavatar($val["uid"]); $tmp[$key]["modified_at"] = $val["updatetime"]; //date('D M d H:i:s O Y', $val["updatetime"]); } unset($result); $this->send_response(200, array("count" => $total, "start" => $start, "pos" => count($tmp), "data" => $tmp)); }
/** * * @param $deal_id * @return array */ public function item($deal_id, $user_id = 0) { $result = $this->get($deal_id); if ($result) { $deal_user_info = sns::getuser($result['uid']); $return = array('deal_id' => (int) $result['id'], 'user' => array('id' => (int) $result['uid'], 'name' => $deal_user_info['realname'], 'mobile' => $deal_user_info['mobile'], 'avatar' => sns::getavatar($result['uid'], 'small')), 'status' => (int) $result['status'], 'private' => (int) $result['private'], 'price' => (double) $result['price'], 'location' => array('longitude' => (double) $result['longitude'], 'latitude' => (double) $result['latitude']), 'created_at' => (int) $result['created_at']); if ($user_id) { $name = $this->_get_relation_contacts_name($user_id, $result['uid']); $return['weight'] = $name ? 1 : 0; $return['relation']['contact'] = array('name' => $name); /*** @todo for deal start ***/ $units = User_Model::instance()->get_unit_dict(array($user_id, $result['uid'])); if ($units[$result['uid']] && $units[$user_id]['unitid'] == $units[$result['uid']]['unitid']) { $return['relation']['company'] = array('name' => $units[$result['uid']]['unitname'], 'username' => $units[$result['uid']]['username']); } /*** @todo for deal end ***/ } $deal_detail = $this->_select_mongo($result['deal_id']); if ($deal_detail) { $return['sync'] = $deal_detail['sync'] ? $deal_detail['sync'] : array(); $return['title'] = $deal_detail['title']; $return['description'] = $deal_detail['description']; $return['image'] = $this->_format_image($deal_detail['image']); } } return $return; }
/** * * 添加群成员 * @param $id */ public function add($id = 0) { if ($this->get_method() != 'POST') { $this->send_response(405, NULL, '请求的方法不存在'); } $data = $this->get_data(); $uid = $data['uid'] ? $data['uid'] : ''; if (empty($uid)) { $this->send_response(400, NULL, '400403:成员uid为空'); } $uids = explode(',', $uid); $groupId = (int) $id; if (empty($id)) { $this->send_response(400, NULL, '400401:群ID为空'); } $groupInfo = $this->model->getGroupInfo($groupId); if (!$groupInfo) { $this->send_response(400, NULL, '400402:群不存在'); } $user = sns::getuser($this->user_id); /* $grade = $this->model->getMemberGrade($groupId, $this->user_id); if($grade < Kohana::config('group.grade.manager')) { $this->send_response(400, NULL, '400404:非群管理员,无权限添加成员'); } */ //查询群组成员总数是否超出最大限制(暂定100) $memberNum = $group_info['member_number']; if ($group_info['type'] == Kohana::config('group.type.public')) { $maxMemberNum = Kohana::config('group.maxMemberNum.public'); } else { $maxMemberNum = Kohana::config('group.maxMemberNum.private'); } if ($memberNum + count($uids) >= $maxMemberNum) { $this->send_response(400, NULL, '400110:群成员人数已满'); } $add_uids = array(); foreach ($uids as $v) { $grade = $this->model->getMemberGrade($groupId, $v); if (!$grade) { $add_uids[] = $v; } } $i = 0; $content = $user['realname'] . '将您加入到群"' . $groupInfo['gname'] . '"'; $opt = array('group' => array('type' => 1, 'id' => $groupId, 'name' => $groupInfo['gname'])); $xiaomo_uid = Kohana::config('uap.xiaomo'); if (count($add_uids) > 0) { foreach ($add_uids as $u) { if ($this->model->addGroupMember($groupId, $u, 1)) { $i++; Tab_Model::instance()->create($u, 1, $groupId); $this->model->addMemberNum($groupId); User_Model::instance()->present_mo_notice($xiaomo_uid, $u, $content, $opt); } } } $this->send_response(200, array('num' => $i)); }
/** * 根据用户权限获取好友信息 * @param int $friend_user_id * @return Contact */ public function get_user_info($user_id) { $user_model = User_Model::instance(); $result = $user_model->get_user_info($user_id); if ($result !== FALSE) { $data = $user_model->profile_assembly($result); //根据权限获取好友信息 $array = array(); foreach ($data as $key => $value) { if (in_array($key, array('family_name', 'given_name', 'nickname', 'department', 'title'))) { $array[$key] = $value; } elseif (in_array($key, array('tels', 'emails', 'ims', 'addresses', 'urls'))) { if (!empty($value)) { foreach ($value as $val) { if (!empty($val['is_master'])) { $array[$key][] = array('type' => $val['type'], 'value' => $val['value'], 'pref' => $val['is_master']); } elseif ($val['is_public']) { $array[$key][] = $val; } } } } elseif ($key == 'company') { $array['organization'] = $value; } } if (!empty($data['is_hide_year'])) { $data['birthyear'] = 1900; } if (!empty($data['birthmonth']) && !empty($data['birthday']) && !empty($data['birthyear'])) { if (strlen($data['birthday']) == 1) { $data['birthday'] = '0' . $data['birthday']; } if (strlen($data['birthmonth']) == 1) { $data['birthmonth'] = '0' . $data['birthmonth']; } if (checkdate($data['birthmonth'], $data['birthday'], $data['birthyear'])) { $array['birthday'] = $data['birthyear'] . '-' . $data['birthmonth'] . '-' . $data['birthday']; } else { $array['birthday'] = ''; } } else { $array['birthday'] = ''; } //获取好友头像 $array['avatar'] = sns::getavatar($user_id, 130); return $this->array_to_Group_contact($array); } return FALSE; }
public function token() { if ($this->get_method() != 'POST') { $this->send_response(405, NULL, '请求的方法不存在'); } $data = $this->get_data(); $zone_code = isset($data['zone_code']) ? $data['zone_code'] : ''; $mobile = isset($data['mobile']) ? $data['mobile'] : ''; $code = isset($data['code']) ? $data['code'] : ''; if (!international::check_is_valid($zone_code, $mobile)) { $this->send_response(400, NULL, Kohana::lang('authorization.mobile_invalid')); } $username = $this->model->get_full_mobile($zone_code, $mobile); if (!$this->is_test_mobile($mobile)) { if (!$this->model->check_verify_code($username, $code)) { $this->send_response(400, NULL, Kohana::lang('authorization.code_invalid')); } } $user = $this->model->get_user_by_mobile($zone_code, $mobile); if ($user) { $id = $user['id']; } else { $regip = $this->get_ip(); $id = $this->model->create_user($zone_code, $mobile, '', $regip); } $token = $this->model->create_token(3600, TRUE, array('zone_code' => $zone_code, 'mobile' => $mobile, 'id' => (int) $id)); if ($user) { $token['name'] = $user['username']; $token['avatar'] = sns::getavatar($user['id']); } $this->send_response(200, $token); }