Commit d851f513 authored by hujun's avatar hujun

jwt token 异常捕获

parent 00330eec
......@@ -14,6 +14,8 @@ use think\Controller;
use think\Request;
use think\Response;
use Qiniu;
use UnexpectedValueException;
use InvalidArgumentException;
class Basic extends Controller
{
......@@ -72,8 +74,18 @@ class Basic extends Controller
}
if (isset($this->params['AuthToken']) && $this->params['AuthToken'] != 'null' && !empty($this->params['AuthToken'])) {
$jwt = new \Firebase\JWT\JWT();
try {
$result = $jwt->decode($this->authToken, config('jwt_key'), array( 'HS256' )); //解码token
} catch( UnexpectedValueException $e) {
echo json_encode(array( "code" => "300", "msg" => "AuthToken parameter error!", "data" => [], "type" => "json" ));
exit;
} catch( InvalidArgumentException $e) {
echo json_encode(array( "code" => "300", "msg" => "AuthToken parameter error!", "data" => [], "type" => "json" ));
exit;
}
$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 = isset($result->data->userNick) ? $result->data->userNick : "";
......
......@@ -11,6 +11,8 @@ namespace app\api_broker\extend;
*/
use app\model\AAgents;
use app\model\GOperatingRecords;
use UnexpectedValueException;
use InvalidArgumentException;
use think\Controller;
use think\Request;
use think\Response;
......@@ -69,14 +71,23 @@ class Basic extends Controller
if (isset($this->params['AuthToken']) && $this->params['AuthToken'] != 'null' && !empty($this->params['AuthToken'])) {
$jwt = new \Firebase\JWT\JWT();
try {
$result = $jwt->decode($this->authToken, config('jwt_key'), array( 'HS256' )); //解码token
} catch( UnexpectedValueException $e) {
echo json_encode(array( "code" => "300", "msg" => "AuthToken参数错误!", "data" => [], "type" => "json" ));
exit;
} catch( InvalidArgumentException $e) {
echo json_encode(array( "code" => "300", "msg" => "AuthToken参数错误!", "data" => [], "type" => "json" ));
exit;
}
$this->authToken = $this->params['AuthToken'];
$result = $jwt->decode($this->authToken, config('jwt_key'), array( 'HS256' )); //解码token
$this->agentId = $result->data->id;
$this->agentPhone = $result->data->phone;
$this->agentName = $result->data->name;
$this->timeStamp_ = $result->timeStamp_;
}
$requestPath = $this->request->routeInfo()["rule"][0] . "/" . $this->request->routeInfo()["rule"][1];
//过滤掉不需要验证token的接口
if (!in_array(trim($requestPath), $this->filterVerify)) {
......
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