/// <summary> /// 获取小程序token /// </summary> /// <param name="appid"></param> /// <param name="token"></param> /// <param name="platAppid"></param> /// <param name="refreToken"></param> /// <returns></returns> public static RefreshAuthorizerTokenResult GetAuthoRizerToken(string appid, string token, string platAppid, string refreToken) { string url = string.Format(_api_authorizer_tokenUrl, token.AsUrlData()); var data = new { component_appid = platAppid, authorizer_appid = appid, authorizer_refresh_token = refreToken }; string dataJson = JsonConvert.SerializeObject(data); string result = HttpHelper.DoPostJson(url, dataJson); RefreshAuthorizerTokenResult model = GetResultModel <RefreshAuthorizerTokenResult>(result); return(model); }
public static string ReloadToken(Guid CompanyID) { wx_userweixin wx = wx_userweixinService.instance().SingleByCompanyID(CompanyID); //if (wx.AppId == null || wx.AppSecret == null || wx.AppId.Trim().Length <= 0 || wx.AppSecret.Trim().Length <= 0) //{ // return "appId或者AppSecret未填写完全,请在[我的公众帐号]里补全信息!"; //} var wx_open = wx_openInfoService.instance().Single(new Guid(System.Configuration.ConfigurationManager.AppSettings["openID"])); RefreshAuthorizerTokenResult result = ComponentApi.ApiAuthorizerToken(wx_open.open_access_token, wx_open.open_sAppID, wx.AppId, wx.refresh_token); if (result.errcode == Entity.Weixin.ReturnCode.请求成功) { wx.Access_Token = result.authorizer_access_token; wx.refresh_token = result.authorizer_refresh_token; wx.expires_in = result.expires_in; wx.ModifyTime = DateTime.Now; if (wx_userweixinService.instance().Update(wx) == 1) { return("ok"); } return("更新数据库出错"); } return(result.errcode.ToString()); }
public OpenAuthorizerInfo getCurrentModel(string user_name, bool isreflsh = false) { string cachekey = string.Format(accestoenkey, user_name); OpenAuthorizerInfo model = RedisUtil.Get <OpenAuthorizerInfo>(cachekey); if (model != null) { if (!(isreflsh || model.refreshtime.AddMinutes(_minutes) < DateTime.Now || string.IsNullOrEmpty(model.authorizer_access_token))) { return(model); } } model = GetModel(string.Format("user_name='{0}'", user_name)); if (model == null) { throw new Exception("没有第三方授权信息:username="******"user_name='{0}'", user_name)); if (model == null) { throw new Exception("没有第三方授权信息:username="******"{user_name}授权公众号刷新token失败:{token.errcode.ToString()}"); } } catch (Exception ex) { log4net.LogHelper.WriteError(this.GetType(), ex); } } RedisUtil.Set <OpenAuthorizerInfo>(cachekey, model, TimeSpan.FromMinutes(_minutes)); } return(model); }