|
|
@@ -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); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |