$code, 'message' => $message, 'data' => $data]); } } /**手机号验证 * @param $mobile * @return bool */ if(!function_exists("checkMobile")){ function checkMobile($mobile){ if (!is_numeric($mobile)) { return false; } return preg_match('#^1[3,4,5,6,7,8,9]{1}[\d]{9}$#', $mobile) ? true : false; } } /**邮箱验证 * @param $email * @return bool */ if(!function_exists("checkEmail")){ function checkEmail($email){ if (!$email) { return false; } return preg_match('#[a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+)?\.[\w\-]+#is', $email) ? true : false; } } /** * @param * @return int */ if(!function_exists("makeSalt")){ function makeSalt(){ $salt = rand(10000000,99999999); return $salt; } } /** * @param $account * @param float|int $expire * @return string */ if(!function_exists("makeToken")){ function makeToken($account){ return sha1($account['username'].$account['mobile'].time()); } } if(!function_exists("checkToken")){ /** * @param $token * @param int $expire * @return array|bool|float|int|mixed|\stdClass|string|null * @throws \Psr\SimpleCache\InvalidArgumentException */ function checkToken($token,$expire=0){ $getToken = think\facade\Cache::store("redis")->get("user:info:{$token}"); if($getToken!=false){ $cache=think\facade\Cache::store("redis")->set("user:info:{$token}",$getToken,$expire); if($cache!=false) return $getToken; } return false; } }