diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareBaseAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareBaseAdapterService.java index 11d54f858..95454e6df 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareBaseAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareBaseAdapterService.java @@ -1,15 +1,34 @@ package com.iformall.service.pay.service.share; +import java.util.Date; import java.util.List; +import java.util.Map; + +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils; import com.iformall.common.ErrorCode; import com.iformall.domain.dto.WxSharingOrderDto; +import com.iformall.domain.po.WxAppinfo; +import com.iformall.domain.po.WxPayAccount; import com.iformall.domain.po.WxProfitSharingReceiver; +import com.iformall.enums.EnumProfitSharingReceiverStatus; import com.iformall.enums.EnumProfitSharingReceiverType; import com.iformall.exception.MallinkException; +import com.iformall.mapper.WxProfitSharingOrderMapper; +import com.iformall.mapper.WxProfitSharingReceiverMapper; +import com.iformall.pay.WxPayment; +import com.iformall.pay.WxProfitSharing; +import com.iformall.pay.WxProfitSharingReceiverP; import com.iformall.service.pay.service.share.entity.PayShareQueryResultReceivers; +import com.iformall.service.pay.service.share.entity.ShareAccountResult; +import com.iformall.service.pay.service.share.wx.v2.WxPayShareService; +import com.iformall.utils.BeanUtils; +import com.iformall.utils.Utility; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public abstract class PayShareBaseAdapterService implements PayShareAdapterService{ @Override @@ -114,5 +133,112 @@ public abstract class PayShareBaseAdapterService implements PayShareAdapterServi }); return receivers.toJSONString(); } + + protected ShareAccountResult _createShareAccount(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingReceiver receiver) { + WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); + if (StringUtils.isNotBlank(appInfo.getParentAppId())) { + wxProfitSharingReceiverP.setAppid(appInfo.getParentAppId()); + wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); + wxProfitSharingReceiverP.setSub_appid(appInfo.getAppId()); + wxProfitSharingReceiverP.setSub_mch_id(payAccount.getSubMchId()); + } else { + wxProfitSharingReceiverP.setAppid(appInfo.getAppId()); + wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); + } + wxProfitSharingReceiverP.setNonce_str(Utility.generate32UUID()); + wxProfitSharingReceiverP.setSign_type("HMAC-SHA256"); + + + JSONObject receiverJSON = new JSONObject(); + receiverJSON.put("type", EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage()); + receiverJSON.put("account", receiver.getReceiverAccount()); + receiverJSON.put("name", receiver.getTrueName()); + + wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString()); + String response; + try { + wxProfitSharingReceiverP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey())); + response = WxProfitSharing.addReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); + log.info(response); + } catch (Exception e) { + log.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + e.getMessage()); + return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), e.getMessage(), null); + } + Map returnMap = WxPayment.xmlToMap(response); + String return_code = returnMap.get("return_code"); + if (!"SUCCESS".equals(return_code)) { + log.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + returnMap.get("return_msg")+":"+JSON.toJSONString(returnMap)); + return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), returnMap.get("return_msg"), null); + } + + String result_code = returnMap.get("result_code"); + if (!"SUCCESS".equals(result_code)) { + log.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + returnMap.get("err_code_des")+":"+JSON.toJSONString(returnMap)); + return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), returnMap.get("err_code_des"), null); + } + + if (!WxPayment.verifyNotifyHMAC(returnMap, payAccount.getApiKey())) { + log.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + "verifyNotifyHMAC"+":"+JSON.toJSONString(returnMap)); + return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage(), null); + } + + return new ShareAccountResult(true, null, "success", returnMap); + } + + protected ShareAccountResult _deleteShareAccount(WxAppinfo appInfo, WxPayAccount payAccount,WxProfitSharingReceiver receiver,WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper) { + //删除分账账户从微信服务器 + WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); + if (StringUtils.isNotBlank(appInfo.getParentAppId())) { + wxProfitSharingReceiverP.setAppid(appInfo.getParentAppId()); + wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); + wxProfitSharingReceiverP.setSub_appid(appInfo.getAppId()); + wxProfitSharingReceiverP.setSub_mch_id(payAccount.getSubMchId()); + } else { + wxProfitSharingReceiverP.setAppid(appInfo.getAppId()); + wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); + } + wxProfitSharingReceiverP.setNonce_str(Utility.generate32UUID()); + wxProfitSharingReceiverP.setSign_type("HMAC-SHA256"); + + JSONObject receiverJSON = new JSONObject(); + receiverJSON.put("type", EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage()); + receiverJSON.put("account", receiver.getReceiverAccount()); + + wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString()); + String response; + try { + wxProfitSharingReceiverP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey())); + response = WxProfitSharing.delReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); + } catch (Exception e) { + log.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + e.getMessage()); + return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), e.getMessage(), null); + } + Map returnMap = WxPayment.xmlToMap(response); + String return_code = returnMap.get("return_code"); + if (!"SUCCESS".equals(return_code)) { + log.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("return_msg")+":"+JSON.toJSONString(returnMap)); + return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("return_msg"), null); + } + + String result_code = returnMap.get("result_code"); + if (!"SUCCESS".equals(result_code)) { + + if (returnMap.get("err_code").contains("USER_NOT_EXIST")) { + receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode()); + receiver.setUpdateTime(new Date()); + wxProfitSharingReceiverMapper.updateById(receiver); + } + log.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("err_code_des")+":"+JSON.toJSONString(returnMap)); + return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("err_code_des"), null); + } + + if (!WxPayment.verifyNotifyHMAC(returnMap, payAccount.getApiKey())) { + log.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage()+":"+JSON.toJSONString(returnMap)); + return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), "verifyNotifyHMAC", null); + } + + return new ShareAccountResult(true, null, "success", returnMap); + } + } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java index eaa32e724..9fb142956 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java @@ -323,114 +323,15 @@ public class WxPayShareService extends PayShareBaseAdapterService{ @Override public ShareAccountResult createShareAccount(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingReceiver receiver) { - WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); - if (StringUtils.isNotBlank(appInfo.getParentAppId())) { - wxProfitSharingReceiverP.setAppid(appInfo.getParentAppId()); - wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); - wxProfitSharingReceiverP.setSub_appid(appInfo.getAppId()); - wxProfitSharingReceiverP.setSub_mch_id(payAccount.getSubMchId()); - } else { - wxProfitSharingReceiverP.setAppid(appInfo.getAppId()); - wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); - } - wxProfitSharingReceiverP.setNonce_str(Utility.generate32UUID()); - wxProfitSharingReceiverP.setSign_type("HMAC-SHA256"); - - - JSONObject receiverJSON = new JSONObject(); - receiverJSON.put("type", EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage()); - receiverJSON.put("account", receiver.getReceiverAccount()); - receiverJSON.put("name", receiver.getTrueName()); - - wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString()); - String response; - try { - wxProfitSharingReceiverP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey())); - response = WxProfitSharing.addReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); - log.info(response); - } catch (Exception e) { - log.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + e.getMessage()); - return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), e.getMessage(), null); - } - Map returnMap = WxPayment.xmlToMap(response); - String return_code = returnMap.get("return_code"); - if (!"SUCCESS".equals(return_code)) { - log.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + returnMap.get("return_msg")+":"+JSON.toJSONString(returnMap)); - return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), returnMap.get("return_msg"), null); - } - - String result_code = returnMap.get("result_code"); - if (!"SUCCESS".equals(result_code)) { - log.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + returnMap.get("err_code_des")+":"+JSON.toJSONString(returnMap)); - return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), returnMap.get("err_code_des"), null); - } - - if (!WxPayment.verifyNotifyHMAC(returnMap, payAccount.getApiKey())) { - log.error(ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage() + "verifyNotifyHMAC"+":"+JSON.toJSONString(returnMap)); - return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getMessage(), null); - } - - return new ShareAccountResult(true, null, "success", returnMap); + return super._createShareAccount(appInfo, payAccount, receiver); } @Autowired WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper; @Override - public ShareAccountResult deleteShareAccount(WxAppinfo appInfo, WxPayAccount payAccount, - WxProfitSharingReceiver receiver) { - //删除分账账户从微信服务器 - WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); - if (StringUtils.isNotBlank(appInfo.getParentAppId())) { - wxProfitSharingReceiverP.setAppid(appInfo.getParentAppId()); - wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); - wxProfitSharingReceiverP.setSub_appid(appInfo.getAppId()); - wxProfitSharingReceiverP.setSub_mch_id(payAccount.getSubMchId()); - } else { - wxProfitSharingReceiverP.setAppid(appInfo.getAppId()); - wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); - } - wxProfitSharingReceiverP.setNonce_str(Utility.generate32UUID()); - wxProfitSharingReceiverP.setSign_type("HMAC-SHA256"); - - JSONObject receiverJSON = new JSONObject(); - receiverJSON.put("type", EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage()); - receiverJSON.put("account", receiver.getReceiverAccount()); - - wxProfitSharingReceiverP.setReceiver(receiverJSON.toJSONString()); - String response; - try { - wxProfitSharingReceiverP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingReceiverP), payAccount.getApiKey())); - response = WxProfitSharing.delReceiver(BeanUtils.toStringMap(wxProfitSharingReceiverP)); - } catch (Exception e) { - log.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + e.getMessage()); - return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), e.getMessage(), null); - } - Map returnMap = WxPayment.xmlToMap(response); - String return_code = returnMap.get("return_code"); - if (!"SUCCESS".equals(return_code)) { - log.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("return_msg")+":"+JSON.toJSONString(returnMap)); - return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("return_msg"), null); - } - - String result_code = returnMap.get("result_code"); - if (!"SUCCESS".equals(result_code)) { - - if (returnMap.get("err_code").contains("USER_NOT_EXIST")) { - receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode()); - receiver.setUpdateTime(new Date()); - wxProfitSharingReceiverMapper.updateById(receiver); - } - log.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("err_code_des")+":"+JSON.toJSONString(returnMap)); - return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("err_code_des"), null); - } - - if (!WxPayment.verifyNotifyHMAC(returnMap, payAccount.getApiKey())) { - log.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage()+":"+JSON.toJSONString(returnMap)); - return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), "verifyNotifyHMAC", null); - } - - return new ShareAccountResult(true, null, "success", returnMap); + public ShareAccountResult deleteShareAccount(WxAppinfo appInfo, WxPayAccount payAccount,WxProfitSharingReceiver receiver) { + return super._deleteShareAccount(appInfo, payAccount, receiver,wxProfitSharingReceiverMapper); } @Override diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java index 4d9554c31..4443645b8 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java @@ -330,8 +330,13 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ @Override public ShareAccountResult createShareAccount(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingReceiver receiver) { - return null; - + //直连模式 + if (payAccount.getMchType() == EnumPayMchType.DIRECT.getCode()) { + return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), "微信支付3.0直连模式下不支持", null); + //总分,跟2.0创建一样 + }else { + return super._createShareAccount(appInfo, payAccount, receiver); + } } @Autowired @@ -340,8 +345,13 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{ @Override public ShareAccountResult deleteShareAccount(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingReceiver receiver) { - return null; - + //直连模式 + if (payAccount.getMchType() == EnumPayMchType.DIRECT.getCode()) { + return new ShareAccountResult(false, ErrorCode.PROFIT_SHARING_RECEIVER_ADD_FAILED.getCode(), "微信支付3.0直连模式下不支持", null); + //总分 + }else { + return super._deleteShareAccount(appInfo, payAccount, receiver, wxProfitSharingReceiverMapper); + } } @Override