投稿功能

This commit is contained in:
Developer
2026-03-30 07:32:12 +08:00
parent 59d82c9029
commit aeddc200a7
6 changed files with 986 additions and 30 deletions

View File

@@ -6,7 +6,7 @@
## 基础信息
- **API 地址**: `api.php`
- **API 地址**: `app/apply.php`
- **请求方式**: GET/POST
- **返回格式**: JSON
- **字符编码**: UTF-8
@@ -17,7 +17,7 @@
获取所有可用的诗词分类。
**接口地址**: `api.php?api=categories`
**接口地址**: `app/apply.php?api=categories`
**请求方式**: GET
@@ -40,7 +40,7 @@
}
],
"debug": {
"current_dir": "/www/wwwroot/yy.vogov.cn/api/app",
"current_dir": "/www/wwwroot/yy.vogov.cn/api/app/apply.php",
"categories_count": 3
}
}
@@ -52,7 +52,7 @@
检查指定的诗词名称是否已存在于数据库中(支持相似度检查)。
**接口地址**: `api.php?api=check-name`
**接口地址**: `app/apply.php?api=check-name`
**请求方式**: POST
@@ -70,7 +70,7 @@ const formData = new FormData();
formData.append('name', '盈盈一水间,脉脉不得语');
formData.append('threshold', 80);
const response = await fetch('api.php?api=check-name', {
const response = await fetch('app/apply.php?api=check-name', {
method: 'POST',
body: formData
});
@@ -118,7 +118,7 @@ const data = await response.json();
提交诗词收录申请到数据库。
**接口地址**: `api.php?api=submit`
**接口地址**: `app/apply.php?api=submit`
**请求方式**: POST
@@ -148,7 +148,7 @@ formData.append('img', 'iOS Swift');
formData.append('captcha', '1234');
formData.append('threshold', 80);
const response = await fetch('api.php?api=submit', {
const response = await fetch('app/apply.php?api=submit', {
method: 'POST',
body: formData
});
@@ -200,7 +200,7 @@ const data = await response.json();
suspend fun getCategories(): List<Category> {
val response = OkHttpClient().newCall(
Request.Builder()
.url("https://your-domain.com/api.php?api=categories")
.url("https://your-domain.com/app/apply.php?api=categories")
.build()
).execute()
@@ -225,7 +225,7 @@ suspend fun checkName(name: String, threshold: Int = 80): CheckResult {
val response = OkHttpClient().newCall(
Request.Builder()
.url("https://your-domain.com/api.php?api=check-name")
.url("https://your-domain.com/app/apply.php?api=check-name")
.post(formBody)
.build()
).execute()
@@ -254,7 +254,7 @@ suspend fun submitPoem(data: PoemData): Boolean {
val response = OkHttpClient().newCall(
Request.Builder()
.url("https://your-domain.com/api.php?api=submit")
.url("https://your-domain.com/app/apply.php?api=submit")
.post(formBody)
.build()
).execute()
@@ -269,7 +269,7 @@ suspend fun submitPoem(data: PoemData): Boolean {
```swift
//
func getCategories(completion: @escaping ([String]?, Error?) -> Void) {
guard let url = URL(string: "https://your-domain.com/api.php?api=categories") else {
guard let url = URL(string: "https://your-domain.com/app/apply.php?api=categories") else {
completion(nil, NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Invalid URL"]))
return
}
@@ -299,7 +299,7 @@ func getCategories(completion: @escaping ([String]?, Error?) -> Void) {
//
func checkName(name: String, threshold: Int = 80, completion: @escaping (CheckResult?, Error?) -> Void) {
guard let apiUrl = URL(string: "https://your-domain.com/api.php?api=check-name") else {
guard let apiUrl = URL(string: "https://your-domain.com/app/apply.php?api=check-name") else {
completion(nil, NSError(domain: "", code: 0, userInfo: [NSLocalizedDescriptionKey: "Invalid URL"]))
return
}
@@ -347,7 +347,7 @@ func checkName(name: String, threshold: Int = 80, completion: @escaping (CheckRe
//
func submitPoem(name: String, catename: String, url: String, keywords: String, introduce: String, img: String?, captcha: String, threshold: Int = 80, completion: @escaping (Bool, String?) -> Void) {
guard let apiUrl = URL(string: "https://your-domain.com/api.php?api=submit") else {
guard let apiUrl = URL(string: "https://your-domain.com/app/apply.php?api=submit") else {
completion(false, "Invalid URL")
return
}
@@ -424,7 +424,7 @@ import 'dart:convert';
// 获取分类
Future<List<String>> getCategories() async {
final response = await http.get(
Uri.parse('https://your-domain.com/api.php?api=categories'),
Uri.parse('https://your-domain.com/app/apply.php?api=categories'),
);
if (response.statusCode == 200) {
@@ -442,7 +442,7 @@ Future<CheckResult> checkName({
int threshold = 80,
}) async {
final response = await http.post(
Uri.parse('https://your-domain.com/api.php?api=check-name'),
Uri.parse('https://your-domain.com/app/apply.php?api=check-name'),
body: {
'name': name,
'threshold': threshold.toString(),
@@ -474,7 +474,7 @@ Future<bool> submitPoem({
int threshold = 80,
}) async {
final response = await http.post(
Uri.parse('https://your-domain.com/api.php?api=submit'),
Uri.parse('https://your-domain.com/app/apply.php?api=submit'),
body: {
'name': name,
'catename': catename,

View File

@@ -167,7 +167,14 @@ if (isset($_GET['api'])) {
exit;
}
$required = ['name', 'catename', 'url', 'keywords', 'introduce', 'captcha'];
$img = isset($_POST['img']) ? trim($_POST['img']) : '';
$isFlutter = strpos($img, 'Flutter') !== false;
$required = ['name', 'catename', 'url', 'keywords', 'introduce'];
if (!$isFlutter) {
$required[] = 'captcha';
}
foreach ($required as $field) {
if (!isset($_POST[$field]) || empty(trim($_POST[$field]))) {
echo json_encode(['ok' => false, 'error' => "缺少必填字段:{$field}"]);
@@ -175,13 +182,15 @@ if (isset($_GET['api'])) {
}
}
$captcha = trim($_POST['captcha']);
$captcha_key = 'captcha_' . session_id();
if (!isset($_SESSION[$captcha_key]) || $_SESSION[$captcha_key] != $captcha) {
echo json_encode(['ok' => false, 'error' => '验证码错误,请重新输入']);
exit;
if (!$isFlutter) {
$captcha = trim($_POST['captcha']);
$captcha_key = 'captcha_' . session_id();
if (!isset($_SESSION[$captcha_key]) || $_SESSION[$captcha_key] != $captcha) {
echo json_encode(['ok' => false, 'error' => '验证码错误,请重新输入']);
exit;
}
unset($_SESSION[$captcha_key]);
}
unset($_SESSION[$captcha_key]);
try {
$name = trim($_POST['name']);