Просмотр исходного кода

[分账账户][修改][同一个商场下有不同商户使用同一个账户不能删除微信账户]

release_toaliyun_real
gongbiao 6 лет назад
Родитель
Сommit
3b7a214e91
1 измененных файлов: 65 добавлений и 50 удалений
  1. +65
    -50
      mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java

+ 65
- 50
mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java Просмотреть файл

@@ -117,8 +117,9 @@ public class WxProfitSharingReceiverServiceImpl implements WxProfitSharingReceiv
receiver.setMerchantId(merchant.getId());
receiver.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode());
receiver.setId(IdWorker.get().nextId());
receiver.setCreateTime(new Date());
receiver.setUpdateTime(new Date());
Date date = new Date();
receiver.setCreateTime(date);
receiver.setUpdateTime(date);
receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode());
receiver.setIsUse(EnumProfitSharingUse.APPLY.getCode());
//passed from uplevel
@@ -258,61 +259,75 @@ 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<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(receiver.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("err_code_des"));
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("err_code_des"));
}
logger.error(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getMessage() + returnMap.get("err_code_des"));
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_DEL_FAILED.getCode(), returnMap.get("err_code_des"));
}

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);
receiver.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_INVALID.getCode());
receiver.setUpdateTime(new Date());
wxProfitSharingReceiverMapper.updateByPrimaryKeySelective(receiver);

//发送短信
if (send.equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) {
sendMsgByType(EnumMsgModel.DELETE_SHARING_ACCOUNT_NOTIFY_MERCHANT.getCode(), receiver.getMerchantId(), receiver.getReceiverAccount(), receiver.getTenantId());
//发送短信
if (send.equals(EnumMsgSend.MSG_SEND_IMMEDIATELY.getCode())) {
sendMsgByType(EnumMsgModel.DELETE_SHARING_ACCOUNT_NOTIFY_MERCHANT.getCode(), receiver.getMerchantId(), receiver.getReceiverAccount(), receiver.getTenantId());
}
}

return new ResultData();
}



Загрузка…
Отмена
Сохранить