EasyImages2.0/api/libs/apiFunction.php

40 lines
922 B
PHP
Raw Normal View History

<?php
2021-05-04 19:51:36 +00:00
require_once __DIR__ . '/tokenList.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/config/config.php';
// Token 生成
2021-05-04 19:51:36 +00:00
function privateToken($length = 32)
{
$output = '';
for ($a = 0; $a < $length; $a++) {
$output .= chr(mt_rand(65, 122)); //生成php随机数
2021-05-04 19:51:36 +00:00
}
return md5($output);
}
2021-05-04 19:51:36 +00:00
// 检查Token
function checkToken($token)
{
global $tokenList;
2021-05-04 19:51:36 +00:00
$token = preg_replace('/[\W]/', '', $token); // 过滤非字母数字,删除空格
2021-05-04 19:51:36 +00:00
if (in_array($token, $tokenList)) {
return True;
} else {
2021-05-04 19:51:36 +00:00
exit('此Token不存在' . $token);
}
}
// 通过Token查找用户ID
2021-05-04 19:51:36 +00:00
function getID($token)
{
global $tokenList;
2021-05-04 19:51:36 +00:00
$token = preg_replace('/[\W]/', '', $token); // 过滤非字母数字,删除空格
$key = array_search($token, $tokenList);
if ($key) {
return $key;
2021-05-04 19:51:36 +00:00
} else {
return ('没有这个用户ID');
}
};