|
@@ -1,39 +1,54 @@
|
|
|
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 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.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
+import com.ym.mec.biz.dal.dto.PaymentParam;
|
|
|
import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
import com.ym.mec.biz.dal.entity.TenantConfig;
|
|
|
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.service.*;
|
|
|
+import com.ym.mec.biz.service.HfMerchantConfigService;
|
|
|
+import com.ym.mec.biz.service.OrderPayOpsService;
|
|
|
+import com.ym.mec.biz.service.StudentPaymentOrderService;
|
|
|
+import com.ym.mec.biz.service.TenantConfigService;
|
|
|
+import com.ym.mec.biz.service.TenantOrderRecordService;
|
|
|
+import com.ym.mec.biz.service.TenantPaymentOrderService;
|
|
|
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.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.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 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;
|
|
|
|
|
|
/**
|
|
|
* @author hgw
|
|
@@ -49,6 +64,10 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
private TenantPaymentOrderService tenantPaymentOrderService;
|
|
|
@Autowired
|
|
|
private TenantOrderRecordService tenantOrderRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HfMerchantConfigService hfMerchantConfigService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private RedissonClient redissonClient;
|
|
|
@Autowired
|
|
@@ -62,9 +81,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
private static final BiPredicate<Object, DealStatusEnum> predicate = (o, s) -> Objects.nonNull(o) && !DealStatusEnum.ING.equals(s);
|
|
|
|
|
|
@Override
|
|
|
- public Map<String, Object> executePayment(BigDecimal amount, String orderNo, String payChannel, String returnUrl, String orderSubject, String orderBody, String sign, String code, String platform) throws Exception {
|
|
|
- PaymentParam payParam = new PaymentParam(amount, orderNo, payChannel, returnUrl,
|
|
|
- orderSubject, orderBody, sign, code, platform);
|
|
|
+ public Map<String, Object> executePayment(PaymentParam payParam) throws Exception {
|
|
|
log.info("executePayment >>>>> {}", JSON.toJSONString(payParam));
|
|
|
if (payParam.getAmount() == null) {
|
|
|
throw new Exception("PaymentParam query is null");
|
|
@@ -74,13 +91,11 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
//返回值
|
|
|
Map<String, Object> payment;
|
|
|
|
|
|
- if (WrapperUtil.checkStr(platform, tenantPlatform)) {
|
|
|
+ if (WrapperUtil.checkStr(payParam.getPlatform(), tenantPlatform)) {
|
|
|
//tenant 机构开通、续费付款、 cloudTeacherOrder 团练宝激活支付、tenantRecharge 机构充值
|
|
|
payment = tenantPlatformOrder(payParam);
|
|
|
//主动延迟检查订单
|
|
|
delayCheckTenant();
|
|
|
- } else if (platform.equals("teacher")) {
|
|
|
- payment = teacher(payParam);
|
|
|
} else {
|
|
|
//如果以上操作都没有 则应该是这一个,因为老代码就是这样写的。
|
|
|
payment = student(payParam);
|
|
@@ -90,13 +105,21 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
}
|
|
|
|
|
|
private void checkSing(PaymentParam param) {
|
|
|
+
|
|
|
+ //查询商户支付账户
|
|
|
+ HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(param.getTenantId());
|
|
|
+ if(hfMerchantConfig == null){
|
|
|
+ throw new BizException("请配置机构的汇付商户信息");
|
|
|
+ }
|
|
|
Map<String, Object> signParams = new LinkedHashMap<>();
|
|
|
- signParams.put("appId", ConfigInit.appId);
|
|
|
+ signParams.put("appId", hfMerchantConfig.getAppId());
|
|
|
signParams.put("amount", param.getAmount().setScale(2, RoundingMode.HALF_UP));
|
|
|
signParams.put("orderNo", param.getOrderNo());
|
|
|
+ signParams.put("notifyUrl", param.getNotifyUrl());
|
|
|
+ signParams.put("returnUrl", param.getReturnUrl());
|
|
|
signParams.put("orderSubject", param.getOrderSubject());
|
|
|
signParams.put("orderBody", param.getOrderBody());
|
|
|
- signParams.put("wxAppId", ConfigInit.wxAppId);
|
|
|
+ signParams.put("wxAppId", hfMerchantConfig.getWxAppId());
|
|
|
String originalStr = JSONObject.toJSONString(signParams);
|
|
|
String newSign = DigestUtils.md5DigestAsHex(originalStr.getBytes());
|
|
|
if (!newSign.equals(param.getSign())) {
|
|
@@ -110,7 +133,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
//查询订单
|
|
|
TenantOrderRecord tenantOrderRecord = tenantOrderRecordService.getOne(new WrapperUtil<TenantOrderRecord>()
|
|
|
.hasEq("order_no_", payParam.getOrderNo()).queryWrapper());
|
|
|
- if (Objects.isNull(tenantOrderRecord)) {
|
|
|
+ if (Objects.isNull(tenantOrderRecord) || tenantOrderRecord.getTenantId().intValue() != payParam.getTenantId()) {
|
|
|
throw new BizException("订单不存在");
|
|
|
}
|
|
|
if (tenantOrderRecord.getOrderState() != 0) {
|
|
@@ -118,7 +141,6 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
}
|
|
|
//获取支付数据
|
|
|
Map<String, Object> payment;
|
|
|
- payParam.setTenantId(tenantOrderRecord.getTenantId());
|
|
|
try {
|
|
|
payment = checkOrderAndGetParam(payParam,
|
|
|
tenantOrderRecord,
|
|
@@ -159,10 +181,10 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
private Map<String, Object> student(PaymentParam payParam) throws Exception {
|
|
|
Map<String, Object> payment;
|
|
|
StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.findOrderByOrderNo(payParam.getOrderNo());
|
|
|
- if (Objects.isNull(studentPaymentOrder)) {
|
|
|
+ if (Objects.isNull(studentPaymentOrder) || studentPaymentOrder.getTenantId().intValue() != payParam.getTenantId()) {
|
|
|
throw new BizException("订单不存在");
|
|
|
}
|
|
|
- payParam.setTenantId(studentPaymentOrder.getTenantId());
|
|
|
+
|
|
|
payment = checkOrderAndGetParam(payParam,
|
|
|
studentPaymentOrder,
|
|
|
StudentPaymentOrder::getStatus,
|
|
@@ -185,12 +207,20 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
Date createTime = dateFunc.apply(clazz);
|
|
|
//校验订单是否超时
|
|
|
String timeExpire = checkOrderTimeOut(createTime);
|
|
|
+
|
|
|
+ //查询商户支付账户
|
|
|
+ HfMerchantConfig hfMerchantConfig = hfMerchantConfigService.queryByTenantId(payParam.getTenantId());
|
|
|
+ if(hfMerchantConfig == null){
|
|
|
+ throw new BizException("请配置机构的汇付商户信息");
|
|
|
+ }
|
|
|
+
|
|
|
//初始化支付数据
|
|
|
- Map<String, Object> paymentParams = getPaymentParam(payParam, clazz);
|
|
|
+ Map<String, Object> paymentParams = getPaymentParam(payParam, clazz, hfMerchantConfig.getPlatformPayeeMemberId());
|
|
|
paymentParams.put("time_expire", timeExpire);
|
|
|
- paymentParams.put("expend", getExpend(payParam));
|
|
|
+ paymentParams.put("expend", getExpend(hfMerchantConfig, payParam));
|
|
|
+ paymentParams.put("notify_url", payParam.getReturnUrl());
|
|
|
//向第三方发起支付,获取第三方的支付的信息
|
|
|
- Map<String, Object> payment = Payment.executePayment(paymentParams);
|
|
|
+ Map<String, Object> payment = Payment.executePayment(hfMerchantConfig.getAppId(), hfMerchantConfig.getMerKey(), paymentParams);
|
|
|
log.info("executePayment create order param >>>>> {}", JSON.toJSONString(payment));
|
|
|
String transNo = (String) payment.get("id");
|
|
|
//修改流水
|
|
@@ -223,12 +253,12 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
action.accept(clazz);
|
|
|
}
|
|
|
|
|
|
- private Map<String, Object> getExpend(PaymentParam payParam) throws Exception {
|
|
|
+ private Map<String, Object> getExpend(HfMerchantConfig hfMerchantConfig, PaymentParam payParam) throws Exception {
|
|
|
Map<String, Object> expendParams = new HashMap<>(5);
|
|
|
String openId = "";
|
|
|
if (payParam.getPayChannel().equals("wx_pub")) {
|
|
|
//微信支付则获取openId
|
|
|
- openId = getOpenId(payParam.getCode());
|
|
|
+ openId = getOpenId(hfMerchantConfig, payParam.getCode());
|
|
|
}
|
|
|
expendParams.put("open_id", openId);
|
|
|
expendParams.put("is_raw", "1");
|
|
@@ -237,12 +267,12 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
return expendParams;
|
|
|
}
|
|
|
|
|
|
- private String getOpenId(String code) throws Exception {
|
|
|
+ private String getOpenId(HfMerchantConfig hfMerchantConfig, String code) throws Exception {
|
|
|
String openId;
|
|
|
if (code == null || code.isEmpty()) {
|
|
|
throw new BizException("微信支付请先授权");
|
|
|
}
|
|
|
- String wxMpOAuth2AccessTokenUrl = String.format(ConfigInit.wxMpOAuth2AccessTokenUrl, ConfigInit.wxAppId, ConfigInit.wxAppSecret, code);
|
|
|
+ String wxMpOAuth2AccessTokenUrl = String.format(ConfigInit.wxMpOAuth2AccessTokenUrl, hfMerchantConfig.getWxAppId(), hfMerchantConfig.getWxAppSecret(), code);
|
|
|
Map<String, String> weChatRes = JSON.parseObject(HttpUtil.get(wxMpOAuth2AccessTokenUrl, new HashMap<>()), Map.class);
|
|
|
if (!weChatRes.containsKey("openid")) {
|
|
|
throw new BizException("授权失败,请重新授权");
|
|
@@ -251,9 +281,8 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
return openId;
|
|
|
}
|
|
|
|
|
|
- private <T> Map<String, Object> getPaymentParam(PaymentParam payParam, T clazz) {
|
|
|
+ private <T> Map<String, Object> getPaymentParam(PaymentParam payParam, T clazz, String platformAccount) {
|
|
|
Map<String, Object> paymentParams = new HashMap<>();
|
|
|
- paymentParams.put("app_id", ConfigInit.appId);
|
|
|
paymentParams.put("order_no", payParam.getOrderNo());
|
|
|
paymentParams.put("pay_channel", payParam.getPayChannel());
|
|
|
paymentParams.put("pay_amt", payParam.getAmount().setScale(2, RoundingMode.HALF_UP));
|
|
@@ -293,7 +322,7 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
throw new BizException("分部[{}]没有设置收款账号", config.getParanValue());
|
|
|
}*/
|
|
|
|
|
|
- String platformAccount = sysConfigDao.findConfigValue(SysConfigService.PLATFORM_PAYEE_ACCOUNT);
|
|
|
+ //String platformAccount = sysConfigDao.findConfigValue(SysConfigService.PLATFORM_PAYEE_ACCOUNT);
|
|
|
|
|
|
if (StringUtils.isBlank(platformAccount)) {
|
|
|
throw new BizException("平台收款账户查询失败");
|
|
@@ -368,111 +397,5 @@ public class OrderPayOpsServiceImpl implements OrderPayOpsService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- static class PaymentParam {
|
|
|
- private BigDecimal amount;
|
|
|
- private String orderNo;
|
|
|
- private String payChannel;
|
|
|
- private String returnUrl;
|
|
|
- private String orderSubject;
|
|
|
- private String orderBody;
|
|
|
- private String sign;
|
|
|
- private String code;
|
|
|
- private String platform;
|
|
|
- private Integer tenantId;
|
|
|
-
|
|
|
- PaymentParam(BigDecimal amount, String orderNo, String payChannel, String returnUrl, String orderSubject,
|
|
|
- String orderBody, String sign, String code, String platform) {
|
|
|
- this.amount = amount;
|
|
|
- this.orderNo = orderNo;
|
|
|
- this.payChannel = payChannel;
|
|
|
- this.returnUrl = returnUrl;
|
|
|
- this.orderSubject = orderSubject;
|
|
|
- this.orderBody = orderBody;
|
|
|
- this.sign = sign;
|
|
|
- this.code = code;
|
|
|
- this.platform = platform;
|
|
|
- }
|
|
|
-
|
|
|
- public BigDecimal getAmount() {
|
|
|
- return amount;
|
|
|
- }
|
|
|
-
|
|
|
- public void setAmount(BigDecimal amount) {
|
|
|
- this.amount = amount;
|
|
|
- }
|
|
|
-
|
|
|
- public String getOrderNo() {
|
|
|
- return orderNo;
|
|
|
- }
|
|
|
-
|
|
|
- public void setOrderNo(String orderNo) {
|
|
|
- this.orderNo = orderNo;
|
|
|
- }
|
|
|
-
|
|
|
- public String getPayChannel() {
|
|
|
- return payChannel;
|
|
|
- }
|
|
|
-
|
|
|
- public void setPayChannel(String payChannel) {
|
|
|
- this.payChannel = payChannel;
|
|
|
- }
|
|
|
-
|
|
|
- public String getReturnUrl() {
|
|
|
- return returnUrl;
|
|
|
- }
|
|
|
-
|
|
|
- public void setReturnUrl(String returnUrl) {
|
|
|
- this.returnUrl = returnUrl;
|
|
|
- }
|
|
|
-
|
|
|
- public String getOrderSubject() {
|
|
|
- return orderSubject;
|
|
|
- }
|
|
|
-
|
|
|
- public void setOrderSubject(String orderSubject) {
|
|
|
- this.orderSubject = orderSubject;
|
|
|
- }
|
|
|
-
|
|
|
- public String getOrderBody() {
|
|
|
- return orderBody;
|
|
|
- }
|
|
|
-
|
|
|
- public void setOrderBody(String orderBody) {
|
|
|
- this.orderBody = orderBody;
|
|
|
- }
|
|
|
-
|
|
|
- public String getSign() {
|
|
|
- return sign;
|
|
|
- }
|
|
|
-
|
|
|
- public void setSign(String sign) {
|
|
|
- this.sign = sign;
|
|
|
- }
|
|
|
-
|
|
|
- public String getCode() {
|
|
|
- return code;
|
|
|
- }
|
|
|
-
|
|
|
- public void setCode(String code) {
|
|
|
- this.code = code;
|
|
|
- }
|
|
|
-
|
|
|
- public String getPlatform() {
|
|
|
- return platform;
|
|
|
- }
|
|
|
-
|
|
|
- public void setPlatform(String platform) {
|
|
|
- this.platform = platform;
|
|
|
- }
|
|
|
-
|
|
|
- public Integer getTenantId() {
|
|
|
- return tenantId;
|
|
|
- }
|
|
|
-
|
|
|
- public void setTenantId(Integer tenantId) {
|
|
|
- this.tenantId = tenantId;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|