取名小程序

This commit is contained in:
cjd
2025-11-06 19:23:42 +08:00
parent 68ae25fac2
commit 823dc8d37b
8 changed files with 490 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Globalization;
using System.Threading.Tasks;
using DouyinApi.Controllers;
@@ -16,11 +16,16 @@ namespace DouyinApi.Api.Controllers.MiniProgram
public class NamingController : BaseApiController
{
private readonly INamingService _namingService;
private readonly IContentSecurityService _contentSecurityService;
private readonly ILogger<NamingController> _logger;
public NamingController(INamingService namingService, ILogger<NamingController> logger)
public NamingController(
INamingService namingService,
IContentSecurityService contentSecurityService,
ILogger<NamingController> logger)
{
_namingService = namingService;
_contentSecurityService = contentSecurityService;
_logger = logger;
}
@@ -33,6 +38,12 @@ namespace DouyinApi.Api.Controllers.MiniProgram
}
var surname = request.Surname?.Trim() ?? string.Empty;
var security = await _contentSecurityService.CheckTextAsync(surname);
if (!security.IsSafe)
{
return Ok(new { isValid = false, message = "输入内容存在风险,请重新输入" });
}
var isValid = await _namingService.ValidateSurnameAsync(surname);
return Ok(new
{
@@ -46,13 +57,28 @@ namespace DouyinApi.Api.Controllers.MiniProgram
{
if (!ModelState.IsValid)
{
return BadRequest(new { message = "参数不合" });
return BadRequest(new { message = "参数不合" });
}
var normalizedRequest = NormalizeRequest(request);
try
{
var payload = string.Join(" ", new[]
{
normalizedRequest.Surname,
normalizedRequest.Gender,
normalizedRequest.BirthDate,
normalizedRequest.BirthTime,
normalizedRequest.NameLength
}).Trim();
var security = await _contentSecurityService.CheckTextAsync(payload);
if (!security.IsSafe)
{
return BadRequest(new { message = "CONTENT_RISK" });
}
var response = await _namingService.GenerateNamesAsync(normalizedRequest);
return Ok(new
{

View File

@@ -256,16 +256,16 @@
"Enabled": true
},
"SignalRSendLog": {
"Enabled": true
"Enabled": false
},
"QuartzNetJob": {
"Enabled": true
"Enabled": false
},
"Consul": {
"Enabled": false
},
"IpRateLimit": {
"Enabled": true
"Enabled": false
},
"EncryptionResponse": {
"Enabled": true,
@@ -362,10 +362,21 @@
},
"DeepSeek": {
"BaseUrl": "https://api.deepseek.com/v1",
"ApiKey": "",
"ApiKey": "sk-97a34dbac42b43b0a8cedc79082df0c6",
"Model": "deepseek-chat",
"TimeoutSeconds": 15,
"TimeoutSeconds": 60,
"Temperature": 0.6,
"MaxTokens": 800
"MaxTokens": 800,
"ResponseFormat": "json_object"
},
"ContentSecurity": {
"Enable": true,
"ClientKey": "tta82ade973724953d01",
"ClientSecret": "4ea9a6eff22158770818b8aa3a77e2b042d1016d",
"AppId": "tta82ade973724953d01",
"TokenUrl": "https://developer.toutiao.com/api/apps/v2/token",
"TextCheckUrl": "https://developer.toutiao.com/api/v2/tags/text/antidirt",
"TokenCacheSeconds": 5400,
"DefaultScene": "naming_input"
}
}