因为access_token的寿命只有7200秒,每日获取access_token存在上限,所以在获取access_token后,需要将其缓存起来.
首先建立一个模型
1 public class AccessToken 2 3 { 4 public string access_token { get; set; } 5 6 public DateTime expires_in { get; set; } 7 8 }
然后存储获取的access_token(获取方法),和当前的时间
1 public static void Save() 2 { 3 var accessToken = new AccessToken(); 4 accessToken.access_token = a_token; 5 accessToken.expires_in = DateTime.Now; 6 //存储 7 System.Web.HttpContext.Current.Application["accessToken"] = accessToken; 8 //获取 9 //var accessToken = System.Web.HttpContext.Current.Application["accessToken"] as AccessToken; 10 }
时间: 2024-11-02 23:39:20