mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
39 lines
1.0 KiB
PHP
39 lines
1.0 KiB
PHP
<?php
|
|
/**
|
|
* 处理Api接入认证
|
|
* @since 2017-07-25
|
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
*/
|
|
|
|
namespace app\admin\behavior;
|
|
|
|
|
|
use app\util\ReturnCode;
|
|
use think\Request;
|
|
|
|
class ApiAuth {
|
|
|
|
/**
|
|
* 默认行为函数
|
|
* @return \think\response\Json
|
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
*/
|
|
public function run() {
|
|
$request = Request::instance();
|
|
$header = config('apiAdmin.CROSS_DOMAIN');
|
|
$ApiAuth = $request->header('ApiAuth', '');
|
|
if ($ApiAuth) {
|
|
$userInfo = cache($ApiAuth);
|
|
$userInfo = json_decode($userInfo, true);
|
|
if (!$userInfo || !isset($userInfo['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);
|
|
}
|
|
}
|
|
|
|
}
|