Commit 30e1fef5 authored by clone's avatar clone

autoken验证

parent adf067c6
......@@ -10,8 +10,10 @@ namespace app\api\extend;
* 基类
*/
use think\Controller;
use think\helper\Time;
use think\Request;
use think\Response;
use Qiniu;
class Basic extends Controller
{
......@@ -21,20 +23,17 @@ class Basic extends Controller
*/
public $request;
/**
* 当前访问身份
* @var string
*/
public $token;
public $params;
protected $authToken;
/**
* @var int userId
*/
protected $userId;
protected $access_token;
protected $phone;
protected $timeStamp_;
/**
* 基础接口SDK
......@@ -46,8 +45,35 @@ class Basic extends Controller
$this->corsOptionsHandler();
// 输入对象
$this->request = is_null($request) ? Request::instance() : $request;
if (strtoupper($this->request->method()) === "GET") {
$this->params = $this->request->param();
} elseif (strtoupper($this->request->method()) === "POST") {
$this->params = json_decode($this->request->param());
}
$jwt = new \Firebase\JWT\JWT();
$this->authToken = $this->params['AuthToken'];
$result = $jwt->decode($this->authToken, config('jwt_key'), array( 'HS256' )); //解码token
$this->userId = $result['data']["userId"];
$this->phone = $result['data']["phone"];
$this->timeStamp_ = $result["timeStamp_"];
$this->verifyTime();
}
public function verifyTime(){
$today = Time::today();
//authToken有效期为30天
if(($today - $this->timeStamp_) > 2592000){
return $this->response("101","AuthToken失效,请重新登录!");
}
}
/**
* 输出返回数据
* @param string $msg 提示消息内容
......@@ -166,24 +192,6 @@ class Basic extends Controller
];
}
/**
* 加密token或解码token
* @param type $data 加密token
* @param type $token 解密token
* @return type
*/
public static function getJwtToken($data, $token = '') {
$jwt = new \Firebase\JWT\JWT();
if ($token) {
$result = $jwt->decode($token, config('jwt_key'), array('HS256')); //解码token
} else {
$data_arr['expire'] = time();
$data_arr['data'] = $data;
$result = $jwt->encode($data, config('jwt_key')); //生成token
}
return $result;
}
}
......
......@@ -84,7 +84,7 @@ class BannerModel extends Model
*/
function upIsShow($param)
{
$this->logger->info('日志信息');
//$this->logger->info('日志信息');
$banner = $this->db;
$arr = array(
"id" => $param['id'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment