浏览代码

Merge remote-tracking branch 'origin/zx_1026_1111' into zx_1026_1111

yuanliang 1 年之前
父节点
当前提交
1df851d798

+ 9 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -1478,13 +1478,21 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         }
 
         String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
+        String notifyUrl = "";
+        if ("YEEPAY".equals(studentPaymentOrder.getPaymentChannel())){
+            notifyUrl = baseApiUrl + "/api-mall-portal/payment/callback_yee/" + studentPaymentOrder.getTenantId();
+        }else if ("ADAPAY".equals(studentPaymentOrder.getPaymentChannel())){
+            notifyUrl = baseApiUrl + "/api-mall-portal/payment/callback";
+        }else {
+            throw new BizException("支付渠道错误");
+        }
 
         //  receiver类型
         payMap = payService.getPayMap(
                 studentPaymentOrder.getActualAmount(),
                 studentPaymentOrder.getBalancePaymentAmount(),
                 model.getOrderNo(),
-                baseApiUrl + "/api-mall-portal/payment/callback",
+                notifyUrl,
                 baseApiUrl + "/api-student/studentOrder/paymentResult?type=edu&orderNo=" + model.getOrderNo(),
                 "商品销售",
                 "商品销售",

+ 2 - 2
mec-client-api/src/main/java/com/ym/mec/web/WebFeignService.java

@@ -43,8 +43,8 @@ public interface WebFeignService {
 	@PostMapping(value = "api/queryVipPracticeGroups")
     Boolean queryVipPracticeGroups();
 
-	@GetMapping(value = "/queryByTenantId/{id}")
-	HttpResponseResult<HfMerchantConfig> queryByTenantId(@PathVariable("id") Integer id);
+	@GetMapping(value = "/queryByTenantId/{payerName}/{id}")
+	HttpResponseResult<HfMerchantConfig> queryByTenantId(@PathVariable("payerName") String payerName,@PathVariable("id") Integer id);
 
 	@PostMapping("/api/mallCreateOrder")
 	HttpResponseResult<Map> mallCreateOrder(@RequestBody MallCreateOrderModel model);

+ 1 - 1
mec-client-api/src/main/java/com/ym/mec/web/fallback/WebFeignServiceFallback.java

@@ -55,7 +55,7 @@ public class WebFeignServiceFallback implements WebFeignService {
 	}
 
 	@Override
-	public HttpResponseResult<HfMerchantConfig> queryByTenantId(Integer id) {
+	public HttpResponseResult<HfMerchantConfig> queryByTenantId(String payerName,Integer id) {
 		return null;
 	}
 

+ 59 - 5
mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/controller/PaymentController.java

@@ -5,11 +5,16 @@ 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.yeepay.g3.sdk.yop.encrypt.DigitalEnvelopeDTO;
+import com.yeepay.g3.sdk.yop.utils.DigitalEnvelopeUtils;
+import com.yeepay.g3.sdk.yop.utils.RSAKeyUtils;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.exception.BizException;
+import com.ym.mec.thirdparty.adapay.entity.HfMerchantConfig;
+import com.ym.mec.web.WebFeignService;
 import com.yonge.cooleshow.mall.common.enums.OrderCacheEnum;
 import com.yonge.cooleshow.mbg.model.UserOrderPayment;
 import com.yonge.cooleshow.portal.dto.OrderPayRes;
@@ -23,14 +28,13 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
 import java.math.BigDecimal;
+import java.security.PrivateKey;
+import java.security.PublicKey;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
@@ -57,6 +61,9 @@ public class PaymentController extends BaseController {
     @Autowired
     private UserOrderPaymentService userOrderPaymentService;
 
+    @Autowired
+    private WebFeignService webFeignService;
+
 
     /***
      * 支付回调
@@ -133,7 +140,7 @@ public class PaymentController extends BaseController {
                     e.printStackTrace();
                     return failed("请求超时");
                 }
-            } else {
+            }else {
                 return "验签失败";
             }
         } catch (Exception e) {
@@ -143,4 +150,51 @@ public class PaymentController extends BaseController {
         return "succeeded";
     }
 
+    /***
+     * 易宝支付回调
+     * @author liweifan
+     * @param: request
+     * @updateTime 2022/3/11 18:35
+     */
+    @RequestMapping("/callback_yee/{tenantId}")
+    public Object callback_yee(@PathVariable("tenantId") Integer tenantId, HttpServletRequest request) {
+        try {
+            String content = request.getParameter("response");
+            JSONObject dataObj = JSON.parseObject(content);
+            String orderNo = dataObj.getString("orderId");
+            UserOrderPayment userOrderPayment = userOrderPaymentService.getByAdapayNo(orderNo);
+            if (userOrderPayment == null) {
+                throw new BizException("订单不存在");
+            }
+            HfMerchantConfig hfMerchantConfig = webFeignService.queryByTenantId("YEEPAY",tenantId).getData();
+            if(hfMerchantConfig == null){
+                throw new BizException("机构[{}][{}]商户信息找不到", tenantId, "YEEPAY");
+            }
+
+            // 构造结果通知请求对象
+            DigitalEnvelopeDTO dto = new DigitalEnvelopeDTO();
+            dto.setCipherText(content);
+            PrivateKey privateKey = RSAKeyUtils.string2PrivateKey(hfMerchantConfig.getRsaPrivateKey());
+            PublicKey publicKey = RSAKeyUtils.string2PublicKey(hfMerchantConfig.getRsaPublicKey());
+
+            dto = DigitalEnvelopeUtils.decrypt(dto, privateKey, publicKey);
+
+            log.info("易宝支付回调信息:response:{} plaintText:{}", content, dto.getPlainText());
+            if("SUCCESS".equals(dataObj.getString("status"))) {
+                orderService.paymentSucceededHandle(orderNo,
+                        dataObj.getBigDecimal("orderAmount"),dataObj.getString("channel"));
+            }else {
+                Map<String,Object> notifyMap = new HashMap<>();
+                notifyMap.put("channelType", dataObj.getString("channel"));
+                notifyMap.put("tradeState", "0");
+                notifyMap.put("totalMoney", dataObj.getString("orderAmount"));
+                notifyMap.put("merOrderNo", orderNo);
+                orderService.paymentFailedHandle(orderNo,notifyMap);
+            }
+        } catch (Exception e) {
+            return e.getMessage();
+        }
+        return "SUCCESS";
+    }
+
 }