using System; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Flurl.Http; namespace SKIT.FlurlHttpClient.Wechat.TenpayV2 { public static class WechatTenpayClientExecutePayExtensions { /// /// 异步调用 [POST] /pay/unifiedorder 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/api/jsapi_sl.php?chapter=9_1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1&index=1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=9_1&index=1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/jsapi_sl.php?chapter=9_1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=9_1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app_sl.php?chapter=9_1&index=1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5_sl.php?chapter=9_1&index=1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_sl_api.php?chapter=9_1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/NativePay/chapter8_1.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/MiniProgramPay/chapter8_1.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/MiniProgramPay/chapter8_10.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/In-AppPay/chapter8_1.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/In-AppPay/chapter8_10.shtml /// /// /// /// /// public static async Task ExecuteCreatePayUnifiedOrderAsync(this WechatTenpayClient client, Models.CreatePayUnifiedOrderRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "pay", "unifiedorder"); return await client.SendRequestWithXmlAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /pay/micropay 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_10&index=1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/micropay_sl.php?chapter=9_10&index=1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/danpin.php?chapter=9_101&index=1 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/QuickPay/chapter3_3.shtml /// /// /// /// /// public static async Task ExecuteCreatePayMicroPayAsync(this WechatTenpayClient client, Models.CreatePayMicroPayRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "pay", "micropay"); return await client.SendRequestWithXmlAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /pay/orderquery 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_02 /// REF: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_2 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_2&index=4 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=9_2&index=2 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_2 /// REF: https://pay.weixin.qq.com/wiki/doc/api/micropay_sl.php?chapter=9_02 /// REF: https://pay.weixin.qq.com/wiki/doc/api/jsapi_sl.php?chapter=9_2 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=9_2 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app_sl.php?chapter=9_2&index=4 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5_sl.php?chapter=9_2&index=2 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_sl_api.php?chapter=9_2 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/QuickPay/chapter8_2.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/NativePay/chapter8_2.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/MiniProgramPay/chapter8_2.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/OfficialPayMent/chapter8_2.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/In-AppPay/chapter8_2.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/H5Payment/chapter8_2.shtml /// /// /// /// /// public static async Task ExecuteGetPayOrderAsync(this WechatTenpayClient client, Models.GetPayOrderRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "pay", "orderquery"); return await client.SendRequestWithXmlAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /secapi/pay/reverse 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/api/micropay_sl.php?chapter=9_11&index=3 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/QuickPay/chapter3_4.shtml /// /// /// /// /// public static async Task ExecuteReversePayOrderAsync(this WechatTenpayClient client, Models.ReversePayOrderRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "secapi", "pay", "reverse"); return await client.SendRequestWithXmlAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /pay/closeorder 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_3 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_3 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_3&index=5 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=9_3&index=3 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_3 /// REF: https://pay.weixin.qq.com/wiki/doc/api/jsapi_sl.php?chapter=9_3 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=9_3 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app_sl.php?chapter=9_3&index=5 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5_sl.php?chapter=9_3&index=3 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_sl_api.php?chapter=9_3 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter4_6.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter5_17.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/NativePay/chapter8_3.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/MiniProgramPay/chapter8_3.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/OfficialPayMent/chapter8_3.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/In-AppPay/chapter8_3.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/H5Payment/chapter8_3.shtml /// /// /// /// /// public static async Task ExecuteClosePayOrderAsync(this WechatTenpayClient client, Models.ClosePayOrderRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "pay", "closeorder"); return await client.SendRequestWithXmlAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /secapi/pay/refund 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_4 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_4 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_4&index=6 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=9_4&index=4 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_4 /// REF: https://pay.weixin.qq.com/wiki/doc/api/jsapi_sl.php?chapter=9_4 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=9_4 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app_sl.php?chapter=9_4&index=6 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5_sl.php?chapter=9_4&index=4 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_sl_api.php?chapter=9_4 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter4_3.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter5_13.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/vehicle_v2_sl.php?chapter=9_4&index=5&p=202 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/QuickPay/chapter8_4.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/NativePay/chapter8_4.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/MiniProgramPay/chapter8_4.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/OfficialPayMent/chapter8_4.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/In-AppPay/chapter8_4.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/H5Payment/chapter8_4.shtml /// /// /// /// /// public static async Task ExecuteCreatePayRefundAsync(this WechatTenpayClient client, Models.CreatePayRefundRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "secapi", "pay", "refund"); return await client.SendRequestWithXmlAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /pay/refundquery 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_5 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_5 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_5&index=7 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=9_5&index=5 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_5 /// REF: https://pay.weixin.qq.com/wiki/doc/api/jsapi_sl.php?chapter=9_5 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=9_5 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app_sl.php?chapter=9_5&index=7 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5_sl.php?chapter=9_5&index=5 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_sl_api.php?chapter=9_5 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter4_4.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter5_14.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/vehicle_v2_sl.php?chapter=9_5&index=6&p=202 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/QuickPay/chapter8_5.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/NativePay/chapter8_5.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/MiniProgramPay/chapter8_5.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/OfficialPayMent/chapter8_5.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/In-AppPay/chapter8_5.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/H5Payment/chapter8_5.shtml /// /// /// /// /// public static async Task ExecuteGetPayRefundAsync(this WechatTenpayClient client, Models.GetPayRefundRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "pay", "refundquery"); return await client.SendRequestWithXmlAsync(flurlReq, data: request, cancellationToken: cancellationToken); } #region Bill /// /// 异步调用 [POST] /pay/downloadbill 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_6 /// REF: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_6 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_6&index=8 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=9_6&index=6 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_6 /// REF: https://pay.weixin.qq.com/wiki/doc/api/jsapi_sl.php?chapter=9_6 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native_sl.php?chapter=9_6 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app_sl.php?chapter=9_6&index=8 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5_sl.php?chapter=9_6&index=6 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_sl_api.php?chapter=9_6 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter4_1.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay_v2/papay/chapter5_11.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/vehicle_v2_sl.php?chapter=9_6&index=3&p=202 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/QuickPay/chapter8_6.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/NativePay/chapter8_6.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/MiniProgramPay/chapter8_6.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/OfficialPayMent/chapter8_6.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/In-AppPay/chapter8_6.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/H5Payment/chapter8_6.shtml /// /// /// /// /// public static async Task ExecuteDownloadPayBillAsync(this WechatTenpayClient client, Models.DownloadPayBillRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "pay", "downloadbill"); return await client.SendRequestWithXmlAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /pay/downloadfundflow 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/api/micropay.php?chapter=9_18&index=7 /// REF: https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_18&index=7 /// REF: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=9_18&index=7 /// REF: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_18&index=9 /// REF: https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=9_18&index=7 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_18&index=7 /// /// /// /// /// public static async Task ExecuteDownloadPayFundFlowAsync(this WechatTenpayClient client, Models.DownloadPayFundFlowRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "pay", "downloadfundflow"); return await client.SendRequestWithXmlAsync(flurlReq, data: request, cancellationToken: cancellationToken); } #endregion #region Settlement /// /// 异步调用 [POST] /pay/settlementquery 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/QuickPay/chapter8_9.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/NativePay/chapter8_9.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/MiniProgramPay/chapter8_9.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/OfficialPayMent/chapter8_9.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/In-AppPay/chapter8_9.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/H5Payment/chapter8_9.shtml /// /// /// /// /// public static async Task ExecuteGetPaySettlementAsync(this WechatTenpayClient client, Models.GetPaySettlementRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "pay", "settlementquery"); return await client.SendRequestWithXmlAsync(flurlReq, data: request, cancellationToken: cancellationToken); } #endregion #region ExchangeRate /// /// 异步调用 [POST] /pay/queryexchagerate 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/QuickPay/chapter8_10.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/NativePay/chapter8_10.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/MiniProgramPay/chapter8_10.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/OfficialPayMent/chapter8_10.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/In-AppPay/chapter8_10.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/api/wxpay/en/pay/In-AppPay/chapter8_10.shtml /// /// /// /// /// public static async Task ExecuteGetPayExchangeRateAsync(this WechatTenpayClient client, Models.GetPayExchangeRateRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "pay", "queryexchagerate"); return await client.SendRequestWithXmlAsync(flurlReq, data: request, cancellationToken: cancellationToken); } #endregion } }