这是我的
[C#] 纯文本查看 复制代码 private static string access_token;
private static DateTime ataddtime = new DateTime(2015, 9, 29, 9, 0, 0);
private static string jsapi_ticket;
private static DateTime jtaddtime = new DateTime(2015, 9, 29, 9, 0, 0);
/// <summary>
/// 得到access_token
/// </summary>
/// <returns></returns>
public static string GetAccess_token() {
if (string.IsNullOrEmpty(access_token)) //如果token为空
{//获取token
access_token = xiaoxi.主功能.access_token.得到access_token(Tools.StaticValue.appid, Tools.StaticValue.AppSecret);
ataddtime = DateTime.Now;
}
else {
DateTime xian = DateTime.Now;
TimeSpan time = xian - ataddtime;
if (time.TotalSeconds > 7100) { //token是否快过期
//获取token
access_token = xiaoxi.主功能.access_token.得到access_token(Tools.StaticValue.appid, Tools.StaticValue.AppSecret);
ataddtime = DateTime.Now;
}
}
return access_token;
}
/// <summary>
/// 得到jsapi_ticket
/// </summary>
/// <returns></returns>
public static string GetJsapi_ticket() {
if (string.IsNullOrEmpty(jsapi_ticket)) //如果ticket为空
{//获取token
jsapi_ticket = xiaoxi.主功能.JSSDK.得到jsapi_ticket(GetAccess_token());
jtaddtime = DateTime.Now;
}
else
{
DateTime xian = DateTime.Now;
TimeSpan time = xian - jtaddtime;
if (time.TotalSeconds > 7100) //ticket是否快过期
{
//获取ticket
jsapi_ticket = xiaoxi.主功能.JSSDK.得到jsapi_ticket(GetAccess_token());
jtaddtime = DateTime.Now;
}
}
return jsapi_ticket;
}
} |