Browse Source

添加日志输出 appid

develop
胡超1 2 years ago
parent
commit
0ae9c1ca1e
  1. 31
      24Hour/WechatMessagerClient.cs

31
24Hour/WechatMessagerClient.cs

@ -31,10 +31,11 @@ namespace _24Hour
/// 小程序secretID /// 小程序secretID
/// </summary> /// </summary>
private string secid = "e752e4fba67526eca21313a18c96a58f"; private string secid = "e752e4fba67526eca21313a18c96a58f";
public WechatMessagerClient(HttpClient _httpCliet, IConfiguration configuration) private readonly ILogger<WechatMessagerClient> logger;
public WechatMessagerClient(HttpClient _httpCliet, IConfiguration configuration, ILogger<WechatMessagerClient> _logger)
{ {
this.httpCliet = _httpCliet; this.httpCliet = _httpCliet;
this.logger = _logger;
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;
@ -43,6 +44,10 @@ namespace _24Hour
appid = $"{configuration.GetSection("Wechat:appid").Value}"; appid = $"{configuration.GetSection("Wechat:appid").Value}";
secret = $"{configuration.GetSection("Wechat:secret").Value}"; secret = $"{configuration.GetSection("Wechat:secret").Value}";
secid = $"{configuration.GetSection("Wechat:secid").Value}"; secid = $"{configuration.GetSection("Wechat:secid").Value}";
logger.LogInformation($"appid {appid}");
logger.LogInformation($"secret {secret}");
logger.LogInformation($"secid {secid}");
} }
public async Task<Result> GetOpenId(string code) public async Task<Result> GetOpenId(string code)
{ {
@ -74,7 +79,7 @@ namespace _24Hour
/// 律师预约微信消息提醒,成功 /// 律师预约微信消息提醒,成功
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public bool wxts(string? useropenId, string? name, string? unit, DateTime? datetime, string? matter,string? attention) public bool wxts(string? useropenId, string? name, string? unit, DateTime? datetime, string? matter, string? attention)
{ {
try try
{ {
@ -104,23 +109,23 @@ namespace _24Hour
string posturl = $"{url}{token}";//发送地址 string posturl = $"{url}{token}";//发送地址
var thing4 = matter; var thing4 = matter;
var thing5 = attention; var thing5 = attention;
if (!string.IsNullOrEmpty(matter) && matter.Length>20) if (!string.IsNullOrEmpty(matter) && matter.Length > 20)
thing4 = matter.Substring(0, 17)+"..."; thing4 = matter.Substring(0, 17) + "...";
if (!string.IsNullOrEmpty(attention) && attention.Length > 20) if (!string.IsNullOrEmpty(attention) && attention.Length > 20)
thing5 = attention.Substring(0, 17) + "..."; thing5 = attention.Substring(0, 17) + "...";
msg = new msg = new
{ {
touser = useropenId, touser = useropenId,
template_id = "mRfzPnc_3JuV9cPhjKrRL3jX1C_JJoBGYtqEnbfadRM", template_id = "mRfzPnc_3JuV9cPhjKrRL3jX1C_JJoBGYtqEnbfadRM",
page= "pages/selfService/reception/reception", page = "pages/selfService/reception/reception",
miniprogram_state= $"{_configuration.GetSection("Wechat:miniprogram_state").Value}", miniprogram_state = $"{_configuration.GetSection("Wechat:miniprogram_state").Value}",
lang ="zh_CN", lang = "zh_CN",
data = new data = new
{ {
//name1 = new { value = $"{name}"},// //name1 = new { value = $"{name}"},//
thing2 = new { value = $"{unit}"},// thing2 = new { value = $"{unit}" },//
date3 = new { value = $"{datetime:yyyy年MM月dd日 HH:mm}"},// date3 = new { value = $"{datetime:yyyy年MM月dd日 HH:mm}" },//
thing4 = new { value = $"{thing4}"},// thing4 = new { value = $"{thing4}" },//
thing5 = new { value = $"{thing5}", color = "#173177" },// thing5 = new { value = $"{thing5}", color = "#173177" },//
}, },
}; };
@ -145,7 +150,7 @@ namespace _24Hour
/// 律师预约微信消息提醒,失败 /// 律师预约微信消息提醒,失败
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public bool sbwxts(string? useropenId,string? name,string? unit,DateTime? datetime,string? matter,string? reason) public bool sbwxts(string? useropenId, string? name, string? unit, DateTime? datetime, string? matter, string? reason)
{ {
try try
{ {
@ -174,7 +179,7 @@ namespace _24Hour
object msg = null; object msg = null;
string posturl = $"{url}{token}";//发送地址 string posturl = $"{url}{token}";//发送地址
var thing4 = matter; var thing4 = matter;
if (!string.IsNullOrEmpty(matter)&&matter.Length > 20) if (!string.IsNullOrEmpty(matter) && matter.Length > 20)
thing4 = matter.Substring(0, 17) + "..."; thing4 = matter.Substring(0, 17) + "...";
var thing5 = reason; var thing5 = reason;
if (!string.IsNullOrEmpty(reason) && reason.Length > 20) if (!string.IsNullOrEmpty(reason) && reason.Length > 20)

Loading…
Cancel
Save