/// <summary> /// 根据Code获取第三方access_token信息 /// </summary> /// <param name="code"></param> /// <returns></returns> public override ThirdOpenAuthorizeViewModel GetThirdOAuth(string code) { string accessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token"; string accessUrl = $"{accessTokenUrl}?appid={WechatConfig.AppId}&secret={WechatConfig.Secret}&code={code}&grant_type=authorization_code"; var oauthTokenResponse = HttpHelper.HttpGet <dynamic>(accessUrl); ThirdOpenAuthorizeViewModel result = new ThirdOpenAuthorizeViewModel { OpenId = oauthTokenResponse.openid, UnionId = oauthTokenResponse.unionid, Token = oauthTokenResponse.access_token, Expires = oauthTokenResponse.expires_in }; return(result); }
/// <summary> /// 根据Code获取第三方access_token信息 /// </summary> /// <param name="code"></param> /// <returns></returns> public override ThirdOpenAuthorizeViewModel GetThirdOAuth(string code) { DefaultAopClient client = new DefaultAopClient(AliPayConfig.gatewayUrl, AliPayConfig.AppId, AliPayConfig.privatekey, "json", "1.0", AliPayConfig.sign_type, AliPayConfig.alipublickey, AliPayConfig.charset, false); AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest { Code = code, GrantType = AliPayConfig.granttype }; AlipaySystemOauthTokenResponse oauthTokenResponse = client.Execute(request); if (oauthTokenResponse.IsError) { throw new Exception(oauthTokenResponse.SubMsg); } ThirdOpenAuthorizeViewModel result = new ThirdOpenAuthorizeViewModel { AlipayId = oauthTokenResponse.UserId, Token = oauthTokenResponse.AccessToken, Expires = int.Parse(oauthTokenResponse.ExpiresIn) }; return(result); }