/// <summary> /// 立即更新AccessToken /// </summary> public static string GetToken() { AccessTokenResult r = CommonApi.GetToken(AppId, AppSecret, "client_credential"); string _username = CommonHelp.GetUserNameByszhlcode(); string strIp = CommonHelp.getIP(HttpContext.Current); string accesstoken = r.access_token; if (accesstoken.Trim().Length > 0) { CommonHelp.UpdateAppConfig("AccessToken", accesstoken); new JH_Auth_LogB().InsertLog("WXFWHelper", "立即更新AccessToken为" + accesstoken, "WXFWHelper", _username, _username, 0, strIp); Updatejsapiticket(accesstoken, _username, strIp); } return(accesstoken); }
/// <summary> /// 异步更新AccessToken /// </summary> /// <param name="getNewToken"></param> public static string GetTokenAsync(bool getNewToken = false) { //AccessTokenResult r = CommonApi.GetToken(Qyinfo.corpId, Qyinfo.corpSecret, "client_credential"); string strIp = CommonHelp.getIP(HttpContext.Current); string _username = CommonHelp.GetUserNameByszhlcode(); var task1 = new Task <string>(() => AccessTokenContainer.TryGetAccessTokenAsync(AppId, AppSecret, getNewToken).Result ); task1.Start(); string accesstoken = task1.Result; if (accesstoken.Trim().Length > 0) { CommonHelp.UpdateAppConfig("AccessToken", accesstoken); new JH_Auth_LogB().InsertLog("WXFWHelper", "更新AccessToken为" + accesstoken, "WXFWHelper", _username, _username, 0, strIp); Updatejsapiticket(accesstoken, _username, strIp); } return(accesstoken); }