Commit 30e1fef5 authored by clone's avatar clone

autoken验证

parent adf067c6
...@@ -10,8 +10,10 @@ namespace app\api\extend; ...@@ -10,8 +10,10 @@ namespace app\api\extend;
* 基类 * 基类
*/ */
use think\Controller; use think\Controller;
use think\helper\Time;
use think\Request; use think\Request;
use think\Response; use think\Response;
use Qiniu;
class Basic extends Controller class Basic extends Controller
{ {
...@@ -21,20 +23,17 @@ class Basic extends Controller ...@@ -21,20 +23,17 @@ class Basic extends Controller
*/ */
public $request; public $request;
/** public $params;
* 当前访问身份
* @var string
*/
public $token;
protected $authToken;
/** /**
* @var int userId * @var int userId
*/ */
protected $userId; protected $userId;
protected $access_token;
protected $phone; protected $phone;
protected $timeStamp_;
/** /**
* 基础接口SDK * 基础接口SDK
...@@ -46,8 +45,35 @@ class Basic extends Controller ...@@ -46,8 +45,35 @@ class Basic extends Controller
$this->corsOptionsHandler(); $this->corsOptionsHandler();
// 输入对象 // 输入对象
$this->request = is_null($request) ? Request::instance() : $request; $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 提示消息内容 * @param string $msg 提示消息内容
...@@ -165,25 +191,7 @@ class Basic extends Controller ...@@ -165,25 +191,7 @@ class Basic extends Controller
'Access-Defined-X-Servers' => 'Guangzhou Cuci Technology Co. Ltd', 'Access-Defined-X-Servers' => 'Guangzhou Cuci Technology Co. Ltd',
]; ];
} }
/**
* 加密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 ...@@ -84,7 +84,7 @@ class BannerModel extends Model
*/ */
function upIsShow($param) function upIsShow($param)
{ {
$this->logger->info('日志信息'); //$this->logger->info('日志信息');
$banner = $this->db; $banner = $this->db;
$arr = array( $arr = array(
"id" => $param['id'], "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