109 lines
2.9 KiB
PHP
109 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: NING MEI
|
|
* Date: 2020/4/13
|
|
* Time: 10:58
|
|
*/
|
|
|
|
namespace app\api\controller;
|
|
|
|
use think\Controller;
|
|
use think\Db;
|
|
use think\facade\Cache;
|
|
use app\lib\exception\ParamException;
|
|
use app\common\controller\Encryption;
|
|
|
|
class BaseController extends Controller
|
|
{
|
|
/**
|
|
* 验证用户token并返回用户id
|
|
* @param $token
|
|
* @return bool|mixed
|
|
*/
|
|
public function verifyToken()
|
|
{
|
|
$token = $this->request->header('token','');
|
|
$userInfo = Cache::store('redis')->get($token);
|
|
|
|
if($userInfo){
|
|
$userInfo = json_decode($userInfo,true);
|
|
if(is_array($userInfo)){
|
|
$user_id = $userInfo['uid'];
|
|
}else{
|
|
$user_id = $userInfo;
|
|
}
|
|
|
|
return $user_id;
|
|
}
|
|
else{
|
|
throw new ParamException([
|
|
'code'=>401,
|
|
'msg' => '登录过期,请重新登录!',
|
|
'errorCode' => 10001
|
|
]);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* rsa加密
|
|
* */
|
|
public function rsaEncry($data){
|
|
$encry = new Encryption();
|
|
$res = $encry->encrypt($data);
|
|
return $res;
|
|
}
|
|
|
|
/*
|
|
* rsa解密
|
|
* */
|
|
public function rsaDecipher($data){
|
|
$encry = new Encryption();
|
|
$res = $encry->decrypt($data);
|
|
return $res;
|
|
}
|
|
|
|
/*
|
|
* 检查用户登录信息
|
|
* 根据身份信息检查用户登录必填参数
|
|
* */
|
|
public function checkUserParam($array){
|
|
$proSubArr = config('setsub.diffProTest');
|
|
if(!empty($array['userPro'])){
|
|
$userPro = $array['userPro'];
|
|
}else{
|
|
if(!empty($array['province'])){
|
|
$userPro = config('province.province')[$array['province']*10000]['code'];
|
|
}
|
|
}
|
|
if(!empty($userPro)){
|
|
//type 1普通高考 2新高考 3特殊高考
|
|
if(in_array($userPro,$proSubArr[1])){
|
|
if(!intval($array['mySub']) || !intval($array['subType'])){
|
|
throw new ParamException([
|
|
'code'=>400,
|
|
'msg' => '文理科或科目必选',
|
|
'errorCode' => 10000
|
|
]);
|
|
}
|
|
}elseif(in_array($userPro,$proSubArr[2])){
|
|
if(!intval($array['mySub'])){
|
|
throw new ParamException([
|
|
'code'=>400,
|
|
'msg' => '科目必选',
|
|
'errorCode' => 10000
|
|
]);
|
|
}
|
|
}else{
|
|
if(!intval($array['subType'])){
|
|
throw new ParamException([
|
|
'code'=>400,
|
|
'msg' => '文理科必选',
|
|
'errorCode' => 10000
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
} |