Files
juipnet/Services/Hncore.Pass.PaymentCenter/Pay/WeiFuTong/ClientExtension/QrPay.cs
wanyongkang d318014316 初始提交
2020-10-07 20:25:03 +08:00

56 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Hncore.Infrastructure.Common;
using Hncore.Infrastructure.Serializer;
using Hncore.Pass.PaymentCenter.WeiFuTong.QrPay;
namespace Hncore.Pass.PaymentCenter.WeiFuTong.ClientExtension
{
public static class QrPay
{
/// <summary>
/// 扫码支付下单
/// </summary>
/// <param name="weiFuTongClient"></param>
/// <param name="request"></param>
/// <returns></returns>
public static async Task<QrPayCreateOrderResponse> QrPayCreateOrderAsync(this WeiFuTongClient weiFuTongClient
, QrPayCreateOrderRequest request)
{
StringBuilder log = new StringBuilder();
var body = request.ToXml();
log.Append("请求:\r\n" + body);
var response = await weiFuTongClient.CreateHttpClient()
.PostAsync(request.PaymentChannel.GetUrl(), new StringContent(body));
var resText = await response.Content.ReadAsStringAsync();
log.Append("\r\n响应" + resText);
string target = "";
if (request.Service == "pay.weixin.native")
{
target = "微信";
}
else if (request.Service == "pay.alipay.native")
{
target = "支付宝";
}
LogHelper.Trace($"威富通-{target}扫码支付下单", log.ToString());
Util.CheckSignFromXml(resText, request.MchInfo);
var res = XML.XmlDeserialize<QrPayCreateOrderResponse>(resText);
res.HandleError();
return res;
}
}
}