@@ -18,21 +18,23 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.WxPayTransferPart
import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient ;
import cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum ;
import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferTypeEnum ;
import com.github.binarywang.wxpay.bean.notify.* ;
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyV3Result ;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult ;
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult ;
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyV3Result ;
import com.github.binarywang.wxpay.bean.request.* ;
import com.github.binarywang.wxpay.bean.result.* ;
import com.github.binarywang.wxpay.bean.transfer.TransferBatchesRequest ;
import com.github.binarywang.wxpay.bean.transfer.TransferBatchesResult ;
import com.github.binarywang.wxpay.config.WxPayConfig ;
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.service.impl.WxPayServiceImpl ;
import lombok.extern.slf4j.Slf4j ;
import java.time.LocalDateTime ;
import java.time.ZoneId ;
import java.util.ArrayList ;
import java.util.Collections ;
import java.util.List ;
import java.util.Map ;
import java.util.Objects ;
@@ -356,17 +358,21 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
switch ( config . getApiVersion ( ) ) {
case API_VERSION_V3 :
return parseTransferNotifyV3 ( body ) ;
case API_VERSION_V2 :
throw new UnsupportedOperationException ( " V2 版本暂不支持,建议使用 V3 版本 " ) ;
default :
throw new IllegalArgumentException ( String . format ( " 未知的 API 版本(%s) " , config . getApiVersion ( ) ) ) ;
}
}
private PayTransferRespDTO parseTransferNotifyV3 ( String body ) throws WxPayException {
// 1. 解析回调
// TODO @luchi: 这个可以复用 wxjava 里的类么?
WxPayTransferPartnerNotifyV3Result response = client . baseParseOrderNotifyV3Result ( body , null , WxPayTransferPartnerNotifyV3Result . class , WxPayTransferPartnerNotifyV3Result . TransferNotifyResult . class ) ;
WxPayTransferPartnerNotifyV3Result . TransferNotifyResult result = response . getResult ( ) ;
// 2. 构建结果
if ( Objects . equals ( " FINISHED " , result . getBatchStatus ( ) ) ) {
if ( result . getFailNum ( ) < = 0 ) {
if ( result . getFailNum ( ) < = 0 ) {
return PayTransferRespDTO . successOf ( result . getBatchId ( ) , parseDateV3 ( result . getUpdateTime ( ) ) ,
result . getOutBatchNo ( ) , response ) ;
}
@@ -453,29 +459,33 @@ public abstract class AbstractWxPayClient extends AbstractPayClient<WxPayClientC
@Override
protected PayTransferRespDTO doUnifiedTransfer ( PayTransferUnifiedReqDTO reqDTO ) throws WxPayException {
TransferService transferService = client . getTransferService ( ) ;
List < TransferBatchesRequest . TransferDetail > transferDetailList = new ArrayList < > ( ) ;
transferDetailList . add ( TransferBatchesRequest . TransferDetail . newBuilder ( )
. outDetailNo ( reqDTO . getOutTransferNo ( ) )
. transferAmount ( reqDTO . getPrice ( ) )
. transferRemark ( reqDTO . getSubject ( ) )
. openid ( reqDTO . getOpenid ( ) )
. build ( ) ) ;
// 1. 构建 TransferBatchesRequest 请求
List < TransferBatchesRequest . TransferDetail > transferDetailList = Collections . singletonList (
TransferBatchesRequest . TransferDetail . newBuilder ( )
. outDetailNo ( reqDTO . getOutTransferNo ( ) )
. transferAmount ( reqDTO . getPrice ( ) )
. transferRemark ( reqDTO . getSubject ( ) )
. openid ( reqDTO . getOpenid ( ) )
. build ( ) ) ;
// TODO @luchi: 能不能我们搞个 TransferBatchesRequestX extends TransferBatchesRequest, 这样更简洁一点。
TransferBatchesRequest transferBatches = TransferBatchesRequest . newBuilder ( )
. appid ( this . config . getAppId ( ) )
. outBatchNo ( reqDTO . getOutTransferNo ( ) )
. batchName ( reqDTO . getSubject ( ) )
. batchRemark ( reqDTO . getSubject ( ) )
. totalAmount ( reqDTO . getPrice ( ) )
. totalNum ( 1 )
. transferDetailList ( transferDetailList ) . build ( ) ;
transferBatches . setNotifyUrl ( reqDTO . getNotifyUrl ( ) ) ;
TransferBatchesResult transferBatchesResult = transferService . transferBatches ( transferBatches ) ;
. totalNum ( transferDetailList . size ( ) )
. transferDetailList ( transferDetailList ) . build ( )
. setNotifyUrl ( reqDTO . getNotifyUrl ( ) ) ;
// 2.1 执行请求
TransferBatchesResult transferBatchesResult = client . getTransferService ( ) . transferBatches ( transferBatches ) ;
// 2.2 创建返回结果
return PayTransferRespDTO . dealingOf ( transferBatchesResult . getBatchId ( ) , reqDTO . getOutTransferNo ( ) , transferBatchesResult ) ;
}
@Override
protected PayTransferRespDTO doGetTransfer ( String outTradeNo , PayTransferTypeEnum type ) {
// TODO luchi: 这个最好实现下。因为可能要主动轮询转账结果
throw new UnsupportedOperationException ( " 待实现 " ) ;
}