From 5e39c6a8e14a4aa05ce72fd7e6c161516fcee649 Mon Sep 17 00:00:00 2001 From: hupeng Date: Tue, 13 Nov 2018 13:55:36 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=88=86=E8=B4=A6][=E4=BF=AE=E5=A4=8D]:?= =?UTF-8?q?=E5=BD=93=E4=B8=80=E4=B8=AA=E6=94=B6=E6=AC=BE=E8=B4=A6=E6=88=B7?= =?UTF-8?q?=E8=A2=AB=E5=A4=9A=E4=B8=AA=E5=95=86=E5=AE=B6=E4=BD=BF=E7=94=A8?= =?UTF-8?q?,=E5=88=A0=E9=99=A4=E5=85=B6=E4=B8=AD=E4=B8=80=E4=B8=AA,?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E4=BB=8E=E5=BE=AE=E4=BF=A1=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E5=88=A0=E9=99=A4=E6=AD=A4=E8=B4=A6=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WxProfitSharingReceiverServiceImpl.java | 98 +++++++++++-------- 1 file changed, 58 insertions(+), 40 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java index c28b8fb11..852829f09 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java @@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Date; +import java.util.List; import java.util.Map; @@ -186,55 +187,72 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv if (receiver == null) return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage()); - //删除分账账户 - WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); - wxProfitSharingReceiverP.setAppid(appInfo.getParentAppId()); - wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); - wxProfitSharingReceiverP.setSub_appid(appInfo.getAppId()); - wxProfitSharingReceiverP.setSub_mch_id(payAccount.getSubMchId()); - 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) { - logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + e.getMessage()); - return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED, e.getMessage()); - } - Map returnMap = WxPayment.xmlToMap(response); - String return_code = returnMap.get("return_code"); - if (!"SUCCESS".equals(return_code)) { - logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("return_msg")); - return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("return_msg")); - } + //检查此接受者是否注册在同一个商场的别的商户下 + + final WxProfitSharingReceiver receiverParam = receiver; + WxProfitSharingReceiver params = new WxProfitSharingReceiver(); + params.setTenantId(merchant.getTenantId()); + params.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode()); + List receiverList = wxProfitSharingReceiverMapper.findList(params); + if (receiverList.stream().anyMatch(r -> ( + r.getReceiverType().equals(receiverParam.getReceiverType()) && + r.getReceiverAccount().equals(receiverParam.getReceiverAccount()) && + r.getTrueName().equals(receiverParam.getTrueName()) && + !r.getMerchantId().equals(receiverParam.getMerchantId()) + ))) { + //还有别的商户使用这个账号,不从微信服务器申请删除 + } else { + //删除分账账户从微信服务器 + WxProfitSharingReceiverP wxProfitSharingReceiverP = new WxProfitSharingReceiverP(); + wxProfitSharingReceiverP.setAppid(appInfo.getParentAppId()); + wxProfitSharingReceiverP.setMch_id(payAccount.getMchId()); + wxProfitSharingReceiverP.setSub_appid(appInfo.getAppId()); + wxProfitSharingReceiverP.setSub_mch_id(payAccount.getSubMchId()); + 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) { + logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + e.getMessage()); + return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED, e.getMessage()); + } + Map returnMap = WxPayment.xmlToMap(response); + String return_code = returnMap.get("return_code"); + if (!"SUCCESS".equals(return_code)) { + logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("return_msg")); + return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("return_msg")); + } - String result_code = returnMap.get("result_code"); - if (!"SUCCESS".equals(result_code)) { + 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.updateByPrimaryKeySelective(receiver); + if (returnMap.get("err_code").contains("USER_NOT_EXIST")) { + receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode()); + receiver.setUpdateTime(new Date()); + wxProfitSharingReceiverMapper.updateByPrimaryKeySelective(receiver); + } + logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("result_msg")); + return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("result_msg")); } - logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("result_msg")); - return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("result_msg")); - } - if (!WxPayment.verifyNotifyHMAC(returnMap, payAccount.getApiKey())) { - logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage()); - return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), "verifyNotifyHMAC"); + if (!WxPayment.verifyNotifyHMAC(returnMap, payAccount.getApiKey())) { + logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage()); + return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), "verifyNotifyHMAC"); + } } receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode()); receiver.setUpdateTime(new Date()); wxProfitSharingReceiverMapper.updateByPrimaryKeySelective(receiver); - return new ResultData(returnMap); + return new ResultData(); } @Override