zouxuan 5 månader sedan
förälder
incheckning
d20efead6a

+ 42 - 31
mec-application/src/main/java/com/ym/mec/student/controller/StudentOrderController.java

@@ -2,18 +2,19 @@ package com.ym.mec.student.controller;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.huifu.adapay.core.AdapayCore;
-import com.huifu.adapay.core.util.AdapaySign;
-import com.yeepay.g3.sdk.yop.encrypt.DigitalEnvelopeDTO;
-import com.yeepay.g3.sdk.yop.utils.DigitalEnvelopeUtils;
-import com.yeepay.g3.sdk.yop.utils.RSAKeyUtils;
+import com.microsvc.toolkit.middleware.payment.common.api.BasePaymentService;
+import com.microsvc.toolkit.middleware.payment.common.api.PaymentServiceContext;
+import com.microsvc.toolkit.middleware.payment.common.api.entity.PaymentResp;
+import com.microsvc.toolkit.middleware.payment.common.api.enums.PaymentStatus;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.*;
-import com.ym.mec.biz.dal.enums.*;
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
+import com.ym.mec.biz.dal.enums.GroupType;
+import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
+import com.ym.mec.biz.dal.enums.OrderTypeEnum;
 import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
 import com.ym.mec.biz.dal.vo.StudentPaymentOrderVo;
 import com.ym.mec.biz.dal.wrapper.CloudTeacherOrderWrapper;
@@ -23,7 +24,6 @@ import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.tenant.TenantContextHolder;
-import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
 import com.ym.mec.thirdparty.yqpay.Msg;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.http.HttpUtil;
@@ -32,6 +32,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+import lombok.Data;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -47,8 +48,6 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.net.URLEncoder;
-import java.security.PrivateKey;
-import java.security.PublicKey;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -118,6 +117,8 @@ public class StudentOrderController extends BaseController {
     private TempDirectorTrainingCampDetailService tempDirectorTrainingCampDetailService;
     @Autowired
     private MusicGroupPaymentCalenderMemberService musicGroupPaymentCalenderMemberService;
+    @Autowired
+    private PaymentServiceContext paymentServiceContext;
 
     @Value("${spring.profiles.active:dev}")
     private String profiles;
@@ -136,14 +137,27 @@ public class StudentOrderController extends BaseController {
 
     @PostMapping("/callback/{orderNo}")
 	public String callback(@PathVariable("orderNo") String orderNo, HttpServletRequest request) {
-		
 		StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findOrderByOrderNo(orderNo);
-		
 		if(studentPaymentOrder == null) {
 			return "订单号错误";
 		}
-		
-		PaymentChannelEnum paymentChannel = PaymentChannelEnum.codeOf(studentPaymentOrder.getPaymentChannel());
+        BasePaymentService paymentService = paymentServiceContext.getPaymentService(studentPaymentOrder.getPaymentChannel() + "_" + studentPaymentOrder.getTenantId());
+        if (paymentService == null) {
+            return "支付渠道不存在 " + studentPaymentOrder.getPaymentChannel();
+        }
+        PaymentResp paymentResp = paymentService.callbackNotifyForPay(request);
+        try {
+            Map<String, String> notifyMap = new HashMap<>(4);
+            notifyMap.put("channelType", paymentResp.getPaymentChannel());
+            notifyMap.put("tradeState", paymentResp.getPaymentStatus() == PaymentStatus.SUCCESSED?"1":"0");
+            notifyMap.put("totalMoney", paymentResp.getPaymentAmount().toString());
+            notifyMap.put("merOrderNo", paymentResp.getMerOrderNo());
+            studentPaymentOrderService.updateOrder(notifyMap);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        /*
+        PaymentChannelEnum paymentChannel = PaymentChannelEnum.codeOf(studentPaymentOrder.getPaymentChannel());
 		
 		try {
 			
@@ -234,24 +248,22 @@ public class StudentOrderController extends BaseController {
 		} catch (Exception e) {
 			return e.getMessage();
 		}
-		
+		*/
 		return "succeeded";
 	}
 
     @PostMapping("/notify")
     public Msg notify(@ModelAttribute Msg msg) throws Exception {
         logger.info(msg.toString());
-        Map<String, Object> rqMap = new LinkedHashMap<String, Object>();
-        rqMap.put("code", msg.getCode());
-        rqMap.put("msg", msg.getMsg());
-        rqMap.put("responseType", msg.getResponseType());
-        rqMap.put("responseParameters", msg.getResponseParameters());
-        rqMap.put("sign", msg.getSign());
+//        Map<String, Object> rqMap = new LinkedHashMap<String, Object>();
+//        rqMap.put("code", msg.getCode());
+//        rqMap.put("msg", msg.getMsg());
+//        rqMap.put("responseType", msg.getResponseType());
+//        rqMap.put("responseParameters", msg.getResponseParameters());
+//        rqMap.put("sign", msg.getSign());
         //boolean rs = YqPayUtil.verify(rqMap);
         msg.setMsg("fail");
-        Map<String, String> notifyMap = new HashMap<>();
-        //if (rs) {
-        notifyMap = JSON.parseObject(msg.getResponseParameters(), Map.class);
+        Map<String, String> notifyMap = JSON.parseObject(msg.getResponseParameters(), Map.class);
         //}
         //支付中订单存在,更新状态
         if (msg.getResponseType().equals("1") && notifyMap.size() > 0) {
@@ -502,11 +514,11 @@ public class StudentOrderController extends BaseController {
     @GetMapping("/setSuccessStatus")
     public HttpResponseResult setSuccessStatus(String orderNo) throws Exception {
         if (!profiles.equals("dev") && !profiles.equals("test")) {
-//            return failed("非法操作");
+            return failed("非法操作");
         }
         List<StudentPaymentOrder> payingOrders = studentPaymentOrderService.findOrdersByStatus(DealStatusEnum.ING);
 
-        String[] statusArr = {"0", "1", "7"};
+//        String[] statusArr = {"0", "1", "7"};
         for (StudentPaymentOrder payingOrder : payingOrders) {
             if (StringUtils.isNotBlank(orderNo) && !orderNo.equals(payingOrder.getOrderNo())) {
                 continue;
@@ -518,7 +530,6 @@ public class StudentOrderController extends BaseController {
                     continue;
                 }
             }
-
             Map<String, String> rpMap = new HashMap<>();
             rpMap.put("tradeState", "1");
             rpMap.put("remarks", "模拟支付成功");
@@ -529,14 +540,14 @@ public class StudentOrderController extends BaseController {
 
             String channelType = rpMap.get("channelType").equals("1") ? "WXPay" : (rpMap.get("channelType").equals("2") ? "Alipay" : "quickPay");
             rpMap.put("channelType", channelType);
-            if (Arrays.asList(statusArr).contains(rpMap.get("tradeState"))) {
+            studentPaymentOrderService.updateOrder(rpMap); //更新订单
+            /*if (Arrays.asList(statusArr).contains(rpMap.get("tradeState"))) {
                 try {
-                    studentPaymentOrderService.updateOrder(rpMap); //更新订单
                 } catch (Exception e) {
                     e.printStackTrace();
                     continue;
                 }
-            }
+            }*/
         }
         return succeed();
     }
@@ -895,7 +906,7 @@ public class StudentOrderController extends BaseController {
 
     @GetMapping("/reConfirmOrder")
     public HttpResponseResult<List<StudentPaymentOrder>> reConfirmOrder(Date startTime, Date endTime) {
-        if (!profiles.equals("prod")) {
+        if (!profiles.equals("prod") && !profiles.equals("pre")) {
             return failed("测试环境不支持");
         }
         return succeed(studentPaymentOrderService.reConfirmOrder(startTime, endTime));

+ 4 - 0
mec-biz/pom.xml

@@ -17,6 +17,10 @@
 
 	<dependencies>
 		<dependency>
+			<groupId>com.microsvc.toolkit.middleware</groupId>
+			<artifactId>microsvc-middleware-payment</artifactId>
+		</dependency>
+		<dependency>
 			<groupId>com.ym</groupId>
 			<artifactId>common-core</artifactId>
 		</dependency>

+ 8 - 10
mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderService.java

@@ -1,15 +1,7 @@
 package com.ym.mec.biz.service;
 
-import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import com.ym.mec.biz.dal.dto.*;
-import com.ym.mec.common.entity.OrderSkuSync;
-import org.apache.ibatis.annotations.Param;
-
 import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
+import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.ActivityUserMapper;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
@@ -23,10 +15,16 @@ import com.ym.mec.biz.dal.vo.StudentPaymentOrderVo;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.entity.MallCreateOrderModel;
 import com.ym.mec.common.entity.OrderCancelModel;
+import com.ym.mec.common.entity.OrderSkuSync;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.BaseService;
 import com.ym.mec.thirdparty.adapay.entity.BaseResult;
-import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
+import org.apache.ibatis.annotations.Param;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
 
 public interface StudentPaymentOrderService extends BaseService<Long, StudentPaymentOrder> {
 

+ 89 - 13
mec-biz/src/main/java/com/ym/mec/biz/service/impl/HfMerchantConfigServiceImpl.java

@@ -1,32 +1,108 @@
 package com.ym.mec.biz.service.impl;
 
-import java.util.HashMap;
-import java.util.Map;
-
-import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
+import com.google.common.collect.Lists;
+import com.microsvc.toolkit.middleware.payment.common.api.PaymentServiceContext;
+import com.microsvc.toolkit.middleware.payment.impl.AdapayPaymentServicePlugin;
+import com.microsvc.toolkit.middleware.payment.impl.YeepayPaymentServicePlugin;
+import com.microsvc.toolkit.middleware.payment.properties.PayConfigProperties;
 import com.ym.mec.biz.dal.dao.HfMerchantConfigDao;
-import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
 import com.ym.mec.biz.service.HfMerchantConfigService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
-import com.ym.mec.thirdparty.adapay.AdapayInit;
 import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
 
+@Slf4j
 @Service
-public class HfMerchantConfigServiceImpl extends BaseServiceImpl<Integer, HfMerchantConfig>  implements HfMerchantConfigService,InitializingBean {
+public class HfMerchantConfigServiceImpl extends BaseServiceImpl<Integer, HfMerchantConfig>  implements HfMerchantConfigService {
 	
-	@Autowired
+	@Resource
 	private HfMerchantConfigDao hfMerchantConfigDao;
+	@Resource
+	private PayConfigProperties properties;
 
 	@Override
 	public BaseDAO<Integer, HfMerchantConfig> getDAO() {
 		return hfMerchantConfigDao;
 	}
 
-	@Override
+	@PostConstruct
+	public void init(){
+		List<HfMerchantConfig> list = hfMerchantConfigDao.findAll(new HashMap<>());
+
+		if(CollectionUtils.isEmpty(list)) {
+			return;
+		}
+
+		List<String> pluginNames = Lists.newArrayList();
+		for (HfMerchantConfig config : list) {
+			if (StringUtils.isEmpty(config.getPayerName())) {
+				log.error("数据错误 {}", config);
+			} else if (StringUtils.equalsIgnoreCase(config.getPayerName(),"ADAPAY")) {
+				PayConfigProperties.AdapayPayConfig adapayPayConfig = new PayConfigProperties.AdapayPayConfig();
+				adapayPayConfig.setEnable(true);
+				adapayPayConfig.setAppId(config.getAppId());
+				adapayPayConfig.setPayType(config.getPayerName() + "_" + config.getTenantId());
+				adapayPayConfig.setMerchantKey(config.getMerKey());
+				adapayPayConfig.setMerchantId(config.getApiKey());
+				adapayPayConfig.setPayNotifyUrl(properties.getPayNotifyUrl());
+				adapayPayConfig.setRefundNotifyUrl(properties.getRefundNotifyUrl());
+				adapayPayConfig.setKeyPublic(config.getRsaPublicKey());
+				adapayPayConfig.setKeyPrivate(config.getRsaPrivateKey());
+				adapayPayConfig.setWxAppId(config.getWxAppId());
+				adapayPayConfig.setWxAppSecret(config.getWxAppSecret());
+//				adapayPayConfig.setMiniAppId(config.getMiniAppId());
+//				adapayPayConfig.setMiniAppSecret(config.getMiniAppSerret());
+				adapayPayConfig.setSupportCreditCards(properties.getSupportCreditCards());
+				try {
+					AdapayPaymentServicePlugin plugin = new AdapayPaymentServicePlugin(adapayPayConfig.getPayType(), adapayPayConfig, false);
+					PaymentServiceContext.addPlugin(plugin);
+					pluginNames.add(plugin.venderName());
+				} catch (Exception e) {
+					log.error("初始[汇付]化支付插件失败", e);
+				}
+			} else if (StringUtils.equalsIgnoreCase(config.getPayerName(),"YEEPAY")){
+				PayConfigProperties.YeepayPayConfig yeepayPayConfig = new PayConfigProperties.YeepayPayConfig();
+				yeepayPayConfig.setEnable(true);
+				yeepayPayConfig.setAppId(config.getAppId());
+				yeepayPayConfig.setPayType(config.getPayerName() + "_" + config.getTenantId());
+				yeepayPayConfig.setMerchantId(config.getMerKey());
+				yeepayPayConfig.setPayNotifyUrl(properties.getPayNotifyUrl());
+				yeepayPayConfig.setRefundNotifyUrl(properties.getRefundNotifyUrl());
+				yeepayPayConfig.setKeyPublic(config.getRsaPublicKey());
+				yeepayPayConfig.setKeyPrivate(config.getRsaPrivateKey());
+				yeepayPayConfig.setWxAppId(config.getWxAppId());
+				yeepayPayConfig.setWxAppSecret(config.getWxAppSecret());
+				yeepayPayConfig.setSupportCreditCards(properties.getSupportCreditCards());
+				yeepayPayConfig.setAlipayAppId(config.getAlipayAppId());
+				yeepayPayConfig.setAlipayPrivateKey(config.getAlipayPrivateKey());
+				yeepayPayConfig.setAlipayPublicKey(config.getAlipayPublicKey());
+//				yeepayPayConfig.setMiniAppId(config.getMiniAppId());
+//				yeepayPayConfig.setMiniAppSecret(config.getMiniAppSerret());
+				try {
+					YeepayPaymentServicePlugin plugin = new YeepayPaymentServicePlugin(yeepayPayConfig.getPayType(), yeepayPayConfig, false);
+					PaymentServiceContext.addPlugin(plugin);
+
+					pluginNames.add(plugin.venderName());
+				} catch (Exception e) {
+					log.error("初始化[易宝]支付插件失败", e);
+				}
+			}else {
+				log.error("数据错误 {}", config);
+			}
+		}
+		log.info("初始化支付插件完成, plugins={}", pluginNames);
+	}
+
+	/*@Override
 	public void afterPropertiesSet() throws Exception {
 		AdapayInit adapayInit = AdapayInit.getInstance(false, true);
 		
@@ -34,7 +110,7 @@ public class HfMerchantConfigServiceImpl extends BaseServiceImpl<Integer, HfMerc
 		params.put("payerName", PaymentChannelEnum.ADAPAY.getCode());
 		
 		adapayInit.initWithMerConfig(hfMerchantConfigDao.findAll(params));
-	}
+	}*/
 
 	@Override
 	public HfMerchantConfig queryByTenantId(Integer tenantId, String payerName) {

+ 20 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MemberRankSettingServiceImpl.java

@@ -5,6 +5,10 @@ import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.Lists;
+import com.microsvc.toolkit.middleware.payment.common.api.BasePaymentService;
+import com.microsvc.toolkit.middleware.payment.common.api.PaymentServiceContext;
+import com.microsvc.toolkit.middleware.payment.common.api.entity.PaymentResp;
+import com.microsvc.toolkit.middleware.payment.common.api.enums.PaymentStatus;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
@@ -140,6 +144,9 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
     @Autowired
     private MemberRankOrganizationFeeMapperDao memberRankOrganizationFeeMapperDao;
 
+    @Autowired
+    private PaymentServiceContext paymentServiceContext;
+
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
     @Override
@@ -724,7 +731,18 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
     //检查订单在第三方是否支付成功
     private void checkOrder(StudentPaymentOrder orderByOrderNo) throws Exception {
         if (StringUtils.isNotBlank(orderByOrderNo.getTransNo())) {
-
+            BasePaymentService paymentService = paymentServiceContext.getPaymentService(orderByOrderNo.getPaymentChannel() + "_" + orderByOrderNo.getTenantId());
+            if (paymentService == null) {
+                throw new BizException("支付渠道[{}]找不到", orderByOrderNo.getPaymentChannel());
+            }
+            PaymentResp paymentResp = paymentService.query(orderByOrderNo.getOrderNo(), orderByOrderNo.getOrderNo());
+            if (Objects.isNull(paymentResp)) {
+                throw new BizException("订单支付状态获取异常,稍后请重试");
+            }
+            if (paymentResp.getPaymentStatus() == PaymentStatus.SUCCESSED) {
+                throw new BizException("该订单已经支付成功,无法关闭。");
+            }
+            /*
             HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(orderByOrderNo.getTenantId(), orderByOrderNo.getPaymentChannel());
             if(hfMerchantConfig == null){
             	throw new BizException("机构[{}]汇付商户信息找不到", orderByOrderNo.getTenantId());
@@ -734,7 +752,7 @@ public class MemberRankSettingServiceImpl extends BaseServiceImpl<Integer, Membe
             String status = (String) payment.get("status");
             if (status.equals("succeeded")) {
                 throw new BizException("该订单已经支付成功,无法关闭。");
-            }
+            }*/
         }
     }
 

+ 57 - 48
mec-biz/src/main/java/com/ym/mec/biz/service/impl/OrderPayOpsServiceImpl.java

@@ -1,33 +1,5 @@
 package com.ym.mec.biz.service.impl;
 
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.TimeUnit;
-import java.util.function.BiPredicate;
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-import com.huifu.adapay.core.util.StringUtil;
-import com.ym.mec.biz.service.*;
-import org.apache.commons.lang3.StringUtils;
-import org.redisson.api.RBucket;
-import org.redisson.api.RedissonClient;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.util.DigestUtils;
-
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alipay.api.AlipayApiException;
@@ -35,6 +7,10 @@ import com.alipay.api.AlipayClient;
 import com.alipay.api.DefaultAlipayClient;
 import com.alipay.api.request.AlipaySystemOauthTokenRequest;
 import com.alipay.api.response.AlipaySystemOauthTokenResponse;
+import com.microsvc.toolkit.middleware.payment.common.api.BasePaymentService;
+import com.microsvc.toolkit.middleware.payment.common.api.PaymentServiceContext;
+import com.microsvc.toolkit.middleware.payment.common.api.entity.PaymentOrder;
+import com.microsvc.toolkit.middleware.payment.common.api.entity.PaymentReq;
 import com.ym.mec.biz.dal.dao.SysConfigDao;
 import com.ym.mec.biz.dal.dto.PaymentParam;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
@@ -43,15 +19,34 @@ import com.ym.mec.biz.dal.entity.TenantOrderRecord;
 import com.ym.mec.biz.dal.entity.TenantPaymentOrder;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.thirdparty.adapay.ConfigInit;
-import com.ym.mec.thirdparty.adapay.Payment;
 import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
 import com.ym.mec.thirdparty.yeepay.YeepayPaymentService;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.http.HttpUtil;
 import com.ym.mec.util.json.JsonUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.joda.time.DateTime;
+import org.redisson.api.RBucket;
+import org.redisson.api.RedissonClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.util.DigestUtils;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.function.BiPredicate;
+import java.util.function.Consumer;
+import java.util.function.Function;
 
 import static com.ym.mec.biz.dal.enums.OrderTypeEnum.MALL_BUY;
 
@@ -63,25 +58,24 @@ import static com.ym.mec.biz.dal.enums.OrderTypeEnum.MALL_BUY;
 public class OrderPayOpsServiceImpl implements OrderPayOpsService {
     private static final Logger log = LoggerFactory.getLogger(OrderPayOpsServiceImpl.class);
 
-    @Autowired
+    @Resource
     private StudentPaymentOrderService studentPaymentOrderService;
-    @Autowired
+    @Resource
     private TenantPaymentOrderService tenantPaymentOrderService;
-    @Autowired
+    @Resource
     private TenantOrderRecordService tenantOrderRecordService;
-    
-    @Autowired
+    @Resource
     private HfMerchantConfigService hfMerchantConfigService;
-    
-    @Autowired
+    @Resource
     private YeepayPaymentService yeepayPaymentService;
-    
-    @Autowired
+    @Resource
     private RedissonClient redissonClient;
-    @Autowired
+    @Resource
     private TenantConfigService tenantConfigService;
-    @Autowired
+    @Resource
     private SysConfigDao sysConfigDao;
+    @Resource
+    private PaymentServiceContext paymentServiceContext;
 
     //tenant 机构开通、续费付款、 cloudTeacherOrder 团练宝激活支付、tenantRecharge 机构充值
     private static final String[] tenantPlatform = {"tenant", "cloudTeacherOrder", "tenantRecharge"};
@@ -141,7 +135,6 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
 
 
     private void checkSing(PaymentParam param) {
-        
         //查询商户支付账户
         HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(param.getTenantId(), param.getPayerName());
         if(hfMerchantConfig == null){
@@ -262,14 +255,30 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
         	throw new BizException("请配置机构的汇付商户信息");
         }
         
-        Map<String, Object> payment = new HashMap<String, Object>();
-        String transNo = null;
-        
+//        Map<String, Object> payment = new HashMap<String, Object>();
+//        String transNo = null;
+        BasePaymentService paymentService = paymentServiceContext.getPaymentService(payParam.getPayerName() + "_" + payParam.getTenantId());
+        if (paymentService == null) {
+            throw new BizException("支付渠道错误:" + payParam.getPayerName());
+        }
+        PaymentOrder paymentOrder = new PaymentOrder();
+        paymentOrder.setMerOrderNo(payParam.getOrderNo());
+        paymentOrder.setPrice(payParam.getAmount());
+        paymentOrder.setSubject(payParam.getOrderSubject());
+        paymentOrder.setBody(payParam.getOrderBody());
+        paymentOrder.setExpirationTime(DateTime.now().plusMinutes(120).toDate());
+        PaymentReq paymentReq = paymentService.pay(paymentOrder);
+        if (Objects.isNull(paymentReq)) {
+            throw new BizException("生成支付参数异常");
+        }
+//        transNo = paymentReq.getTransNo();
+        /*
         PaymentChannelEnum paymentChannel = PaymentChannelEnum.codeOf(payParam.getPayerName());
         
         switch (paymentChannel) {
 		case ADAPAY:
 
+
 	        //初始化支付数据
 	        Map<String, Object> paymentParams = getPaymentParam(payParam, clazz, hfMerchantConfig.getPlatformPayeeMemberId());
 	        paymentParams.put("time_expire", timeExpire);
@@ -320,12 +329,12 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
 
 		default:
 			break;
-		}
-        log.info("executePayment create order param >>>>> {}", JSON.toJSONString(payment));
+		}*/
+        log.info("executePayment create order param >>>>> {}", JSON.toJSONString(paymentReq));
         //修改流水
-        setTransNoByApply(transNo, clazz, setOption, action);
+        setTransNoByApply(paymentReq.getTransNo(), clazz, setOption, action);
 
-        return payment;
+        return paymentReq.getReqParams();
     }
 
     private <T> void checkOrderState(T obj, Function<T, DealStatusEnum> func) {

+ 8 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PayServiceImpl.java

@@ -5,6 +5,9 @@ import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
+import com.microsvc.toolkit.middleware.payment.common.api.BasePaymentConfig;
+import com.microsvc.toolkit.middleware.payment.common.api.BasePaymentService;
+import com.microsvc.toolkit.middleware.payment.common.api.PaymentServiceContext;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -94,7 +97,7 @@ public class PayServiceImpl implements PayService {
 		PaymentChannelEnum paymentChannel = PaymentChannelEnum.codeOf(paymentChannelStr);
         
         Integer tenantId = studentPaymentOrder.getTenantId();
-        
+
         HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(tenantId, paymentChannelStr);
         if(hfMerchantConfig == null){
         	throw new BizException("机构[{}][{}]商户信息找不到", tenantId, paymentChannelStr);
@@ -135,11 +138,11 @@ public class PayServiceImpl implements PayService {
 		Date date = new Date();
         
         //如果当前是买的小课/网管课
-		if (studentPaymentOrder != null && (studentPaymentOrder.getType() == OrderTypeEnum.SMALL_CLASS_TO_BUY || studentPaymentOrder.getType() == OrderTypeEnum.PRACTICE_GROUP_BUY
-				|| studentPaymentOrder.getType() == OrderTypeEnum.PRACTICE_GROUP_RENEW || studentPaymentOrder.getType() == OrderTypeEnum.LIVE_GROUP_BUY)) {
+		if (studentPaymentOrder.getType() == OrderTypeEnum.SMALL_CLASS_TO_BUY || studentPaymentOrder.getType() == OrderTypeEnum.PRACTICE_GROUP_BUY
+				|| studentPaymentOrder.getType() == OrderTypeEnum.PRACTICE_GROUP_RENEW || studentPaymentOrder.getType() == OrderTypeEnum.LIVE_GROUP_BUY) {
 			
 			//忽略的分部
-			List<Integer> ignoreOrganList = Arrays.asList(4);
+			List<Integer> ignoreOrganList = Collections.singletonList(4);
 			
 			// 是否由平台收款
 			String isPlatformCollection = sysConfigDao.findConfigValue(SysConfigService.IS_OPEN_SMALL_CLASS_INCOME_TO_PLATFORM);
@@ -190,7 +193,7 @@ public class PayServiceImpl implements PayService {
 		}
 		
 		//如果是乐队指导培训的订单,由武汉学校收款
-		if(studentPaymentOrder != null && studentPaymentOrder.getType() == OrderTypeEnum.DIRECTOR_TRAINING_CAMP) {
+		if(studentPaymentOrder.getType() == OrderTypeEnum.DIRECTOR_TRAINING_CAMP) {
 			
 			Integer routeOrganId = 50;
 			HfMember receiverMember = hfMemberDao.getByOrganId(routeOrganId, paymentChannelStr);

+ 148 - 42
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -3,6 +3,12 @@ package com.ym.mec.biz.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.google.common.collect.Lists;
+import com.microsvc.toolkit.common.tools.ThreadPool;
+import com.microsvc.toolkit.middleware.payment.common.api.BasePaymentService;
+import com.microsvc.toolkit.middleware.payment.common.api.PaymentServiceContext;
+import com.microsvc.toolkit.middleware.payment.common.api.entity.*;
+import com.microsvc.toolkit.middleware.payment.common.api.enums.PaymentStatus;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
@@ -27,18 +33,17 @@ import com.ym.mec.common.service.IdGeneratorService;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.thirdparty.adapay.ConfigInit;
-import com.ym.mec.thirdparty.adapay.Payment;
 import com.ym.mec.thirdparty.adapay.entity.BaseResult;
 import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
 import com.ym.mec.thirdparty.yeepay.YeepayPaymentService;
 import com.ym.mec.thirdparty.yqpay.*;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Service;
@@ -46,7 +51,6 @@ import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.*;
@@ -57,6 +61,7 @@ import java.util.stream.Collectors;
 import static com.ym.mec.biz.dal.enums.DealStatusEnum.CLOSE;
 import static com.ym.mec.biz.dal.enums.DealStatusEnum.SUCCESS;
 
+@Slf4j
 @Service
 public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentOrder> implements StudentPaymentOrderService {
 
@@ -150,6 +155,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     private MusicGroupPaymentCalenderAddressService musicGroupPaymentCalenderAddressService;
     @Resource
     private MusicGroupPaymentCalenderMemberService musicGroupPaymentCalenderMemberService;
+    @Resource
+    private PaymentServiceContext paymentServiceContext;
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
     @Override
@@ -361,11 +368,15 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             throw new BizException("机构[{}]汇付商户信息找不到", payingOrder.getTenantId());
         }
         
-        PaymentChannelEnum paymentChannel = PaymentChannelEnum.codeOf(payingOrder.getPaymentChannel());
+//        PaymentChannelEnum paymentChannel = PaymentChannelEnum.codeOf(payingOrder.getPaymentChannel());
         
-        OrderCancelModel  model = new OrderCancelModel();
-        Map<String, Object> payment = new HashMap<String, Object>();
-
+//        Map<String, Object> payment = new HashMap<String, Object>();
+        PaymentResp paymentResp = paymentServiceContext.getPaymentService(payingOrder.getPaymentChannel() + "_" + payingOrder.getTenantId())
+                .query(payingOrder.getTransNo(), payingOrder.getOrderNo());
+        if (paymentResp == null) {
+            throw new BizException("订单支付状态获取异常,稍后请重试,transNo:{},orderNo:{},paymentChannel:{}", payingOrder.getTransNo(), payingOrder.getOrderNo(), payingOrder.getPaymentChannel());
+        }
+/*
         if(paymentChannel == PaymentChannelEnum.ADAPAY) {
         	payment = Payment.queryPayment(payingOrder.getTransNo(), hfMerchantConfig.getMerKey());
         }else if(paymentChannel == PaymentChannelEnum.YEEPAY) {
@@ -386,28 +397,33 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         	throw new BizException("[{}]支付渠道不支持", payingOrder.getPaymentChannel());
         }
         
-        LOGGER.warn("订单[{}]交易主动查询接口返回:{}", payingOrder.getTransNo(), payment);
-
+        LOGGER.warn("订单[{}]交易主动查询接口返回:{}", payingOrder.getTransNo(), payment);*/
         Map<String, String> rpMap = new HashMap<>();
         rpMap.put("merOrderNo", payingOrder.getOrderNo());
         rpMap.put("orderNo", payingOrder.getTransNo());
-        rpMap.put("channelType", (String) payment.get("pay_channel"));
-        model.setPayChannel((String) payment.get("pay_channel"));
-        String status = (String) payment.get("status");
-        if (payment.containsKey("error_msg")) {
-            rpMap.put("remarks", (String) payment.get("error_msg"));
+        rpMap.put("channelType", paymentResp.getPaymentChannel());
+        OrderCancelModel  model = new OrderCancelModel();
+        model.setPayChannel(paymentResp.getPaymentChannel());
+//        String status = (String) payment.get("status");
+        if (paymentResp.getPaymentStatus() == PaymentStatus.FAILED || (DateUtil.minutesBetween(DateUtil.addHours(payingOrder.getUpdateTime(), 2),date) > 0)) {
+            rpMap.put("remarks", paymentResp.getMsg());
+            rpMap.put("tradeState", "0");
+            model.setStatus(false);
+        }else if (paymentResp.getPaymentStatus() == PaymentStatus.SUCCESSED) {
+            rpMap.put("tradeState", "1");
+            model.setStatus(true);
         }
-        if (status.equals("succeeded")) {
+        /*if (status.equals("succeeded")) {
             rpMap.put("tradeState", "1");
             model.setStatus(true);
         } else if (status.equals("failed")
                 || (DateUtil.minutesBetween(DateUtil.addHours(payingOrder.getUpdateTime(), 2),date) > 0)) {
             rpMap.put("tradeState", "0");
             model.setStatus(false);
-        }
+        }*/
 
-        if (status.equals("succeeded") ||
-                (status.equals("failed") || payingOrder.getCreateTime().before(DateUtil.addMinutes(new Date(), -35)))) {
+        if (paymentResp.getPaymentStatus() == PaymentStatus.SUCCESSED ||
+                (paymentResp.getPaymentStatus() == PaymentStatus.FAILED || payingOrder.getCreateTime().before(DateUtil.addMinutes(new Date(), -35)))) {
             try {
                 updateOrder(rpMap); //更新订单
                 model.setSuccess(true);
@@ -501,21 +517,39 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         }
         Date date = new Date();
         
-        HfMerchantConfig hfMerchantConfig = null;
-        
         List<StudentPaymentRouteOrder> routeOrders = studentPaymentRouteOrderService.getDao().getRouteOrders(order.getOrderNo());
-        
-        PaymentChannelEnum paymentChannel = PaymentChannelEnum.codeOf(order.getPaymentChannel());
-        
 
-    	if(hfMerchantConfig == null){
-    		hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId(), order.getPaymentChannel());
-    	}
+        HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId(), order.getPaymentChannel());
         if(hfMerchantConfig == null){
-        	throw new BizException("机构[{}][{}]商户信息找不到", order.getTenantId(), order.getPaymentChannel());
+            throw new BizException("机构[{}][{}]商户信息找不到", order.getTenantId(), order.getPaymentChannel());
+        }
+        BasePaymentService paymentService = paymentServiceContext.getPaymentService(order.getPaymentChannel() + "_" + order.getTenantId());
+        for (StudentPaymentRouteOrder routeOrder : routeOrders) {
+            // 执行分账逻辑
+            DivideReq.DivMember divMember = DivideReq.DivMember.builder()
+                    .memberId(routeOrder.getMerNo().equals(ConfigInit.merNo) ? "0" : routeOrder.getMerNo())
+                    .amount(routeOrder.getRouteAmount().setScale(2, RoundingMode.HALF_UP))
+                    .feeFlag("Y")
+                    .build();
+            DivideReq divideReq = DivideReq.builder()
+                    .transNo(order.getTransNo())
+                    .orderNo(order.getOrderNo())
+                    .divideOrderNo(idGeneratorService.generatorId("payment") + "")
+                    .divideAmount(divMember.getAmount())
+                    .divMembers(Lists.newArrayList(divMember))
+                    .build();
+            try {
+                DivideResp divide = paymentService.divide(divideReq);
+                log.info("分账信息返回:{}", divide);
+                routeOrder.setServiceFee(divide.getFeeAmount());
+                routeOrder.setUpdateTime(date);
+                studentPaymentRouteOrderService.getDao().update(routeOrder);
+            } catch (Exception e) {
+                log.error("分账失败 orderId:{}", order.getId(), e);
+            }
         }
-        
-        StudentPaymentRouteOrder studentPaymentRouteOrder = null;
+
+        /*StudentPaymentRouteOrder studentPaymentRouteOrder = null;
         
         if(paymentChannel == PaymentChannelEnum.ADAPAY) {
         	
@@ -601,7 +635,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
 
                 studentPaymentRouteOrderService.getDao().update(spro);
 			}
-		}
+		}*/
         
         return true;
     }
@@ -890,8 +924,20 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         if(hfMerchantConfig == null){
         	throw new BizException("机构[{}]汇付商户信息找不到", studentPaymentOrder.getTenantId());
         }
-        
-        if (StringUtils.equals(paymentChannel, "ADAPAY")) {
+        PaymentResp paymentResp = paymentServiceContext.getPaymentService(paymentChannel + "_" + studentPaymentOrder.getTenantId())
+                .query(transNo, orderNo);
+        if (paymentResp == null) {
+            throw new BizException("订单支付状态获取异常,稍后请重试,transNo:{},orderNo:{},paymentChannel:{}", transNo, orderNo, paymentChannel);
+        }
+        if (paymentResp.getPaymentStatus() == PaymentStatus.SUCCESSED) {
+            return PayStatus.SUCCESSED;
+        } else if (paymentResp.getPaymentStatus() == PaymentStatus.PENDDING) {
+            return PayStatus.PAYING;
+        }else {
+            return PayStatus.FAILED;
+        }
+
+        /*if (StringUtils.equals(paymentChannel, "ADAPAY")) {
             Map<String, Object> payment = Payment.queryPayment(transNo, hfMerchantConfig.getMerKey());
             String status = (String) payment.get("status");
             if (status.equals("succeeded")) {
@@ -945,7 +991,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         	}
             throw new BizException(result.get("message").toString());
         }
-        throw new BizException("支付渠道错误");
+        throw new BizException("支付渠道错误");*/
     }
 
     @Override
@@ -1685,12 +1731,52 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     @Override
-    @Transactional
+    @Transactional(rollbackFor = Exception.class)
     public OrderCancelModel cancelOrder(StudentPaymentOrder order, String reason) {
         OrderCancelModel model = new OrderCancelModel();
         model.setSuccess(true);
         try {
-            HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId(), order.getPaymentChannel());
+            String errorMessage = null;
+            BasePaymentService paymentService = paymentServiceContext.getPaymentService(order.getPaymentChannel() + "_" + order.getTenantId());
+            if (paymentService == null) {
+                throw new BizException("支付渠道不支持:{}", order.getPaymentChannel());
+            }
+            PaymentResp paymentResp = paymentService.query(order.getTransNo(), order.getOrderNo());
+            if (paymentResp == null) {
+                throw new BizException("订单支付状态获取异常,稍后请重试,transNo:{},orderNo:{},paymentChannel:{}", order.getTransNo(), order.getOrderNo(), order.getPaymentChannel());
+            }
+            if (paymentResp.getPaymentStatus() == PaymentStatus.SUCCESSED) {
+                model.setStatus(true);
+                order.setStatus(SUCCESS);
+            } else if (paymentResp.getPaymentStatus() == PaymentStatus.PENDDING) {
+                // 执行关单操作
+                PaymentClose paymentClose = paymentService.close(order.getTransNo(), reason, order.getOrderNo());
+                model.setSuccess(false);
+                if (Objects.nonNull(paymentClose)) {
+                    model.setMessage(paymentClose.getMsg());
+                    errorMessage = paymentClose.getMsg();
+                    // 订单取消,三方返回异常信息
+                    if (StringUtils.isNotEmpty(errorMessage)) {
+                        log.warn("cancelPayment orderNo={}, ex={}", order.getOrderNo(), errorMessage);
+                        // 记录异常消息
+                        ThreadPool.getExecutor().submit(() -> {
+                            order.setMemo(paymentClose.getMsg());
+                            // 更新订单关单异常信息
+                            studentPaymentOrderDao.update(order);
+                        });
+                    }else {
+                        model.setSuccess(true);
+                    }
+                }
+                model.setStatus(false);
+                order.setStatus(CLOSE);
+            }else {
+                model.setStatus(false);
+                order.setStatus(CLOSE);
+                order.setMemo(reason);
+            }
+
+            /*HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(order.getTenantId(), order.getPaymentChannel());
             if(hfMerchantConfig == null){
                 throw new BizException("机构[{}]汇付商户信息找不到", order.getTenantId());
             }
@@ -1738,7 +1824,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                 order.setStatus(CLOSE);
                 model.setSuccess(success);
                 model.setMessage(closeInfo.get("msg"));
-            }
+            }*/
             if (model.getSuccess()) {
                 TenantContextHolder.setTenantId(order.getTenantId());
                 callOrderCallBack(order);
@@ -1753,23 +1839,43 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     @Override
-    @Transactional
+    @Transactional(rollbackFor = Exception.class)
     public BaseResult<Map<String, Object>> refund(String orderNo, String notifyUrl, String refundNo) {
 
-        StudentPaymentOrder orderByOrderNo = this.findOrderByOrderNo(orderNo);
-        if (orderByOrderNo == null) {
+        StudentPaymentOrder paymentOrder = this.findOrderByOrderNo(orderNo);
+        if (paymentOrder == null) {
             throw new BizException("为找到订单");
         }
-        if (orderByOrderNo.getActualAmount().compareTo(BigDecimal.ZERO) ==0) {
+        if (paymentOrder.getActualAmount().compareTo(BigDecimal.ZERO) ==0) {
             throw new BizException("0元订单");
         }
-
+        BasePaymentService paymentService = paymentServiceContext.getPaymentService(paymentOrder.getPaymentChannel() + "_" + paymentOrder.getTenantId());
+        if (paymentService == null) {
+            throw new BizException("支付渠道不支持:{}", paymentOrder.getPaymentChannel());
+        }
+        RefundOrder refundOrder = new RefundOrder();
+        refundOrder.setUserId(paymentOrder.getUserId().toString());
+        refundOrder.setMerOrderNo(refundNo);
+        refundOrder.setRefundAmount(paymentOrder.getActualAmount());
+        refundOrder.setOrderAmount(paymentOrder.getActualAmount());
+        refundOrder.setTransNo(paymentOrder.getTransNo());
+        refundOrder.setPaymentOrderNo(paymentOrder.getOrderNo());
+        RefundResp refundResp = paymentService.refund(refundOrder);
+        // 申请请求失败
+        if (PaymentStatus.FAILED == refundResp.getPaymentStatus()) {
+            return BaseResult.failed(refundResp.getMsg());
+        } else {
+            Map<String,Object> param = new HashMap<>();
+            param.put("refundNo",refundNo);
+            return BaseResult.succeed(param);
+        }
+/*
         HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(orderByOrderNo.getTenantId(), orderByOrderNo.getPaymentChannel());
         if(hfMerchantConfig == null){
             throw new BizException("请配置机构的汇付商户信息");
         }
         return Payment.reversePayment(orderByOrderNo.getTransNo(),hfMerchantConfig.getAppId(),refundNo,
-                               orderByOrderNo.getActualAmount().setScale(2,BigDecimal.ROUND_HALF_UP).toString(),notifyUrl);
+                               orderByOrderNo.getActualAmount().setScale(2, RoundingMode.HALF_UP).toString(),notifyUrl);*/
     }
 
     @Override

+ 25 - 4
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantOrderRecordServiceImpl.java

@@ -14,6 +14,10 @@ import java.util.function.Consumer;
 import com.alibaba.fastjson.JSONObject;
 import com.huifu.adapay.core.AdapayCore;
 import com.huifu.adapay.core.util.AdapaySign;
+import com.microsvc.toolkit.middleware.payment.common.api.BasePaymentService;
+import com.microsvc.toolkit.middleware.payment.common.api.PaymentServiceContext;
+import com.microsvc.toolkit.middleware.payment.common.api.entity.PaymentResp;
+import com.microsvc.toolkit.middleware.payment.common.api.enums.PaymentStatus;
 import com.yeepay.g3.sdk.yop.encrypt.DigitalEnvelopeDTO;
 import com.yeepay.g3.sdk.yop.utils.DigitalEnvelopeUtils;
 import com.yeepay.g3.sdk.yop.utils.RSAKeyUtils;
@@ -115,6 +119,8 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
     
     @Autowired
     private TenantOrderRecordDao tenantOrderRecordDao;
+    @Autowired
+    private PaymentServiceContext paymentServiceContext;
 
     //订单不存在
     private static final String PAYMENT_ID_NOT_EXISTS = "payment_id_not_exists";
@@ -230,13 +236,13 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
 
     //开通成功
     @Transactional(rollbackFor = Exception.class)
-    private void open(TenantOrderRecord record) {
+    public void open(TenantOrderRecord record) {
         tenantInfoService.tenantOpenSuccess(record.getTenantId());
     }
 
     //续费成功
     @Transactional(rollbackFor = Exception.class)
-    private void renew(TenantOrderRecord record) {
+    public void renew(TenantOrderRecord record) {
         //机构产品信息
         TenantProductInfo productInfo = tenantProductInfoService.getOne(new WrapperUtil<TenantProductInfo>()
                 .hasEq("tenant_id_", record.getTenantId()).queryWrapper().eq("using_", 0));
@@ -355,7 +361,22 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
 
     //主动去第三方查询订单状态
     private void checkTransOrderState(TenantOrderRecord orderRecord) {
-        Map<String, Object> payment = new HashMap<String, Object>();
+        BasePaymentService paymentService = paymentServiceContext.getPaymentService(orderRecord.getPaymentChannel() + "_" + orderRecord.getTenantId());
+        if (paymentService == null) {
+            throw new BizException("支付渠道[{}]找不到", orderRecord.getPaymentChannel());
+        }
+        PaymentResp paymentResp = paymentService.query(orderRecord.getOrderNo(), orderRecord.getOrderNo());
+        if (Objects.isNull(paymentResp)) {
+            throw new BizException("订单支付状态获取异常,稍后请重试");
+        }
+        if (paymentResp.getPaymentStatus() == PaymentStatus.SUCCESSED) {
+            orderRecord.setOrderState(1);
+        }else if (paymentResp.getPaymentStatus() == PaymentStatus.PENDDING) {
+            orderRecord.setOrderState(0);
+        }else {
+            orderRecord.setOrderState(2);
+        }
+        /*Map<String, Object> payment = new HashMap<String, Object>();
         try {
             Integer tenantId = orderRecord.getTenantId();
             HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(tenantId, orderRecord.getPaymentChannel());
@@ -402,7 +423,7 @@ public class TenantOrderRecordServiceImpl extends ServiceImpl<TenantOrderRecordD
             log.info("    >>>>> checkTenantOrder  orderRecord >>>>> {}", JSON.toJSONString(orderRecord));
         } catch (Exception e) {
             log.error("    >>>>> checkTenantOrder  payment error>>>>> {}", JSON.toJSONString(orderRecord));
-        }
+        }*/
     }
 
     //超时返回true

+ 2 - 1
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/adapay/Payment.java

@@ -1,6 +1,7 @@
 package com.ym.mec.thirdparty.adapay;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 
 import com.alibaba.fastjson.JSON;
@@ -132,7 +133,7 @@ public class Payment {
 
         Map<String, Object> paymentParams = new LinkedHashMap<>();
         paymentParams.put("appId", hfMerchantConfig.getAppId());
-        paymentParams.put("amount", amount.setScale(2, BigDecimal.ROUND_HALF_UP));
+        paymentParams.put("amount", amount.setScale(2, RoundingMode.HALF_UP));
         paymentParams.put("orderNo", orderNo);
 //        paymentParams.put("notifyUrl", notifyUrl);
         paymentParams.put("returnUrl", returnUrl);

+ 0 - 1
mec-thirdparty/src/main/java/com/ym/mec/thirdparty/yqpay/CFCARAUtil.java

@@ -6,7 +6,6 @@ import cfca.sadk.lib.crypto.JCrypto;
 import cfca.sadk.system.FileHelper;
 import cfca.sadk.util.*;
 import cfca.sadk.x509.certificate.X509Cert;
-import org.hibernate.validator.internal.util.privilegedactions.GetClassLoader;
 import org.springframework.core.io.ClassPathResource;
 
 import javax.crypto.spec.SecretKeySpec;

+ 8 - 0
pom.xml

@@ -27,6 +27,7 @@
 		<docker.maven.plugin.version>1.2.2</docker.maven.plugin.version>
 		<com.microsvc.toolkit.version>1.0.8-RC1</com.microsvc.toolkit.version>
 		<cbs.version>1.0.26</cbs.version>
+		<microsvc.version>1.1.9</microsvc.version>
 	</properties>
 
 	<dependencyManagement>
@@ -37,6 +38,13 @@
 				<version>2.2.1.RELEASE</version>
 			</dependency>-->
 			<dependency>
+				<groupId>com.microsvc.toolkit</groupId>
+				<artifactId>microsvc-dependencies-bom</artifactId>
+				<version>${microsvc.version}</version>
+				<type>pom</type>
+				<scope>import</scope>
+			</dependency>
+			<dependency>
 				<groupId>org.springframework.cloud</groupId>
 				<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
 				<version>0.9.0.RELEASE</version>