Browse Source

支持access_token过期

master
yashen 9 years ago
parent
commit
895316a791
1 changed files with 11 additions and 1 deletions
  1. +11
    -1
      B3WeChat/Utils/InOutMessageUtil.cs

+ 11
- 1
B3WeChat/Utils/InOutMessageUtil.cs View File

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


Loading…
Cancel
Save