yonge преди 3 години
родител
ревизия
1eb4d95b1c

+ 16 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/impl/TenantInfoServiceImpl.java

@@ -54,6 +54,7 @@ import com.ym.mec.auth.api.entity.SysRole;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.auth.api.enums.SysUserType;
 import com.ym.mec.biz.dal.dao.OrganizationDao;
+import com.ym.mec.biz.dal.dao.SysConfigDao;
 import com.ym.mec.biz.dal.dao.TenantInfoDao;
 import com.ym.mec.biz.dal.dto.TenantConfigDto;
 import com.ym.mec.biz.dal.dto.TenantInfoDto;
@@ -142,6 +143,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
     @Autowired
     private OrganizationDao organizationDao;
     @Autowired
+    private SysConfigDao sysConfigDao;
+    @Autowired
     private PayService payService;
     @Autowired
     private IdGeneratorService idGenerator;
@@ -792,6 +795,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         //生成订单编号
         String orderNo = idGenerator.generatorId("payment") + "";
         int orderState = 0;
+
+        String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
         //消费大于0元则拉起支付
         if (productInfo.getPayAmount().compareTo(BigDecimal.ZERO) > 0) {
             result = payService.getPayToPlatformMap(tenantId,
@@ -799,8 +804,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
                     productInfo.getPayAmount(),
                     BigDecimal.ZERO,
                     orderNo,
-                    null,
-                    null,
+                    baseApiUrl + "/api-web/tenantInfo/callback",
+                    baseApiUrl + "/api-web/tenantInfo/paymentResult?orderNo=" + orderNo,
                     tenantEnum.getMsg(),
                     tenantEnum.getMsg()
             );
@@ -837,6 +842,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         //生成订单编号
         String orderNo = idGenerator.generatorId("payment") + "";
         int orderState = 0;
+
+        String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
         //消费大于0元则拉起支付
         if (amount.compareTo(BigDecimal.ZERO) > 0) {
             result = payService.getPayToPlatformMap(tenantId,
@@ -844,8 +851,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
                     amount,
                     BigDecimal.ZERO,
                     orderNo,
-                    null,
-                    null,
+                    baseApiUrl + "/api-web/tenantInfo/callback",
+                    baseApiUrl + "/api-web/tenantInfo/paymentResult?orderNo=" + orderNo,
                     tenantEnum.getMsg(),
                     tenantEnum.getMsg()
             );
@@ -1121,6 +1128,9 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
         TenantOrderRecordEnum tenantEnum = TenantOrderRecordEnum.TENANT_RECHARGE;
         Map<String, Object> result = new HashMap<>();
         int orderState = 0;
+
+        String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
+        
         //消费大于0元则拉起支付
         if (amount.compareTo(BigDecimal.ZERO) > 0) {
             result = payService.getPayToPlatformMap(tenantId,
@@ -1128,8 +1138,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo
                     amount,
                     BigDecimal.ZERO,
                     orderNo,
-                    null,
-                    null,
+                    baseApiUrl + "/api-web/tenantInfo/callback",
+                    baseApiUrl + "/api-web/tenantInfo/paymentResult?orderNo=" + orderNo,
                     tenantEnum.getMsg(),
                     tenantEnum.getMsg()
             );

+ 61 - 0
mec-web/src/main/java/com/ym/mec/web/controller/TenantInfoController.java

@@ -1,5 +1,9 @@
 package com.ym.mec.web.controller;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.huifu.adapay.core.AdapayCore;
+import com.huifu.adapay.core.util.AdapaySign;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.TenantInfoDto;
@@ -13,7 +17,9 @@ import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.util.validator.ValidationKit;
+
 import io.swagger.annotations.*;
+
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
@@ -21,8 +27,11 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
+
 import java.math.BigDecimal;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
@@ -178,4 +187,56 @@ public class TenantInfoController extends BaseController {
         return succeed();
     }
 
+    @PostMapping("/callback")
+	public String callback(HttpServletRequest request) {
+		try {
+			// 验签请参data
+			String data = request.getParameter("data");
+			// 验签请参sign
+			String sign = request.getParameter("sign");
+			
+			logger.info("callback request param:{}", data);
+
+			// 验签
+			if (AdapaySign.verifySign(data, sign, AdapayCore.PUBLIC_KEY)) {
+				
+				JSONObject dataObj = JSON.parseObject(data);
+				
+				String transType = request.getParameter("type");
+				
+				Map<String, String> notifyMap = new HashMap<>();
+
+				switch (transType) {
+				case "payment.succeeded":// 支付成功
+
+					notifyMap.put("channelType", dataObj.getString("pay_channel"));
+					notifyMap.put("tradeState", "1");
+					notifyMap.put("totalMoney", dataObj.getString("pay_amt"));
+					notifyMap.put("merOrderNo", dataObj.getString("order_no"));
+					studentPaymentOrderService.updateOrder(notifyMap);
+					break;
+
+				case "payment.failed":// 支付失败
+
+					notifyMap.put("channelType", dataObj.getString("pay_channel"));
+					notifyMap.put("tradeState", "0");
+					notifyMap.put("totalMoney", dataObj.getString("pay_amt"));
+					notifyMap.put("merOrderNo", dataObj.getString("order_no"));
+					studentPaymentOrderService.updateOrder(notifyMap);
+
+					break;
+
+				default:
+					break;
+				}
+			} else {
+				return "验签失败";
+			}
+		} catch (Exception e) {
+			return e.getMessage();
+		}
+		
+		return "succeeded";
+	}
+
 }