public Task <T> PageExecuteAsync <T>(IWeChatPayRequest <T> request, WeChatPayOptions options) where T : WeChatPayResponse { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (string.IsNullOrEmpty(options.AppId)) { throw new ArgumentNullException(nameof(options.AppId)); } if (string.IsNullOrEmpty(options.MchId)) { throw new ArgumentNullException(nameof(options.MchId)); } if (string.IsNullOrEmpty(options.Key)) { throw new ArgumentNullException(nameof(options.Key)); } var signType = request.GetSignType(); var sortedTxtParams = new WeChatPayDictionary(request.GetParameters()); request.PrimaryHandler(options, signType, sortedTxtParams); var url = request.GetRequestUrl(); if (url.Contains("?")) { url += "&" + WeChatPayUtility.BuildQuery(sortedTxtParams); } else { url += "?" + WeChatPayUtility.BuildQuery(sortedTxtParams); } var rsp = Activator.CreateInstance <T>(); rsp.ResponseBody = url; return(Task.FromResult(rsp)); }
public async Task <T> ExecuteAsync <T>(IWeChatPayRequest <T> request, WeChatPayOptions options) where T : WeChatPayResponse { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (string.IsNullOrEmpty(options.AppId)) { throw new WeChatPayException($"options.{nameof(WeChatPayOptions.AppId)} is Empty!"); } if (string.IsNullOrEmpty(options.MchId)) { throw new WeChatPayException($"options.{nameof(WeChatPayOptions.MchId)} is Empty!"); } if (string.IsNullOrEmpty(options.APIKey)) { throw new WeChatPayException($"options.{nameof(WeChatPayOptions.APIKey)} is Empty!"); } var sortedTxtParams = new WeChatPayDictionary(request.GetParameters()); request.PrimaryHandler(sortedTxtParams, options); var client = _httpClientFactory.CreateClient(Name); var body = await client.PostAsync(request, sortedTxtParams); var parser = new WeChatPayResponseXmlParser <T>(); var response = parser.Parse(body); if (request.GetNeedCheckSign()) { var signType = request.GetSignType(); CheckResponseSign(response, options, signType); } return(response); }