where($condition)->find(); } public function getMbUserTokenInfoByToken($token) { if (empty($token)) { return null; } return $this->getMbUserTokenInfo(array('token' => $token)); } /** * 新增 * * @param array $param 参数内容 * @return bool 布尔类型的返回结果 */ public function addMbUserToken($param) { return $this->insert($param); } /** * 生成token * * @param array $param 参数内容 * @return bool 布尔类型的返回结果 */ public function gen_token($member_id, $member_name, $client) { //生成新的token $mb_user_token_info = array(); $token = md5($member_name . strval(time()) . strval(rand(0, 999999))); $mb_user_token_info['member_id'] = $member_id; $mb_user_token_info['member_name'] = $member_name; $mb_user_token_info['token'] = $token; $mb_user_token_info['login_time'] = time(); $mb_user_token_info['client_type'] = $client; $condition['member_id'] = $member_id; $result = $this->where($condition)->select(); foreach($result as $value){ $key = func::gen_token_key($value['token']); dcache($key); } $this->where($condition)->delete(); $ret = $this->addMbUserToken($mb_user_token_info); if ($ret) { $key = func::gen_token_key($token); wcache($key, array('info' => serialize($mb_user_token_info)),'',func::token_expire); return $token; } else { return null; } } /** * 删除token * * @param $token * @return mixed */ public function del_token($token){ $key = func::gen_token_key($token); dcache($key); return $this->where(array('token'=>$token))->delete(); } /** * 删除 * * @param int $condition 条件 * @return bool 布尔类型的返回结果 */ public function delMbUserToken($condition) { return $this->where($condition)->delete(); } }