123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- // 应用公共文件
- if(!function_exists("json_show")){
- function json_show(int $code = 0, string $message = '请求成功', array $data = [])
- {
- return json(['code' => $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;
- }
- }
|