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

fix pay v3

release_toaliyun_real
zhengfangyuan 3 лет назад
Родитель
Сommit
c9a9d85bf9
3 измененных файлов: 143 добавлений и 106 удалений
  1. +126
    -0
      mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareBaseAdapterService.java
  2. +3
    -102
      mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java
  3. +14
    -4
      mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java

+ 126
- 0
mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareBaseAdapterService.java Просмотреть файл

@@ -1,15 +1,34 @@
package com.iformall.service.pay.service.share; package com.iformall.service.pay.service.share;


import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils; import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils;
import com.iformall.common.ErrorCode; import com.iformall.common.ErrorCode;
import com.iformall.domain.dto.WxSharingOrderDto; 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.domain.po.WxProfitSharingReceiver;
import com.iformall.enums.EnumProfitSharingReceiverStatus;
import com.iformall.enums.EnumProfitSharingReceiverType; import com.iformall.enums.EnumProfitSharingReceiverType;
import com.iformall.exception.MallinkException; 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.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{ public abstract class PayShareBaseAdapterService implements PayShareAdapterService{


@Override @Override
@@ -114,5 +133,112 @@ public abstract class PayShareBaseAdapterService implements PayShareAdapterServi
}); });
return receivers.toJSONString(); 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<String, String> 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<String, String> 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);
}


} }

+ 3
- 102
mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v2/WxPayShareService.java Просмотреть файл

@@ -323,114 +323,15 @@ public class WxPayShareService extends PayShareBaseAdapterService{


@Override @Override
public ShareAccountResult createShareAccount(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingReceiver receiver) { 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<String, String> 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 @Autowired
WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper; WxProfitSharingReceiverMapper wxProfitSharingReceiverMapper;
@Override @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<String, String> 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 @Override


+ 14
- 4
mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/v3/WxPayShareV3Service.java Просмотреть файл

@@ -330,8 +330,13 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{


@Override @Override
public ShareAccountResult createShareAccount(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingReceiver receiver) { 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 @Autowired
@@ -340,8 +345,13 @@ public class WxPayShareV3Service extends PayShareBaseAdapterService{
@Override @Override
public ShareAccountResult deleteShareAccount(WxAppinfo appInfo, WxPayAccount payAccount, public ShareAccountResult deleteShareAccount(WxAppinfo appInfo, WxPayAccount payAccount,
WxProfitSharingReceiver receiver) { 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 @Override


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