public static void LoadToken() { string fileName = GetTokenFileName(); if (File.Exists(fileName)) { fCurrent = new CorpAccessTokenList(); fCurrent.ReadFromFile("Json", null, fileName, ReadSettings.Default, QName.Toolkit); } }
public static string GetToken(string secret) { TkDebug.AssertArgumentNullOrEmpty(secret, "secret", null); IRWLock rwLock = BaseGlobalVariable.Current.CreateRWLock(); CorpAccessToken token; using (rwLock) { if (fCurrent == null) { token = RWLock.WriteLockAction(rwLock, () => { CorpAccessToken result = CorpAccessToken.CreateToken(secret); fCurrent = new CorpAccessTokenList(); fCurrent.AddToken(result); SaveToken(); return(result); }); return(token.Token); } else { token = RWLock.ReadLockAction(rwLock, () => { CorpAccessToken result = fCurrent.CorpTokens[secret]; if (result == null || result.IsExpire) { result = RWLock.WriteLockAction(rwLock, () => { CorpAccessToken newToken = CorpAccessToken.CreateToken(secret); fCurrent.CorpTokens.AddOrReplace(newToken); SaveToken(); return(newToken); }); } return(result); }); return(token.Token); } } }
public static string GetToken(string secret) { TkDebug.AssertArgumentNullOrEmpty(secret, "secret", null); IRWLock rwLock = BaseGlobalVariable.Current.CreateRWLock(); CorpAccessToken token; using (rwLock) { if (fCurrent == null) { token = RWLock.WriteLockAction(rwLock, () => { CorpAccessToken result = CorpAccessToken.CreateToken(secret); fCurrent = new CorpAccessTokenList(); fCurrent.AddToken(result); SaveToken(); return result; }); return token.Token; } else { token = RWLock.ReadLockAction(rwLock, () => { CorpAccessToken result = fCurrent.CorpTokens[secret]; if (result == null || result.IsExpire) { result = RWLock.WriteLockAction(rwLock, () => { CorpAccessToken newToken = CorpAccessToken.CreateToken(secret); fCurrent.CorpTokens.AddOrReplace(newToken); SaveToken(); return newToken; }); } return result; }); return token.Token; } } }
public void AppStarting(object application, BaseAppSetting appsetting, BaseGlobalVariable globalVariable) { string path = Path.Combine(appsetting.XmlPath, "weixin.xml"); if (File.Exists(path)) { WeixinXml xml = new WeixinXml(); xml.ReadXmlFromFile(path); WeixinSettings.Current = new WeixinSettings(xml); if (WeixinSettings.Current.Mode == WeixinMode.Normal) { AccessToken.LoadToken(); JsAccessToken.LoadToken(); } else { CorpAccessTokenList.LoadToken(); } } }
public static string GetTokenWithSecret(string secret) { return(CorpAccessTokenList.GetToken(secret)); }