using System; using System.Net.Http; using System.Threading; using System.Threading.Tasks; using Flurl; using Flurl.Http; namespace SKIT.FlurlHttpClient.Wechat.TenpayV3 { public static class WechatTenpayClientExecuteMerchantFundExtensions { #region Balance /// /// 异步调用 [GET] /merchant/fund/balance/{account_type} 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_3.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter5_1.shtml /// /// /// /// /// public static async Task ExecuteGetMerchantFundBalanceAsync(this WechatTenpayClient client, Models.GetMerchantFundBalanceRequest 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.Get, "merchant", "fund", "balance", request.AccountType); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [GET] /merchant/fund/dayendbalance/{account_type} 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_4.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter5_2.shtml /// /// /// /// /// public static async Task ExecuteGetMerchantFundDayendBalanceAsync(this WechatTenpayClient client, Models.GetMerchantFundDayendBalanceRequest 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.Get, "merchant", "fund", "dayendbalance", request.AccountType) .SetQueryParam("date", request.DateString); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } #endregion #region IncomeRecords /// /// 异步调用 [GET] /merchantfund/merchant/income-records 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter3_7.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer/chapter3_7.shtml /// /// /// /// /// public static async Task ExecuteQueryMerchantFundMerchantIncomeRecordsAsync(this WechatTenpayClient client, Models.QueryMerchantFundMerchantIncomeRecordsRequest 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.Get, "merchantfund", "merchant", "income-records") .SetQueryParam("account_type", request.AccountType) .SetQueryParam("date", request.DateString) .SetQueryParam("limit", request.Limit); if (request.Offset != null) flurlReq.SetQueryParam("offset", request.Offset); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [GET] /merchantfund/partner/income-records 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer_partner/chapter3_6.shtml /// /// /// /// /// public static async Task ExecuteQueryMerchantFundPartnerIncomeRecordsAsync(this WechatTenpayClient client, Models.QueryMerchantFundPartnerIncomeRecordsRequest 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.Get, "merchantfund", "partner", "income-records") .SetQueryParam("sub_mchid", request.SubMerchantId) .SetQueryParam("account_type", request.AccountType) .SetQueryParam("date", request.DateString) .SetQueryParam("limit", request.Limit); if (request.Offset != null) flurlReq.SetQueryParam("offset", request.Offset); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } #endregion #region Withdraw /// /// 异步调用 [POST] /merchant/fund/withdraw 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_5.shtml /// /// /// /// /// public static async Task ExecuteCreateMerchantFundWithdrawAsync(this WechatTenpayClient client, Models.CreateMerchantFundWithdrawRequest 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, "merchant", "fund", "withdraw"); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [GET] /merchant/fund/withdraw/out-request-no/{out_request_no} 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_3.shtml /// /// /// /// /// public static async Task ExecuteGetMerchantFundWithdrawByOutRequestNumberAsync(this WechatTenpayClient client, Models.GetMerchantFundWithdrawByOutRequestNumberRequest 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.Get, "merchant", "fund", "withdraw", "out-request-no", request.OutRequestNumber); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [GET] /merchant/fund/withdraw/{withdraw_id} 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_3.shtml /// /// /// /// /// public static async Task ExecuteGetMerchantFundWithdrawByWithdrawIdAsync(this WechatTenpayClient client, Models.GetMerchantFundWithdrawByWithdrawIdRequest 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.Get, "merchant", "fund", "withdraw", request.WithdrawId); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [GET] /merchant/fund/withdraw/bill-type/{bill_type} 接口。 /// REF: https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_8_4.shtml /// REF: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/transfer_partner/chapter6_3.shtml /// /// /// /// /// public static async Task ExecuteGetMerchantFundWithdrawBillAsync(this WechatTenpayClient client, Models.GetMerchantFundWithdrawBillRequest 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.Get, "merchant", "fund", "withdraw", "bill-type", request.BillType) .SetQueryParam("bill_date", request.BillDateString); if (request.TarType != null) flurlReq.SetQueryParam("tar_type", request.TarType); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } #endregion } }