public TenPayHttpClient(SenparcHttpClient httpClient, ISenparcWeixinSettingForTenpayV3 senparcWeixinSettingForTenpayV3 = null, CertType certType = CertType.RSA) { this._httpClient = httpClient; this._client = this._httpClient.Client; _tenpayV3Setting = senparcWeixinSettingForTenpayV3 ?? Senparc.Weixin.Config.SenparcWeixinSetting.TenpayV3Setting; //从工厂获得签名和验签的方法类 _signer = TenPayCertFactory.GetSigner(certType); _verifier = TenPayCertFactory.GetVerifier(certType); #region 配置UA //ACCEPT header _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*")); //User-Agent header var userAgentValues = UserAgentValues.Instance; _client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("Senparc.Weixin.TenPayV3-C#", userAgentValues.TenPayV3Version)); _client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue($"(Senparc.Weixin {userAgentValues.SenparcWeixinVersion})")); _client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(".NET", userAgentValues.RuntimeVersion)); _client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue($"({userAgentValues.OSVersion})")); #endregion }
public async Task <IActionResult> GetOpenIdAsync(string code) { try { string strAppId = "wx133b351ac060a310"; string strSecret = "ad86ca4cb847a418346a8f0558bcca14"; string strRequestUrl = $"https://api.weixin.qq.com/sns/jscode2session?appid={strAppId}&secret={strSecret}&js_code={code}&grant_type=authorization_code"; HttpClient httpClient = new HttpClient(); SenparcHttpClient senparcHttpClient = new SenparcHttpClient(httpClient); var httpResponse = await senparcHttpClient.Client.GetAsync(strRequestUrl); var response = httpResponse.Content.ReadAsStringAsync().Result; return(Success(response)); } catch (Exception ex) { return(Fail(ex.Message)); } }
/// <summary> /// 构造函数 /// </summary> /// <param name="senparcWeixinSettingForTenpayV3"></param> public BasePayApis2(SenparcHttpClient httpClient, ISenparcWeixinSettingForTenpayV3 senparcWeixinSettingForTenpayV3 = null, CertType certType = CertType.RSA) { this._httpClient = httpClient; _tenpayV3Setting = senparcWeixinSettingForTenpayV3 ?? Senparc.Weixin.Config.SenparcWeixinSetting.TenpayV3Setting; this._certType = certType; }
public TenPayRealV3Controller(SenparcHttpClient httpClient) { _tenpayV3Setting = Senparc.Weixin.Config.SenparcWeixinSetting.TenpayV3Setting; _basePayApis = new BasePayApis(_tenpayV3Setting); this._httpClient = httpClient; }