Commit c7a03fb9 authored by clone's avatar clone

token验证

parent 271ae4a8
...@@ -33,9 +33,21 @@ class Basic extends Controller ...@@ -33,9 +33,21 @@ class Basic extends Controller
* @var int userId * @var int userId
*/ */
protected $userId; protected $userId;
protected $user_nick; protected $userNick;
protected $phone; protected $phone;
protected $timeStamp_; protected $timeStamp_;
protected $filterVerify = array(
"api/shopDetail",
"api/sendSms",
"api/logout",
"api/login",
"api/register",
"api/shopList",
"api/filtrateCondition",
"api/shopDetail",
"api/bannerList",
"api/averagePriceAndTurnover",
);
/** /**
* 基础接口SDK * 基础接口SDK
...@@ -43,42 +55,38 @@ class Basic extends Controller ...@@ -43,42 +55,38 @@ class Basic extends Controller
*/ */
public function __construct(Request $request = null) public function __construct(Request $request = null)
{ {
/* ob_start();
ob_end_flush();
ob_end_clean();
ob_get_contents();*/
// CORS 跨域 Options 检测响应 // CORS 跨域 Options 检测响应
$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") { if (strtoupper($this->request->method()) === "GET") {
$this->params = $this->request->param(); $this->params = $this->request->param();
} elseif (strtoupper($this->request->method()) === "POST") { } elseif (strtoupper($this->request->method()) === "POST") {
$this->params = $this->request->param() != null ? $this->request->param() : null; $this->params = $this->request->param() != null ? $this->request->param() : null;
} }
/*
if (!isset($this->params['AuthToken'])) {
echo json_encode(array( "code" => "101", "msg" => "AuthToken不能为空!", "data" => [], "type" => "json" ));
exit;
}
$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->id;
$this->phone = $result->data->phone;
$this->user_nick = $result->data->user_nick;
$this->timeStamp_ = $result->timeStamp_;
$this->verifyTime();*/ $requestPath = $this->request->path();
//过滤掉不需要验证token的接口
if (!in_array(trim($requestPath), $this->filterVerify)) {
if (!isset($this->params['AuthToken'])) {
echo json_encode(array( "code" => "101", "msg" => "AuthToken不能为空!", "data" => [], "type" => "json" ));
exit;
}
$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->id;
$this->phone = $result->data->phone;
$this->userNick = $result->data->userNick;
$this->timeStamp_ = $result->timeStamp_;
$this->verifyUserInfo();
$this->verifyTime();
}
} }
public function verifyTime() public function verifyTime()
{ {
$today = Time::today(); $today = Time::today();
...@@ -94,7 +102,7 @@ class Basic extends Controller ...@@ -94,7 +102,7 @@ class Basic extends Controller
//todo 待完成 //todo 待完成
$userModel = new Users(); $userModel = new Users();
$userArr = $userModel->selectUser($this->userId); $userArr = $userModel->selectUser($this->userId);
if (count($userArr) > 0 && ( $userArr["id"] != $this->userId || $userArr["user_phone"] != $this->phone)) { if (count($userArr) > 0 && ($userArr["id"] != $this->userId || $userArr["user_phone"] != $this->phone)) {
echo json_encode(array( "code" => "101", "msg" => "用户验证失败,重新登录!", "data" => [], "type" => "json" )); echo json_encode(array( "code" => "101", "msg" => "用户验证失败,重新登录!", "data" => [], "type" => "json" ));
exit; exit;
} }
......
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