| @@ -88,7 +88,7 @@ public interface WxCouponOrderService { | |||
| * 核销分账 | |||
| * @param couponOrder | |||
| */ | |||
| void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId); | |||
| void shareAfterVerify(WxCouponOrder couponOrder, Long merchantId,Integer payWay); | |||
| /** | |||
| * 核销后补贴 | |||
| @@ -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); | |||
| @@ -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()); | |||
| @@ -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) { | |||
| @@ -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 | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| @@ -1,9 +0,0 @@ | |||
| package com.iformall.service.pay.service; | |||
| /** | |||
| * 分账接口 | |||
| * @author alascor | |||
| */ | |||
| public interface PayShareAdapterService { | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service; | |||
| package com.iformall.service.pay.service.pay; | |||
| /** | |||
| * C端主动发起的支付 | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service; | |||
| package com.iformall.service.pay.service.pay; | |||
| import java.util.Date; | |||
| @@ -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; | |||
| @@ -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 { | |||
| @@ -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; | |||
| @@ -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; | |||
| @@ -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{ | |||
| } | |||
| @@ -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); | |||
| } | |||
| @@ -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); | |||
| } | |||
| } | |||
| @@ -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")); | |||
| } | |||
| } | |||