feat:第一次提交
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
namespace NapCatRobotClient.Core.RobotAPI.Dto.Request
|
||||
{
|
||||
public class GroupSendMessageRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 群号码
|
||||
/// </summary>
|
||||
[JsonProperty("group_id")]
|
||||
public string GroupId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
[JsonProperty("message")]
|
||||
public List<MessageItem> Message { get; set; }
|
||||
}
|
||||
|
||||
public class MessageItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 消息类型 每一种消息一个item (text:文本 at:艾特 reply:引用)
|
||||
/// </summary>
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据
|
||||
/// </summary>
|
||||
[JsonProperty("data")]
|
||||
public MessageData Data { get; set; }
|
||||
}
|
||||
|
||||
public class MessageData
|
||||
{
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
[JsonProperty("text", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string Text { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 如果是艾特,这里填写QQ
|
||||
/// </summary>
|
||||
[JsonProperty("qq", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string QQ { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 如果是引用,这里填写引用的消息ID
|
||||
/// </summary>
|
||||
[JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Flurl.Http;
|
||||
using NapCatRobotClient.Core.RobotAPI.Dto.Request;
|
||||
|
||||
namespace NapCatRobotClient.Core.RobotAPI
|
||||
{
|
||||
public class RobotAPI
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送群文本消息
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<string> SendGroupText(GroupSendMessageRequest request)
|
||||
{
|
||||
return await Post(JsonConvert.SerializeObject(request), "/send_group_msg");
|
||||
}
|
||||
|
||||
private static async Task<string> Post(string parameters, string action)
|
||||
{
|
||||
string url = App.Configuration["QQConfig:SendApiUrl"] + action;
|
||||
string response = await url.WithHeader("Authorization", "Bearer " + App.Configuration["QQConfig:AccessToken"])
|
||||
.WithHeader("Content-Type", "application/json;charset=utf-8")
|
||||
.PostStringAsync(parameters)
|
||||
.ReceiveString();
|
||||
Console.WriteLine($"{DateTime.Now} 请求地址:{url} 请求结果:{response}");
|
||||
return response;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user