From 895316a7918e13783bc72ba2e9fe5557fb4a2786 Mon Sep 17 00:00:00 2001 From: yashen Date: Tue, 27 Sep 2016 17:45:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81access=5Ftoken=E8=BF=87?= =?UTF-8?q?=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- B3WeChat/Utils/InOutMessageUtil.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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);