first commit
This commit is contained in:
41
pgserver/application/admin/behavior/ApiAuth.php
Normal file
41
pgserver/application/admin/behavior/ApiAuth.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* 处理Api接入认证
|
||||
* @since 2017-07-25
|
||||
* @author
|
||||
*/
|
||||
|
||||
namespace app\admin\behavior;
|
||||
|
||||
|
||||
use app\util\ReturnCode;
|
||||
use think\Request;
|
||||
|
||||
class ApiAuth {
|
||||
/**
|
||||
* 当前请求实例
|
||||
* @var Request
|
||||
*/
|
||||
protected $request;
|
||||
/**
|
||||
* 默认行为函数
|
||||
* @return \think\response\Json
|
||||
* @author
|
||||
*/
|
||||
public function run() {
|
||||
$this->request = Request::instance();
|
||||
$header = config('apiBusiness.CROSS_DOMAIN');
|
||||
$ApiAuth = $this->request->header('userId');
|
||||
if ($ApiAuth) {
|
||||
$userInfo = cache('userinfo'.$ApiAuth);
|
||||
if (!$userInfo || !isset($userInfo['user_id'])) {
|
||||
$data = ['code' => ReturnCode::AUTH_ERROR, 'msg' => 'ApiAuth不匹配', 'data' => []];
|
||||
return json($data, 200, $header);
|
||||
}
|
||||
} else {
|
||||
$data = ['code' => ReturnCode::AUTH_ERROR, 'msg' => '缺少ApiAuth', 'data' => []];
|
||||
return json($data, 200, $header);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
26
pgserver/application/admin/behavior/BuildResponse.php
Normal file
26
pgserver/application/admin/behavior/BuildResponse.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* 支持跨域
|
||||
* @since 2022-9-23
|
||||
* @author
|
||||
*/
|
||||
|
||||
namespace app\admin\behavior;
|
||||
|
||||
|
||||
use think\Config;
|
||||
use think\Response;
|
||||
|
||||
class BuildResponse {
|
||||
|
||||
/**
|
||||
* 跨域处理
|
||||
* @param $response
|
||||
* @author
|
||||
*/
|
||||
public function run(Response $response) {
|
||||
$header = config('apiBusiness.CROSS_DOMAIN');
|
||||
$response->header($header);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user