| Server IP : 156.238.232.47 / Your IP : 216.73.216.150 Web Server : nginx/1.25.3 System : Linux C202504152095410 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : www ( 1000) PHP Version : 8.3.25 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /www/wwwroot/2026_02_17_02/apps/common/ |
Upload File : |
<?php
/**
* @copyright (C)2016-2099 Hnaoyun Inc.
* @author XingMeng
* @email hnxsh@foxmail.com
* @date 2018年4月22日
* API公共控制类
*/
namespace app\common;
use core\basic\Controller;
use core\basic\Config;
class ApiController extends Controller
{
public function __construct()
{
// 自动缓存基础信息
cache_config();
// 从配置文件读取cmsname参数来设置系统名称
define("CMSNAME", $this->config("cmsname") ?: 'PbootCMS');
$this->checkAccess($this->config());
}
/**
* 客户端发起请求必须包含appid、timestamp、signature三个参数;
* signature通过appid、secret、timestamp连接为一个字符串,然后进行双层md5加密生成;
*/
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) { // 请求时间戳认证,不得超过15秒
json(0, '请求失败:接口时间戳验证失败!');
}
// 验证签名
if ($signature != md5(md5($config['api_appid'] . $config['api_secret'] . $timestamp))) {
error('请求失败:接口签名信息错误!');
}
}
}
}