| @@ -30,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @@ -186,55 +187,72 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv | |||||
| if (receiver == null) | if (receiver == null) | ||||
| return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage()); | 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<String, String> 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<WxProfitSharingReceiver> 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<String, String> 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.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode()); | ||||
| receiver.setUpdateTime(new Date()); | receiver.setUpdateTime(new Date()); | ||||
| wxProfitSharingReceiverMapper.updateByPrimaryKeySelective(receiver); | wxProfitSharingReceiverMapper.updateByPrimaryKeySelective(receiver); | ||||
| return new ResultData(returnMap); | |||||
| return new ResultData(); | |||||
| } | } | ||||
| @Override | @Override | ||||