AssetManager.API/AssetManager.Services/Services/WechatService.cs
OpenClaw Agent 1977dd609d fix: 请求收益曲线时自动回填历史数据
- GetNavHistoryAsync现在会自动检查是否有历史数据
- 无历史数据时自动调用BackfillNavHistoryInternalAsync
- 拆分内部回填方法,避免重复验证权限
2026-03-13 16:21:31 +00:00

41 lines
1.3 KiB
C#
Executable File

using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
namespace AssetManager.Services.Services;
public class WechatService
{
private readonly HttpClient _httpClient;
private readonly string _appId;
private readonly string _appSecret;
public WechatService(HttpClient httpClient)
{
_httpClient = httpClient;
// 完全从环境变量读取
_appId = Environment.GetEnvironmentVariable("Wechat__AppId")
?? "wx245f0f3ebcfcf5a7";
_appSecret = Environment.GetEnvironmentVariable("Wechat__AppSecret")
?? "809c740129bc8b434177ce12ef292dd0";
}
public async Task<WechatAuthResult> GetOpenIdAsync(string code)
{
var url = $"https://api.weixin.qq.com/sns/jscode2session?appid={_appId}&secret={_appSecret}&js_code={code}&grant_type=authorization_code";
var response = await _httpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<WechatAuthResult>(content) ?? new WechatAuthResult();
}
}
public class WechatAuthResult
{
public string? OpenId { get; set; }
public string? SessionKey { get; set; }
public string? UnionId { get; set; }
public int Errcode { get; set; }
public string? Errmsg { get; set; }
}