/// <summary> /// 第二步,通过code换取网页授权access_token /// </summary> public void GetAccess_Token() { try { //1.处理跳转 this.Code = ReqHelper.GetString("code"); if (string.IsNullOrEmpty(this.Code)) { throw new Exception("获取code参数失败或用户禁止授权获取基本信息"); } //1.发送获取access_token请求 string url = GetAccess_TokenUrl(); string result = NetHelper.Get(url); //2.解析相应结果 TokenData = JsonConvert.DeserializeObject <OAuthAccess_Token>(result); if (TokenData == null) { throw new Exception("反序列化结果失败,返回内容为:" + result); } //3.获取成功 if (OnGetTokenSuccess != null) { OnGetTokenSuccess(TokenData); } } catch (Exception ex) { Error("第二步,通过code换取网页授权access_token异常", ex); } }
/// <summary> /// 刷新当前access_token /// </summary> public OAuthAccess_Token RefreshAccess_Token() { try { //1.发送请求 string url = GetReferesh_TokenUrl(); string result = NetHelper.Get(url); //2.解析结果 OAuthAccess_Token token = JsonConvert.DeserializeObject <OAuthAccess_Token>(result); if (token == null) { throw new Exception("反序列化结果失败,返回内容:" + result); } return(token); } catch (Exception ex) { Error("刷新当前access_token失败", ex); return(null); } }