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

[分账][修复]:当一个收款账户被多个商家使用,删除其中一个,不能从微信服务器删除此账户

release_toaliyun_real
hupeng 7 лет назад
Родитель
Сommit
5e39c6a8e1
1 измененных файлов: 58 добавлений и 40 удалений
  1. +58
    -40
      mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingReceiverServiceImpl.java

+ 58
- 40
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<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.setUpdateTime(new Date());
wxProfitSharingReceiverMapper.updateByPrimaryKeySelective(receiver);
return new ResultData(returnMap);
return new ResultData();
}

@Override


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