From 1b34078a710c56179f4a4beeef5c13ccaaed8048 Mon Sep 17 00:00:00 2001 From: xiaohanzi Date: Sun, 13 Sep 2020 14:33:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E8=B4=A6=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schedule/SharingOrderRedoSchedule.java | 1 + .../domain/dto/WxProfitShareAppInoDto.java | 21 +++ .../com/iformall/domain/po/WxAppinfo.java | 1 - .../domain/po/WxProfitSharingOrder.java | 1 - .../service/WxProfitSharingOrderService.java | 1 + .../impl/WxProfitSharingOrderServiceImpl.java | 171 ++++++------------ .../service/share/PayShareAdapterService.java | 12 ++ .../share/entity/PayShareQueryResult.java | 22 +++ .../service/share/entity/PayShareResult.java | 3 - .../service/share/wx/WxPayShareService.java | 51 ++++++ 10 files changed, 159 insertions(+), 125 deletions(-) create mode 100644 mallinkService/src/main/java/com/iformall/domain/dto/WxProfitShareAppInoDto.java create mode 100644 mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareQueryResult.java diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoSchedule.java index 9b79bcb73..d7b296e97 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoSchedule.java @@ -4,6 +4,7 @@ import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.dto.WxSharingOrderDto; import com.iformall.domain.po.WxProfitSharingOrder; +import com.iformall.enums.EnumPayWay; import com.iformall.enums.EnumProfitSharingOrderStatus; import com.iformall.enums.EnumProfitSharingOrderType; import com.iformall.mapper.WxPayOrderMapper; diff --git a/mallinkService/src/main/java/com/iformall/domain/dto/WxProfitShareAppInoDto.java b/mallinkService/src/main/java/com/iformall/domain/dto/WxProfitShareAppInoDto.java new file mode 100644 index 000000000..8af5e1f2e --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/dto/WxProfitShareAppInoDto.java @@ -0,0 +1,21 @@ +package com.iformall.domain.dto; + +import java.io.Serializable; + +import com.iformall.domain.po.WxAppinfo; + +import lombok.Data; + +@Data +public class WxProfitShareAppInoDto implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -8159673293532875743L; + + private WxAppinfo appinfo; + private Integer payWay; + + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxAppinfo.java b/mallinkService/src/main/java/com/iformall/domain/po/WxAppinfo.java index 459bd3363..f930b145b 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxAppinfo.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxAppinfo.java @@ -44,5 +44,4 @@ public class WxAppinfo extends BaseTenantEntity { private Integer enable; @io.swagger.annotations.ApiModelProperty(value="app平台 EnumAppPlat ",name="plat") private Integer plat; - } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingOrder.java b/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingOrder.java index 650713344..12fcd9a58 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingOrder.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingOrder.java @@ -41,5 +41,4 @@ public class WxProfitSharingOrder extends TenantEntity { @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createTime") private Date createTime; - } diff --git a/mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java b/mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java index a457e7a80..4df58d67b 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java @@ -8,6 +8,7 @@ import com.iformall.domain.po.WxProfitSharingOrder; import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.vo.WxProfitSharingOrderQueryVo; import com.iformall.domain.vo.WxProfitSharingOrderVo; +import com.iformall.enums.EnumPayWay; import java.util.Map; diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java index 9b5db6010..20b7cd99b 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java @@ -9,6 +9,7 @@ import com.github.pagehelper.PageInfo; import com.iformall.common.ErrorCode; import com.iformall.common.IdWorker; import com.iformall.common.ResultData; +import com.iformall.domain.dto.WxProfitShareAppInoDto; import com.iformall.domain.dto.WxSharingOrderDto; import com.iformall.domain.po.*; import com.iformall.domain.po.base.TenantEntity; @@ -21,6 +22,7 @@ import com.iformall.mapper.*; import com.iformall.pay.*; import com.iformall.service.WxProfitSharingOrderService; import com.iformall.service.pay.PayServiceFactory; +import com.iformall.service.pay.service.share.entity.PayShareQueryResult; import com.iformall.service.pay.service.share.entity.PayShareResult; import com.iformall.utils.BeanUtils; import com.iformall.utils.DateUtils; @@ -93,11 +95,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ "\"ORDERNOTEXIST\":{\"detail\":\"分账单不存在\",\"reason\":\"订单号错误或分账单号错误\",\"resolution\":\"请检查订单号或分账单号是否有错误\"}}"); - final JSONObject statusMap = JSON.parseObject( - "{\"ACCEPTED\":3," + - "\"PROCESSING\": 4," + - "\"FINISHED\": 5," + - "\"CLOSED\": 6}"); + final JSONObject resultStatusMap = JSON.parseObject( "{\"PENDING\": 1," + @@ -120,6 +118,32 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ return wxAppinfo; } + private WxProfitShareAppInoDto getAppinfo(WxProfitSharingOrder wxProfitSharingOrder) { + WxAppinfo appinfo; + Integer payWay; + if (wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()) + ||wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode())){ + WxPayOrder wxPayOrder = wxPayOrderMapper.selectById(wxProfitSharingOrder.getOrderId()); + if (wxPayOrder == null) + throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(),"wxProfitSharingOrder["+wxProfitSharingOrder.getId()+"] 没有payOrder信息."); + appinfo = getAppinfo(wxPayOrder.getTenantId(),wxPayOrder.getPayVendor()); + payWay = wxPayOrder.getPayVendor(); + } else if(wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode()) + ||wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI_FINISH.getCode())){ + WxCardSpend wxCardSpend = wxCardSpendMapper.selectById(wxProfitSharingOrder.getOrderId()); + if (wxCardSpend == null) + throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(),"wxProfitSharingOrder["+wxProfitSharingOrder.getId()+"] 没有WxCardSpend信息."); + appinfo = getAppinfo(wxCardSpend.getTenantId(),EnumCardSpendFrom.getPayWay(wxCardSpend.getPayFrom()).getCode()); + payWay = EnumCardSpendFrom.getPayWay(wxCardSpend.getPayFrom()).getCode(); + } else { + throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_UNKNOWN_TYPE); + } + + WxProfitShareAppInoDto rt = new WxProfitShareAppInoDto(); + rt.setAppinfo(appinfo); + rt.setPayWay(payWay); + return rt; + } @Override @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) @@ -131,8 +155,8 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); } - WxPayOrder payOrder = wxPayOrderMapper.selectById(sharingOrder.getOrderId()); - WxAppinfo appInfo = getAppinfo(payOrder.getTenantId(),payOrder.getPayVendor()); + WxProfitShareAppInoDto dto = getAppinfo(sharingOrder); + WxAppinfo appInfo = dto.getAppinfo(); WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); List receivers; @@ -166,66 +190,18 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); } - //分账提交 - WxProfitSharingP psCmd = new WxProfitSharingP(); - psCmd.setMch_id(payAccount.getMchId()); - psCmd.setSub_mch_id(payAccount.getSubMchId()); - psCmd.setAppid(appInfo.getParentAppId()); - psCmd.setSub_appid(appInfo.getAppId()); - psCmd.setNonce_str(Utility.generate32UUID()); - psCmd.setTransaction_id(sharingOrder.getTransactionId()); - psCmd.setOut_order_no(sharingOrder.getId().toString()); - psCmd.setSign_type("HMAC-SHA256"); - psCmd.setReceivers(sharingOrder.getReceivers()); - - String response; - try { - psCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psCmd), payAccount.getApiKey())); - logger.info("request:" + psCmd.toString()); - if(sharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode())) { - response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId()); - } else if(sharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode())) { - response = WxProfitSharing.pushMultiOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId()); - } else { - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); - } - } catch (Exception e) { - sharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode()); - sharingOrder.setErrorMsg("REDO:"+ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage()); - sharingOrder.setUpdateTime(new Date()); - wxProfitSharingOrderMapper.updateById(sharingOrder); - return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED); - } - - logger.info("response: " + response); - Map returnMap = WxPayment.xmlToMap(response); - String return_code = returnMap.get("return_code"); - - if (!"SUCCESS".equals(return_code)) { - sharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode()); - sharingOrder.setErrorMsg("REDO:"+returnMap.get("return_msg")); - sharingOrder.setUpdateTime(new Date()); - wxProfitSharingOrderMapper.updateById(sharingOrder); - return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); - } - - if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){ - sharingOrder.setErrorMsg("REDO:"+ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage()); - sharingOrder.setUpdateTime(new Date()); - wxProfitSharingOrderMapper.updateById(sharingOrder); - return new ResultData(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode()); - } - - String result_code = returnMap.get("result_code"); - if (!"SUCCESS".equals(result_code)) { - sharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode()); - sharingOrder.setUpdateTime(new Date()); - sharingOrder.setErrorMsg("REDO:"+returnMap.get("err_code_des")); + + PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(dto.getPayWay()).haveReciversShare(appInfo, payAccount, frecord, + sharingOrder.getTransactionId(), JSONArray.parseArray(JSON.toJSONString(receivers)), EnumProfitSharingOrderType.getEnum(sharingOrder.getType())); + if (!shareResult.isSuccess()) { + sharingOrder.setSharingStatus(shareResult.getCode()); + sharingOrder.setErrorMsg("REDO:"+shareResult.getMsg()); + sharingOrder.setUpdateTime(new Date()); wxProfitSharingOrderMapper.updateById(sharingOrder); - return new ResultData(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("err_code_des")); + return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),sharingOrder.getErrorMsg()); } - - sharingOrder.setSharingOrderNo(returnMap.get("order_id")); + + sharingOrder.setSharingOrderNo(shareResult.getShareOrderNo()); sharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); sharingOrder.setErrorMsg("REDO:重试分账成功"); sharingOrder.setUpdateTime(new Date()); @@ -233,8 +209,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ for (WxProfitSharingResult result:resultList) { wxProfitSharingResultMapper.insert(result); } - - return new ResultData(returnMap); + return new ResultData(shareResult.getData()); } @@ -380,22 +355,8 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ WxProfitSharingOrder record = new WxProfitSharingOrder(); - WxAppinfo appInfo; - if (wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()) - ||wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode())){ - WxPayOrder wxPayOrder = wxPayOrderMapper.selectById(wxProfitSharingOrder.getOrderId()); - if (wxPayOrder == null) - return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); - appInfo = getAppinfo(wxPayOrder.getTenantId(),wxPayOrder.getPayVendor()); - } else if(wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode()) - ||wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI_FINISH.getCode())){ - WxCardSpend wxCardSpend = wxCardSpendMapper.selectById(wxProfitSharingOrder.getOrderId()); - if (wxCardSpend == null) - return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); - appInfo = getAppinfo(wxCardSpend.getTenantId(),EnumCardSpendFrom.getPayWay(wxCardSpend.getPayFrom()).getCode()); - } else { - return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_UNKNOWN_TYPE); - } + WxProfitShareAppInoDto dto = getAppinfo(wxProfitSharingOrder); + WxAppinfo appInfo = dto.getAppinfo(); WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); //是否已创建分账订单 @@ -404,46 +365,16 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ if (record == null) return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); - //分账查询提交 - WxProfitSharingQueryP wxProfitSharingQueryP = new WxProfitSharingQueryP();; - wxProfitSharingQueryP.setMch_id(payAccount.getMchId()); - wxProfitSharingQueryP.setSub_mch_id(payAccount.getSubMchId()); - wxProfitSharingQueryP.setNonce_str(Utility.generate32UUID()); - wxProfitSharingQueryP.setTransaction_id(wxProfitSharingOrder.getTransactionId()); - wxProfitSharingQueryP.setOut_order_no(record.getId().toString()); - wxProfitSharingQueryP.setSign_type("HMAC-SHA256"); - String response; - try { - wxProfitSharingQueryP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingQueryP),payAccount.getApiKey())); - response = WxProfitSharing.queryOrder(BeanUtils.toStringMap(wxProfitSharingQueryP), payAccount.getCertPath(), payAccount.getMchId()); - }catch (Exception e){ - return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getMessage()+e.getMessage()); - } - Map returnMap = WxPayment.xmlToMap(response); - String return_code = returnMap.get("return_code"); - if (!"SUCCESS".equals(return_code)) { - return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); - } - - if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){ - return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID); - } - - String result_code = returnMap.get("result_code"); - if (!"SUCCESS".equals(result_code)) { - return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_APPLY_FAILED.getCode(), returnMap.get("err_code_des")); - } - - String out_order_no = returnMap.get("out_order_no"); - if (StringUtils.isBlank(out_order_no) || !out_order_no.equals(record.getId().toString())){ - return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID); + PayShareQueryResult shareResult = payServiceFactory.getPayShareAdapterService(dto.getPayWay()).shareQuery(appInfo, payAccount, record); + if (!shareResult.isSuccess()) { + throw new MallinkException(shareResult.getCode(),shareResult.getMsg()); } - - record.setSharingStatus((Integer) statusMap.get(returnMap.get("status"))); + + record.setSharingStatus(shareResult.getCode()); record.setUpdateTime(new Date()); wxProfitSharingOrderMapper.updateById(record); - String receivers = returnMap.get("receivers"); + String receivers = shareResult.getReceivers(); if (receivers != null) { JSONArray jReceivers = JSONArray.parseArray(receivers); @@ -509,7 +440,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ } } } - return new ResultData(returnMap); + return new ResultData(shareResult.getData()); } // 分账完结 diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java index ce13de44b..d65cc639e 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java @@ -12,6 +12,7 @@ import com.iformall.enums.EnumProfitSharingOrderType; import com.iformall.enums.EnumProfitSharingReceiverType; import com.iformall.exception.MallinkException; import com.iformall.service.pay.service.share.entity.ShareAccountResult; +import com.iformall.service.pay.service.share.entity.PayShareQueryResult; import com.iformall.service.pay.service.share.entity.PayShareResult; import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; @@ -57,6 +58,17 @@ public interface PayShareAdapterService { */ public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,JSONArray receivers,EnumProfitSharingOrderType shareType ) throws MallinkException; + /** + * 分账结果查询 + * @param appInfo + * @param payAccount + * @param record + * @return + * @throws MallinkException + */ + public PayShareQueryResult shareQuery(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record) throws MallinkException; + + /** * 获取分账账号类型 * @param accountType diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareQueryResult.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareQueryResult.java new file mode 100644 index 000000000..878cbc1f9 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareQueryResult.java @@ -0,0 +1,22 @@ +package com.iformall.service.pay.service.share.entity; + +import java.io.Serializable; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class PayShareQueryResult implements Serializable{ + + private static final long serialVersionUID = -3701322871877301001L; + + private boolean isSuccess; + private Integer code; + private String msg; + private Object data; + private String receivers;//数组字符串,平台查询返回的分账账户列表 + + + +} diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareResult.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareResult.java index 4d76cd443..044326a76 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareResult.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareResult.java @@ -16,7 +16,4 @@ public class PayShareResult implements Serializable{ private String msg; private Object data; private String shareOrderNo; - - - } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java index eec4c1cc0..488aae2a7 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java @@ -37,10 +37,12 @@ import com.iformall.pay.WxPayment; import com.iformall.pay.WxProfitSharing; import com.iformall.pay.WxProfitSharingFinishP; import com.iformall.pay.WxProfitSharingP; +import com.iformall.pay.WxProfitSharingQueryP; import com.iformall.pay.WxProfitSharingReceiverP; import com.iformall.service.pay.service.share.PayShareAdapterService; import com.iformall.service.pay.service.share.PayShareBaseAdapterService; import com.iformall.service.pay.service.share.entity.ShareAccountResult; +import com.iformall.service.pay.service.share.entity.PayShareQueryResult; import com.iformall.service.pay.service.share.entity.PayShareResult; import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; import com.iformall.utils.BeanUtils; @@ -53,6 +55,13 @@ import lombok.extern.slf4j.Slf4j; @Service public class WxPayShareService extends PayShareBaseAdapterService{ + final JSONObject statusMap = JSON.parseObject( + "{\"ACCEPTED\":3," + + "\"PROCESSING\": 4," + + "\"FINISHED\": 5," + + "\"CLOSED\": 6}"); + + @Override public Integer getSubsidyType() { return EnumMerchantSubsidyType.WECHAT.getCode(); @@ -155,6 +164,46 @@ public class WxPayShareService extends PayShareBaseAdapterService{ return new PayShareResult(true, null, "success",returnMap, returnMap.get("order_id")); } + @Override + public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException { + WxProfitSharingQueryP wxProfitSharingQueryP = new WxProfitSharingQueryP();; + wxProfitSharingQueryP.setMch_id(payAccount.getMchId()); + wxProfitSharingQueryP.setSub_mch_id(payAccount.getSubMchId()); + wxProfitSharingQueryP.setNonce_str(Utility.generate32UUID()); + wxProfitSharingQueryP.setTransaction_id(record.getTransactionId()); + wxProfitSharingQueryP.setOut_order_no(record.getId().toString()); + wxProfitSharingQueryP.setSign_type("HMAC-SHA256"); + String response; + try { + wxProfitSharingQueryP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingQueryP),payAccount.getApiKey())); + response = WxProfitSharing.queryOrder(BeanUtils.toStringMap(wxProfitSharingQueryP), payAccount.getCertPath(), payAccount.getMchId()); + }catch (Exception e){ + throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getMessage()+e.getMessage()); + } + Map returnMap = WxPayment.xmlToMap(response); + String return_code = returnMap.get("return_code"); + if (!"SUCCESS".equals(return_code)) { + throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); + } + + if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){ + throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID); + } + + String result_code = returnMap.get("result_code"); + if (!"SUCCESS".equals(result_code)) { + throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_APPLY_FAILED.getCode(), returnMap.get("err_code_des")); + } + + String out_order_no = returnMap.get("out_order_no"); + if (StringUtils.isBlank(out_order_no) || !out_order_no.equals(record.getId().toString())){ + throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID.getCode(),"out_order_no:["+out_order_no+"] WxProfitSharingOrder:["+record.getId()+"]"); + } + + Integer code = (Integer) statusMap.get(returnMap.get("status")); + return new PayShareQueryResult(true, code, "success",returnMap, returnMap.get("receivers")); + } + @Autowired WxAppinfoMapper wxAppinfoMapper; @@ -379,4 +428,6 @@ public class WxPayShareService extends PayShareBaseAdapterService{ return new ShareAccountResult(true, null, "success", returnMap); } + + }