public static string GetTokenValue() { string appid = System.Web.Configuration.WebConfigurationManager.AppSettings["appID"]; string appSecret = System.Web.Configuration.WebConfigurationManager.AppSettings["appsecret"]; _boxs = (_boxs == null ? new List <AccessTokenBox>() : _boxs.Where(b => b.Token.ExpirationTime > DateTime.Now).ToList()); var tempat = _boxs.FirstOrDefault(b => b.AppId == appid); if (tempat != null) { return(tempat.Token.access_token); } var newAT = BaseServices.GetAccessToken(appid, appSecret); if (!string.IsNullOrEmpty(newAT.access_token)) { _boxs.Add(new AccessTokenBox { AppId = appid, Token = newAT }); return(newAT.access_token); } else { //此处可以写日志,将错误信息保存。 return(""); } }
public static string GetTokenValue(string appid, string appSerect) { _boxs = (_boxs == null ? new List <AccessTokenBox>():_boxs.Where(b => b.Token.ExpirationTime > DateTime.Now).ToList()); var tempat = _boxs.FirstOrDefault(b => b.AppId == appid); if (tempat != null) { return(tempat.Token.access_token); } var newAT = BaseServices.GetAccessToken(appid, appSerect); if (!string.IsNullOrEmpty(newAT.access_token)) { _boxs.Add(new AccessTokenBox { AppId = appid, Token = newAT }); return(newAT.access_token); } else { // 此处可以写日志,保存错误信息 return(""); } }