public async Task <WeChatPayRefundResponse> Refund([FromQuery] WeChatSignSettings weChatSignSettings, [FromBody] WeChatPayRefundRequest refundRequest) { try { WeChatPayRefundResponse result = await _weChatPayClient.Refund(weChatSignSettings, refundRequest); return(result); } catch (Exception ex) { throw; } }
protected override async Task <object> GetTaskResult(ApiActionContext context) { System.Net.Http.HttpResponseMessage response = context.ResponseMessage; string xml = await response.Content.ReadAsStringAsync().ConfigureAwait(false); Type dataType = context.ApiActionDescriptor.Return.DataType.Type; object result = context.HttpApiConfig.XmlFormatter.Deserialize(xml, dataType); IEnumerable <XElement> elements = XDocument.Parse(xml)?.Root?.Elements(); if (elements != null && elements.Any()) { if (result is WeChat.ApiModels.Response.WeChatPayResponse weChatPayResponse) { weChatPayResponse.OriginalContent = xml; } {//验签 string returnSign = elements.FirstOrDefault(e => e.Name == "sign")?.Value; if (!string.IsNullOrWhiteSpace(returnSign)) { WeChatSignSettings signSettings = context.ApiActionDescriptor.Arguments.FirstOrDefault(arg => arg is WeChatSignSettings) as WeChatSignSettings; SortedDictionary <string, string> parameters = new SortedDictionary <string, string>(); foreach (XElement element in elements) { if (!string.IsNullOrEmpty(element.Name.LocalName) && !string.IsNullOrEmpty(element.Value)) { parameters.Add(element.Name.LocalName, element.Value); } } string sign = new WeChatSignProvider(signSettings).SignWithKey(parameters); if (sign != returnSign) { throw new CheckSignException($"targetSign:{sign} != {returnSign}"); } } } if (result is IWeChatPayXmlReturnListPropertParser weChatPayXmlReturnListPropertParser) { weChatPayXmlReturnListPropertParser.ParseListProperty(elements); } } return(result); }
public async Task <WeChatPayMicroPayResponse> MicroPay([FromQuery] WeChatSignSettings weChatSignSettings, [FromBody] WeChatPayMicroPayRequest microPayRequest) { try { WeChatPayMicroPayResponse result = await _weChatPayClient.MicroPay(weChatSignSettings, microPayRequest); WeChatPayReverseResponse a = await _weChatPayClient.Reverse(weChatSignSettings, new WeChatPayReverseRequest() { OutTradeNo = result.OutTradeNo, SubMchId = result.SubMchId, }); return(result); } catch (Exception ex) { throw; } }
public override async Task SignRequestAsync(ApiActionContext context) { WeChatSignSettings signSettings = context.ApiActionDescriptor.Arguments.FirstOrDefault(arg => arg is WeChatSignSettings) as WeChatSignSettings; string xmlstring = await context.RequestMessage.Content.ReadAsStringAsync(); XDocument xml = XDocument.Parse(xmlstring); XElement bodyDoc = xml.Root; bodyDoc.Add(new XElement("sign_type", signSettings.SignType.GetDescription())); SortedDictionary <string, string> parameters = new SortedDictionary <string, string>(); foreach (XElement element in bodyDoc.Elements()) { if (!string.IsNullOrEmpty(element.Name.LocalName) && !string.IsNullOrEmpty(element.Value)) { parameters.Add(element.Name.LocalName, element.Value); } } string sign = new WeChatSignProvider(signSettings).SignWithKey(parameters); bodyDoc.Add(new XElement("sign", sign)); context.RequestMessage.Content = new StringContent(bodyDoc.ToString(), Encoding.UTF8, "application/xml"); }
public async Task <WeChatPayFacePayAuthResponse> FacePayAuth([FromServices] IWeChatPayAuthContract weChatPayAuthContract, [FromQuery] WeChatSignSettings weChatSignSettings, [FromBody] WeChatPayFacePayAuthRequest microPayRequest) { try { WeChatPayFacePayAuthResponse result = await weChatPayAuthContract.FacePayAuth(weChatSignSettings, microPayRequest); return(result); } catch (Exception ex) { throw; } }