diff --git a/B3WeChat/Utils/InOutMessageUtil.cs b/B3WeChat/Utils/InOutMessageUtil.cs index 7a364f3..c69d4f0 100644 --- a/B3WeChat/Utils/InOutMessageUtil.cs +++ b/B3WeChat/Utils/InOutMessageUtil.cs @@ -20,13 +20,23 @@ namespace BWP.B3WeChat.Utils static string token; + + static DateTime? getTokenTime; + + static readonly TimeSpan expiredSpan = new TimeSpan(2, 0, 0); static string TOKEN { get { + if (getTokenTime.HasValue && ((TimeSpan)(DateTime.Now - getTokenTime.Value)) >= expiredSpan) + { + token = string.Empty; + } + if (string.IsNullOrEmpty(token)) { token = GetToken(); + getTokenTime = DateTime.Now; } return token; } @@ -90,7 +100,7 @@ namespace BWP.B3WeChat.Utils SendTemplateMessageResult result = new SendTemplateMessageResult(); MeassageBody body = new MeassageBody(); body.touser = openID; - body.template_id = templateID; + body.template_id = templateID; body.url = url; body.data = dic; string postData = jsonHelper.Serialize(body);