You've already forked EasyImages2.0
mirror of
https://github.com/icret/EasyImages2.0.git
synced 2025-12-13 11:43:58 +08:00
v2.5.5
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once './../config/api_key.php';
|
||||
require_once './../config/config.php';
|
||||
|
||||
// Token 生成
|
||||
function privateToken($length = 32)
|
||||
{
|
||||
$output = '';
|
||||
for ($a = 0; $a < $length; $a++) {
|
||||
$output .= chr(mt_rand(65, 122)); //生成php随机数
|
||||
}
|
||||
return md5($output);
|
||||
}
|
||||
|
||||
// 通过Token查找用户ID
|
||||
function getID($token)
|
||||
{
|
||||
global $tokenList;
|
||||
$token = preg_replace('/[\W]/', '', $token); // 过滤非字母数字,删除空格
|
||||
$key = array_search($token, $tokenList);
|
||||
if ($key >= 0) {
|
||||
return $key;
|
||||
} else {
|
||||
return ('没有这个用户ID');
|
||||
}
|
||||
}
|
||||
|
||||
// 通过ID查找用户Token
|
||||
function getIDToken($id)
|
||||
{
|
||||
global $tokenList;
|
||||
$id = preg_replace('/[\W]/', '', $id); // 过滤非字母数字,删除空格
|
||||
foreach ($tokenList as $key => $value) {
|
||||
if ($key == $id) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否开启api上传
|
||||
* code:201 访问成功但是服务端关闭API上传
|
||||
* code:202 访问成功但是Token错误
|
||||
*/
|
||||
function check_api($token)
|
||||
{
|
||||
global $config;
|
||||
global $tokenList;
|
||||
|
||||
if (!$config['apiStatus']) {
|
||||
// API关闭 服务端关闭API上传
|
||||
$reJson = array(
|
||||
"result" => 'failed',
|
||||
'code' => 201,
|
||||
'message' => 'API Closed',
|
||||
);
|
||||
exit(json_encode($reJson, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
if (!in_array($tokenList[$token], $tokenList)) {
|
||||
// Token 是否存在
|
||||
$reJson = array(
|
||||
"result" => 'failed',
|
||||
'code' => 202,
|
||||
'message' => 'Token Error',
|
||||
);
|
||||
exit(json_encode($reJson, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
if ($tokenList[$token]['expired'] < time()) {
|
||||
// Token 是否过期
|
||||
$reJson = array(
|
||||
"result" => 'failed',
|
||||
'code' => 203,
|
||||
'message' => 'Token Expired',
|
||||
);
|
||||
exit(json_encode($reJson, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../application/function.php';
|
||||
require_once APP_ROOT . '/api/function_API.php';
|
||||
require_once APP_ROOT . '/application/class.upload.php';
|
||||
require_once APP_ROOT . '/config/api_key.php';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user