12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- /**
- * 手机端令牌模型
- *
- *
- *
- *
- */
- defined('InShopNC') or exit('Access Invalid!');
- class mb_user_tokenModel extends Model
- {
- const token_expire = 3; // 单位:分钟
- public function __construct()
- {
- parent::__construct('mb_user_token');
- }
- /**
- * 查询
- *
- * @param array $condition 查询条件
- * @return array
- */
- public function getMbUserTokenInfo($condition)
- {
- return $this->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(TIMESTAMP) . 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'] = TIMESTAMP;
- $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)),'',self::token_expire);
- return $token;
- } else {
- return null;
- }
- }
- /**
- * 删除
- *
- * @param int $condition 条件
- * @return bool 布尔类型的返回结果
- */
- public function delMbUserToken($condition)
- {
- return $this->where($condition)->delete();
- }
- }
|