12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
-
- namespace app\common;
-
- use core\basic\Controller;
- use core\basic\Config;
-
- class ApiController extends Controller
- {
-
- public function __construct()
- {
-
- cache_config();
-
-
- define("CMSNAME", $this->config("cmsname") ?: 'PbootCMS');
-
- $this->checkAccess($this->config());
- }
-
-
-
- public static function checkAccess($config)
- {
- if (! isset($config['api_open']) || ! $config['api_open']) {
- json(0, '系统尚未开启API功能,请到后台配置');
- }
-
-
- if ($config['api_auth']) {
-
-
- if (! $config['api_appid']) {
- json(0, '请求失败:管理后台接口认证用户配置有误');
- }
-
-
- if (! $config['api_secret']) {
- json(0, '请求失败:管理后台接口认证密钥配置有误');
- }
-
-
- if (! $appid = request('appid')) {
- json(0, '请求失败:未检查到appid参数');
- }
- if (! $timestamp = request('timestamp')) {
- json(0, '请求失败:未检查到timestamp参数');
- }
- if (! $signature = request('signature')) {
- json(0, '请求失败:未检查到signature参数');
- }
-
-
- if (strpos($_SERVER['HTTP_REFERER'], get_http_url()) === false && time() - $timestamp > 15) {
- json(0, '请求失败:接口时间戳验证失败!');
- }
-
-
- if ($signature != md5(md5($config['api_appid'] . $config['api_secret'] . $timestamp))) {
- error('请求失败:接口签名信息错误!');
- }
- }
- }
- }
|