private function _set_block($status) { $data = $this->get_data(); $mobile = isset($data['mobile']) ? $data['mobile'] : ''; if (!$mobile) { $this->send_response(400, NULL, Kohana::lang('graph.mobile_not_allow')); } $id = $this->user_id; if (empty($id)) { $id = isset($data['guid']) ? $data['guid'] : ''; $id_type = 'guid'; if (empty($id)) { $this->send_response(400, NULL, Kohana::lang('graph.guid_empty')); } } else { $id_type = 'uid'; } if ($res = international::check_mobile($mobile)) { $result = $this->model->set_block($id, implode('', $res), $status, $id_type); if ($result === -1) { $this->send_response(400, NULL, Kohana::lang('graph.mobile_not_exist')); } else { $this->send_response(200, array('result' => (bool) $result)); } } else { $this->send_response(400, NULL, Kohana::lang('graph.mobile_not_allow')); } }
/** * 查询手机号码归属地 * @param int $tel 手机号码 * @param int $type 是否值类型 0 不返回运营商、1 返回运营商、2 只返回城市 * @return string 归属地名 */ public function get_tel_location($tel, $type = 1) { $data = international::check_mobile($tel, 86, FALSE); $country_code = !empty($data['country_code']) ? $data['country_code'] : 86; $cell = isset($data['mobile']) ? $data['mobile'] : ''; //中国归属地 if ($country_code == 86) { $location = self::_get_location($cell, $type); } else { $location = self::_get_country($country_code, $cell); } return $location; }
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); }
/** * 检查用户是否合法的回调方法 * @param $type 活动类型值 */ public function _check_user_validation($post) { $array = $post->as_array(); foreach ($array['user'] as $k => $v) { if (empty($v['name'])) { $post->add_error('user_name_empty', 'user_name_empty'); } if (empty($v['mobile'])) { $post->add_error('user_mobile_empty', 'user_mobile_empty'); } if (!international::check_is_valid('86', $v['mobile'])) { $post->add_error('user_mobile_format', 'user_mobile_format'); } } }
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); }