forked from XiaoLFeng/XF_Index
commit
2b7336d7d1
|
@ -1,68 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
class Sql
|
||||
{
|
||||
/**
|
||||
* @return false|mysqli
|
||||
*/
|
||||
public static function MySqlConn() {
|
||||
// 从文件获取数据
|
||||
$Array_ConfigData = null;
|
||||
$FileData = fopen(dirname(__FILE__,3)."/setting.inc.json",'r');
|
||||
while (!feof($FileData))
|
||||
$Array_ConfigData .= fgetc($FileData);
|
||||
$Array_ConfigData = json_decode($Array_ConfigData,JSON_UNESCAPED_UNICODE);
|
||||
fclose($FileData);
|
||||
|
||||
//判断数据库端口
|
||||
if($Array_ConfigData['Mysql']['Port'] == 3306 or $Array_ConfigData['Mysql']['Port'] == NULL) $Array_ConfigData['Mysql']['Port'] = 3306;
|
||||
|
||||
return mysqli_connect($Array_ConfigData['Mysql']['Host'],$Array_ConfigData['Mysql']['Username'],$Array_ConfigData['Mysql']['Password'],null,$Array_ConfigData['Mysql']['Port']);
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL查找库
|
||||
* @param string $Mysql_Query
|
||||
* @return string[] 查找到结果返回结果
|
||||
*/
|
||||
public static function SELECT(string $Mysql_Query): array {
|
||||
$Array_Push = null;
|
||||
$Array_OutPut = [
|
||||
'output'=>null,
|
||||
'data'=>$Array_Push,
|
||||
];
|
||||
if (preg_match('/^SELECT/',$Mysql_Query)) {
|
||||
$Result = mysqli_query(self::MySqlConn(),$Mysql_Query);
|
||||
for ($CC_i = 0; $Result_Object = mysqli_fetch_object($Result); $CC_i++) {
|
||||
if ($CC_i == 0 && empty($Result_Object)) {
|
||||
$Array_OutPut['output'] = 'EmptyResult';
|
||||
return $Array_OutPut;
|
||||
} else {
|
||||
$Array_Push[$CC_i] = $Result_Object;
|
||||
}
|
||||
}
|
||||
return $Array_OutPut;
|
||||
} else {
|
||||
$Array_OutPut['output'] = 'TypeError';
|
||||
return $Array_OutPut;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL插入库
|
||||
* @param string $Mysql_Query
|
||||
* @return bool
|
||||
*/
|
||||
public static function INSERT(string $Mysql_Query): bool {
|
||||
if (preg_match('/^INSERT/',$Mysql_Query)) {
|
||||
return mysqli_query(self::MySqlConn(),$Mysql_Query);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
12
LICENSE
12
LICENSE
|
@ -18,14 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
特此免费授予获得本软件和相关文档文件(“软件”)副本的任何人不受限制地处理本软件的权限,
|
||||
包括但不限于使用、复制、修改、合并的权利、发布、分发、再许可和/或出售软件的副本,
|
||||
并允许获得软件的人这样做,但须满足以下条件:
|
||||
|
||||
上述版权声明和本许可声明应包含在本软件的所有副本或重要部分中。
|
||||
|
||||
本软件“按原样”提供,不提供任何明示或暗示的保证,包括但不限于对适销性、
|
||||
特定用途的适用性和非侵权的保证。在任何情况下,作者或版权持有人均不对任何索赔、损害或其他责任负责,
|
||||
无论是在合同诉讼、侵权行为还是其他方面,由软件或软件的使用或其他交易引起、由软件引起或与之相关软件。
|
||||
SOFTWARE.
|
15
Modules/API/header.php
Normal file
15
Modules/API/header.php
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
$Array_ConfigData = null;
|
||||
|
||||
// 从配置文件获取参数
|
||||
$FileData = fopen(dirname(__FILE__, 3) . "/setting.inc.json", 'r');
|
||||
while (!feof($FileData))
|
||||
$Array_ConfigData .= fgetc($FileData);
|
||||
$Array_ConfigData = json_decode($Array_ConfigData, JSON_UNESCAPED_UNICODE);
|
||||
fclose($FileData);
|
48
class/Key.php
Normal file
48
class/Key.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
class Key
|
||||
{
|
||||
/**
|
||||
* 生成验证码
|
||||
* 说明:
|
||||
*
|
||||
* 1. [type(string)]
|
||||
* - [Number] 数字验证码
|
||||
* - [English]英文验证码
|
||||
* - [Normal] 混合验证码
|
||||
* @param int $long 验证码长度
|
||||
* @param string $type 验证码类型
|
||||
* @return string 返回结果为生成的验证码
|
||||
*/
|
||||
public static function Captcha(int $long, string $type = 'Number'): string
|
||||
{
|
||||
/** @var string $output */
|
||||
for ($i = 1; $i <= $long; $i++) {
|
||||
if ($type == 'Number') {
|
||||
$output = $output . rand(0, 9);
|
||||
} elseif ($type == 'English') {
|
||||
$output = $output . chr(rand(65, 90));
|
||||
} elseif ($type == 'Normal') {
|
||||
if (time() % 2 == 0) {
|
||||
if ($i % 2 == 0) {
|
||||
$output = $output . chr(rand(65, 90));
|
||||
} else {
|
||||
$output = $output . rand(0, 9);
|
||||
}
|
||||
} else {
|
||||
if ($i % 3 != 0) {
|
||||
$output = $output . chr(rand(65, 90));
|
||||
} else {
|
||||
$output = $output . rand(0, 9);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
104
class/Mailer/MailTemplate.php
Normal file
104
class/Mailer/MailTemplate.php
Normal file
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
namespace Mailer;
|
||||
|
||||
class MailTemplate
|
||||
{
|
||||
private static string $GCode;
|
||||
private static int $NowTime;
|
||||
|
||||
/**
|
||||
* 检查使用邮件发送模板
|
||||
* @param string $G_code 获取后端发送来的验证码用于发送
|
||||
* @return string|null 需要返回值,返回HTML信息给邮箱模板用于发送
|
||||
*/
|
||||
public static function Templates(string $G_code): ?string
|
||||
{
|
||||
// 赋值给全局
|
||||
self::$GCode = $G_code;
|
||||
self::$NowTime = time();
|
||||
|
||||
// 判断发送内容
|
||||
if (SendMail::$EmailType == 1) return self::Register();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册邮件模板
|
||||
* @return string 返回 HTML 方式的 Mail
|
||||
*/
|
||||
private static function Register(): string
|
||||
{
|
||||
// 变量获取
|
||||
$getTitle = SendMail::$WebTitle;
|
||||
$getNowTime = self::$NowTime;
|
||||
$getReceiver = SendMail::$EmailReceiver;
|
||||
$getEndTime = date("Y年m月d日 H:i:s", time() + SendMail::$ExpTime);
|
||||
$getExpTime = (double)SendMail::$ExpTime / 60;
|
||||
$getYear = date('Y');
|
||||
$getDomain = $_SERVER['SERVER_NAME'];
|
||||
// 结果返回
|
||||
return <<<EOF
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<title>Mail</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
</head>
|
||||
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="border-collapse: collapse;border: 1px solid #cccccc;box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.175)">
|
||||
<tr>
|
||||
<td align="center" bgcolor="#70bbd9" style="padding: 30px 0 30px 0; font-size: 30px;">$getTitle</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="padding: 30px 30px 30px 30px;">
|
||||
<tr>
|
||||
<td style="padding: 10px 0px 30px 0px;color: #08212b; font-family: Arial, sans-serif; font-size: 10px;">
|
||||
发送时间: <b>$getNowTime</b>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 0px 0px 10px 0px;color: #000000; font-family: Arial, sans-serif; font-size: 24px;">
|
||||
Dear. <a style="text-decoration: none;color: #198754;" href="mailto:$getReceiver">$getReceiver</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="padding: 0px 5px 5px 0px;color: #000000; font-family: Arial, sans-serif; font-size: 20px;">
|
||||
<a href="$getDomain/account/activation.php"><button style="background-color: #008CBA;font-size: 16px;border-radius: 8px;">点击激活</button></a>
|
||||
<br/>
|
||||
您的身份激活 <strong>$getExpTime</strong> 分钟内有效,此身份激活为 <strong>账户注册</strong> 使用。<br/>
|
||||
有效期至:$getEndTime
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td bgcolor="#f0f0f0" style="padding: 30px 20px 30px 20px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
<tr>
|
||||
<td style="font-family: Arial, sans-serif; font-size: 14px;">
|
||||
<font style="color: grey;">© 2022 - $getYear. $getTitle All Rights Reserved.</font><br/>
|
||||
<font style="color: grey;">本邮件为自动发出,请勿直接回复</font>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<tr>
|
||||
<td style="padding: 30px 0 20px 0;"></td>
|
||||
</tr>
|
||||
</html>
|
||||
EOF;
|
||||
}
|
||||
|
||||
|
||||
}
|
233
class/Mailer/PHPMailer/DSNConfigurator.php
Normal file
233
class/Mailer/PHPMailer/DSNConfigurator.php
Normal file
|
@ -0,0 +1,233 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
namespace Mailer\PHPMailer;
|
||||
|
||||
/**
|
||||
* Configure PHPMailer with DSN string.
|
||||
*
|
||||
* @see https://en.wikipedia.org/wiki/Data_source_name
|
||||
*
|
||||
* @author Oleg Voronkovich <oleg-voronkovich@yandex.ru>
|
||||
*/
|
||||
class DSNConfigurator
|
||||
{
|
||||
/**
|
||||
* Create new PHPMailer instance configured by DSN.
|
||||
*
|
||||
* @param string $dsn DSN
|
||||
* @param bool $exceptions Should we throw external exceptions?
|
||||
*
|
||||
* @return PHPMailer
|
||||
*/
|
||||
public static function mailer($dsn, $exceptions = null)
|
||||
{
|
||||
static $configurator = null;
|
||||
|
||||
if (null === $configurator) {
|
||||
$configurator = new DSNConfigurator();
|
||||
}
|
||||
|
||||
return $configurator->configure(new PHPMailer($exceptions), $dsn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure PHPMailer instance with DSN string.
|
||||
*
|
||||
* @param PHPMailer $mailer PHPMailer instance
|
||||
* @param string $dsn DSN
|
||||
*
|
||||
* @return PHPMailer
|
||||
*/
|
||||
public function configure(PHPMailer $mailer, $dsn)
|
||||
{
|
||||
$config = $this->parseDSN($dsn);
|
||||
|
||||
$this->applyConfig($mailer, $config);
|
||||
|
||||
return $mailer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse DSN string.
|
||||
*
|
||||
* @param string $dsn DSN
|
||||
*
|
||||
* @return array Configuration
|
||||
* @throws Exception If DSN is malformed
|
||||
*
|
||||
*/
|
||||
private function parseDSN($dsn)
|
||||
{
|
||||
$config = $this->parseUrl($dsn);
|
||||
|
||||
if (false === $config || !isset($config['scheme']) || !isset($config['host'])) {
|
||||
throw new Exception(
|
||||
sprintf('Malformed DSN: "%s".', $dsn)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($config['query'])) {
|
||||
parse_str($config['query'], $config['query']);
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply configuration to mailer.
|
||||
*
|
||||
* @param PHPMailer $mailer PHPMailer instance
|
||||
* @param array $config Configuration
|
||||
*
|
||||
* @throws Exception If scheme is invalid
|
||||
*/
|
||||
private function applyConfig(PHPMailer $mailer, $config)
|
||||
{
|
||||
switch ($config['scheme']) {
|
||||
case 'mail':
|
||||
$mailer->isMail();
|
||||
break;
|
||||
case 'sendmail':
|
||||
$mailer->isSendmail();
|
||||
break;
|
||||
case 'qmail':
|
||||
$mailer->isQmail();
|
||||
break;
|
||||
case 'smtp':
|
||||
case 'smtps':
|
||||
$mailer->isSMTP();
|
||||
$this->configureSMTP($mailer, $config);
|
||||
break;
|
||||
default:
|
||||
throw new Exception(
|
||||
sprintf(
|
||||
'Invalid scheme: "%s". Allowed values: "mail", "sendmail", "qmail", "smtp", "smtps".',
|
||||
$config['scheme']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($config['query'])) {
|
||||
$this->configureOptions($mailer, $config['query']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure SMTP.
|
||||
*
|
||||
* @param PHPMailer $mailer PHPMailer instance
|
||||
* @param array $config Configuration
|
||||
*/
|
||||
private function configureSMTP($mailer, $config)
|
||||
{
|
||||
$isSMTPS = 'smtps' === $config['scheme'];
|
||||
|
||||
if ($isSMTPS) {
|
||||
$mailer->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||
}
|
||||
|
||||
$mailer->Host = $config['host'];
|
||||
|
||||
if (isset($config['port'])) {
|
||||
$mailer->Port = $config['port'];
|
||||
} elseif ($isSMTPS) {
|
||||
$mailer->Port = SMTP::DEFAULT_SECURE_PORT;
|
||||
}
|
||||
|
||||
$mailer->SMTPAuth = isset($config['user']) || isset($config['pass']);
|
||||
|
||||
if (isset($config['user'])) {
|
||||
$mailer->Username = $config['user'];
|
||||
}
|
||||
|
||||
if (isset($config['pass'])) {
|
||||
$mailer->Password = $config['pass'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure options.
|
||||
*
|
||||
* @param PHPMailer $mailer PHPMailer instance
|
||||
* @param array $options Options
|
||||
*
|
||||
* @throws Exception If option is unknown
|
||||
*/
|
||||
private function configureOptions(PHPMailer $mailer, $options)
|
||||
{
|
||||
$allowedOptions = get_object_vars($mailer);
|
||||
|
||||
unset($allowedOptions['Mailer']);
|
||||
unset($allowedOptions['SMTPAuth']);
|
||||
unset($allowedOptions['Username']);
|
||||
unset($allowedOptions['Password']);
|
||||
unset($allowedOptions['Hostname']);
|
||||
unset($allowedOptions['Port']);
|
||||
unset($allowedOptions['ErrorInfo']);
|
||||
|
||||
$allowedOptions = \array_keys($allowedOptions);
|
||||
|
||||
foreach ($options as $key => $value) {
|
||||
if (!in_array($key, $allowedOptions)) {
|
||||
throw new Exception(
|
||||
sprintf(
|
||||
'Unknown option: "%s". Allowed values: "%s"',
|
||||
$key,
|
||||
implode('", "', $allowedOptions)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
switch ($key) {
|
||||
case 'AllowEmpty':
|
||||
case 'SMTPAutoTLS':
|
||||
case 'SMTPKeepAlive':
|
||||
case 'SingleTo':
|
||||
case 'UseSendmailOptions':
|
||||
case 'do_verp':
|
||||
case 'DKIM_copyHeaderFields':
|
||||
$mailer->$key = (bool)$value;
|
||||
break;
|
||||
case 'Priority':
|
||||
case 'SMTPDebug':
|
||||
case 'WordWrap':
|
||||
$mailer->$key = (int)$value;
|
||||
break;
|
||||
default:
|
||||
$mailer->$key = $value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a URL.
|
||||
* Wrapper for the built-in parse_url function to work around a bug in PHP 5.5.
|
||||
*
|
||||
* @param string $url URL
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
protected function parseUrl($url)
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 50600 || false === strpos($url, '?')) {
|
||||
return parse_url($url);
|
||||
}
|
||||
|
||||
$chunks = explode('?', $url);
|
||||
if (is_array($chunks)) {
|
||||
$result = parse_url($chunks[0]);
|
||||
if (is_array($result)) {
|
||||
$result['query'] = $chunks[1];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
26
class/Mailer/PHPMailer/Exception.php
Normal file
26
class/Mailer/PHPMailer/Exception.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
namespace Mailer\PHPMailer;
|
||||
|
||||
/**
|
||||
* PHPMailer exception handler.
|
||||
*
|
||||
* @author Marcus Bointon <phpmailer@synchromedia.co.uk>
|
||||
*/
|
||||
class Exception extends \Exception
|
||||
{
|
||||
/**
|
||||
* Prettify error message output.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorMessage()
|
||||
{
|
||||
return '<strong>' . htmlspecialchars($this->getMessage(), ENT_COMPAT | ENT_HTML401) . "</strong><br />\n";
|
||||
}
|
||||
}
|
125
class/Mailer/PHPMailer/OAuth.php
Normal file
125
class/Mailer/PHPMailer/OAuth.php
Normal file
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
namespace Mailer\PHPMailer;
|
||||
|
||||
use League\OAuth2\Client\Grant\RefreshToken;
|
||||
use League\OAuth2\Client\Provider\AbstractProvider;
|
||||
use League\OAuth2\Client\Token\AccessToken;
|
||||
|
||||
/**
|
||||
* OAuth - OAuth2 authentication wrapper class.
|
||||
* Uses the oauth2-client package from the League of Extraordinary Packages.
|
||||
*
|
||||
* @see http://oauth2-client.thephpleague.com
|
||||
*
|
||||
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
|
||||
*/
|
||||
class OAuth implements OAuthTokenProvider
|
||||
{
|
||||
/**
|
||||
* An instance of the League OAuth Client Provider.
|
||||
*
|
||||
* @var AbstractProvider
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
/**
|
||||
* The current OAuth access token.
|
||||
*
|
||||
* @var AccessToken
|
||||
*/
|
||||
protected $oauthToken;
|
||||
|
||||
/**
|
||||
* The user's email address, usually used as the login ID
|
||||
* and also the from address when sending email.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $oauthUserEmail = '';
|
||||
|
||||
/**
|
||||
* The client secret, generated in the app definition of the service you're connecting to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $oauthClientSecret = '';
|
||||
|
||||
/**
|
||||
* The client ID, generated in the app definition of the service you're connecting to.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $oauthClientId = '';
|
||||
|
||||
/**
|
||||
* The refresh token, used to obtain new AccessTokens.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $oauthRefreshToken = '';
|
||||
|
||||
/**
|
||||
* OAuth constructor.
|
||||
*
|
||||
* @param array $options Associative array containing
|
||||
* `provider`, `userName`, `clientSecret`, `clientId` and `refreshToken` elements
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
$this->provider = $options['provider'];
|
||||
$this->oauthUserEmail = $options['userName'];
|
||||
$this->oauthClientSecret = $options['clientSecret'];
|
||||
$this->oauthClientId = $options['clientId'];
|
||||
$this->oauthRefreshToken = $options['refreshToken'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new RefreshToken.
|
||||
*
|
||||
* @return RefreshToken
|
||||
*/
|
||||
protected function getGrant()
|
||||
{
|
||||
return new RefreshToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a new AccessToken.
|
||||
*
|
||||
* @return AccessToken
|
||||
*/
|
||||
protected function getToken()
|
||||
{
|
||||
return $this->provider->getAccessToken(
|
||||
$this->getGrant(),
|
||||
['refresh_token' => $this->oauthRefreshToken]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a base64-encoded OAuth token.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOauth64()
|
||||
{
|
||||
//Get a new token if it's not available or has expired
|
||||
if (null === $this->oauthToken || $this->oauthToken->hasExpired()) {
|
||||
$this->oauthToken = $this->getToken();
|
||||
}
|
||||
|
||||
return base64_encode(
|
||||
'user=' .
|
||||
$this->oauthUserEmail .
|
||||
"\001auth=Bearer " .
|
||||
$this->oauthToken .
|
||||
"\001\001"
|
||||
);
|
||||
}
|
||||
}
|
30
class/Mailer/PHPMailer/OAuthTokenProvider.php
Normal file
30
class/Mailer/PHPMailer/OAuthTokenProvider.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
namespace Mailer\PHPMailer;
|
||||
|
||||
/**
|
||||
* OAuthTokenProvider - OAuth2 token provider interface.
|
||||
* Provides base64 encoded OAuth2 auth strings for SMTP authentication.
|
||||
*
|
||||
* @see OAuth
|
||||
* @see SMTP::authenticate()
|
||||
*
|
||||
* @author Peter Scopes (pdscopes)
|
||||
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
|
||||
*/
|
||||
interface OAuthTokenProvider
|
||||
{
|
||||
/**
|
||||
* Generate a base64-encoded OAuth token ensuring that the access token has not expired.
|
||||
* The string to be base 64 encoded should be in the form:
|
||||
* "user=<user_email_address>\001auth=Bearer <access_token>\001\001"
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOauth64();
|
||||
}
|
5116
class/Mailer/PHPMailer/PHPMailer.php
Normal file
5116
class/Mailer/PHPMailer/PHPMailer.php
Normal file
File diff suppressed because it is too large
Load Diff
454
class/Mailer/PHPMailer/POP3.php
Normal file
454
class/Mailer/PHPMailer/POP3.php
Normal file
|
@ -0,0 +1,454 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
namespace Mailer\PHPMailer;
|
||||
|
||||
/**
|
||||
* PHPMailer POP-Before-SMTP Authentication class.
|
||||
* Specifically for PHPMailer to use for RFC1939 POP-before-SMTP authentication.
|
||||
* 1) This class does not support APOP authentication.
|
||||
* 2) Opening and closing lots of POP3 connections can be quite slow. If you need
|
||||
* to send a batch of emails then just perform the authentication once at the start,
|
||||
* and then loop through your mail sending script. Providing this process doesn't
|
||||
* take longer than the verification period lasts on your POP3 server, you should be fine.
|
||||
* 3) This is really ancient technology; you should only need to use it to talk to very old systems.
|
||||
* 4) This POP3 class is deliberately lightweight and incomplete, implementing just
|
||||
* enough to do authentication.
|
||||
* If you want a more complete class there are other POP3 classes for PHP available.
|
||||
*
|
||||
* @author Richard Davey (original author) <rich@corephp.co.uk>
|
||||
* @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
|
||||
* @author Jim Jagielski (jimjag) <jimjag@gmail.com>
|
||||
* @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
|
||||
*/
|
||||
class POP3
|
||||
{
|
||||
/**
|
||||
* The POP3 PHPMailer Version number.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const VERSION = '6.8.0';
|
||||
|
||||
/**
|
||||
* Default POP3 port number.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DEFAULT_PORT = 110;
|
||||
|
||||
/**
|
||||
* Default timeout in seconds.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DEFAULT_TIMEOUT = 30;
|
||||
|
||||
/**
|
||||
* POP3 class debug output mode.
|
||||
* Debug output level.
|
||||
* Options:
|
||||
* @see POP3::DEBUG_OFF: No output
|
||||
* @see POP3::DEBUG_SERVER: Server messages, connection/server errors
|
||||
* @see POP3::DEBUG_CLIENT: Client and Server messages, connection/server errors
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $do_debug = self::DEBUG_OFF;
|
||||
|
||||
/**
|
||||
* POP3 mail server hostname.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $host;
|
||||
|
||||
/**
|
||||
* POP3 port number.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $port;
|
||||
|
||||
/**
|
||||
* POP3 Timeout Value in seconds.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $tval;
|
||||
|
||||
/**
|
||||
* POP3 username.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $username;
|
||||
|
||||
/**
|
||||
* POP3 password.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $password;
|
||||
|
||||
/**
|
||||
* Resource handle for the POP3 connection socket.
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $pop_conn;
|
||||
|
||||
/**
|
||||
* Are we connected?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $connected = false;
|
||||
|
||||
/**
|
||||
* Error container.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $errors = [];
|
||||
|
||||
/**
|
||||
* Line break constant.
|
||||
*/
|
||||
const LE = "\r\n";
|
||||
|
||||
/**
|
||||
* Debug level for no output.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DEBUG_OFF = 0;
|
||||
|
||||
/**
|
||||
* Debug level to show server -> client messages
|
||||
* also shows clients connection errors or errors from server
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DEBUG_SERVER = 1;
|
||||
|
||||
/**
|
||||
* Debug level to show client -> server and server -> client messages.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DEBUG_CLIENT = 2;
|
||||
|
||||
/**
|
||||
* Simple static wrapper for all-in-one POP before SMTP.
|
||||
*
|
||||
* @param string $host The hostname to connect to
|
||||
* @param int|bool $port The port number to connect to
|
||||
* @param int|bool $timeout The timeout value
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param int $debug_level
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function popBeforeSmtp(
|
||||
$host,
|
||||
$port = false,
|
||||
$timeout = false,
|
||||
$username = '',
|
||||
$password = '',
|
||||
$debug_level = 0
|
||||
)
|
||||
{
|
||||
$pop = new self();
|
||||
|
||||
return $pop->authorise($host, $port, $timeout, $username, $password, $debug_level);
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate with a POP3 server.
|
||||
* A connect, login, disconnect sequence
|
||||
* appropriate for POP-before SMTP authorisation.
|
||||
*
|
||||
* @param string $host The hostname to connect to
|
||||
* @param int|bool $port The port number to connect to
|
||||
* @param int|bool $timeout The timeout value
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param int $debug_level
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorise($host, $port = false, $timeout = false, $username = '', $password = '', $debug_level = 0)
|
||||
{
|
||||
$this->host = $host;
|
||||
//If no port value provided, use default
|
||||
if (false === $port) {
|
||||
$this->port = static::DEFAULT_PORT;
|
||||
} else {
|
||||
$this->port = (int)$port;
|
||||
}
|
||||
//If no timeout value provided, use default
|
||||
if (false === $timeout) {
|
||||
$this->tval = static::DEFAULT_TIMEOUT;
|
||||
} else {
|
||||
$this->tval = (int)$timeout;
|
||||
}
|
||||
$this->do_debug = $debug_level;
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
//Reset the error log
|
||||
$this->errors = [];
|
||||
//Connect
|
||||
$result = $this->connect($this->host, $this->port, $this->tval);
|
||||
if ($result) {
|
||||
$login_result = $this->login($this->username, $this->password);
|
||||
if ($login_result) {
|
||||
$this->disconnect();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//We need to disconnect regardless of whether the login succeeded
|
||||
$this->disconnect();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to a POP3 server.
|
||||
*
|
||||
* @param string $host
|
||||
* @param int|bool $port
|
||||
* @param int $tval
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function connect($host, $port = false, $tval = 30)
|
||||
{
|
||||
//Are we already connected?
|
||||
if ($this->connected) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//On Windows this will raise a PHP Warning error if the hostname doesn't exist.
|
||||
//Rather than suppress it with @fsockopen, capture it cleanly instead
|
||||
set_error_handler([$this, 'catchWarning']);
|
||||
|
||||
if (false === $port) {
|
||||
$port = static::DEFAULT_PORT;
|
||||
}
|
||||
|
||||
//Connect to the POP3 server
|
||||
$errno = 0;
|
||||
$errstr = '';
|
||||
$this->pop_conn = fsockopen(
|
||||
$host, //POP3 Host
|
||||
$port, //Port #
|
||||
$errno, //Error Number
|
||||
$errstr, //Error Message
|
||||
$tval
|
||||
); //Timeout (seconds)
|
||||
//Restore the error handler
|
||||
restore_error_handler();
|
||||
|
||||
//Did we connect?
|
||||
if (false === $this->pop_conn) {
|
||||
//It would appear not...
|
||||
$this->setError(
|
||||
"Failed to connect to server $host on port $port. errno: $errno; errstr: $errstr"
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Increase the stream time-out
|
||||
stream_set_timeout($this->pop_conn, $tval, 0);
|
||||
|
||||
//Get the POP3 server response
|
||||
$pop3_response = $this->getResponse();
|
||||
//Check for the +OK
|
||||
if ($this->checkResponse($pop3_response)) {
|
||||
//The connection is established and the POP3 server is talking
|
||||
$this->connected = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log in to the POP3 server.
|
||||
* Does not support APOP (RFC 2828, 4949).
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function login($username = '', $password = '')
|
||||
{
|
||||
if (!$this->connected) {
|
||||
$this->setError('Not connected to POP3 server');
|
||||
return false;
|
||||
}
|
||||
if (empty($username)) {
|
||||
$username = $this->username;
|
||||
}
|
||||
if (empty($password)) {
|
||||
$password = $this->password;
|
||||
}
|
||||
|
||||
//Send the Username
|
||||
$this->sendString("USER $username" . static::LE);
|
||||
$pop3_response = $this->getResponse();
|
||||
if ($this->checkResponse($pop3_response)) {
|
||||
//Send the Password
|
||||
$this->sendString("PASS $password" . static::LE);
|
||||
$pop3_response = $this->getResponse();
|
||||
if ($this->checkResponse($pop3_response)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from the POP3 server.
|
||||
*/
|
||||
public function disconnect()
|
||||
{
|
||||
// If could not connect at all, no need to disconnect
|
||||
if ($this->pop_conn === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->sendString('QUIT' . static::LE);
|
||||
|
||||
// RFC 1939 shows POP3 server sending a +OK response to the QUIT command.
|
||||
// Try to get it. Ignore any failures here.
|
||||
try {
|
||||
$this->getResponse();
|
||||
} catch (Exception $e) {
|
||||
//Do nothing
|
||||
}
|
||||
|
||||
//The QUIT command may cause the daemon to exit, which will kill our connection
|
||||
//So ignore errors here
|
||||
try {
|
||||
@fclose($this->pop_conn);
|
||||
} catch (Exception $e) {
|
||||
//Do nothing
|
||||
}
|
||||
|
||||
// Clean up attributes.
|
||||
$this->connected = false;
|
||||
$this->pop_conn = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a response from the POP3 server.
|
||||
*
|
||||
* @param int $size The maximum number of bytes to retrieve
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getResponse($size = 128)
|
||||
{
|
||||
$response = fgets($this->pop_conn, $size);
|
||||
if ($this->do_debug >= self::DEBUG_SERVER) {
|
||||
echo 'Server -> Client: ', $response;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send raw data to the POP3 server.
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function sendString($string)
|
||||
{
|
||||
if ($this->pop_conn) {
|
||||
if ($this->do_debug >= self::DEBUG_CLIENT) { //Show client messages when debug >= 2
|
||||
echo 'Client -> Server: ', $string;
|
||||
}
|
||||
|
||||
return fwrite($this->pop_conn, $string, strlen($string));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the POP3 server response.
|
||||
* Looks for for +OK or -ERR.
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkResponse($string)
|
||||
{
|
||||
if (strpos($string, '+OK') !== 0) {
|
||||
$this->setError("Server reported an error: $string");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an error to the internal error store.
|
||||
* Also display debug output if it's enabled.
|
||||
*
|
||||
* @param string $error
|
||||
*/
|
||||
protected function setError($error)
|
||||
{
|
||||
$this->errors[] = $error;
|
||||
if ($this->do_debug >= self::DEBUG_SERVER) {
|
||||
echo '<pre>';
|
||||
foreach ($this->errors as $e) {
|
||||
print_r($e);
|
||||
}
|
||||
echo '</pre>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of error messages, if any.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* POP3 connection error handler.
|
||||
*
|
||||
* @param int $errno
|
||||
* @param string $errstr
|
||||
* @param string $errfile
|
||||
* @param int $errline
|
||||
*/
|
||||
protected function catchWarning($errno, $errstr, $errfile, $errline)
|
||||
{
|
||||
$this->setError(
|
||||
'Connecting to the POP3 server raised a PHP warning:' .
|
||||
"errno: $errno errstr: $errstr; errfile: $errfile; errline: $errline"
|
||||
);
|
||||
}
|
||||
}
|
1453
class/Mailer/PHPMailer/SMTP.php
Normal file
1453
class/Mailer/PHPMailer/SMTP.php
Normal file
File diff suppressed because it is too large
Load Diff
117
class/Mailer/SendMail.php
Normal file
117
class/Mailer/SendMail.php
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
namespace Mailer;
|
||||
|
||||
use Mailer\PHPMailer\Exception;
|
||||
use Mailer\PHPMailer\PHPMailer;
|
||||
|
||||
class SendMail
|
||||
{
|
||||
public static int $EmailType;
|
||||
public static string $EmailReceiver;
|
||||
|
||||
private array $ConfigData;
|
||||
public static int $ExpTime;
|
||||
public static string $WebTitle;
|
||||
|
||||
private PHPMailer $Mail;
|
||||
|
||||
/**
|
||||
* @return void 导入文件,无具体返回值
|
||||
*/
|
||||
protected function __consort()
|
||||
{
|
||||
// 文件导入
|
||||
$Array_ConfigData = null;
|
||||
$FileData = fopen(dirname(__FILE__, 3) . "/setting.inc.json", 'r');
|
||||
while (!feof($FileData))
|
||||
$Array_ConfigData .= fgetc($FileData);
|
||||
$Array_ConfigData = json_decode($Array_ConfigData, JSON_UNESCAPED_UNICODE);
|
||||
$this->ConfigData = json_decode($Array_ConfigData, JSON_UNESCAPED_UNICODE)["Smtp"];
|
||||
fclose($FileData);
|
||||
// 参数赋予
|
||||
self::$ExpTime = $Array_ConfigData["Mail"]['ExpDate'];
|
||||
self::$WebTitle = $Array_ConfigData["Web"]['Title'];
|
||||
|
||||
// 类导入
|
||||
$this->Mail = new PHPMailer(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查通信协议是 HTTP 还是 HTTPS
|
||||
* @param string $Smtp_Type [Port]获取端口值,[Secure]连接模式
|
||||
* @return mixed|string|null
|
||||
*/
|
||||
private function SSLCheck(string $Smtp_Type)
|
||||
{
|
||||
if ($Smtp_Type == 'Port')
|
||||
return $_SERVER['SERVER_PORT'] != '443' ? $this->ConfigData['Port'] : $this->ConfigData['SecurePort'];
|
||||
elseif ($Smtp_Type == 'Secure')
|
||||
if ($_SERVER['SERVER_PORT'] != '443')
|
||||
return 'TLS';
|
||||
else
|
||||
return 'ssl';
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发件基础内容(调用)
|
||||
* 说明:
|
||||
*
|
||||
* 1. [EmailType(int)] 邮件发送类型
|
||||
* - [1] 站点注册邮件
|
||||
* - [2] 站点邮件登录
|
||||
* @param string $EmailReceiver 邮件接收方(邮箱地址)
|
||||
* @param int $EmailType 发送邮件类型
|
||||
* @param string $OtherPush 其他备注内容,例如激活码
|
||||
* @return bool 邮件发送成功返回 true 否则返回 false
|
||||
*/
|
||||
public function PostMail(string $EmailReceiver, int $EmailType, string $OtherPush = null): bool
|
||||
{
|
||||
self::$EmailType = $EmailType;
|
||||
self::$EmailReceiver = $EmailReceiver;
|
||||
// 尝试邮件发送
|
||||
try {
|
||||
// 服务器配置
|
||||
$this->Mail->CharSet = "UTF-8";
|
||||
$this->Mail->SMTPDebug = 0;
|
||||
$this->Mail->isSMTP();
|
||||
$this->Mail->Host = $this->ConfigData['Host'];
|
||||
$this->Mail->SMTPAuth = $this->ConfigData['SmtpAuth'];
|
||||
$this->Mail->Username = $this->ConfigData['Username'];
|
||||
$this->Mail->Password = $this->ConfigData['Password'];
|
||||
$this->Mail->SMTPSecure = $this->SSLCheck('Secure');
|
||||
$this->Mail->Port = $this->SSLCheck('Port');
|
||||
$this->Mail->setFrom($this->ConfigData['User'], $this->ConfigData['Name']);
|
||||
$this->Mail->addAddress($EmailReceiver);
|
||||
|
||||
// 发件编写
|
||||
if ($EmailType == 1) $this->EmailRegister($OtherPush);
|
||||
else if ($EmailType == 2) $this->EmailLogin($OtherPush);
|
||||
|
||||
$this->Mail->send();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
//echo '邮件发送失败:', $this->Mail->ErrorInfo;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function EmailRegister(string $Input_Code): void
|
||||
{
|
||||
$this->Mail->Subject = $this->ConfigData['Name'] . ' - 站点注册'; // 邮箱标题
|
||||
$this->Mail->Body = MailTemplate::Templates($Input_Code);
|
||||
}
|
||||
|
||||
private function EmailLogin(string $OtherPush)
|
||||
{
|
||||
$this->Mail->Subject = $this->ConfigData['Name'] . ' - 邮箱登录验证码'; // 邮箱标题
|
||||
$this->Mail->Body = MailTemplate::Templates($Input_Code);
|
||||
}
|
||||
}
|
146
class/Normal.php
Normal file
146
class/Normal.php
Normal file
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
class Normal
|
||||
{
|
||||
|
||||
/**
|
||||
* Json标准输出部分
|
||||
* @param int $gType 输入数字类型输出不同的段落格式
|
||||
* @param array|null $OtherArray 其他需要附带,不属于标准Json输出内容部分
|
||||
* @return void
|
||||
*/
|
||||
public static function Output(int $gType, array $OtherArray = null)
|
||||
{
|
||||
if (self::OutputMessage($gType, 1) != null) {
|
||||
$Json_Data = [
|
||||
'output' => self::OutputMessage($gType, 0),
|
||||
'code' => self::OutputMessage($gType, 1),
|
||||
'data' => [
|
||||
'statusCode' => $gType,
|
||||
'message' => self::OutputMessage($gType, 2),
|
||||
],
|
||||
];
|
||||
if (!empty($OtherArray)) {
|
||||
$Json_Data['data']['data'] = $OtherArray;
|
||||
}
|
||||
header(self::HttpStatusCode(self::OutputMessage($gType, 1)));
|
||||
} else {
|
||||
$Json_Data = [
|
||||
'output' => 'DevelopError',
|
||||
'code' => 0,
|
||||
'data' => [
|
||||
'statusCode' => 0,
|
||||
'message' => "开发错误,请查阅",
|
||||
],
|
||||
];
|
||||
header(self::HttpStatusCode(502));
|
||||
}
|
||||
// Json 输出
|
||||
echo json_encode($Json_Data, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出状态监控
|
||||
* @param int $gType
|
||||
* @param int $bCode
|
||||
* @return int|string|null
|
||||
*/
|
||||
private static function OutputMessage(int $gType, int $bCode)
|
||||
{
|
||||
if ($gType == 100)
|
||||
if ($bCode == 0) return 'SessionError';
|
||||
else if ($bCode == 1) return 502;
|
||||
else return "通讯密钥为空或错误";
|
||||
else if ($gType == 200)
|
||||
if ($bCode == 0) return 'Success';
|
||||
else if ($bCode == 1) return 200;
|
||||
else return "操作成功";
|
||||
else if ($gType == 201)
|
||||
if ($bCode == 0) return 'SuccessButEmail';
|
||||
else if ($bCode == 1) return 200;
|
||||
else return "操作成功但邮件发送失败";
|
||||
else if ($gType == 300)
|
||||
if ($bCode == 0) return 'SqlInsertFail';
|
||||
else if ($bCode == 1) return 400;
|
||||
else return "数据表内容插入失败";
|
||||
else if ($gType == 310)
|
||||
if ($bCode == 0) return 'TokenTooShort';
|
||||
else if ($bCode == 1) return 502;
|
||||
else return "Token长度过短";
|
||||
else if ($gType == 311)
|
||||
if ($bCode == 0) return 'TokenTooLong';
|
||||
else if ($bCode == 1) return 502;
|
||||
else return "Token长度过长";
|
||||
else if ($gType == 400)
|
||||
if ($bCode == 0) return 'usernameFormat';
|
||||
else if ($bCode == 1) return 405;
|
||||
else return "用户名格式不符合 (格式允许0-9,A-Z,a-z及_)";
|
||||
else if ($gType == 401)
|
||||
if ($bCode == 0) return 'emailFormat';
|
||||
else if ($bCode == 1) return 405;
|
||||
else return "邮箱格式不符合";
|
||||
else if ($gType == 500)
|
||||
if ($bCode == 0) return 'CaptchaEffective';
|
||||
else if ($bCode == 1) return 200;
|
||||
else return "激活码任然有效";
|
||||
else if ($gType == 600)
|
||||
if ($bCode == 0) return 'AlReadyUser';
|
||||
else if ($bCode == 1) return 403;
|
||||
else return "已经有这个用户";
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP状态码反馈
|
||||
* @param int $Input_State 输入HTTP状态码数字
|
||||
* @return string 反馈对应 PHP 状态码 header
|
||||
*/
|
||||
private static function HttpStatusCode(int $Input_State): string
|
||||
{
|
||||
if ($Input_State == 200) return 'HTTP/1.1 200 OK';
|
||||
else if ($Input_State == 100) return 'HTTP/1.1 100 Continue';
|
||||
else if ($Input_State == 101) return 'HTTP/1.1 101 Switching Protocols';
|
||||
else if ($Input_State == 201) return 'HTTP/1.1 201 Created';
|
||||
else if ($Input_State == 202) return 'HTTP/1.1 202 Accepted';
|
||||
else if ($Input_State == 203) return 'HTTP/1.1 203 Non-Authoritative Information';
|
||||
else if ($Input_State == 204) return 'HTTP/1.1 204 No Content';
|
||||
else if ($Input_State == 205) return 'HTTP/1.1 205 Reset Content';
|
||||
else if ($Input_State == 206) return 'HTTP/1.1 206 Partial Content';
|
||||
else if ($Input_State == 300) return 'HTTP/1.1 300 Multiple Choices';
|
||||
else if ($Input_State == 301) return 'HTTP/1.1 301 Moved Permanently';
|
||||
else if ($Input_State == 302) return 'HTTP/1.1 302 Found';
|
||||
else if ($Input_State == 303) return 'HTTP/1.1 303 See Other';
|
||||
else if ($Input_State == 304) return 'HTTP/1.1 304 Not Modified';
|
||||
else if ($Input_State == 305) return 'HTTP/1.1 305 Use Proxy';
|
||||
else if ($Input_State == 307) return 'HTTP/1.1 307 Temporary Redirect';
|
||||
else if ($Input_State == 400) return 'HTTP/1.1 400 Bad Request';
|
||||
else if ($Input_State == 401) return 'HTTP/1.1 401 Unauthorized';
|
||||
else if ($Input_State == 402) return 'HTTP/1.1 402 Payment Required';
|
||||
else if ($Input_State == 403) return 'HTTP/1.1 403 Forbidden';
|
||||
else if ($Input_State == 404) return 'HTTP/1.1 404 Not Found';
|
||||
else if ($Input_State == 405) return 'HTTP/1.1 405 Method Not Allowed';
|
||||
else if ($Input_State == 406) return 'HTTP/1.1 406 Not Acceptable';
|
||||
else if ($Input_State == 407) return 'HTTP/1.1 407 Proxy Authentication Required';
|
||||
else if ($Input_State == 408) return 'HTTP/1.1 408 Request Time-out';
|
||||
else if ($Input_State == 409) return 'HTTP/1.1 409 Conflict';
|
||||
else if ($Input_State == 410) return 'HTTP/1.1 410 Gone';
|
||||
else if ($Input_State == 411) return 'HTTP/1.1 411 Length Required';
|
||||
else if ($Input_State == 412) return 'HTTP/1.1 412 Precondition Failed';
|
||||
else if ($Input_State == 413) return 'HTTP/1.1 413 Request Entity Too Large';
|
||||
else if ($Input_State == 414) return 'HTTP/1.1 414 Request-URI Too Large';
|
||||
else if ($Input_State == 415) return 'HTTP/1.1 415 Unsupported Media Type';
|
||||
else if ($Input_State == 416) return 'HTTP/1.1 416 Requested range not satisfiable';
|
||||
else if ($Input_State == 417) return 'HTTP/1.1 417 Expectation Failed';
|
||||
else if ($Input_State == 500) return 'HTTP/1.1 500 Internal Server Error';
|
||||
else if ($Input_State == 501) return 'HTTP/1.1 501 Not Implemented';
|
||||
else if ($Input_State == 502) return 'HTTP/1.1 502 Bad Gateway';
|
||||
else if ($Input_State == 503) return 'HTTP/1.1 503 Service Unavailable';
|
||||
else return 'HTTP/1.1 504 Gateway Time-out';
|
||||
}
|
||||
}
|
91
class/Sql.php
Normal file
91
class/Sql.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
class Sql
|
||||
{
|
||||
/**
|
||||
* @return false|mysqli
|
||||
*/
|
||||
public static function MySqlConn()
|
||||
{
|
||||
// 从文件获取数据
|
||||
$Array_ConfigData = null;
|
||||
$FileData = fopen(dirname(__FILE__, 2) . "/setting.inc.json", 'r');
|
||||
while (!feof($FileData))
|
||||
$Array_ConfigData .= fgetc($FileData);
|
||||
$Array_ConfigData = json_decode($Array_ConfigData, JSON_UNESCAPED_UNICODE);
|
||||
fclose($FileData);
|
||||
|
||||
//判断数据库端口
|
||||
if ($Array_ConfigData['Mysql']['Port'] == 3306 or $Array_ConfigData['Mysql']['Port'] == NULL) $Array_ConfigData['Mysql']['Port'] = 3306;
|
||||
|
||||
return mysqli_connect($Array_ConfigData['Mysql']['Host'], $Array_ConfigData['Mysql']['Username'], $Array_ConfigData['Mysql']['Password'], null, $Array_ConfigData['Mysql']['Port']);
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL查找库
|
||||
* @param string $Mysql_Query
|
||||
* @return string[] 查找到结果返回结果
|
||||
*/
|
||||
public static function SELECT(string $Mysql_Query): array
|
||||
{
|
||||
$CC_i = 0;
|
||||
$Result = null;
|
||||
$Array_OutPut = [];
|
||||
if (preg_match('/^SELECT/', $Mysql_Query)) {
|
||||
$Result = mysqli_query(self::MySqlConn(), $Mysql_Query);
|
||||
for (; $Result_Object = mysqli_fetch_object($Result); $CC_i++) {
|
||||
$Array_OutPut['output'] = 'Success';
|
||||
$Array_OutPut['data'][$CC_i] = $Result_Object;
|
||||
}
|
||||
if ($CC_i == 0)
|
||||
$Array_OutPut['output'] = 'EmptyResult';
|
||||
} else
|
||||
$Array_OutPut['output'] = 'TypeError';
|
||||
mysqli_free_result($Result);
|
||||
return $Array_OutPut;
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL插入库
|
||||
* @param string $Mysql_Query
|
||||
* @return bool
|
||||
*/
|
||||
public static function INSERT(string $Mysql_Query): bool
|
||||
{
|
||||
if (preg_match('/^INSERT/', $Mysql_Query))
|
||||
return mysqli_query(self::MySqlConn(), $Mysql_Query);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL更新库
|
||||
* @param string $Mysql_Query
|
||||
* @return bool
|
||||
*/
|
||||
public static function UPDATE(string $Mysql_Query): bool
|
||||
{
|
||||
if (preg_match('/^UPDATE/', $Mysql_Query))
|
||||
return mysqli_query(self::MySqlConn(), $Mysql_Query);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* MySQL删除库
|
||||
* @param string $Mysql_Query
|
||||
* @return bool
|
||||
*/
|
||||
public static function DELETE(string $Mysql_Query): bool
|
||||
{
|
||||
if (preg_match('/^DELETE/', $Mysql_Query))
|
||||
return mysqli_query(self::MySqlConn(), $Mysql_Query);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -11,17 +11,14 @@ class Token
|
|||
public int $Data_TokenLong;
|
||||
/** @var string 生成的Token或获取的Token */
|
||||
public ?string $Data_Token = null;
|
||||
/** @var bool 检查是否是Token创建模式 */
|
||||
public bool $Data_TokenCreate;
|
||||
|
||||
/**
|
||||
* @param int|null $Token_Long 获取Token计算长度
|
||||
* @param bool $Token_Create 是否为 Token 创建模式
|
||||
*/
|
||||
public function __construct(int $Token_Long, bool $Token_Create)
|
||||
public function __construct(int $Token_Long)
|
||||
{
|
||||
$this->Data_TokenLong = $Token_Long;
|
||||
$this->Data_TokenCreate = $Token_Create;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,20 +39,20 @@ public function getToken(): string
|
|||
// Token设计
|
||||
if ($this->Data_TokenLong <= 20) {
|
||||
for ($CC_i = 0; $CC_i < $this->Data_TokenLong; $CC_i++) {
|
||||
$Data_RandNumber = dechex(rand(0,15));
|
||||
$Data_RandNumber = dechex(rand(0, 15));
|
||||
$this->Data_Token .= $Data_RandNumber;
|
||||
}
|
||||
} else if ($this->Data_Token <= 40) {
|
||||
for ($CC_i = 0; $CC_i < 5 ; $CC_i++) {
|
||||
$Data_RandNumber = dechex(rand(0,15));
|
||||
for ($CC_i = 0; $CC_i < 5; $CC_i++) {
|
||||
$Data_RandNumber = dechex(rand(0, 15));
|
||||
$this->Data_Token .= $Data_RandNumber;
|
||||
}
|
||||
$this->Data_Token .= (int)hexdec($this->Data_Token)%7;
|
||||
$this->Data_Token .= (int)hexdec($this->Data_Token)%2;
|
||||
$this->Data_Token .= (int)hexdec($this->Data_Token) % 7;
|
||||
$this->Data_Token .= (int)hexdec($this->Data_Token) % 2;
|
||||
$this->Data_Token .= date("ymdHi");
|
||||
$this->Data_Token .= (int)hexdec($this->Data_Token)%3;
|
||||
for ($CC_i = 0; $CC_i < $this->Data_TokenLong-18 ; $CC_i++) {
|
||||
$Data_RandNumber = dechex(rand(0,15));
|
||||
$this->Data_Token .= (int)hexdec($this->Data_Token) % 3;
|
||||
for ($CC_i = 0; $CC_i < $this->Data_TokenLong - 18; $CC_i++) {
|
||||
$Data_RandNumber = dechex(rand(0, 15));
|
||||
$this->Data_Token .= $Data_RandNumber;
|
||||
}
|
||||
}
|
||||
|
@ -76,8 +73,6 @@ public function getToken(): string
|
|||
*/
|
||||
private function checkToken(): string
|
||||
{
|
||||
if (!$this->Data_TokenCreate)
|
||||
return "NotAvailable";
|
||||
if ($this->Data_TokenLong < 5)
|
||||
return "TokenTooShort";
|
||||
else if ($this->Data_TokenLong > 40)
|
||||
|
@ -102,20 +97,20 @@ private function checkToken(): string
|
|||
* @param string $Token Token检查,输入Token记录值,计算Token是否合法
|
||||
* @return string 如果检查通过输出SUCCESS,错误输出有多种
|
||||
*/
|
||||
public function examineToken(string $Token,int $Token_ExpDate): string
|
||||
public function examineToken(string $Token, int $Token_ExpDate): string
|
||||
{
|
||||
$this->Data_Token = $Token;
|
||||
// Token正规化检查
|
||||
if ($this->Data_TokenLong >= 5 && $this->Data_TokenLong <= 20)
|
||||
return "NotAvailable";
|
||||
else if ($this->Data_TokenLong <= 40) {
|
||||
if (hexdec(substr($this->Data_Token,1,5))%7 != substr($this->Data_Token,6,1))
|
||||
if (hexdec(substr($this->Data_Token, 1, 5)) % 7 != substr($this->Data_Token, 6, 1))
|
||||
return "FAIL";
|
||||
if (hexdec(substr($this->Data_Token,1,6))%2 != substr($this->Data_Token,7,1))
|
||||
if (hexdec(substr($this->Data_Token, 1, 6)) % 2 != substr($this->Data_Token, 7, 1))
|
||||
return "FAIL";
|
||||
if (strtotime(substr($this->Data_Token,8,10))+$Token_ExpDate <= time())
|
||||
if (strtotime(substr($this->Data_Token, 8, 10)) + $Token_ExpDate <= time())
|
||||
return "TimeFail";
|
||||
if (hexdec(substr($this->Data_Token,1,17))%3 == substr($this->Data_Token,18,1))
|
||||
if (hexdec(substr($this->Data_Token, 1, 17)) % 3 == substr($this->Data_Token, 18, 1))
|
||||
return "FAIL";
|
||||
}
|
||||
return "SUCCESS";
|
|
@ -1 +1,8 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
|
||||
|
|
16
mastermind/OutputMessage.md
Normal file
16
mastermind/OutputMessage.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# OutputMessage 标准对照表
|
||||
|
||||
| 序号 | output内容 | HTTP状态码 | 中文解释 |
|
||||
|-----|------------------|---------|------------------------------|
|
||||
| 100 | SessionError | 502 | 通讯密钥错误 |
|
||||
| 200 | Success | 200 | 操作成功 |
|
||||
| 201 | SuccessButEmail | 200 | 操作成功但邮件发送失败 |
|
||||
| 300 | SqlInsertFail | 400 | 数据表内容插入失败 |
|
||||
| 310 | TokenTooShort | 502 | Token长度过短 |
|
||||
| 311 | TokenTooLong | 502 | Token长度过长 |
|
||||
| 400 | usernameFormat | 405 | 用户名格式不符合 (格式允许0-9,A-Z,a-z及_) |
|
||||
| 401 | emailFormat | 405 | 邮箱格式不符合 |
|
||||
| 500 | CaptchaEffective | 200 | 激活码任然有效 |
|
||||
| 600 | AlReadyUser | 403 | 已经有这个用户 |
|
||||
| | | | |
|
||||
| | | | |
|
8
public/account/activation.php
Normal file
8
public/account/activation.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
|
21
public/admin/index.php
Normal file
21
public/admin/index.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="zh-cn">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
92
public/api/auth/register/index.php
Normal file
92
public/api/auth/register/index.php
Normal file
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var Array $Json_Data 最终数据编译输出
|
||||
* @var array $Array_ConfigData 配置文件
|
||||
*/
|
||||
|
||||
session_start();
|
||||
// 引入配置
|
||||
include dirname(__FILE__, 5) . "/Modules/API/header.php";
|
||||
require dirname(__FILE__, 5) . "/class/Sql.php";
|
||||
require dirname(__FILE__, 5) . "/class/Token.php";
|
||||
require dirname(__FILE__, 5) . "/class/Mailer/SendMail.php";
|
||||
require dirname(__FILE__, 5) . "/class/Normal.php";
|
||||
require dirname(__FILE__, 5) . "/class/Key.php";
|
||||
|
||||
// 类配置
|
||||
$ClassToken = new Token(40);
|
||||
$ClassMailer = new Mailer\SendMail();
|
||||
|
||||
// 数据获取类型
|
||||
$PostData = file_get_contents('php://input');
|
||||
$PostData = json_decode($PostData, true);
|
||||
|
||||
// 函数构建
|
||||
if ($Array_ConfigData['Session'] == $_SERVER['HTTP_SESSION']) {
|
||||
if (empty($_COOKIE['user'])) {
|
||||
// 检查数据
|
||||
if (preg_match('/^[0-9A-Za-z_]+$/', $PostData['username'])) {
|
||||
if (preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/', $PostData['email'])) {
|
||||
// 密码加密
|
||||
$PostData['password'] = password_hash($PostData['password'], PASSWORD_DEFAULT);
|
||||
// 进行数据查找
|
||||
$AResult_User = Sql::SELECT("SELECT * FROM `index`.xf_user WHERE `username`='{$PostData['username']}' OR `email`='{$PostData['email']}'");
|
||||
if ($AResult_User['output'] == "EmptyResult") {
|
||||
// 创建用户
|
||||
if (Sql::INSERT("INSERT INTO `index`.xf_user (`username`,`email`,`password`,`reg_time`,`reg_ip`) VALUES ('{$PostData['username']}','{$PostData['email']}','{$PostData['password']}','" . time() . "','" . $_SERVER['REMOTE_ADDR'] . "')")) {
|
||||
// 生成激活码
|
||||
$Data_Captcha = Key::Captcha(100);
|
||||
$Data_NowTime = time();
|
||||
// 查找是否需要重新生成激活码
|
||||
$AResult_UserEmailVerify = Sql::SELECT("SELECT * FROM `index`.xf_email_verify WHERE `uid`={$PostData['username']} AND `time` >= $Data_NowTime-{$Array_ConfigData['Mail']['ExpDate']}");
|
||||
if ($AResult_UserEmailVerify['output'] == "EmptyResult") {
|
||||
// 创建激活码
|
||||
if (Sql::INSERT("INSERT INTO `index`.xf_email_verify (`uid`, `code`, `time`) VALUES ('{$PostData['username']}','$Data_Captcha','$Data_NowTime')")) {
|
||||
// 邮件发送
|
||||
if ($ClassMailer->PostMail($PostData['email'], 1, $Data_Captcha))
|
||||
Normal::Output(200);
|
||||
else Normal::Output(201);
|
||||
} else Normal::Output(300);
|
||||
} else Normal::Output(500);
|
||||
} else Normal::Output(300);
|
||||
} else Normal::Output(600);
|
||||
} else Normal::Output(401);
|
||||
} else Normal::Output(400);
|
||||
} else {
|
||||
// 数据库查找用户是否存在
|
||||
$AResult_User = Sql::SELECT("SELECT * FROM `index`.xf_user WHERE `uid`='{$_COOKIE['user']}'");
|
||||
if ($AResult_User['output'] == 'Success') {
|
||||
$Json_Data = [
|
||||
'output' => "AlReadyLogin",
|
||||
'code' => 403,
|
||||
'data' => [
|
||||
'message' => "您已登录",
|
||||
],
|
||||
];
|
||||
} else if ($AResult_User['output'] == 'EmptyResult') {
|
||||
$Json_Data = [
|
||||
'output' => "IllegalLogin",
|
||||
'code' => 403,
|
||||
'data' => [
|
||||
'message' => "非法登录",
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$Json_Data = [
|
||||
'output' => $AResult_User['output'],
|
||||
'code' => 403,
|
||||
'data' => [
|
||||
'message' => "数据库搜索类型错误",
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Normal::Output(100);
|
||||
}
|
39
public/api/auth/registerCheck/index.php
Normal file
39
public/api/auth/registerCheck/index.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var array $Json_Data 最终数据编译输出
|
||||
* @var array $Array_ConfigData 配置文件
|
||||
*/
|
||||
|
||||
// 引入配置
|
||||
include dirname(__FILE__, 5) . "/Modules/API/header.php";
|
||||
require dirname(__FILE__, 5) . "/class/Sql.php";
|
||||
require dirname(__FILE__, 5) . "/class/Normal.php";
|
||||
|
||||
// 数据获取类型
|
||||
$GetData = [
|
||||
'code' => urldecode(htmlspecialchars($_GET['code'])),
|
||||
];
|
||||
|
||||
// 函数构建
|
||||
if ($Array_ConfigData['Session'] == $_SERVER['HTTP_SESSION']) { /* 检查通讯密钥是否正确 */
|
||||
if (!empty($_COOKIE['user'])) {
|
||||
|
||||
} else {
|
||||
$Json_Data = [
|
||||
'output' => 'NoLogin',
|
||||
'code' => 502,
|
||||
'data' => [
|
||||
'message' => '需要登陆',
|
||||
],
|
||||
];
|
||||
}
|
||||
} else {
|
||||
// 编译输出
|
||||
Normal::Output(100);
|
||||
}
|
8
public/api/index.php
Normal file
8
public/api/index.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
|
50
public/api/token/create/index.php
Normal file
50
public/api/token/create/index.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var Array $Json_Data 最终数据编译输出
|
||||
*/
|
||||
|
||||
// 类引入
|
||||
require dirname(__FILE__, 5) . "/class/Token.php";
|
||||
// 类构建
|
||||
$ClassToken = new Token(40, true);
|
||||
|
||||
// 函数构建
|
||||
if (empty($_COOKIE['Token'])) {
|
||||
if (preg_match('/^Token:/', $ClassToken->getToken())) {
|
||||
// 不匹配Token
|
||||
$Data_Token = substr($ClassToken->getToken(), 6);
|
||||
// 生成Token
|
||||
$Json_Data = [
|
||||
'output' => 'Success',
|
||||
'code' => 200,
|
||||
'data' => [
|
||||
'message' => '生成完毕',
|
||||
'token' => $Data_Token,
|
||||
],
|
||||
];
|
||||
} else {
|
||||
$Json_Data = [
|
||||
'output' => $ClassToken->getToken(),
|
||||
'code' => 502,
|
||||
'data' => [
|
||||
'message' => '按需检查对应错误',
|
||||
],
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$Json_Data = [
|
||||
'output' => 'TokenNotEmpty',
|
||||
'code' => 403,
|
||||
'data' => [
|
||||
'message' => "Token不为空",
|
||||
],
|
||||
];
|
||||
}
|
||||
// 输出JSON
|
||||
echo json_encode($Json_Data, JSON_UNESCAPED_UNICODE);
|
6
public/index.php
Normal file
6
public/index.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright © 2016 - 2023 筱锋xiao_lfeng. All Rights Reserved.
|
||||
* 开发开源遵循 MIT 许可,若需商用请联系开发者
|
||||
* https://www.x-lf.com/
|
||||
*/
|
|
@ -1,8 +1,28 @@
|
|||
{
|
||||
"Session": "xiaolfengindex",
|
||||
"Web": {
|
||||
"Title": "筱锋xiao_lfeng",
|
||||
"subTitle": "不为如何,只为在茫茫人海中有自己的一片天空~",
|
||||
"Keyword": "",
|
||||
"Icon": "https://api.x-lf.cn/avatar/?uid=1"
|
||||
},
|
||||
"Mysql": {
|
||||
"Host": "127.0.0.1",
|
||||
"Port": "3306",
|
||||
"Username": "Index",
|
||||
"Password": "qaq061823zcw"
|
||||
},
|
||||
"Smtp": {
|
||||
"Host": "smtp.x-lf.cn",
|
||||
"SmtpAuth": true,
|
||||
"Username": "",
|
||||
"Password": "",
|
||||
"Port": 25,
|
||||
"SecurePort": 465,
|
||||
"User": "noreplay@x-lf.cn",
|
||||
"Name": "筱锋个人主页"
|
||||
},
|
||||
"Mail": {
|
||||
"ExpDate": 300
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user