新增qq消息链

This commit is contained in:
杨毅 2024-11-16 21:30:23 +08:00
parent d8def7dd67
commit 3d4e0b261f
3 changed files with 97 additions and 0 deletions

29
NewFile.cs Normal file
View File

@ -0,0 +1,29 @@
using System.Net.Http;
using System.Threading.Tasks;
public class CaptchaService
{
private readonly HttpClient _httpClient;
public CaptchaService(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<bool> ValidateCaptcha(string token, string ip)
{
var requestData = new
{
id = "67134feddc0ff12924d9aaf4",
secretkey = "c3e08b07b8034e6b961f010abed5586a",
scene = 3,
token = token,
ip = ip
};
var response = await _httpClient.PostAsJsonAsync("your-captcha-endpoint", requestData);
var result = await response.Content.ReadAsAsync<dynamic>();
return result.success == 1;
}
}

View File

@ -30,6 +30,7 @@ using Flandre.Core.Messaging;
using Mirai.Net.Data.Messages.Concretes; using Mirai.Net.Data.Messages.Concretes;
using Flandre.Core.Messaging.Segments; using Flandre.Core.Messaging.Segments;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Net;
namespace asg_form.Controllers namespace asg_form.Controllers
{ {
@ -130,10 +131,17 @@ namespace asg_form.Controllers
} }
public class qqmsg
{
public string type { get; set;}
public string content { get; set; }
}
[Route("api/v1/admin/post_qqbotmsg")] [Route("api/v1/admin/post_qqbotmsg")]
[HttpPost] [HttpPost]
[Authorize] [Authorize]
public async Task<ActionResult<object>> post_qqbotmsg([FromBody] string msg,string qqgrope,string atuserqq) public async Task<ActionResult<object>> post_qqbotmsg([FromBody] string msg,string qqgrope,string atuserqq)
{ {
@ -157,6 +165,65 @@ namespace asg_form.Controllers
[Route("api/v2/admin/post_qqbotmsg")]
[HttpPost]
[Authorize]
public async Task<ActionResult<object>> post_qqbotmsgv2([FromBody] List<qqmsg> qqmsgs, string qqgrope)
{
if (!this.User.FindAll(ClaimTypes.Role).Any(a => a.Value == "admin"))
{
return BadRequest(new error_mb { code = 400, message = "无权访问" });
}
var message = new MessageBuilder();
foreach (var item in qqmsgs)
{
switch (item.type)
{
case "text":
message.Text(item.content);
break;
case "image":
message.Image(GetImageByte(item.content));
break;
case "at":
message.Add(new AtSegment(item.content));
break;
default:
message.Text("不支持的消息类型");
break;
}
}
await runbot.runbotr.SendMessageAsync(MessageEnvironment.Channel, qqgrope, null, message, qqgrope);
return Ok("成功!");
}
//把url图片转换为byte数组
public static byte[] GetImageByte(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
BinaryReader reader = new BinaryReader(stream);
byte[] bytes = reader.ReadBytes(int.MaxValue);
return bytes;
}
[Route("api/v1/admin/allschedle_c")] [Route("api/v1/admin/allschedle_c")]
[HttpGet] [HttpGet]

View File

@ -775,6 +775,7 @@ namespace asg_form.Controllers
DateTime expires = DateTime.Now.AddSeconds(options.ExpireSeconds); DateTime expires = DateTime.Now.AddSeconds(options.ExpireSeconds);
byte[] keyBytes = Encoding.UTF8.GetBytes(options.SigningKey); byte[] keyBytes = Encoding.UTF8.GetBytes(options.SigningKey);
var secKey = new SymmetricSecurityKey(keyBytes); var secKey = new SymmetricSecurityKey(keyBytes);
var credentials = new SigningCredentials(secKey, var credentials = new SigningCredentials(secKey,
SecurityAlgorithms.HmacSha256Signature); SecurityAlgorithms.HmacSha256Signature);
var tokenDescriptor = new JwtSecurityToken(expires: expires, var tokenDescriptor = new JwtSecurityToken(expires: expires,