Преглед изворни кода

分账接口修改

release_toaliyun_real
xiaohanzi пре 5 година
родитељ
комит
1b34078a71
10 измењених фајлова са 159 додато и 125 уклоњено
  1. +1
    -0
      mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoSchedule.java
  2. +21
    -0
      mallinkService/src/main/java/com/iformall/domain/dto/WxProfitShareAppInoDto.java
  3. +0
    -1
      mallinkService/src/main/java/com/iformall/domain/po/WxAppinfo.java
  4. +0
    -1
      mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingOrder.java
  5. +1
    -0
      mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java
  6. +51
    -120
      mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java
  7. +12
    -0
      mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java
  8. +22
    -0
      mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareQueryResult.java
  9. +0
    -3
      mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareResult.java
  10. +51
    -0
      mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java

+ 1
- 0
mallinkSchedule/src/main/java/com/iformall/schedule/SharingOrderRedoSchedule.java Прегледај датотеку

@@ -4,6 +4,7 @@ import com.iformall.common.ErrorCode;
import com.iformall.common.ResultData; import com.iformall.common.ResultData;
import com.iformall.domain.dto.WxSharingOrderDto; import com.iformall.domain.dto.WxSharingOrderDto;
import com.iformall.domain.po.WxProfitSharingOrder; import com.iformall.domain.po.WxProfitSharingOrder;
import com.iformall.enums.EnumPayWay;
import com.iformall.enums.EnumProfitSharingOrderStatus; import com.iformall.enums.EnumProfitSharingOrderStatus;
import com.iformall.enums.EnumProfitSharingOrderType; import com.iformall.enums.EnumProfitSharingOrderType;
import com.iformall.mapper.WxPayOrderMapper; import com.iformall.mapper.WxPayOrderMapper;


+ 21
- 0
mallinkService/src/main/java/com/iformall/domain/dto/WxProfitShareAppInoDto.java Прегледај датотеку

@@ -0,0 +1,21 @@
package com.iformall.domain.dto;

import java.io.Serializable;

import com.iformall.domain.po.WxAppinfo;

import lombok.Data;

@Data
public class WxProfitShareAppInoDto implements Serializable{

/**
*
*/
private static final long serialVersionUID = -8159673293532875743L;
private WxAppinfo appinfo;
private Integer payWay;

}

+ 0
- 1
mallinkService/src/main/java/com/iformall/domain/po/WxAppinfo.java Прегледај датотеку

@@ -44,5 +44,4 @@ public class WxAppinfo extends BaseTenantEntity {
private Integer enable; private Integer enable;
@io.swagger.annotations.ApiModelProperty(value="app平台 EnumAppPlat ",name="plat") @io.swagger.annotations.ApiModelProperty(value="app平台 EnumAppPlat ",name="plat")
private Integer plat; private Integer plat;

} }

+ 0
- 1
mallinkService/src/main/java/com/iformall/domain/po/WxProfitSharingOrder.java Прегледај датотеку

@@ -41,5 +41,4 @@ public class WxProfitSharingOrder extends TenantEntity {
@io.swagger.annotations.ApiModelProperty(value="创建时间",name="createTime") @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createTime")
private Date createTime; private Date createTime;



} }

+ 1
- 0
mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java Прегледај датотеку

@@ -8,6 +8,7 @@ import com.iformall.domain.po.WxProfitSharingOrder;
import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.po.base.TenantEntity;
import com.iformall.domain.vo.WxProfitSharingOrderQueryVo; import com.iformall.domain.vo.WxProfitSharingOrderQueryVo;
import com.iformall.domain.vo.WxProfitSharingOrderVo; import com.iformall.domain.vo.WxProfitSharingOrderVo;
import com.iformall.enums.EnumPayWay;


import java.util.Map; import java.util.Map;




+ 51
- 120
mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java Прегледај датотеку

@@ -9,6 +9,7 @@ import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode; import com.iformall.common.ErrorCode;
import com.iformall.common.IdWorker; import com.iformall.common.IdWorker;
import com.iformall.common.ResultData; import com.iformall.common.ResultData;
import com.iformall.domain.dto.WxProfitShareAppInoDto;
import com.iformall.domain.dto.WxSharingOrderDto; import com.iformall.domain.dto.WxSharingOrderDto;
import com.iformall.domain.po.*; import com.iformall.domain.po.*;
import com.iformall.domain.po.base.TenantEntity; import com.iformall.domain.po.base.TenantEntity;
@@ -21,6 +22,7 @@ import com.iformall.mapper.*;
import com.iformall.pay.*; import com.iformall.pay.*;
import com.iformall.service.WxProfitSharingOrderService; import com.iformall.service.WxProfitSharingOrderService;
import com.iformall.service.pay.PayServiceFactory; import com.iformall.service.pay.PayServiceFactory;
import com.iformall.service.pay.service.share.entity.PayShareQueryResult;
import com.iformall.service.pay.service.share.entity.PayShareResult; import com.iformall.service.pay.service.share.entity.PayShareResult;
import com.iformall.utils.BeanUtils; import com.iformall.utils.BeanUtils;
import com.iformall.utils.DateUtils; import com.iformall.utils.DateUtils;
@@ -93,11 +95,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
"\"ORDERNOTEXIST\":{\"detail\":\"分账单不存在\",\"reason\":\"订单号错误或分账单号错误\",\"resolution\":\"请检查订单号或分账单号是否有错误\"}}"); "\"ORDERNOTEXIST\":{\"detail\":\"分账单不存在\",\"reason\":\"订单号错误或分账单号错误\",\"resolution\":\"请检查订单号或分账单号是否有错误\"}}");




final JSONObject statusMap = JSON.parseObject(
"{\"ACCEPTED\":3," +
"\"PROCESSING\": 4," +
"\"FINISHED\": 5," +
"\"CLOSED\": 6}");



final JSONObject resultStatusMap = JSON.parseObject( final JSONObject resultStatusMap = JSON.parseObject(
"{\"PENDING\": 1," + "{\"PENDING\": 1," +
@@ -120,6 +118,32 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
return wxAppinfo; return wxAppinfo;
} }


private WxProfitShareAppInoDto getAppinfo(WxProfitSharingOrder wxProfitSharingOrder) {
WxAppinfo appinfo;
Integer payWay;
if (wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode())
||wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode())){
WxPayOrder wxPayOrder = wxPayOrderMapper.selectById(wxProfitSharingOrder.getOrderId());
if (wxPayOrder == null)
throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(),"wxProfitSharingOrder["+wxProfitSharingOrder.getId()+"] 没有payOrder信息.");
appinfo = getAppinfo(wxPayOrder.getTenantId(),wxPayOrder.getPayVendor());
payWay = wxPayOrder.getPayVendor();
} else if(wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode())
||wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI_FINISH.getCode())){
WxCardSpend wxCardSpend = wxCardSpendMapper.selectById(wxProfitSharingOrder.getOrderId());
if (wxCardSpend == null)
throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND.getCode(),"wxProfitSharingOrder["+wxProfitSharingOrder.getId()+"] 没有WxCardSpend信息.");
appinfo = getAppinfo(wxCardSpend.getTenantId(),EnumCardSpendFrom.getPayWay(wxCardSpend.getPayFrom()).getCode());
payWay = EnumCardSpendFrom.getPayWay(wxCardSpend.getPayFrom()).getCode();
} else {
throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_UNKNOWN_TYPE);
}
WxProfitShareAppInoDto rt = new WxProfitShareAppInoDto();
rt.setAppinfo(appinfo);
rt.setPayWay(payWay);
return rt;
}


@Override @Override
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) @Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
@@ -131,8 +155,8 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR); return new ResultData(ErrorCode.SYS_PARAMETER_ERROR);
} }


WxPayOrder payOrder = wxPayOrderMapper.selectById(sharingOrder.getOrderId());
WxAppinfo appInfo = getAppinfo(payOrder.getTenantId(),payOrder.getPayVendor());
WxProfitShareAppInoDto dto = getAppinfo(sharingOrder);
WxAppinfo appInfo = dto.getAppinfo();
WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId());


List<JSONObject> receivers; List<JSONObject> receivers;
@@ -166,66 +190,18 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID); return new ResultData(ErrorCode.PROFIT_SHARING_RECEIVER_INVALID);
} }


//分账提交
WxProfitSharingP psCmd = new WxProfitSharingP();
psCmd.setMch_id(payAccount.getMchId());
psCmd.setSub_mch_id(payAccount.getSubMchId());
psCmd.setAppid(appInfo.getParentAppId());
psCmd.setSub_appid(appInfo.getAppId());
psCmd.setNonce_str(Utility.generate32UUID());
psCmd.setTransaction_id(sharingOrder.getTransactionId());
psCmd.setOut_order_no(sharingOrder.getId().toString());
psCmd.setSign_type("HMAC-SHA256");
psCmd.setReceivers(sharingOrder.getReceivers());

String response;
try {
psCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psCmd), payAccount.getApiKey()));
logger.info("request:" + psCmd.toString());
if(sharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode())) {
response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId());
} else if(sharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode())) {
response = WxProfitSharing.pushMultiOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId());
} else {
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR);
}
} catch (Exception e) {
sharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode());
sharingOrder.setErrorMsg("REDO:"+ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage());
sharingOrder.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(sharingOrder);
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED);
}

logger.info("response: " + response);
Map<String, String> returnMap = WxPayment.xmlToMap(response);
String return_code = returnMap.get("return_code");

if (!"SUCCESS".equals(return_code)) {
sharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode());
sharingOrder.setErrorMsg("REDO:"+returnMap.get("return_msg"));
sharingOrder.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(sharingOrder);
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg"));
}

if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){
sharingOrder.setErrorMsg("REDO:"+ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage());
sharingOrder.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(sharingOrder);
return new ResultData(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode());
}

String result_code = returnMap.get("result_code");
if (!"SUCCESS".equals(result_code)) {
sharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode());
sharingOrder.setUpdateTime(new Date());
sharingOrder.setErrorMsg("REDO:"+returnMap.get("err_code_des"));
PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(dto.getPayWay()).haveReciversShare(appInfo, payAccount, frecord,
sharingOrder.getTransactionId(), JSONArray.parseArray(JSON.toJSONString(receivers)), EnumProfitSharingOrderType.getEnum(sharingOrder.getType()));
if (!shareResult.isSuccess()) {
sharingOrder.setSharingStatus(shareResult.getCode());
sharingOrder.setErrorMsg("REDO:"+shareResult.getMsg());
sharingOrder.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(sharingOrder); wxProfitSharingOrderMapper.updateById(sharingOrder);
return new ResultData(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("err_code_des"));
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),sharingOrder.getErrorMsg());
} }
sharingOrder.setSharingOrderNo(returnMap.get("order_id"));
sharingOrder.setSharingOrderNo(shareResult.getShareOrderNo());
sharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode()); sharingOrder.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode());
sharingOrder.setErrorMsg("REDO:重试分账成功"); sharingOrder.setErrorMsg("REDO:重试分账成功");
sharingOrder.setUpdateTime(new Date()); sharingOrder.setUpdateTime(new Date());
@@ -233,8 +209,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
for (WxProfitSharingResult result:resultList) { for (WxProfitSharingResult result:resultList) {
wxProfitSharingResultMapper.insert(result); wxProfitSharingResultMapper.insert(result);
} }

return new ResultData(returnMap);
return new ResultData(shareResult.getData());
} }




@@ -380,22 +355,8 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ


WxProfitSharingOrder record = new WxProfitSharingOrder(); WxProfitSharingOrder record = new WxProfitSharingOrder();


WxAppinfo appInfo;
if (wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode())
||wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode())){
WxPayOrder wxPayOrder = wxPayOrderMapper.selectById(wxProfitSharingOrder.getOrderId());
if (wxPayOrder == null)
return new ResultData(ErrorCode.ORDER_IS_NOT_FIND);
appInfo = getAppinfo(wxPayOrder.getTenantId(),wxPayOrder.getPayVendor());
} else if(wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode())
||wxProfitSharingOrder.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_MULTI_FINISH.getCode())){
WxCardSpend wxCardSpend = wxCardSpendMapper.selectById(wxProfitSharingOrder.getOrderId());
if (wxCardSpend == null)
return new ResultData(ErrorCode.ORDER_IS_NOT_FIND);
appInfo = getAppinfo(wxCardSpend.getTenantId(),EnumCardSpendFrom.getPayWay(wxCardSpend.getPayFrom()).getCode());
} else {
return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_UNKNOWN_TYPE);
}
WxProfitShareAppInoDto dto = getAppinfo(wxProfitSharingOrder);
WxAppinfo appInfo = dto.getAppinfo();
WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId()); WxPayAccount payAccount = wxPayAccountMapper.selectById(appInfo.getPayId());


//是否已创建分账订单 //是否已创建分账订单
@@ -404,46 +365,16 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
if (record == null) if (record == null)
return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); return new ResultData(ErrorCode.ORDER_IS_NOT_FIND);


//分账查询提交
WxProfitSharingQueryP wxProfitSharingQueryP = new WxProfitSharingQueryP();;
wxProfitSharingQueryP.setMch_id(payAccount.getMchId());
wxProfitSharingQueryP.setSub_mch_id(payAccount.getSubMchId());
wxProfitSharingQueryP.setNonce_str(Utility.generate32UUID());
wxProfitSharingQueryP.setTransaction_id(wxProfitSharingOrder.getTransactionId());
wxProfitSharingQueryP.setOut_order_no(record.getId().toString());
wxProfitSharingQueryP.setSign_type("HMAC-SHA256");
String response;
try {
wxProfitSharingQueryP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingQueryP),payAccount.getApiKey()));
response = WxProfitSharing.queryOrder(BeanUtils.toStringMap(wxProfitSharingQueryP), payAccount.getCertPath(), payAccount.getMchId());
}catch (Exception e){
return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getMessage()+e.getMessage());
}
Map<String, String> returnMap = WxPayment.xmlToMap(response);
String return_code = returnMap.get("return_code");
if (!"SUCCESS".equals(return_code)) {
return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), returnMap.get("return_msg"));
}

if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){
return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID);
}

String result_code = returnMap.get("result_code");
if (!"SUCCESS".equals(result_code)) {
return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_APPLY_FAILED.getCode(), returnMap.get("err_code_des"));
}

String out_order_no = returnMap.get("out_order_no");
if (StringUtils.isBlank(out_order_no) || !out_order_no.equals(record.getId().toString())){
return new ResultData(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID);
PayShareQueryResult shareResult = payServiceFactory.getPayShareAdapterService(dto.getPayWay()).shareQuery(appInfo, payAccount, record);
if (!shareResult.isSuccess()) {
throw new MallinkException(shareResult.getCode(),shareResult.getMsg());
} }
record.setSharingStatus((Integer) statusMap.get(returnMap.get("status")));
record.setSharingStatus(shareResult.getCode());
record.setUpdateTime(new Date()); record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(record); wxProfitSharingOrderMapper.updateById(record);


String receivers = returnMap.get("receivers");
String receivers = shareResult.getReceivers();


if (receivers != null) { if (receivers != null) {
JSONArray jReceivers = JSONArray.parseArray(receivers); JSONArray jReceivers = JSONArray.parseArray(receivers);
@@ -509,7 +440,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
} }
} }
} }
return new ResultData(returnMap);
return new ResultData(shareResult.getData());
} }


// 分账完结 // 分账完结


+ 12
- 0
mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java Прегледај датотеку

@@ -12,6 +12,7 @@ import com.iformall.enums.EnumProfitSharingOrderType;
import com.iformall.enums.EnumProfitSharingReceiverType; import com.iformall.enums.EnumProfitSharingReceiverType;
import com.iformall.exception.MallinkException; import com.iformall.exception.MallinkException;
import com.iformall.service.pay.service.share.entity.ShareAccountResult; import com.iformall.service.pay.service.share.entity.ShareAccountResult;
import com.iformall.service.pay.service.share.entity.PayShareQueryResult;
import com.iformall.service.pay.service.share.entity.PayShareResult; import com.iformall.service.pay.service.share.entity.PayShareResult;
import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult;


@@ -57,6 +58,17 @@ public interface PayShareAdapterService {
*/ */
public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,JSONArray receivers,EnumProfitSharingOrderType shareType ) throws MallinkException; public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,JSONArray receivers,EnumProfitSharingOrderType shareType ) throws MallinkException;
/**
* 分账结果查询
* @param appInfo
* @param payAccount
* @param record
* @return
* @throws MallinkException
*/
public PayShareQueryResult shareQuery(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record) throws MallinkException;
/** /**
* 获取分账账号类型 * 获取分账账号类型
* @param accountType * @param accountType


+ 22
- 0
mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareQueryResult.java Прегледај датотеку

@@ -0,0 +1,22 @@
package com.iformall.service.pay.service.share.entity;

import java.io.Serializable;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class PayShareQueryResult implements Serializable{

private static final long serialVersionUID = -3701322871877301001L;

private boolean isSuccess;
private Integer code;
private String msg;
private Object data;
private String receivers;//数组字符串,平台查询返回的分账账户列表
}

+ 0
- 3
mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareResult.java Прегледај датотеку

@@ -16,7 +16,4 @@ public class PayShareResult implements Serializable{
private String msg; private String msg;
private Object data; private Object data;
private String shareOrderNo; private String shareOrderNo;
} }

+ 51
- 0
mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java Прегледај датотеку

@@ -37,10 +37,12 @@ import com.iformall.pay.WxPayment;
import com.iformall.pay.WxProfitSharing; import com.iformall.pay.WxProfitSharing;
import com.iformall.pay.WxProfitSharingFinishP; import com.iformall.pay.WxProfitSharingFinishP;
import com.iformall.pay.WxProfitSharingP; import com.iformall.pay.WxProfitSharingP;
import com.iformall.pay.WxProfitSharingQueryP;
import com.iformall.pay.WxProfitSharingReceiverP; import com.iformall.pay.WxProfitSharingReceiverP;
import com.iformall.service.pay.service.share.PayShareAdapterService; import com.iformall.service.pay.service.share.PayShareAdapterService;
import com.iformall.service.pay.service.share.PayShareBaseAdapterService; import com.iformall.service.pay.service.share.PayShareBaseAdapterService;
import com.iformall.service.pay.service.share.entity.ShareAccountResult; import com.iformall.service.pay.service.share.entity.ShareAccountResult;
import com.iformall.service.pay.service.share.entity.PayShareQueryResult;
import com.iformall.service.pay.service.share.entity.PayShareResult; import com.iformall.service.pay.service.share.entity.PayShareResult;
import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult;
import com.iformall.utils.BeanUtils; import com.iformall.utils.BeanUtils;
@@ -53,6 +55,13 @@ import lombok.extern.slf4j.Slf4j;
@Service @Service
public class WxPayShareService extends PayShareBaseAdapterService{ public class WxPayShareService extends PayShareBaseAdapterService{


final JSONObject statusMap = JSON.parseObject(
"{\"ACCEPTED\":3," +
"\"PROCESSING\": 4," +
"\"FINISHED\": 5," +
"\"CLOSED\": 6}");
@Override @Override
public Integer getSubsidyType() { public Integer getSubsidyType() {
return EnumMerchantSubsidyType.WECHAT.getCode(); return EnumMerchantSubsidyType.WECHAT.getCode();
@@ -155,6 +164,46 @@ public class WxPayShareService extends PayShareBaseAdapterService{
return new PayShareResult(true, null, "success",returnMap, returnMap.get("order_id")); return new PayShareResult(true, null, "success",returnMap, returnMap.get("order_id"));
} }


@Override
public PayShareQueryResult shareQuery(WxAppinfo appInfo, WxPayAccount payAccount, WxProfitSharingOrder record) throws MallinkException {
WxProfitSharingQueryP wxProfitSharingQueryP = new WxProfitSharingQueryP();;
wxProfitSharingQueryP.setMch_id(payAccount.getMchId());
wxProfitSharingQueryP.setSub_mch_id(payAccount.getSubMchId());
wxProfitSharingQueryP.setNonce_str(Utility.generate32UUID());
wxProfitSharingQueryP.setTransaction_id(record.getTransactionId());
wxProfitSharingQueryP.setOut_order_no(record.getId().toString());
wxProfitSharingQueryP.setSign_type("HMAC-SHA256");
String response;
try {
wxProfitSharingQueryP.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(wxProfitSharingQueryP),payAccount.getApiKey()));
response = WxProfitSharing.queryOrder(BeanUtils.toStringMap(wxProfitSharingQueryP), payAccount.getCertPath(), payAccount.getMchId());
}catch (Exception e){
throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getMessage()+e.getMessage());
}
Map<String, String> returnMap = WxPayment.xmlToMap(response);
String return_code = returnMap.get("return_code");
if (!"SUCCESS".equals(return_code)) {
throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_REQUEST_FAILED.getCode(), returnMap.get("return_msg"));
}

if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){
throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID);
}

String result_code = returnMap.get("result_code");
if (!"SUCCESS".equals(result_code)) {
throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_APPLY_FAILED.getCode(), returnMap.get("err_code_des"));
}

String out_order_no = returnMap.get("out_order_no");
if (StringUtils.isBlank(out_order_no) || !out_order_no.equals(record.getId().toString())){
throw new MallinkException(ErrorCode.PROFIT_SHARING_QUERY_RETURN_INVALID.getCode(),"out_order_no:["+out_order_no+"] WxProfitSharingOrder:["+record.getId()+"]");
}
Integer code = (Integer) statusMap.get(returnMap.get("status"));
return new PayShareQueryResult(true, code, "success",returnMap, returnMap.get("receivers"));
}
@Autowired @Autowired
WxAppinfoMapper wxAppinfoMapper; WxAppinfoMapper wxAppinfoMapper;
@@ -379,4 +428,6 @@ public class WxPayShareService extends PayShareBaseAdapterService{
return new ShareAccountResult(true, null, "success", returnMap); return new ShareAccountResult(true, null, "success", returnMap);
} }


} }

Loading…
Откажи
Сачувај