mirror of
https://github.com/oshima-studios/OshimaGameModule.git
synced 2025-04-23 04:19:36 +08:00
整合 RainBot
This commit is contained in:
parent
1bdb4507c5
commit
e4520a1953
@ -19,7 +19,8 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
|||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
public class FunGameController(ILogger<FunGameController> logger) : ControllerBase
|
public class FunGameController(ILogger<FunGameController> logger) : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ILogger<FunGameController> _logger = logger;
|
private ILogger<FunGameController> Logger { get; set; } = logger;
|
||||||
|
|
||||||
private const int drawCardReduce = 2000;
|
private const int drawCardReduce = 2000;
|
||||||
private const int drawCardReduce_Material = 10;
|
private const int drawCardReduce_Material = 10;
|
||||||
private const string noSaved = "你还没有创建存档!请发送【创建存档】创建。";
|
private const string noSaved = "你还没有创建存档!请发送【创建存档】创建。";
|
||||||
|
@ -12,11 +12,12 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
|||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
public class QQBotController(IOptions<BotConfig> botConfig, ILogger<QQBotController> logger, QQBotService service) : ControllerBase
|
public class QQBotController(IOptions<BotConfig> botConfig, ILogger<QQBotController> logger, QQBotService service, RainBOTService fungameService) : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly BotConfig _botConfig = botConfig.Value;
|
private BotConfig BotConfig { get; set; } = botConfig.Value;
|
||||||
private readonly ILogger<QQBotController> _logger = logger;
|
private ILogger<QQBotController> Logger { get; set; } = logger;
|
||||||
private readonly QQBotService _service = service;
|
private QQBotService Service { get; set; } = service;
|
||||||
|
private RainBOTService FungameService { get; set; } = fungameService;
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> Post([FromBody] Payload? payload)
|
public async Task<IActionResult> Post([FromBody] Payload? payload)
|
||||||
@ -26,7 +27,7 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
|||||||
return BadRequest("Payload 格式无效");
|
return BadRequest("Payload 格式无效");
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogDebug("收到 Webhook 请求:{payload.Op}", payload.Op);
|
Logger.LogDebug("收到 Webhook 请求:{payload.Op}", payload.Op);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -41,13 +42,13 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogWarning("未处理操作码:{payload.Op}", payload.Op);
|
Logger.LogWarning("未处理操作码:{payload.Op}", payload.Op);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.LogError("Error: {e}", e);
|
Logger.LogError("Error: {e}", e);
|
||||||
return StatusCode(500, "服务器内部错误");
|
return StatusCode(500, "服务器内部错误");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,10 +58,10 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
|||||||
ValidationRequest? validationPayload = JsonSerializer.Deserialize<ValidationRequest>(payload.Data.ToString() ?? "");
|
ValidationRequest? validationPayload = JsonSerializer.Deserialize<ValidationRequest>(payload.Data.ToString() ?? "");
|
||||||
if (validationPayload is null)
|
if (validationPayload is null)
|
||||||
{
|
{
|
||||||
_logger.LogError("反序列化验证 Payload 失败");
|
Logger.LogError("反序列化验证 Payload 失败");
|
||||||
return BadRequest("无效的验证 Payload 格式");
|
return BadRequest("无效的验证 Payload 格式");
|
||||||
}
|
}
|
||||||
string seed = _botConfig.Secret;
|
string seed = BotConfig.Secret;
|
||||||
while (seed.Length < 32)
|
while (seed.Length < 32)
|
||||||
{
|
{
|
||||||
seed += seed;
|
seed += seed;
|
||||||
@ -88,13 +89,13 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
|||||||
Signature = signature
|
Signature = signature
|
||||||
};
|
};
|
||||||
string responseJson = JsonSerializer.Serialize(response);
|
string responseJson = JsonSerializer.Serialize(response);
|
||||||
_logger.LogDebug("验证相应:{responseJson}", responseJson);
|
Logger.LogDebug("验证相应:{responseJson}", responseJson);
|
||||||
return Ok(response);
|
return Ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IActionResult> HandleEventAsync(Payload payload)
|
private async Task<IActionResult> HandleEventAsync(Payload payload)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("处理事件:{EventType}, 数据:{Data}", payload.EventType, payload.Data);
|
Logger.LogDebug("处理事件:{EventType}, 数据:{Data}", payload.EventType, payload.Data);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -105,26 +106,27 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
|||||||
if (c2cMessage != null)
|
if (c2cMessage != null)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
_logger.LogInformation("收到来自用户 {c2cMessage.Author.UserOpenId} 的消息:{c2cMessage.Content}", c2cMessage.Author.UserOpenId, c2cMessage.Content);
|
Logger.LogInformation("收到来自用户 {c2cMessage.Author.UserOpenId} 的消息:{c2cMessage.Content}", c2cMessage.Author.UserOpenId, c2cMessage.Content);
|
||||||
// 上传图片
|
//// 上传图片
|
||||||
string url = $"{Request.Scheme}://{Request.Host}{Request.PathBase}/images/zi/dj1.png";
|
//string url = $"{Request.Scheme}://{Request.Host}{Request.PathBase}/images/zi/dj1.png";
|
||||||
var (fileUuid, fileInfo, ttl, error) = await _service.UploadC2CMediaAsync(c2cMessage.Author.UserOpenId, 1, url);
|
//var (fileUuid, fileInfo, ttl, error) = await _service.UploadC2CMediaAsync(c2cMessage.Author.UserOpenId, 1, url);
|
||||||
_logger.LogDebug("发送的图片地址:{url}", url);
|
//_logger.LogDebug("发送的图片地址:{url}", url);
|
||||||
if (string.IsNullOrEmpty(error))
|
//if (string.IsNullOrEmpty(error))
|
||||||
{
|
//{
|
||||||
// 回复消息
|
// // 回复消息
|
||||||
await _service.SendC2CMessageAsync(c2cMessage.Author.UserOpenId, $"你发送的消息是:{c2cMessage.Content}", msgId: c2cMessage.Id);
|
// await _service.SendC2CMessageAsync(c2cMessage.Author.UserOpenId, $"你发送的消息是:{c2cMessage.Content}", msgId: c2cMessage.Id);
|
||||||
// 回复富媒体消息
|
// // 回复富媒体消息
|
||||||
await _service.SendC2CMessageAsync(c2cMessage.Author.UserOpenId, "", msgType: 7, media: new { file_info = fileInfo }, msgId: c2cMessage.Id);
|
// await _service.SendC2CMessageAsync(c2cMessage.Author.UserOpenId, "", msgType: 7, media: new { file_info = fileInfo }, msgId: c2cMessage.Id);
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// _logger.LogError("上传图片失败:{error}", error);
|
||||||
|
//}
|
||||||
|
await FungameService.Handler(c2c: c2cMessage);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogError("上传图片失败:{error}", error);
|
Logger.LogError("反序列化 C2C 消息数据失败");
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.LogError("反序列化 C2C 消息数据失败");
|
|
||||||
return BadRequest("无效的 C2C 消息数据格式");
|
return BadRequest("无效的 C2C 消息数据格式");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -132,31 +134,33 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
|||||||
GroupAtMessage? groupAtMessage = JsonSerializer.Deserialize<GroupAtMessage>(payload.Data.ToString() ?? "");
|
GroupAtMessage? groupAtMessage = JsonSerializer.Deserialize<GroupAtMessage>(payload.Data.ToString() ?? "");
|
||||||
if (groupAtMessage != null)
|
if (groupAtMessage != null)
|
||||||
{
|
{
|
||||||
|
groupAtMessage.Detail = groupAtMessage.Detail.Trim();
|
||||||
// TODO
|
// TODO
|
||||||
_logger.LogInformation("收到来自群组 {groupAtMessage.GroupOpenId} 的消息:{groupAtMessage.Content}", groupAtMessage.GroupOpenId, groupAtMessage.Content);
|
Logger.LogInformation("收到来自群组 {groupAtMessage.GroupOpenId} 的消息:{groupAtMessage.Content}", groupAtMessage.GroupOpenId, groupAtMessage.Content);
|
||||||
// 回复消息
|
// 回复消息
|
||||||
await _service.SendGroupMessageAsync(groupAtMessage.GroupOpenId, $"你发送的消息是:{groupAtMessage.Content}", msgId: groupAtMessage.Id);
|
//await _service.SendGroupMessageAsync(groupAtMessage.GroupOpenId, $"你发送的消息是:{groupAtMessage.Content}", msgId: groupAtMessage.Id);
|
||||||
|
await FungameService.Handler(groupAt: groupAtMessage);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_logger.LogError("反序列化群聊消息数据失败");
|
Logger.LogError("反序列化群聊消息数据失败");
|
||||||
return BadRequest("无效的群聊消息数据格式");
|
return BadRequest("无效的群聊消息数据格式");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
_logger.LogWarning("未定义事件:{EventType}", payload.EventType);
|
Logger.LogWarning("未定义事件:{EventType}", payload.EventType);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
catch (JsonException e)
|
catch (JsonException e)
|
||||||
{
|
{
|
||||||
_logger.LogError("反序列化过程遇到错误:{e}", e);
|
Logger.LogError("反序列化过程遇到错误:{e}", e);
|
||||||
return BadRequest("Invalid JSON format");
|
return BadRequest("Invalid JSON format");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.LogError("Error: {e}", e);
|
Logger.LogError("Error: {e}", e);
|
||||||
return StatusCode(500, "服务器内部错误");
|
return StatusCode(500, "服务器内部错误");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,17 @@ namespace Oshima.FunGame.WebAPI.Models
|
|||||||
public string Url { get; set; } = "";
|
public string Url { get; set; } = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public class C2CMessage
|
public interface IBotMessage
|
||||||
|
{
|
||||||
|
public string Id { get; }
|
||||||
|
public bool IsGroup { get; }
|
||||||
|
public string Detail { get; set; }
|
||||||
|
public string Timestamp { get; }
|
||||||
|
public string OpenId { get; }
|
||||||
|
public string AuthorOpenId { get; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class C2CMessage : IBotMessage
|
||||||
{
|
{
|
||||||
[JsonPropertyName("id")]
|
[JsonPropertyName("id")]
|
||||||
public string Id { get; set; } = "";
|
public string Id { get; set; } = "";
|
||||||
@ -90,9 +100,18 @@ namespace Oshima.FunGame.WebAPI.Models
|
|||||||
|
|
||||||
[JsonPropertyName("attachments")]
|
[JsonPropertyName("attachments")]
|
||||||
public Attachment[] Attachments { get; set; } = [];
|
public Attachment[] Attachments { get; set; } = [];
|
||||||
|
|
||||||
|
public string Detail
|
||||||
|
{
|
||||||
|
get => Content;
|
||||||
|
set => Content = value;
|
||||||
|
}
|
||||||
|
public string OpenId => Author.UserOpenId;
|
||||||
|
public bool IsGroup => false;
|
||||||
|
public string AuthorOpenId => Author.UserOpenId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GroupAtMessage
|
public class GroupAtMessage : IBotMessage
|
||||||
{
|
{
|
||||||
[JsonPropertyName("id")]
|
[JsonPropertyName("id")]
|
||||||
public string Id { get; set; } = "";
|
public string Id { get; set; } = "";
|
||||||
@ -111,6 +130,15 @@ namespace Oshima.FunGame.WebAPI.Models
|
|||||||
|
|
||||||
[JsonPropertyName("attachments")]
|
[JsonPropertyName("attachments")]
|
||||||
public Attachment[] Attachments { get; set; } = [];
|
public Attachment[] Attachments { get; set; } = [];
|
||||||
|
|
||||||
|
public string Detail
|
||||||
|
{
|
||||||
|
get => Content;
|
||||||
|
set => Content = value;
|
||||||
|
}
|
||||||
|
public string OpenId => GroupOpenId;
|
||||||
|
public bool IsGroup => true;
|
||||||
|
public string AuthorOpenId => Author.MemberOpenId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MediaResponse
|
public class MediaResponse
|
||||||
|
@ -6,6 +6,7 @@ using Oshima.Core.Configs;
|
|||||||
using Oshima.Core.Constant;
|
using Oshima.Core.Constant;
|
||||||
using Oshima.FunGame.OshimaServers.Service;
|
using Oshima.FunGame.OshimaServers.Service;
|
||||||
using Oshima.FunGame.WebAPI.Constant;
|
using Oshima.FunGame.WebAPI.Constant;
|
||||||
|
using Oshima.FunGame.WebAPI.Controllers;
|
||||||
using Oshima.FunGame.WebAPI.Models;
|
using Oshima.FunGame.WebAPI.Models;
|
||||||
using Oshima.FunGame.WebAPI.Services;
|
using Oshima.FunGame.WebAPI.Services;
|
||||||
|
|
||||||
@ -44,6 +45,9 @@ namespace Oshima.FunGame.WebAPI
|
|||||||
{
|
{
|
||||||
builder.Services.AddMemoryCache();
|
builder.Services.AddMemoryCache();
|
||||||
builder.Services.AddScoped<QQBotService>();
|
builder.Services.AddScoped<QQBotService>();
|
||||||
|
builder.Services.AddScoped<RainBOTService>();
|
||||||
|
builder.Services.AddScoped<FunGameController>();
|
||||||
|
builder.Services.AddScoped<QQController>();
|
||||||
// 使用 Configure<BotConfig> 从配置源绑定
|
// 使用 Configure<BotConfig> 从配置源绑定
|
||||||
builder.Services.Configure<BotConfig>(builder.Configuration.GetSection("Bot"));
|
builder.Services.Configure<BotConfig>(builder.Configuration.GetSection("Bot"));
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,11 @@ namespace Oshima.FunGame.WebAPI.Services
|
|||||||
{
|
{
|
||||||
public class QQBotService(IOptions<BotConfig> botConfig, ILogger<QQBotService> logger, IHttpClientFactory httpClientFactory, IMemoryCache memoryCache)
|
public class QQBotService(IOptions<BotConfig> botConfig, ILogger<QQBotService> logger, IHttpClientFactory httpClientFactory, IMemoryCache memoryCache)
|
||||||
{
|
{
|
||||||
private readonly BotConfig _botConfig = botConfig.Value;
|
private BotConfig BotConfig { get; set; } = botConfig.Value;
|
||||||
private readonly ILogger<QQBotService> _logger = logger;
|
private ILogger<QQBotService> Logger { get; set; } = logger;
|
||||||
private readonly HttpClient _httpClient = httpClientFactory.CreateClient();
|
private HttpClient HttpClient { get; set; } = httpClientFactory.CreateClient();
|
||||||
private readonly IMemoryCache _memoryCache = memoryCache;
|
private IMemoryCache MemoryCache { get; set; } = memoryCache;
|
||||||
|
|
||||||
private const string AccessTokenCacheKey = "QQBotAccessToken";
|
private const string AccessTokenCacheKey = "QQBotAccessToken";
|
||||||
|
|
||||||
public async Task SendC2CMessageAsync(string openid, string content, int msgType = 0, object? media = null, string? msgId = null, int? msgSeq = null)
|
public async Task SendC2CMessageAsync(string openid, string content, int msgType = 0, object? media = null, string? msgId = null, int? msgSeq = null)
|
||||||
@ -30,7 +31,7 @@ namespace Oshima.FunGame.WebAPI.Services
|
|||||||
string accessToken = await GetAccessTokenAsync();
|
string accessToken = await GetAccessTokenAsync();
|
||||||
HttpRequestMessage request = new(HttpMethod.Post, $"https://api.sgroup.qq.com{url}");
|
HttpRequestMessage request = new(HttpMethod.Post, $"https://api.sgroup.qq.com{url}");
|
||||||
request.Headers.Authorization = new AuthenticationHeaderValue("QQBot", accessToken);
|
request.Headers.Authorization = new AuthenticationHeaderValue("QQBot", accessToken);
|
||||||
_logger.LogDebug("使用的 Access Token:{accessToken}", accessToken);
|
Logger.LogDebug("使用的 Access Token:{accessToken}", accessToken);
|
||||||
Dictionary<string, object> requestBody = new()
|
Dictionary<string, object> requestBody = new()
|
||||||
{
|
{
|
||||||
{ "content", content },
|
{ "content", content },
|
||||||
@ -50,11 +51,11 @@ namespace Oshima.FunGame.WebAPI.Services
|
|||||||
}
|
}
|
||||||
request.Content = new StringContent(JsonSerializer.Serialize(requestBody), System.Text.Encoding.UTF8, "application/json");
|
request.Content = new StringContent(JsonSerializer.Serialize(requestBody), System.Text.Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
HttpResponseMessage response = await _httpClient.SendAsync(request);
|
HttpResponseMessage response = await HttpClient.SendAsync(request);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
string errorBody = await response.Content.ReadAsStringAsync();
|
string errorBody = await response.Content.ReadAsStringAsync();
|
||||||
_logger.LogError("状态码:{response.StatusCode},错误信息:{errorBody}", response.StatusCode, errorBody);
|
Logger.LogError("状态码:{response.StatusCode},错误信息:{errorBody}", response.StatusCode, errorBody);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ namespace Oshima.FunGame.WebAPI.Services
|
|||||||
string accessToken = await GetAccessTokenAsync();
|
string accessToken = await GetAccessTokenAsync();
|
||||||
HttpRequestMessage request = new(HttpMethod.Post, $"https://api.sgroup.qq.com{url}");
|
HttpRequestMessage request = new(HttpMethod.Post, $"https://api.sgroup.qq.com{url}");
|
||||||
request.Headers.Authorization = new AuthenticationHeaderValue("QQBot", accessToken);
|
request.Headers.Authorization = new AuthenticationHeaderValue("QQBot", accessToken);
|
||||||
_logger.LogDebug("使用的 Access Token:{accessToken}", accessToken);
|
Logger.LogDebug("使用的 Access Token:{accessToken}", accessToken);
|
||||||
Dictionary<string, object> requestBody = new()
|
Dictionary<string, object> requestBody = new()
|
||||||
{
|
{
|
||||||
{ "file_type", fileType },
|
{ "file_type", fileType },
|
||||||
@ -82,7 +83,7 @@ namespace Oshima.FunGame.WebAPI.Services
|
|||||||
};
|
};
|
||||||
request.Content = new StringContent(JsonSerializer.Serialize(requestBody), System.Text.Encoding.UTF8, "application/json");
|
request.Content = new StringContent(JsonSerializer.Serialize(requestBody), System.Text.Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
HttpResponseMessage response = await _httpClient.SendAsync(request);
|
HttpResponseMessage response = await HttpClient.SendAsync(request);
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
string errorBody = await response.Content.ReadAsStringAsync();
|
string errorBody = await response.Content.ReadAsStringAsync();
|
||||||
@ -94,13 +95,13 @@ namespace Oshima.FunGame.WebAPI.Services
|
|||||||
{
|
{
|
||||||
return (null, null, 0, "反序列化富媒体消息失败。");
|
return (null, null, 0, "反序列化富媒体消息失败。");
|
||||||
}
|
}
|
||||||
_logger.LogDebug("接收到的富媒体消息:{mediaResponse.FileInfo},有效时间:{mediaResponse.Ttl}", mediaResponse.FileInfo, mediaResponse.Ttl);
|
Logger.LogDebug("接收到的富媒体消息:{mediaResponse.FileInfo},有效时间:{mediaResponse.Ttl}", mediaResponse.FileInfo, mediaResponse.Ttl);
|
||||||
return (mediaResponse.FileUuid, mediaResponse.FileInfo, mediaResponse.Ttl, null);
|
return (mediaResponse.FileUuid, mediaResponse.FileInfo, mediaResponse.Ttl, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GetAccessTokenAsync()
|
public async Task<string> GetAccessTokenAsync()
|
||||||
{
|
{
|
||||||
if (_memoryCache.TryGetValue(AccessTokenCacheKey, out string? accessToken) && !string.IsNullOrEmpty(accessToken))
|
if (MemoryCache.TryGetValue(AccessTokenCacheKey, out string? accessToken) && !string.IsNullOrEmpty(accessToken))
|
||||||
{
|
{
|
||||||
return accessToken;
|
return accessToken;
|
||||||
}
|
}
|
||||||
@ -112,9 +113,9 @@ namespace Oshima.FunGame.WebAPI.Services
|
|||||||
{
|
{
|
||||||
HttpRequestMessage request = new(HttpMethod.Post, "https://bots.qq.com/app/getAppAccessToken")
|
HttpRequestMessage request = new(HttpMethod.Post, "https://bots.qq.com/app/getAppAccessToken")
|
||||||
{
|
{
|
||||||
Content = new StringContent(JsonSerializer.Serialize(new { appId = _botConfig.AppId, clientSecret = _botConfig.Secret }), System.Text.Encoding.UTF8, "application/json")
|
Content = new StringContent(JsonSerializer.Serialize(new { appId = BotConfig.AppId, clientSecret = BotConfig.Secret }), System.Text.Encoding.UTF8, "application/json")
|
||||||
};
|
};
|
||||||
HttpResponseMessage response = await _httpClient.SendAsync(request);
|
HttpResponseMessage response = await HttpClient.SendAsync(request);
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
string responseBody = await response.Content.ReadAsStringAsync();
|
string responseBody = await response.Content.ReadAsStringAsync();
|
||||||
AccessTokenResponse? tokenResponse = JsonSerializer.Deserialize<AccessTokenResponse>(responseBody);
|
AccessTokenResponse? tokenResponse = JsonSerializer.Deserialize<AccessTokenResponse>(responseBody);
|
||||||
@ -122,8 +123,8 @@ namespace Oshima.FunGame.WebAPI.Services
|
|||||||
{
|
{
|
||||||
throw new Exception("获取 Access Token 失败!");
|
throw new Exception("获取 Access Token 失败!");
|
||||||
}
|
}
|
||||||
_memoryCache.Set(AccessTokenCacheKey, tokenResponse.AccessToken, TimeSpan.FromSeconds(expiresIn - 60));
|
MemoryCache.Set(AccessTokenCacheKey, tokenResponse.AccessToken, TimeSpan.FromSeconds(expiresIn - 60));
|
||||||
_logger.LogDebug("获取到 Access Token:{tokenResponse.AccessToken}", tokenResponse.AccessToken);
|
Logger.LogDebug("获取到 Access Token:{tokenResponse.AccessToken}", tokenResponse.AccessToken);
|
||||||
return tokenResponse.AccessToken;
|
return tokenResponse.AccessToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
1817
OshimaWebAPI/Services/RainBOTService.cs
Normal file
1817
OshimaWebAPI/Services/RainBOTService.cs
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user