Commit db77d583 authored by clone's avatar clone

basic

parent e08f0af6
......@@ -9,8 +9,8 @@ namespace app\api\extend;
* Time: 9:35
* 基类
*/
use app\model\Users;
use think\Controller;
use think\Exception;
use think\helper\Time;
use think\Request;
use think\Response;
......@@ -44,10 +44,10 @@ class Basic extends Controller
public function __construct(Request $request = null)
{
/* ob_start();
ob_end_flush();
ob_end_clean();
ob_get_contents();*/
/* ob_start();
ob_end_flush();
ob_end_clean();
ob_get_contents();*/
// CORS 跨域 Options 检测响应
......@@ -66,19 +66,19 @@ class Basic extends Controller
}
throw new Exception($this->response("101", "AuthToken失效,请重新登录!"));
/* $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->phone = $result->data->user_nick;
$this->timeStamp_ = $result->timeStamp_;
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(); */
$this->verifyTime();
}
......@@ -87,16 +87,20 @@ class Basic extends Controller
$today = Time::today();
//authToken有效期为30天
if (($today - $this->timeStamp_) > 2592000) {
$this->response("101", "AuthToken失效,请重新登录!");
echo json_encode(array( "code" => "101", "msg" => "AuthToken失效,请重新登录!", "data" => [], "type" => "json" ));
exit;
}
}
public function verifyUserInfo(){
public function verifyUserInfo()
{
//todo 待完成
$userArr = Session::get("u_user");
if(count($userArr) > 0 && ($userArr["status"] != 0 || $userArr["id"] != $this->userId || $userArr["user_phone"] != $this->phone) ){
$this->response("101", "用户验证失败,重新登录!");
$userModel = new Users();
$userArr = $userModel->selectUser($this->userId);
if (count($userArr) > 0 && ($userArr["status"] != 0 || $userArr["id"] != $this->userId || $userArr["user_phone"] != $this->phone)) {
echo json_encode(array( "code" => "101", "msg" => "用户验证失败,重新登录!", "data" => [], "type" => "json" ));
exit;
}
return true;
}
......
......@@ -2,10 +2,23 @@
namespace app\model;
use think\Db;
use think\Model;
class Users extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'u_users';
protected $db ;
public function __construct()
{
$this->db = Db($this->table);
}
public function selectUser($user_id){
return $this->db
->field("id,status,user_phone")
->find($user_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