private string GetAccessToken(string appid, string appSecret) { AccessTokenResult tokenResult = new AccessTokenResult(); Senparc.Weixin.MP.CommonAPIs.AccessTokenHandlerWapper.Do(appid, appSecret, GetAPIInterface); Senparc.Weixin.MP.CommonAPIs.AccessTokenContainer container = new Senparc.Weixin.MP.CommonAPIs.AccessTokenContainer(); return tokenResult.access_token; Senparc.Weixin.MP.AdvancedAPIs.OAuthUserInfo userinfo = new Senparc.Weixin.MP.AdvancedAPIs.OAuthUserInfo(); Senparc.Weixin.MP.AdvancedAPIs.OpenIdResultJson openID = new Senparc.Weixin.MP.AdvancedAPIs.OpenIdResultJson(); Senparc.Weixin.MP.AdvancedAPIs.OpenIdResultJson_Data openidData = new Senparc.Weixin.MP.AdvancedAPIs.OpenIdResultJson_Data(); }
protected AccessTokenResult LoadToken() { if (tokenResult == null || string.IsNullOrEmpty(tokenResult.access_token)) { //正确数据,请填写微信公众账号后台的AppId及AppSecret tokenResult = CommonApi.GetToken(AppId, AppSecret); } return tokenResult; }
/// <summary> /// 获取可用Token /// </summary> /// <param name="appId"></param> /// <param name="getNewToken">是否强制重新获取新的Token</param> /// <returns></returns> public static AccessTokenResult GetAccessTokenResult(string appId, bool getNewToken = false) { if (!CheckRegistered(appId)) { throw new WeixinException("此appId尚未注册,请先使用AccessTokenContainer.Register完成注册(全局执行一次即可)!"); } var appSecret = Wraper.StringGet(appId); var tokenkey = $"{appId}:token"; var token = Wraper.StringGet(tokenkey); var accessTokenResult = new AccessTokenResult(); if (token == null || getNewToken) { var tokendata = CommonApi.GetToken(appId, appSecret); Wraper.StringSet(tokenkey, tokendata.access_token); Wraper.KeyExpire(tokenkey, new TimeSpan(0, 0, tokendata.expires_in)); token = tokendata.access_token; accessTokenResult.expires_in = tokendata.expires_in; } accessTokenResult.access_token = token; accessTokenResult.expires_in = 7200; return accessTokenResult; }