Procházet zdrojové kódy

update

release_toaliyun_real
xiaohanzi před 5 roky
rodič
revize
1f76657d59
18 změnil soubory, kde provedl 303 přidání a 168 odebrání
  1. +1
    -1
      mallinkService/src/main/java/com/iformall/service/WxCouponOrderService.java
  2. +2
    -2
      mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java
  3. +9
    -6
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java
  4. +4
    -4
      mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java
  5. +32
    -118
      mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java
  6. +25
    -6
      mallinkService/src/main/java/com/iformall/service/pay/PayServiceFactory.java
  7. +22
    -0
      mallinkService/src/main/java/com/iformall/service/pay/entity/PayShareResult.java
  8. +0
    -9
      mallinkService/src/main/java/com/iformall/service/pay/service/PayShareAdapterService.java
  9. +1
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/CDrivingPayService.java
  10. +1
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/CPassivePayService.java
  11. +1
    -1
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/PayAdapterService.java
  12. +2
    -2
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/miniApp/wx/BaseWxPayAdapterService.java
  13. +3
    -3
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/miniApp/wx/appPay/WxMiniAppPayAdapterService.java
  14. +3
    -3
      mallinkService/src/main/java/com/iformall/service/pay/service/pay/miniApp/wx/maPay/WxMiniMaPayAdapterService.java
  15. +0
    -11
      mallinkService/src/main/java/com/iformall/service/pay/service/payway/MiniAppPayBaseService.java
  16. +53
    -0
      mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java
  17. +11
    -0
      mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareBaseAdapterService.java
  18. +133
    -0
      mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java

+ 1
- 1
mallinkService/src/main/java/com/iformall/service/WxCouponOrderService.java Zobrazit soubor

@@ -88,7 +88,7 @@ public interface WxCouponOrderService {
* 核销分账
* @param couponOrder
*/
void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId);
void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId,Integer payWay);

/**
* 核销后补贴


+ 2
- 2
mallinkService/src/main/java/com/iformall/service/WxProfitSharingOrderService.java Zobrazit soubor

@@ -16,7 +16,7 @@ public interface WxProfitSharingOrderService {
/**
* 创建分账订单
*/
ResultData createSharingOrder(WxSharingOrderDto wxSharingOrderDto);
ResultData createSharingOrder(WxSharingOrderDto wxSharingOrderDto,Integer payway);

/**
* 分账重试
@@ -31,7 +31,7 @@ public interface WxProfitSharingOrderService {
/**
* 结束分账订单
*/
ResultData finishSharingOrder(WxSharingOrderDto sharingOrderDto);
ResultData finishSharingOrder(WxSharingOrderDto sharingOrderDto,Integer payway);


PageInfo<WxProfitSharingOrderVo> listAsPage(WxProfitSharingOrderQueryVo order, Integer pageNum, Integer pageSize);


+ 9
- 6
mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java Zobrazit soubor

@@ -25,6 +25,7 @@ import com.iformall.mapper.*;
import com.iformall.mq.MqBaseProducer;
import com.iformall.pay.WxPayConstant;
import com.iformall.service.*;
import com.iformall.service.pay.PayServiceFactory;
import com.iformall.utils.Constant;
import com.iformall.utils.DateUtils;
import com.iformall.utils.PayUtils;
@@ -133,6 +134,9 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {

@Autowired
WxPayOrderMapper payOrderMapper;
@Autowired
PayServiceFactory payServiceFactory;

@Autowired
@Qualifier("couponDetailRedisTemplate")
@@ -484,7 +488,8 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
} else {
try {
// 核销分账
shareAfterVerify(couponOrder, bUser.getMerchantId());
shareAfterVerify(couponOrder, bUser.getMerchantId(),couponOrder.getPayVendor());
111111111111111111111
} catch (Exception e) {
logger.error(e.getMessage());
}
@@ -543,9 +548,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
merchantSubsidy.setRealPayment(couponOrder.getCouponPrice());
merchantSubsidy.setSubsidy(couponOrder.getCouponPrice());
merchantSubsidy.setRealSubsidy(couponOrder.getCouponPrice());
couponOrder.getPayVendor();
11111111111
merchantSubsidy.setType(EnumMerchantSubsidyType.WECHAT.getCode());
merchantSubsidy.setType(payServiceFactory.getPayShareAdapterService(couponOrder.getPayVendor()).getType());
merchantSubsidy.setCreateDate(curDate);
merchantSubsidy.setUpdateDate(curDate);
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode());
@@ -554,7 +557,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {

@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId) {
public void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId,Integer payWay) {
// 微信分账
try {
WxPayOrder wxPayOrder = new WxPayOrder();
@@ -575,7 +578,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
wxSharingOrderDto.updateTenantInfo(wxPayOrder);
wxSharingOrderDto.setTransactionId(wxPayOrder.getTransactionId());
wxSharingOrderDto.setShareAmount(wxPayOrder.getShareAmount());
wxProfitSharingOrderService.createSharingOrder(wxSharingOrderDto);
wxProfitSharingOrderService.createSharingOrder(wxSharingOrderDto,payWay);
}
} catch (Exception e) {
logger.error("微信分账: " + e.getMessage());


+ 4
- 4
mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java Zobrazit soubor

@@ -23,9 +23,9 @@ import com.iformall.service.pay.entity.CreateCUser;
import com.iformall.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.entity.PayExtraParam;
import com.iformall.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.CDrivingPayService;
import com.iformall.service.pay.service.CPassivePayService;
import com.iformall.service.pay.service.PayAdapterService;
import com.iformall.service.pay.service.pay.CDrivingPayService;
import com.iformall.service.pay.service.pay.CPassivePayService;
import com.iformall.service.pay.service.pay.PayAdapterService;
import com.iformall.utils.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -1141,7 +1141,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService {
logger.error(e.getMessage());
}
// 更新后处理
wxCouponOrderService.sendInsideCouponVerifyMsg(unPayOrder, unPayOrder.getPosPayOrderId(), user.getId(),payWay);
wxCouponOrderService.sendInsideCouponVerifyMsg(unPayOrder, unPayOrder.getPosPayOrderId(), user.getId());
}
}
} catch (Exception e) {


+ 32
- 118
mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java Zobrazit soubor

@@ -20,6 +20,8 @@ import com.iformall.exception.MallinkException;
import com.iformall.mapper.*;
import com.iformall.pay.*;
import com.iformall.service.WxProfitSharingOrderService;
import com.iformall.service.pay.PayServiceFactory;
import com.iformall.service.pay.entity.PayShareResult;
import com.iformall.utils.BeanUtils;
import com.iformall.utils.DateUtils;
import com.iformall.utils.Utility;
@@ -66,6 +68,9 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ

@Autowired
WxCardSpendMapper wxCardSpendMapper;
@Autowired
PayServiceFactory payServiceFactory;

final JSONObject errorMap = JSON.parseObject("{" +
"\"SYSTEMERROR\":{\"detail\":\"接口返回错误\",\"reason\":\"系统超时\",\"resolution\":\"系统异常,请用相同参数重新调用\"}," +
@@ -238,7 +243,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ

@Override
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
public ResultData createSharingOrder(WxSharingOrderDto sharingOrderDto) {
public ResultData createSharingOrder(WxSharingOrderDto sharingOrderDto,Integer payWay) {
final IdWorker idworker = IdWorker.get();

if (!sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode()) &&
@@ -253,7 +258,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver();
psReceiverQ.updateTenantInfo(payAccount);
psReceiverQ.setMerchantId(sharingOrderDto.getMerchantId());
psReceiverQ.setSharingType(EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode());
psReceiverQ.setSharingType(payServiceFactory.getPayShareAdapterService(payWay).getProfitSharingType());
psReceiverQ.setStatus(EnumProfitSharingReceiverStatus.PROFIT_SHARING_RECEIVER_STATUS_VALID.getCode());
List<WxProfitSharingReceiver> psReceiverList = wxProfitSharingReceiverMapper.findList(psReceiverQ);
if (psReceiverList.size() < 0 || psReceiverList.size() > 50) {
@@ -269,9 +274,8 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
// 分账完结
sharingOrderDto.setShareAmount(sharingOrderDto.getPayAmount()+sharingOrderDto.getRateAmount());
}
return finishSharingOrder(sharingOrderDto);
return finishSharingOrder(sharingOrderDto,payWay);
}

//计算分账账户合法性
if (psReceiverList.size() > 1 &&
psReceiverList.stream().filter(r->(r.getParameter() == null)).count() > 0) {
@@ -325,7 +329,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
psReceiverList.stream().forEach(receiver->{
Date currentDate = new Date();
JSONObject jo = new JSONObject();
jo.put("type",EnumProfitSharingReceiverType.getEnum(receiver.getReceiverType()).getMessage());
jo.put("type",payServiceFactory.getPayShareAdapterService(payWay).getShareAccount(receiver.getReceiverType()).getMessage());
jo.put("account",receiver.getReceiverAccount());
jo.put("amount", receiver.getSharingAmount());
//jo.put("description",receiver.getReceiverComments()); //改为存ID,
@@ -346,78 +350,31 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
resultList.add(result);
});


//分账提交
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(sharingOrderDto.getTransactionId());
psCmd.setOut_order_no(record.getId().toString());
psCmd.setSign_type("HMAC-SHA256");
psCmd.setReceivers(receivers.toJSONString());

record.setReceivers(receivers.toJSONString());
wxProfitSharingOrderMapper.updateById(record);
String response;
try {
psCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psCmd), payAccount.getApiKey()));
logger.info("request:" + psCmd.toString());
if(sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode())) {
response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId());
} else if(sharingOrderDto.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) {
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode());
record.setErrorMsg(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(record);
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)) {
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode());
record.setErrorMsg(returnMap.get("return_msg"));
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(record);
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg"));
}

if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){
record.setErrorMsg(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(record);
return new ResultData(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode());
EnumProfitSharingOrderType shareType = EnumProfitSharingOrderType.getEnum(sharingOrderDto.getType());
if (null == shareType) {
new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),sharingOrderDto.getType()+"在分账方式中不存在。EnumProfitSharingOrderType");
}
PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(payWay).haveReciversShare(appInfo, payAccount, frecord,
sharingOrderDto.getTransactionId(), receivers, shareType);
if (!shareResult.isSuccess()) {
record.setSharingStatus(shareResult.getCode());
record.setErrorMsg(shareResult.getMsg());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(record);
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),record.getErrorMsg());
}

String result_code = returnMap.get("result_code");
if (!"SUCCESS".equals(result_code)) {
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode());
record.setUpdateTime(new Date());
record.setErrorMsg(returnMap.get("err_code_des"));
wxProfitSharingOrderMapper.updateById(record);
return new ResultData(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("err_code_des"));
}

record.setSharingOrderNo(returnMap.get("order_id"));
record.setSharingOrderNo(shareResult.getShareOrderNo());
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(record);
for (WxProfitSharingResult result:resultList) {
wxProfitSharingResultMapper.insert(result);
}

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

@Override
@@ -561,7 +518,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
// 分账完结
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public ResultData finishSharingOrder(WxSharingOrderDto sharingOrderDto) {
public ResultData finishSharingOrder(WxSharingOrderDto sharingOrderDto,Integer payWay) {
final IdWorker idworker = IdWorker.get();

if (!sharingOrderDto.getType().equals(EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE_FINISH.getCode())
@@ -593,63 +550,20 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ
wxProfitSharingOrderMapper.insert(record);

//分账提交
WxProfitSharingFinishP psFCmd = new WxProfitSharingFinishP();
psFCmd.setMch_id(payAccount.getMchId());
psFCmd.setSub_mch_id(payAccount.getSubMchId());
psFCmd.setAppid(appInfo.getParentAppId());
psFCmd.setNonce_str(Utility.generate32UUID());
psFCmd.setTransaction_id(sharingOrderDto.getTransactionId());
psFCmd.setOut_order_no(record.getId().toString());
psFCmd.setAmount(sharingOrderDto.getShareAmount());
psFCmd.setDescription("分账已完结");
psFCmd.setSign_type("HMAC-SHA256");

String response;
try {
psFCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psFCmd), payAccount.getApiKey()));
logger.info("request:" + psFCmd.toString());
response = WxProfitSharing.finishOrder(BeanUtils.toStringMap(psFCmd), payAccount.getCertPath(), payAccount.getMchId());
} catch (Exception e) {
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode());
record.setErrorMsg(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(record);
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)) {
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode());
record.setErrorMsg(returnMap.get("return_msg"));
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(record);
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg"));
}

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

String result_code = returnMap.get("result_code");
if (!"SUCCESS".equals(result_code)) {
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode());
PayShareResult shareResult = payServiceFactory.getPayShareAdapterService(payWay).noReciverShare(appInfo,payAccount,record,sharingOrderDto.getTransactionId(),sharingOrderDto.getShareAmount());
if (!shareResult.isSuccess()) {
record.setSharingStatus(shareResult.getCode());
record.setErrorMsg(shareResult.getMsg());
record.setUpdateTime(new Date());
record.setErrorMsg(returnMap.get("err_code_des"));
wxProfitSharingOrderMapper.updateById(record);
return new ResultData(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("err_code_des"));
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(),record.getErrorMsg());
}

record.setSharingOrderNo(returnMap.get("order_id"));
record.setSharingOrderNo(shareResult.getShareOrderNo());
record.setSharingStatus(EnumProfitSharingOrderStatus.PROFIT_SHARING_ACCEPTED.getCode());
record.setUpdateTime(new Date());
wxProfitSharingOrderMapper.updateById(record);
return new ResultData(returnMap);
return new ResultData(shareResult.getData());
}

@Override


+ 25
- 6
mallinkService/src/main/java/com/iformall/service/pay/PayServiceFactory.java Zobrazit soubor

@@ -11,11 +11,13 @@ import com.iformall.domain.po.WxPayOrder;
import com.iformall.enums.EnumPayWay;
import com.iformall.exception.MallinkException;
import com.iformall.service.WxPayOrderService;
import com.iformall.service.pay.service.CDrivingPayService;
import com.iformall.service.pay.service.CPassivePayService;
import com.iformall.service.pay.service.PayAdapterService;
import com.iformall.service.pay.service.miniApp.wx.appPay.WxMiniAppPayAdapterService;
import com.iformall.service.pay.service.miniApp.wx.maPay.WxMiniMaPayAdapterService;
import com.iformall.service.pay.service.pay.CDrivingPayService;
import com.iformall.service.pay.service.pay.CPassivePayService;
import com.iformall.service.pay.service.pay.PayAdapterService;
import com.iformall.service.pay.service.pay.miniApp.wx.appPay.WxMiniAppPayAdapterService;
import com.iformall.service.pay.service.pay.miniApp.wx.maPay.WxMiniMaPayAdapterService;
import com.iformall.service.pay.service.share.PayShareAdapterService;
import com.iformall.service.pay.service.share.wx.WxPayShareService;

/**
* 支付方式工厂
@@ -25,6 +27,7 @@ import com.iformall.service.pay.service.miniApp.wx.maPay.WxMiniMaPayAdapterServi
public class PayServiceFactory {

private Map<Integer,PayAdapterService> serviceMap = null;
private Map<Integer,PayShareAdapterService> shareMap = null;
@Autowired
WxMiniAppPayAdapterService wxMiniAppPayService;
@@ -32,6 +35,8 @@ public class PayServiceFactory {
WxMiniMaPayAdapterService wxMiniAppMaPayService;
@Autowired
WxPayOrderService wxPayOrderService;
@Autowired
WxPayShareService wxShareService;
public PayAdapterService getPayAdapterService(Integer type) throws MallinkException{
PayAdapterService service = getServiceMap().get(type);
@@ -74,6 +79,20 @@ public class PayServiceFactory {
return serviceMap;
}
private Map<Integer,PayShareAdapterService> getShareMap(){
if (null != shareMap ) {
shareMap = new ConcurrentHashMap<Integer, PayShareAdapterService>();
shareMap.put(EnumPayWay.PAY_WAY_WECHAT.getCode(), wxShareService);
shareMap.put(EnumPayWay.PAY_WAY_WECHAT_MA.getCode(), wxShareService);
}
return shareMap;
}
public PayShareAdapterService getPayShareAdapterService(Integer type) throws MallinkException{
PayShareAdapterService shareService = getShareMap().get(type);
if (null == shareService) {
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"payType["+type+"] 分账service未找到");
}
return shareService;
}
}

+ 22
- 0
mallinkService/src/main/java/com/iformall/service/pay/entity/PayShareResult.java Zobrazit soubor

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

import java.io.Serializable;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class PayShareResult implements Serializable{

private static final long serialVersionUID = -3701322871877301001L;

private boolean isSuccess;
private Integer code;
private String msg;
private Object data;
private String shareOrderNo;
}

+ 0
- 9
mallinkService/src/main/java/com/iformall/service/pay/service/PayShareAdapterService.java Zobrazit soubor

@@ -1,9 +0,0 @@
package com.iformall.service.pay.service;

/**
* 分账接口
* @author alascor
*/
public interface PayShareAdapterService {

}

mallinkService/src/main/java/com/iformall/service/pay/service/CDrivingPayService.java → mallinkService/src/main/java/com/iformall/service/pay/service/pay/CDrivingPayService.java Zobrazit soubor

@@ -1,4 +1,4 @@
package com.iformall.service.pay.service;
package com.iformall.service.pay.service.pay;

/**
* C端主动发起的支付

mallinkService/src/main/java/com/iformall/service/pay/service/CPassivePayService.java → mallinkService/src/main/java/com/iformall/service/pay/service/pay/CPassivePayService.java Zobrazit soubor

@@ -1,4 +1,4 @@
package com.iformall.service.pay.service;
package com.iformall.service.pay.service.pay;

import java.util.Date;


mallinkService/src/main/java/com/iformall/service/pay/service/PayAdapterService.java → mallinkService/src/main/java/com/iformall/service/pay/service/pay/PayAdapterService.java Zobrazit soubor

@@ -1,4 +1,4 @@
package com.iformall.service.pay.service;
package com.iformall.service.pay.service.pay;

import java.util.Date;
import com.iformall.domain.po.WxAppinfo;

mallinkService/src/main/java/com/iformall/service/pay/service/miniApp/wx/BaseWxPayAdapterService.java → mallinkService/src/main/java/com/iformall/service/pay/service/pay/miniApp/wx/BaseWxPayAdapterService.java Zobrazit soubor

@@ -1,4 +1,4 @@
package com.iformall.service.pay.service.miniApp.wx;
package com.iformall.service.pay.service.pay.miniApp.wx;

import java.util.Map;

@@ -8,7 +8,7 @@ import com.iformall.domain.po.WxPayAccount;
import com.iformall.domain.po.WxPayOrder;
import com.iformall.service.helper.WxPayOrderServiceHelper;
import com.iformall.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.PayAdapterService;
import com.iformall.service.pay.service.pay.PayAdapterService;

public class BaseWxPayAdapterService {


mallinkService/src/main/java/com/iformall/service/pay/service/miniApp/wx/appPay/WxMiniAppPayAdapterService.java → mallinkService/src/main/java/com/iformall/service/pay/service/pay/miniApp/wx/appPay/WxMiniAppPayAdapterService.java Zobrazit soubor

@@ -1,4 +1,4 @@
package com.iformall.service.pay.service.miniApp.wx.appPay;
package com.iformall.service.pay.service.pay.miniApp.wx.appPay;

import java.util.Date;
import java.util.Map;
@@ -25,8 +25,8 @@ import com.iformall.pay.WxPayment;
import com.iformall.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.entity.PayExtraParam;
import com.iformall.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.CDrivingPayService;
import com.iformall.service.pay.service.miniApp.wx.BaseWxPayAdapterService;
import com.iformall.service.pay.service.pay.CDrivingPayService;
import com.iformall.service.pay.service.pay.miniApp.wx.BaseWxPayAdapterService;
import com.iformall.utils.BeanUtils;
import com.iformall.utils.MapUtil;
import com.iformall.utils.Utility;

mallinkService/src/main/java/com/iformall/service/pay/service/miniApp/wx/maPay/WxMiniMaPayAdapterService.java → mallinkService/src/main/java/com/iformall/service/pay/service/pay/miniApp/wx/maPay/WxMiniMaPayAdapterService.java Zobrazit soubor

@@ -1,4 +1,4 @@
package com.iformall.service.pay.service.miniApp.wx.maPay;
package com.iformall.service.pay.service.pay.miniApp.wx.maPay;

import java.util.Date;
import java.util.Map;
@@ -26,8 +26,8 @@ import com.iformall.service.pay.entity.CreateCUser;
import com.iformall.service.pay.entity.PayAdapterResult;
import com.iformall.service.pay.entity.PayExtraParam;
import com.iformall.service.pay.entity.PayQueryAdapterResult;
import com.iformall.service.pay.service.CPassivePayService;
import com.iformall.service.pay.service.miniApp.wx.BaseWxPayAdapterService;
import com.iformall.service.pay.service.pay.CPassivePayService;
import com.iformall.service.pay.service.pay.miniApp.wx.BaseWxPayAdapterService;
import com.iformall.utils.BeanUtils;
import com.iformall.utils.Utility;
import lombok.extern.slf4j.Slf4j;

+ 0
- 11
mallinkService/src/main/java/com/iformall/service/pay/service/payway/MiniAppPayBaseService.java Zobrazit soubor

@@ -1,11 +0,0 @@
package com.iformall.service.pay.service.payway;

import com.iformall.service.pay.service.PayAdapterService;

/**
* 小程序app支付service
* @author alascor
*/
public abstract class MiniAppPayBaseService implements PayAdapterService{

}

+ 53
- 0
mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java Zobrazit soubor

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

import com.alibaba.fastjson.JSONArray;
import com.iformall.domain.po.WxAppinfo;
import com.iformall.domain.po.WxPayAccount;
import com.iformall.domain.po.WxProfitSharingOrder;
import com.iformall.enums.EnumProfitSharingOrderType;
import com.iformall.enums.EnumProfitSharingReceiverType;
import com.iformall.exception.MallinkException;
import com.iformall.service.pay.entity.PayShareResult;

/**
* 分账接口
* @author alascor
*/
public interface PayShareAdapterService {

public Integer getType();
public Integer getProfitSharingType();
/**
* 无分账接收方分账 ,钱直接分给小程序方 调用API分账
* @param appInfo
* @param payAccount
* @param record
* @param transcationId
* @param amount 分账金额
* @return
*/
public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount);
/**
* 有分账接收账号分账 ,钱分给小程序方,还要分给分账账号 调用API分账
* @param appInfo
* @param payAccount
* @param record
* @param transcationId
* @param receivers 接收方账号 {"type":${EnumProfitSharingReceiverType.message},"account":${String},"amount":${Integer},"description":${id}}
* @param shareType
* @return
* @throws MallinkException
*/
public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,JSONArray receivers,EnumProfitSharingOrderType shareType ) throws MallinkException;
/**
* 获取分账账号类型
* @param accountType
* @return
*/
public EnumProfitSharingReceiverType getShareAccount(Integer accountType);
}

+ 11
- 0
mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareBaseAdapterService.java Zobrazit soubor

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

import com.iformall.enums.EnumProfitSharingReceiverType;
public abstract class PayShareBaseAdapterService implements PayShareAdapterService{

@Override
public EnumProfitSharingReceiverType getShareAccount(Integer accountType) {
return EnumProfitSharingReceiverType.getEnum(accountType);
}

}

+ 133
- 0
mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java Zobrazit soubor

@@ -0,0 +1,133 @@
package com.iformall.service.pay.service.share.wx;

import java.util.Map;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.iformall.common.ErrorCode;
import com.iformall.domain.po.WxAppinfo;
import com.iformall.domain.po.WxPayAccount;
import com.iformall.domain.po.WxProfitSharingOrder;
import com.iformall.enums.EnumMerchantSubsidyType;
import com.iformall.enums.EnumProfitSharingOrderStatus;
import com.iformall.enums.EnumProfitSharingOrderType;
import com.iformall.enums.EnumProfitSharingReceiverType;
import com.iformall.enums.EnumProfitSharingType;
import com.iformall.exception.MallinkException;
import com.iformall.pay.WxPayment;
import com.iformall.pay.WxProfitSharing;
import com.iformall.pay.WxProfitSharingFinishP;
import com.iformall.pay.WxProfitSharingP;
import com.iformall.service.pay.entity.PayShareResult;
import com.iformall.service.pay.service.share.PayShareAdapterService;
import com.iformall.service.pay.service.share.PayShareBaseAdapterService;
import com.iformall.utils.BeanUtils;
import com.iformall.utils.Utility;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class WxPayShareService extends PayShareBaseAdapterService{

@Override
public Integer getType() {
return EnumMerchantSubsidyType.WECHAT.getCode();
}

@Override
public Integer getProfitSharingType() {
return EnumProfitSharingType.PROFIT_SHARING_TYPE_WECHAT.getCode();
}

@Override
public PayShareResult noReciverShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,Integer amount) {
WxProfitSharingFinishP psFCmd = new WxProfitSharingFinishP();
psFCmd.setMch_id(payAccount.getMchId());
psFCmd.setSub_mch_id(payAccount.getSubMchId());
psFCmd.setAppid(appInfo.getParentAppId());
psFCmd.setNonce_str(Utility.generate32UUID());
psFCmd.setTransaction_id(transcationId);
psFCmd.setOut_order_no(record.getId().toString());
psFCmd.setAmount(amount);
psFCmd.setDescription("分账已完结");
psFCmd.setSign_type("HMAC-SHA256");

String response;
try {
psFCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psFCmd), payAccount.getApiKey()));
log.info("request:" + psFCmd.toString());
response = WxProfitSharing.finishOrder(BeanUtils.toStringMap(psFCmd), payAccount.getCertPath(), payAccount.getMchId());
} catch (Exception e) {
log.error("wx noreciver share error:",e);
return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(),ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage()+":"+e.getMessage(), null,null);
}

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

if (!"SUCCESS".equals(return_code)) {
return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(),returnMap.get("return_msg"), null,null);
}
if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){
return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(),ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage(), null,null);
}
String result_code = returnMap.get("result_code");
if (!"SUCCESS".equals(result_code)) {
return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode(),returnMap.get("err_code_des"), null,null);
}
return new PayShareResult(true, null,"success", returnMap,returnMap.get("order_id"));
}

@Override
public PayShareResult haveReciversShare(WxAppinfo appInfo,WxPayAccount payAccount,WxProfitSharingOrder record,String transcationId,JSONArray receivers,EnumProfitSharingOrderType shareType ) throws MallinkException {
//分账提交
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(transcationId);
psCmd.setOut_order_no(record.getId().toString());
psCmd.setSign_type("HMAC-SHA256");
psCmd.setReceivers(receivers.toJSONString());
String response;
try {
psCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psCmd), payAccount.getApiKey()));
log.info("request:" + psCmd.toString());
if(shareType.getCode().intValue()==EnumProfitSharingOrderType.PROFIT_SHARING_SINGLE.getCode().intValue()) {
response = WxProfitSharing.pushOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId());
} else if(shareType.getCode().intValue()==EnumProfitSharingOrderType.PROFIT_SHARING_MULTI.getCode().intValue()) {
response = WxProfitSharing.pushMultiOrder(BeanUtils.toStringMap(psCmd), payAccount.getCertPath(), payAccount.getMchId());
} else {
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR);
}
} catch (Exception e) {
log.error("wx recivers share error:",e);
return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(), ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getMessage()+":"+e.getMessage(), null, null);
}

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

if (!"SUCCESS".equals(return_code)) {
return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(), returnMap.get("return_msg"), null, null);
}

if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){
return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_REQ_FAILED.getCode(), ErrorCode.PROFIT_SHARING_RETURN_INVALID.getMessage(), null, null);
}

String result_code = returnMap.get("result_code");
if (!"SUCCESS".equals(result_code)) {
return new PayShareResult(false, EnumProfitSharingOrderStatus.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("err_code_des"), null, null);
}
return new PayShareResult(true, null, "success",returnMap, returnMap.get("order_id"));
}
}

Načítá se…
Zrušit
Uložit