From 4d498d0c65e8bc19fcc08f3abc753fb256a3dcbd Mon Sep 17 00:00:00 2001 From: XiaoLFeng Date: Fri, 12 May 2023 14:58:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=8B=E9=93=BE=E5=88=9B=E5=BB=BA=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/Mailer/MailTemplate.php | 19 +++-- class/Normal.php | 65 ++++++++++++++- class/Sql.php | 5 ++ mastermind/OutputMessage.md | 40 +++++---- public/api/blog/friends_link/create/index.php | 83 +++++++++++++++++++ setting.inc.json | 11 +-- 6 files changed, 192 insertions(+), 31 deletions(-) create mode 100644 public/api/blog/friends_link/create/index.php diff --git a/class/Mailer/MailTemplate.php b/class/Mailer/MailTemplate.php index ed5e153..0108257 100644 --- a/class/Mailer/MailTemplate.php +++ b/class/Mailer/MailTemplate.php @@ -12,8 +12,8 @@ class MailTemplate { - private static string $GCode; - private static int $NowTime; + protected static ?string $GCode; + protected static string $NowTime; /** * 检查使用邮件发送模板 @@ -24,12 +24,11 @@ public static function Templates(string $G_code = null): ?string { // 赋值给全局 self::$GCode = $G_code; - self::$NowTime = time(); + self::$NowTime = date("Y-m-d H:i"); // 判断发送内容 if (SendMail::$EmailType == 1) return self::Register(); - - return null; + else return null; } /** @@ -45,7 +44,8 @@ private static function Register(): string $getEndTime = date("Y年m月d日 H:i:s", time() + SendMail::$ExpTime); $getExpTime = (double)SendMail::$ExpTime / 60; $getYear = date('Y'); - $getDomain = $_SERVER['SERVER_NAME']; + $getDomain = SendMail::$getDomain; + $GCode = self::$GCode; // 结果返回 return << @@ -74,10 +74,15 @@ private static function Register(): string - + 点击激活
您的身份激活 $getExpTime 分钟内有效,此身份激活为 账户注册 使用。
有效期至:$getEndTime +
+
+ 若链接无法点击,可直接复制 ↓ +
+ http://$getDomain/account/activation.php?code=$GCode diff --git a/class/Normal.php b/class/Normal.php index cc4e0dd..07146aa 100644 --- a/class/Normal.php +++ b/class/Normal.php @@ -14,11 +14,15 @@ class Normal * @param array|null $OtherArray 其他需要附带,不属于标准Json输出内容部分 * @return void */ - public static function Output(int $gType, array $OtherArray = null) + public static function Output(int $gType, array $OtherArray = null, string $OtherOutput = null) { if (self::OutputMessage($gType, 1) != null) { + if (!empty($OtherOutput)) + $OtherOutput = '__' . $OtherOutput; + else + $OtherOutput = null; $Json_Data = [ - 'output' => self::OutputMessage($gType, 0), + 'output' => self::OutputMessage($gType, 0) . $OtherOutput, 'code' => self::OutputMessage($gType, 1), 'data' => [ 'statusCode' => $gType, @@ -44,6 +48,39 @@ public static function Output(int $gType, array $OtherArray = null) echo json_encode($Json_Data, JSON_UNESCAPED_UNICODE); } + /** + * 自定义生成标标准接口输出 | 样式举例 + * + * - Json + * - output( **$Json_Output** ) + * - code( **$Json_Code** ) + * - data + * - [data]statusCode: 999 + * - [data]message( **$Json_Message** ) + * - [data]data( **$Json_Other** ) + * @param string $Json_Output 输出代码 + * @param int $Json_Code + * @param string $Json_Message + * @param array $Json_Other + * @return void + */ + public static function CustomOutput(string $Json_Output, int $Json_Code, string $Json_Message, array $Json_Other = null) + { + $Json_Data = [ + 'output' => $Json_Output, + 'code' => $Json_Code, + 'data' => [ + 'statusCode' => 999, + 'message' => $Json_Message, + ], + ]; + if (!empty($Json_Other)) { + $Json_Data['data']['data'] = $Json_Other; + } + header(self::HttpStatusCode($Json_Code)); + echo json_encode($Json_Data, JSON_UNESCAPED_UNICODE); + } + /** * 输出状态监控 * @param int $gType @@ -96,6 +133,30 @@ private static function OutputMessage(int $gType, int $bCode) if ($bCode == 0) return 'passwordIncorrect'; else if ($bCode == 1) return 403; else return "密码不正确"; + else if ($gType == 404) + if ($bCode == 0) return 'typeFormat'; + else if ($bCode == 1) return 403; + else return "类型不正确"; + else if ($gType == 405) + if ($bCode == 0) return 'blog_nameFormat'; + else if ($bCode == 1) return 403; + else return "博客名字格式不符合"; + else if ($gType == 406) + if ($bCode == 0) return 'blog_introduceFormat'; + else if ($bCode == 1) return 403; + else return "博客描述格式不符合"; + else if ($gType == 407) + if ($bCode == 0) return 'internetFormat'; + else if ($bCode == 1) return 403; + else return "地址格式错误"; + else if ($gType == 408) + if ($bCode == 0) return 'booleanFormat'; + else if ($bCode == 1) return 403; + else return "布尔值格式错误"; + else if ($gType == 409) + if ($bCode == 0) return 'blog_hostFormat'; + else if ($bCode == 1) return 403; + else return "主机格式不符合"; else if ($gType == 500) if ($bCode == 0) return 'CaptchaEffective'; else if ($bCode == 1) return 200; diff --git a/class/Sql.php b/class/Sql.php index 63ec439..afec125 100644 --- a/class/Sql.php +++ b/class/Sql.php @@ -29,6 +29,11 @@ protected static function MySqlConn() /** * MySQL查找库 | * [Tips] 在PHP中,Mysql查询语句一次只允许查询一次数据,不可多个代码进行连续查询 + * + * [output] 反馈 + * - [Success] 查询记录成功 + * - [EmptyResult] 没有对应记录 + * - [TypeError] 类型错误,出现这个多半是自己开发的问题 * @param string $Mysql_Query 输入Mysql查询语句 * @return string[] 查找到结果返回结果 */ diff --git a/mastermind/OutputMessage.md b/mastermind/OutputMessage.md index a63ed9a..1858fcc 100644 --- a/mastermind/OutputMessage.md +++ b/mastermind/OutputMessage.md @@ -1,19 +1,25 @@ # OutputMessage 标准对照表 -| 序号 | output内容 | HTTP状态码 | 中文解释 | -|-----|-------------------|---------|------------------------------| -| 100 | SessionError | 502 | 通讯密钥错误 | -| 200 | Success | 200 | 操作成功 | -| 201 | SuccessButEmail | 200 | 操作成功但邮件发送失败 | -| 300 | SqlInsertFail | 400 | 数据表内容插入失败 | -| 301 | SqlSelectFail | 400 | 数据表内容查询失败 | -| 310 | TokenTooShort | 502 | Token长度过短 | -| 311 | TokenTooLong | 502 | Token长度过长 | -| 400 | usernameFormat | 405 | 用户名格式不符合 (格式允许0-9,A-Z,a-z及_) | -| 401 | emailFormat | 405 | 邮箱格式不符合 | -| 402 | userFormat | 405 | 用户格式不符合 | -| 403 | passwordIncorrect | 403 | 密码不正确 | -| 500 | CaptchaEffective | 200 | 激活码任然有效 | -| 600 | AlReadyUser | 403 | 已经有这个用户 | -| 601 | NoUser | 403 | 没有这个用户 | -| | | | | \ No newline at end of file +| 序号 | output内容 | HTTP状态码 | 中文解释 | +|-----|----------------------|---------|---------------------------------| +| 100 | SessionError | 502 | 通讯密钥错误 | +| 200 | Success | 200 | 操作成功 | +| 201 | SuccessButEmail | 200 | 操作成功但邮件发送失败 | +| 300 | SqlInsertFail | 400 | 数据表内容插入失败 | +| 301 | SqlSelectFail | 400 | 数据表内容查询失败 | +| 310 | TokenTooShort | 502 | Token长度过短 | +| 311 | TokenTooLong | 502 | Token长度过长 | +| 400 | usernameFormat | 405 | 用户名格式不符合 (格式允许0-9,A-Z,a-z及_) | +| 401 | emailFormat | 405 | 邮箱格式不符合 | +| 402 | userFormat | 405 | 用户格式不符合 | +| 403 | passwordIncorrect | 403 | 密码不正确 | +| 404 | typeFormat | 403 | 类型不正确 | +| 405 | blog_nameFormat | 403 | 博客名字格式不符合(格式允许0-9,A-Z,a-z,_及中文) | +| 406 | blog_introduceFormat | 403 | 博客描述格式不符合(格式允许0-9,A-Z,a-z,_及中文) | +| 407 | internetFormat | 403 | 地址格式错误 | +| 408 | booleanFormat | 403 | 布尔值格式错误 | +| 409 | blog_hostFormat | 403 | 主机格式不符合(格式允许0-9,A-Z,a-z,_及中文) | +| 500 | CaptchaEffective | 200 | 激活码任然有效 | +| 600 | AlReadyUser | 403 | 已经有这个用户 | +| 601 | NoUser | 403 | 没有这个用户 | +| 999 | | | (自定义输出模块 CustomOutput模块) | \ No newline at end of file diff --git a/public/api/blog/friends_link/create/index.php b/public/api/blog/friends_link/create/index.php new file mode 100644 index 0000000..98c5c3b --- /dev/null +++ b/public/api/blog/friends_link/create/index.php @@ -0,0 +1,83 @@ +uid; + } + // 检查数据是否合法 + if (!DataCheck()) { + // 检查数据库内是否有数据 + $AResult_BlogLink = Sql::SELECT("SELECT * FROM `index`.xf_blog_link WHERE `name`='{$PostData['blog_name']}' OR `owner_email`='{$PostData['user_email']}' OR `url`='{$PostData['blog_url']}'"); + if ($AResult_BlogLink['output'] == 'EmptyResult') { + // 没有数据执行插入 + if (Sql::INSERT("INSERT INTO `index`.xf_blog_link (`name`, `url`, `owner_email`, `introduce`, `icon`, `rss_judge`, `rss`, `serverhost`, `adv`, `blog_ssl`, `location`, `sel_color`, `deleted`) VALUES ('{$PostData['blog_name']}','{$PostData['blog_url']}','{$PostData['user_email']}','{$PostData['blog_introduce']}','{$PostData['blog_icon']}','{$PostData['blog_rss_judge']}','{$PostData['blog_rss']}','{$PostData['blog_host']}',{$PostData['blog_adv_judge']},{$PostData['blog_ssl_judge']},0,0,0)")) { + // 插入成功返回结果 + Normal::Output(200); + } else Normal::Output(300); + } else { + // 检查博客主要数据是否重复 + if ($AResult_BlogLink['data'][0]['owner_email'] == $PostData['user_email']) { + Normal::CustomOutput('UserEmailDuplication', 403, '用户邮箱与数据库重复'); + } else if ($AResult_BlogLink['data'][0]['name'] == $PostData['blog_name']) { + Normal::CustomOutput('BlogNameDuplication', 403, '博客名字与数据库重复'); + } else if ($AResult_BlogLink['data'][0]['url'] == $PostData['blog_url']) + Normal::CustomOutput('BlogUrlDuplication', 403, '博客地址与数据库重复');// 数据库信息查询不正确 + } + } +} else Normal::Output(100); // SESSION是否合法 + +/** + * @return false|void 返回结果为 + */ +function DataCheck() +{ + global $PostData; + if (preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/', $PostData['user_email'])) { + if (preg_match('/^[一-龥0-9A-Za-z_\']+$/', $PostData['blog_name'])) { + if (preg_match('/^[一-龥0-9A-Za-z_\']+$/', $PostData['blog_introduce'])) { + if (preg_match('/^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$/', $PostData['blog_url'])) { + if (preg_match('/^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$/', $PostData['blog_icon'])) { + if ((string)$PostData['blog_ssl_judge'] == "true" || (string)$PostData['blog_ssl_judge'] == "false") { + if ((string)$PostData['blog_adv_judge'] == "true" || (string)$PostData['blog_adv_judge'] == "false") { + if ((string)$PostData['blog_rss_judge'] == "true" || (string)$PostData['blog_rss_judge'] == "false") { + if (preg_match('/^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$/', $PostData['blog_rss'])) { + if (preg_match('/^[一-龥0-9A-Za-z_\']+$/', $PostData['blog_host'])) { + if (preg_match('/^[0-9]+$/', $PostData['blog_color'])) { + return false; + } else Normal::Output(410); + } else Normal::Output(409); // 地址格式错误(RSS地址) + } else Normal::Output(407, null, 'blog_rss'); // 地址格式错误(RSS地址) + } else Normal::Output(408, null, 'blog_rss_judge'); // 不符合布尔值参数 + } else Normal::Output(408, null, 'blog_adv_judge'); // 不符合布尔值参数 + } else Normal::Output(408, null, 'blog_ssl_judge'); // 不符合布尔值参数 + } else Normal::Output(407, null, 'blog_icon'); // 地址格式错误(图标地址) + } else Normal::Output(407, null, 'blog_url'); // 地址格式错误 + } else Normal::Output(406); // 博客描述格式不符合 + } else Normal::Output(405); // 博客名字格式不符合 + } else Normal::Output(401); // 邮箱是否合法 +} \ No newline at end of file diff --git a/setting.inc.json b/setting.inc.json index 5a5c2ed..7808c2f 100644 --- a/setting.inc.json +++ b/setting.inc.json @@ -1,10 +1,11 @@ { "Session": "xiaolfengindex", "Web": { - "Title": "筱锋xiao_lfeng", + "Title": "筱锋个人主页", "subTitle": "不为如何,只为在茫茫人海中有自己的一片天空~", "Keyword": "", - "Icon": "https://api.x-lf.cn/avatar/?uid=1" + "Icon": "https://api.x-lf.cn/avatar/?uid=1", + "Domain": "index.develop.x-lf.cn" }, "Mysql": { "Host": "127.0.0.1", @@ -13,10 +14,10 @@ "Password": "qaq061823zcw" }, "Smtp": { - "Host": "smtp.x-lf.cn", + "Host": "smtp.qiye.aliyun.com", "SmtpAuth": true, - "Username": "", - "Password": "", + "Username": "noreplay@x-lf.cn", + "Password": "X+7ily20040722", "Port": 25, "SecurePort": 465, "User": "noreplay@x-lf.cn",