Browse Source

统一在构造函数中解密小程序配置信息

develop-FileUpload-test
胡超1 2 years ago
parent
commit
bd3991a5d3
  1. 35
      24Hour/WechatMessagerClient.cs

35
24Hour/WechatMessagerClient.cs

@ -21,31 +21,34 @@ namespace _24Hour
private readonly HttpClient httpCliet; private readonly HttpClient httpCliet;
// 实例化MemoryCache对象 // 实例化MemoryCache对象
MemoryCache cache = MemoryCache.Default; MemoryCache cache = MemoryCache.Default;
private readonly IConfiguration _configuration;
/// <summary> /// <summary>
/// 小程序AppID /// 小程序AppID
/// </summary> /// </summary>
private string appid = "wx48108a0c98a3dab0"; private string appid;
/// <summary> /// <summary>
/// 小程序AppID /// 小程序AppID
/// </summary> /// </summary>
private string secret = "wx48108a0c98a3dab0"; private string secret;
/// <summary> /// <summary>
/// 微信公众号AppID /// 微信公众号AppID
/// </summary> /// </summary>
private string Gzhappid = "wx48108a0c98a3dab0"; private string Gzhappid;
/// <summary> /// <summary>
/// 微信公众号密码 /// 微信公众号密码
/// </summary> /// </summary>
private string Gzhsecret = "wx48108a0c98a3dab0"; private string Gzhsecret;
/// <summary> /// <summary>
/// 微信公众号模板Id /// 微信公众号模板Id
/// </summary> /// </summary>
private string GzhtemplateId = "wx48108a0c98a3dab0"; private string GzhtemplateId;
/// <summary> /// <summary>
/// 小程序secretID /// 小程序secretID
/// </summary> /// </summary>
private string secid = "e752e4fba67526eca21313a18c96a58f"; private string secid;
private string miniprogram_state;
private string GzhTemplateId1;
private string GzhTemplateId2;
private string TemplateIdSuccess { get; set; } = ""; private string TemplateIdSuccess { get; set; } = "";
private string TemplateIdFail { get; set; } = ""; private string TemplateIdFail { get; set; } = "";
private readonly ILogger<WechatMessagerClient> logger; private readonly ILogger<WechatMessagerClient> logger;
@ -56,7 +59,7 @@ namespace _24Hour
httpCliet.DefaultRequestHeaders.Add("Accept", "application/json"); httpCliet.DefaultRequestHeaders.Add("Accept", "application/json");
httpCliet.DefaultRequestHeaders.Add("User-Agent", "HttpClientFactory-Sample"); httpCliet.DefaultRequestHeaders.Add("User-Agent", "HttpClientFactory-Sample");
httpCliet.DefaultRequestHeaders.ConnectionClose = true; httpCliet.DefaultRequestHeaders.ConnectionClose = true;
_configuration = configuration;
appid =AES.Decrypt( $"{configuration.GetSection("Wechat:appid").Value}"); appid =AES.Decrypt( $"{configuration.GetSection("Wechat:appid").Value}");
secret = AES.Decrypt($"{configuration.GetSection("Wechat:secret").Value}"); secret = AES.Decrypt($"{configuration.GetSection("Wechat:secret").Value}");
@ -66,6 +69,9 @@ namespace _24Hour
GzhtemplateId = AES.Decrypt($"{configuration.GetSection("WechatGzh:templateId").Value}"); GzhtemplateId = AES.Decrypt($"{configuration.GetSection("WechatGzh:templateId").Value}");
TemplateIdSuccess = AES.Decrypt($"{configuration.GetSection("Wechat:templateIdSuccess").Value}"); TemplateIdSuccess = AES.Decrypt($"{configuration.GetSection("Wechat:templateIdSuccess").Value}");
TemplateIdFail = AES.Decrypt($"{configuration.GetSection("Wechat:templateIdFail").Value}"); TemplateIdFail = AES.Decrypt($"{configuration.GetSection("Wechat:templateIdFail").Value}");
GzhTemplateId1 = AES.Decrypt($"{configuration.GetSection("WechatGzh:templateId1").Value}");
GzhTemplateId2 = AES.Decrypt($"{configuration.GetSection("WechatGzh:templateId2").Value}");
miniprogram_state = $"{configuration.GetSection("Wechat:miniprogram_state").Value}";
} }
//小程序获取openId //小程序获取openId
public async Task<Result> GetOpenId(string code) public async Task<Result> GetOpenId(string code)
@ -166,9 +172,9 @@ namespace _24Hour
{ {
touser = useropenId, touser = useropenId,
//兼容北关区模板id,那边的配置文件没有模板id的字段 //兼容北关区模板id,那边的配置文件没有模板id的字段
template_id = string.IsNullOrEmpty(TemplateIdSuccess) ? "XgrMTq1gwDfMJI6vN0jsSEv3xGy7v3amh0JMWj4SnAY" : TemplateIdSuccess, template_id = TemplateIdSuccess,
page = "pages/selfService/reception/reception", page = "pages/selfService/reception/reception",
miniprogram_state = $"{_configuration.GetSection("Wechat:miniprogram_state").Value}", miniprogram_state = miniprogram_state,
lang = "zh_CN", lang = "zh_CN",
data = new data = new
{ {
@ -239,10 +245,9 @@ namespace _24Hour
msg = new msg = new
{ {
touser = useropenId, touser = useropenId,
//兼容北关区模板id,那边的配置文件没有模板id的字段 template_id = TemplateIdFail,
template_id = string.IsNullOrEmpty(TemplateIdFail) ? "bfA-t5EN4pkQzAOS17SRPRKvmMteaJt0kw3YKIcovIQ" : TemplateIdFail,
page = "pages/selfService/reception/reception", page = "pages/selfService/reception/reception",
miniprogram_state = $"{_configuration.GetSection("Wechat:miniprogram_state").Value}", miniprogram_state = miniprogram_state,
lang = "zh_CN", lang = "zh_CN",
data = new data = new
{ {
@ -389,7 +394,7 @@ namespace _24Hour
msg = new msg = new
{ {
touser = useropenId, touser = useropenId,
template_id = $"{_configuration.GetSection("WechatGzh:templateId1").Value}", template_id = GzhTemplateId1,
//miniprogram =new{ //miniprogram =new{
// appid= appid, // appid= appid,
// pagepath= "pages/selfService/reception/reception" // pagepath= "pages/selfService/reception/reception"
@ -467,7 +472,7 @@ namespace _24Hour
msg = new msg = new
{ {
touser = useropenId, touser = useropenId,
template_id = $"{_configuration.GetSection("WechatGzh:templateId2").Value}", template_id = GzhTemplateId2,
//miniprogram =new{ //miniprogram =new{
// appid= appid, // appid= appid,
// pagepath= "pages/selfService/reception/reception" // pagepath= "pages/selfService/reception/reception"

Loading…
Cancel
Save