🆕 #2672 【微信支付】新增商家转账的相关接口

This commit is contained in:
zhongjun
2022-06-20 16:27:53 +08:00
committed by GitHub
parent d5c6803260
commit 4590c9c333
10 changed files with 608 additions and 1 deletions

View File

@@ -0,0 +1,102 @@
package com.github.binarywang.wxpay.service;
import com.github.binarywang.wxpay.bean.transfer.*;
import com.github.binarywang.wxpay.exception.WxPayException;
/**
* 商家转账到零钱
*
* @author zhongjun
* @date 2022/6/17
**/
public interface TransferService {
/**
* <pre>
*
* 发起商家转账API
*
* 请求方式POSTHTTPS
* 请求地址:<a href="https://api.mch.weixin.qq.com/v3/transfer/batches">请求地址</a>
*
* 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_1.shtml">发起商家转账API</a>
* </pre>
*
* @param request 转账请求参数
* @return TransferBatchesResult 转账结果
* @throws WxPayException .
*/
TransferBatchesResult transferBatches(TransferBatchesRequest request) throws WxPayException;
/**
* <pre>
*
* 微信批次单号查询批次单API
*
* 请求方式GETHTTPS
* 请求地址:<a href="https://api.mch.weixin.qq.com/v3/transfer/batches/batch-id/{batch_id}">请求地址</a>
*
* 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_2.shtml">微信批次单号查询批次单API</a>
* </pre>
*
* @param request 查询请求参数
* @return TransferBatchesResult 查询结果
* @throws WxPayException .
*/
QueryTransferBatchesResult transferBatchesBatchId(QueryTransferBatchesRequest request) throws WxPayException;
/**
* <pre>
*
* 微信明细单号查询明细单API
*
* 请求方式GETHTTPS
* 请求地址:<a href="https://api.mch.weixin.qq.com/v3/transfer/batches/batch-id/{batch_id}/details/detail-id/{detail_id}">请求地址</a>
*
* 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_3.shtml">微信明细单号查询明细单API</a>
* </pre>
*
* @param batchId 微信批次单号
* @param detailId 微信明细单号
* @return TransferBatchDetailResult 查询结果
* @throws WxPayException .
*/
TransferBatchDetailResult transferBatchesBatchIdDetail(String batchId, String detailId) throws WxPayException;
/**
* <pre>
*
* 商家批次单号查询批次单API
*
* 请求方式GETHTTPS
* 请求地址:<a href="https://api.mch.weixin.qq.com/v3/transfer/batches/out-batch-no/{out_batch_no}">请求地址</a>
*
* 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_5.shtml">商家批次单号查询批次单API</a>
* </pre>
*
* @param request 查询请求参数
* @return TransferBatchesResult 查询结果
* @throws WxPayException .
* @throws WxPayException .
*/
QueryTransferBatchesResult transferBatchesOutBatchNo(QueryTransferBatchesRequest request) throws WxPayException;
/**
* <pre>
*
* 商家明细单号查询明细单API
*
* 请求方式GETHTTPS
* 请求地址:<a href="https://api.mch.weixin.qq.com/v3/transfer/batches/out-batch-no/{out_batch_no}/details/out-detail-no/{out_detail_no}">请求地址</a>
*
* 文档地址:<a href="https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter4_3_6.shtml">商家明细单号查询明细单API</a>
* </pre>
*
* @param outBatchNo 商家明细单号
* @param outDetailNo 商家批次单号
* @return TransferBatchDetailResult 查询结果
* @throws WxPayException .
*/
TransferBatchDetailResult transferBatchesOutBatchNoDetail(String outBatchNo, String outDetailNo) throws WxPayException;
}

View File

@@ -1352,7 +1352,15 @@ public interface WxPayService {
/**
* 获取银行组件服务
* @return 银行组件服务
*
* @return 银行组件服务
*/
BankService getBankService();
/**
* 获取商家转账到零钱服务类.
*
* @return the transfers service
*/
TransferService getTransferService();
}

View File

@@ -79,6 +79,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
private final PayrollService payrollService = new PayrollServiceImpl(this);
private final ComplaintService complaintsService = new ComplaintServiceImpl(this);
private final BankService bankService = new BankServiceImpl(this);
private final TransferService transferService = new TransferServiceImpl(this);
protected Map<String, WxPayConfig> configMap;
@@ -1269,4 +1270,9 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
public BankService getBankService() {
return bankService;
}
@Override
public TransferService getTransferService() {
return transferService;
}
}

View File

@@ -0,0 +1,61 @@
package com.github.binarywang.wxpay.service.impl;
import com.github.binarywang.wxpay.bean.transfer.*;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.TransferService;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.RequiredArgsConstructor;
/**
* 商家转账到零钱
*
* @author zhongjun
* @date 2022/6/17
**/
@RequiredArgsConstructor
public class TransferServiceImpl implements TransferService {
private static final Gson GSON = new GsonBuilder().create();
private final WxPayService payService;
@Override
public TransferBatchesResult transferBatches(TransferBatchesRequest request) throws WxPayException {
String url = String.format("%s/v3/transfer/batches", this.payService.getPayBaseUrl());
RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate());
String result = this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
return GSON.fromJson(result, TransferBatchesResult.class);
}
@Override
public QueryTransferBatchesResult transferBatchesBatchId(QueryTransferBatchesRequest request) throws WxPayException {
String url = String.format("%s/v3/transfer/batches/batch-id/%s?need_query_detail=%s&offset=%s&limit=%s&detail_status=%s",
this.payService.getPayBaseUrl(), request.getBatchId(), request.getNeedQueryDetail(), request.getOffset(), request.getLimit(), request.getDetailStatus());
String result = this.payService.getV3(url);
return GSON.fromJson(result, QueryTransferBatchesResult.class);
}
@Override
public TransferBatchDetailResult transferBatchesBatchIdDetail(String batchId, String detailId) throws WxPayException {
String url = String.format("%s/v3/transfer/batches/batch-id/%s/details/detail-id/%s", this.payService.getPayBaseUrl(), batchId, detailId);
String result = this.payService.getV3(url);
return GSON.fromJson(result, TransferBatchDetailResult.class);
}
@Override
public QueryTransferBatchesResult transferBatchesOutBatchNo(QueryTransferBatchesRequest request) throws WxPayException {
String url = String.format("%s/v3/transfer/batches/out-batch-no/%s?need_query_detail=%s&offset=%s&limit=%s&detail_status=%s",
this.payService.getPayBaseUrl(), request.getOutBatchNo(), request.getNeedQueryDetail(), request.getOffset(), request.getLimit(), request.getDetailStatus());
String result = this.payService.getV3(url);
return GSON.fromJson(result, QueryTransferBatchesResult.class);
}
@Override
public TransferBatchDetailResult transferBatchesOutBatchNoDetail(String outBatchNo, String outDetailNo) throws WxPayException {
String url = String.format("%s/v3/transfer/batches/out-batch-no/%s/details/out-detail-no/%s", this.payService.getPayBaseUrl(), outBatchNo, outDetailNo);
String result = this.payService.getV3(url);
return GSON.fromJson(result, TransferBatchDetailResult.class);
}
}