TRX 1 рік тому
батько
коміт
16ad2241b4

+ 2 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/payment/HxzController.java

@@ -5,6 +5,7 @@ import com.github.microservice.models.hxz.*;
 import com.github.microservice.models.hxz.base.BaseResultModel;
 import com.zhongshu.card.client.ret.ResultContent;
 import com.zhongshu.card.server.core.service.payment.HxzService;
+import io.swagger.v3.oas.annotations.Hidden;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.extern.slf4j.Slf4j;
@@ -19,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
 @RestController
 @RequestMapping("hxz/v1")
 @Tag(name = "云版消费机接口-HXZ")
+@Hidden
 public class HxzController {
 
     @Autowired

+ 24 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/payment/ExpenseFlow.java

@@ -2,8 +2,10 @@ package com.zhongshu.card.server.core.domain.payment;
 
 import cn.hutool.json.JSONObject;
 import com.github.microservice.models.type.PaymentDeviceType;
+import com.github.microservice.models.type.PaymentType;
 import com.zhongshu.card.client.utils.type.RefundState;
 import com.zhongshu.card.server.core.domain.base.SuperMain;
+import com.zhongshu.card.server.core.domain.org.UserAccount;
 import com.zhongshu.card.server.core.domain.school.CardInfo;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
@@ -36,9 +38,19 @@ public class ExpenseFlow extends SuperMain {
     @Schema(description = "用户名称")
     private String userName;
 
+    @Schema(description = "用户信息")
+    @DBRef(lazy = true)
+    private UserAccount userAccount;
+
     @Schema(description = "消费机设备ID")
     private String deviceId;
 
+    @Schema(description = "订单所属的商户")
+    private String shopOid;
+
+    @Schema(description = "订单所属的学校")
+    private String schoolOid;
+
     @Schema(description = "卡片的编号,也是终端刷卡的 卡号")
     private String cardNo;
 
@@ -71,6 +83,12 @@ public class ExpenseFlow extends SuperMain {
     @Indexed
     private String paymentWay;
 
+    @Schema(description = "支付方式")
+    PaymentType paymentType = PaymentType.WxQrCode;
+
+    @Schema(description = "付款码内容")
+    private String qr;
+
     @Schema(description = "消费金额(单位:分)")
     @Indexed
     private BigDecimal payAmount;
@@ -85,6 +103,12 @@ public class ExpenseFlow extends SuperMain {
     @Schema(description = "编辑支付设备和方式")
     PaymentDeviceType paymentDeviceType;
 
+    @Schema(description = "验证参数是否符合要求")
+    private Boolean verifyParamIsSuccess = Boolean.TRUE;
+
+    @Schema(description = "验证参数的提示")
+    private String verifyParamMsg;
+
     //------------------支付结果 start-------------------------
 
     @Schema(description = "支付订单状态")

+ 6 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/httpRequest/ApiRequestService.java

@@ -18,6 +18,7 @@ import com.zhongshu.card.server.core.service.payment.RequestInfoService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.kafka.common.protocol.types.Field;
 import org.springdoc.webmvc.core.service.RequestService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -116,7 +117,11 @@ public class ApiRequestService extends SuperService {
             if (result.isSuccess()) {
                 responseModel.setIsSuccess();
             } else {
-                responseModel.setIsFailed(result.getMsg());
+                String msg = result.getMsg();
+                if (msg != null && msg.contains("每个二维码仅限使用一次")) {
+                    msg = "重复扫码";
+                }
+                responseModel.setIsFailed(msg);
             }
             responseModel.setContent(JSONUtil.toJsonStr(result));
             // 请求API参数

+ 165 - 123
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/payment/ExpenseFlowServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.json.JSONUtil;
 import com.github.microservice.components.data.base.util.PageEntityUtil;
 import com.github.microservice.models.hxz.*;
 import com.github.microservice.models.type.PaymentDeviceType;
+import com.github.microservice.models.type.PaymentType;
 import com.zhongshu.card.client.model.payment.ExpenseFlowCount;
 import com.zhongshu.card.client.model.payment.ExpenseFlowModel;
 import com.zhongshu.card.client.model.payment.ExpenseFlowSearch;
@@ -19,6 +20,7 @@ import com.zhongshu.card.server.core.dao.org.UserCountDao;
 import com.zhongshu.card.server.core.dao.payment.ExpenseFlowDao;
 import com.zhongshu.card.server.core.dao.payment.WalletDao;
 import com.zhongshu.card.server.core.dao.payment.WalletRechargeDao;
+import com.zhongshu.card.server.core.dao.school.DeviceBindDao;
 import com.zhongshu.card.server.core.dao.school.DeviceInfoDao;
 import com.zhongshu.card.server.core.domain.org.UserAccount;
 import com.zhongshu.card.server.core.domain.payment.ExpenseFlow;
@@ -26,15 +28,14 @@ import com.zhongshu.card.server.core.domain.payment.Wallet;
 import com.zhongshu.card.server.core.domain.payment.WalletRecharge;
 import com.zhongshu.card.server.core.domain.school.CardInfo;
 import com.zhongshu.card.server.core.domain.org.DeviceInfo;
+import com.zhongshu.card.server.core.domain.school.DeviceBind;
 import com.zhongshu.card.server.core.httpRequest.ApiRequestService;
 import com.zhongshu.card.server.core.httpRequest.apiConf.APIResponseModel;
 import com.zhongshu.card.server.core.service.base.SuperService;
-import com.zhongshu.card.server.core.util.BeanUtils;
-import com.zhongshu.card.server.core.util.CommonUtil;
-import com.zhongshu.card.server.core.util.DateUtils;
-import com.zhongshu.card.server.core.util.NextNoUtil;
+import com.zhongshu.card.server.core.util.*;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
@@ -70,9 +71,13 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
 
     @Autowired
     CardInfoDao cardInfoDao;
+
     @Autowired
     private ApiRequestService apiRequestService;
 
+    @Autowired
+    DeviceBindDao deviceBindDao;
+
     /**
      * 创建订单
      *
@@ -89,21 +94,28 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
 
         // 消费订单号
         expenseFlow.setOrderNo(iotParam.getOrder());
+        // 卡片信息
         expenseFlow.setCardNo(iotParam.getCardNo());
+
         String paymentNo = NextNoUtil.getNextPaymentNo(null);
         // 支付订单号
         expenseFlow.setPaymentNo(paymentNo);
+        // 支付金额
         BigDecimal amount = CommonUtil.turnMoney2BigDecimal(iotParam.getAmount());
         expenseFlow.setPayAmount(amount);
 
         String deviceId = iotParam.getDeviceId();
-        // 设备信息
         expenseFlow.setDeviceId(deviceId);
+
         // 支付方式
         expenseFlow.setPaymentWay(param.getPaymentType().getRemark());
+        expenseFlow.setPaymentType(param.getPaymentType());
         expenseFlow.setParam(iotParam);
         expenseFlow.setPaymentDeviceType(PaymentDeviceType.HxzConsumTransactions);
-        expenseFlowDao.save(expenseFlow);
+
+        // 验证参数、填充数据
+        commonVerifyExpenseFlow(expenseFlow);
+//        expenseFlowDao.save(expenseFlow);
         return ResultContent.buildSuccess(expenseFlow);
     }
 
@@ -115,89 +127,10 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
      */
     @Transactional
     public ResultContent<ExpenseFlow> expendPay(ExpenseFlow entity) {
-        String deviceId = entity.getDeviceId();
-
-        // 验证卡片
-        CardInfo cardInfo = cardInfoDao.findByCode(entity.getCardNo());
-        if (ObjectUtils.isEmpty(cardInfo)) {
-            entity.setIsPaySuccess(Boolean.FALSE);
-            entity.setPayRemark("卡片未注册");
-            entity.setPaymentStatus("支付失败");
-            expenseFlowDao.save(entity);
-            return ResultContent.buildSuccess(entity);
-        }
-        entity.setCardInfo(cardInfo);
-        entity.setUserId(cardInfo.getUserId());
-
-        String userId = cardInfo.getUserId();
-        UserAccount userAccount = userCountDao.findTopByUserId(userId);
-        if (ObjectUtils.isEmpty(userAccount)) {
-            entity.setIsPaySuccess(Boolean.FALSE);
-            entity.setPayRemark("持卡人为空");
-            entity.setPaymentStatus("支付失败");
-            expenseFlowDao.save(entity);
-            return ResultContent.buildSuccess(entity);
-        }
-        entity.setUserName(userAccount.getName());
-
-        if (userAccount.getState() == UserState.Locked) {
-            entity.setIsPaySuccess(Boolean.FALSE);
-            entity.setPayRemark("持卡人已锁定");
-            entity.setPaymentStatus("支付失败");
-            expenseFlowDao.save(entity);
-            return ResultContent.buildSuccess(entity);
-        }
-
-        DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
-        if (ObjectUtils.isEmpty(deviceInfo)) {
-            entity.setIsPaySuccess(Boolean.FALSE);
-            entity.setPayRemark("业务设备未注册");
-            entity.setPaymentStatus("支付失败");
-            expenseFlowDao.save(entity);
-            return ResultContent.buildSuccess(entity);
-        }
-
-        // 消费
-        if (deviceInfo.getDeviceType() != null) {
-            entity.setPayType(deviceInfo.getDeviceType().getRemark());
-        } else {
-            entity.setPayType("消费");
-        }
-
-        // 判断卡片是否可用
-        if (cardInfo.getCardState() != CardState.Enable) {
-            entity.setIsPaySuccess(Boolean.FALSE);
-            entity.setPayRemark(String.format("卡片", cardInfo.getCardState().getRemark()));
-            entity.setPaymentStatus("支付失败");
-            expenseFlowDao.save(entity);
-            return ResultContent.buildSuccess(entity);
-        }
-
-        ConsumTransactionsModel iotParam = (ConsumTransactionsModel) entity.getParam();
-        if (iotParam.getMode() != 0 && iotParam.getPayType() != 0) {
+        if (entity.getVerifyParamIsSuccess() == null || !entity.getVerifyParamIsSuccess()) {
+            // 参数失败
             entity.setIsPaySuccess(Boolean.FALSE);
-            entity.setPayRemark("消费模式不支持");
-            entity.setPaymentStatus("支付失败");
-            expenseFlowDao.save(entity);
-            return ResultContent.buildSuccess(entity);
-        }
-
-        // 得到钱包的金额
-        BigDecimal amount = entity.getPayAmount();
-        // 钱包信息
-        Wallet wallet = walletService.getUserWalletByUserId(userId);
-        if (wallet.getDataState() != DataState.Enable) {
-            entity.setIsPaySuccess(Boolean.FALSE);
-            entity.setPayRemark(String.format("支付失败钱包%s", wallet.getDataState().getRemark()));
-            entity.setPaymentStatus("支付失败");
-            expenseFlowDao.save(entity);
-            return ResultContent.buildSuccess(entity);
-        }
-
-        // 检查
-        if (wallet.getAmount().compareTo(amount) < 0) {
-            entity.setIsPaySuccess(Boolean.FALSE);
-            entity.setPayRemark("余额不足");
+            entity.setPayRemark(entity.getVerifyParamMsg());
             entity.setPaymentStatus("支付失败");
             expenseFlowDao.save(entity);
             return ResultContent.buildSuccess(entity);
@@ -207,8 +140,10 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
         entity.setPaymentStatus("支付成功");
         entity.setIsPaySuccess(Boolean.TRUE);
         entity.setPayRemark("支付成功");
-        expenseFlowDao.save(entity);
 
+        Wallet wallet = walletDao.findByUserId(entity.getUserId());
+        BigDecimal amount = entity.getPayAmount();
+        UserAccount userAccount = entity.getUserAccount();
         // 扣款
         // 消费金额
         try {
@@ -223,7 +158,7 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
             walletRecharge.setAmount(amount);
             walletRecharge.setRechargeType(RechargeType.Expend);
             walletRecharge.setAfterAmount(afterAmount);
-            walletRecharge.setUserId(userId);
+            walletRecharge.setUserId(userAccount.getUserId());
             walletRecharge.setUserAccount(userAccount);
             walletRecharge.setWallet(wallet);
             walletRecharge.setUserName(userAccount.getName());
@@ -237,6 +172,8 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
         } catch (Exception e) {
             e.printStackTrace();
         }
+        expenseFlowDao.save(entity);
+
         return ResultContent.buildSuccess();
     }
 
@@ -277,6 +214,9 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
     public ResultContent<ExpenseFlow> createExpenseFlowByHxz(QRCodeTransactionModel iotParam) {
         ExpenseFlow expenseFlow = new ExpenseFlow();
 
+        String userId = "665fc0389083d203896d3541";
+        expenseFlow.setUserId(userId);
+
         expenseFlow.setYear(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyy));
         expenseFlow.setMonth(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternMM));
         expenseFlow.setPaymentTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
@@ -293,69 +233,171 @@ public class ExpenseFlowServiceImpl extends SuperService implements ExpenseFlowS
         expenseFlow.setPayAmount(amount);
 
         String deviceId = iotParam.getDeviceId();
-        // 设备信息
         expenseFlow.setDeviceId(deviceId);
-        // 支付方式 钱包  二维码
-        expenseFlow.setPaymentWay(iotParam.getPaymentType().getRemark());
+
+        // 支付方式 付款码
+        String QR = iotParam.getQR();
+        // 判断 是 微信、支付宝的付款码
+        PaymentType paymentType = PaymentUtil.getPaymentTypeByQr(QR);
+        expenseFlow.setQr(QR);
+        if (paymentType != null) {
+            expenseFlow.setPaymentWay(paymentType.getRemark());
+        }
+        expenseFlow.setPaymentType(paymentType);
         expenseFlow.setParam(iotParam);
         expenseFlow.setPaymentDeviceType(PaymentDeviceType.HxzConsumTransactions);
-        expenseFlowDao.save(expenseFlow);
+
+        commonVerifyExpenseFlow(expenseFlow);
+
+//        expenseFlowDao.save(expenseFlow);
         return ResultContent.buildSuccess(expenseFlow);
     }
 
     /**
-     * 消费机 B扫C的支付
+     * 同意验证 支付订单的数据是否符合要求
      *
      * @param entity
-     * @return
      */
-    @Transactional
-    public ResultContent<ExpenseFlow> expendPayQrCode(ExpenseFlow entity) {
-        // 验证QR 关联的用户信息
-        String userId = "665fc0389083d203896d3541";
+    private void commonVerifyExpenseFlow(ExpenseFlow entity) {
+        String deviceId = entity.getDeviceId();
+        // 查询设备绑定德 商户 学校
+        if (StringUtils.isNotEmpty(deviceId)) {
+            DeviceBind deviceBind = deviceBindDao.findTopByDeviceId(deviceId);
+            if (ObjectUtils.isNotEmpty(deviceBind)) {
+                entity.setSchoolOid(deviceBind.getSchoolInfoOid());
+                entity.setShopOid(deviceBind.getShopInfoOid());
+            }
+        }
 
-        UserAccount userAccount = userCountDao.findTopByUserId(userId);
-        if (ObjectUtils.isEmpty(userAccount)) {
-            entity.setIsPaySuccess(Boolean.FALSE);
-            entity.setPayRemark("账号未注册");
-            entity.setPaymentStatus("支付失败");
-            expenseFlowDao.save(entity);
-            return ResultContent.buildSuccess(entity);
+        if (StringUtils.isNotEmpty(entity.getSchoolOid())) {
+            entity.setVerifyParamIsSuccess(Boolean.FALSE);
+            entity.setVerifyParamMsg("设备未绑定学校");
+            return;
+        }
+
+        if (StringUtils.isNotEmpty(entity.getShopOid())) {
+            entity.setVerifyParamIsSuccess(Boolean.FALSE);
+            entity.setVerifyParamMsg("设备未绑定商户");
+            return;
+        }
+
+        PaymentType paymentType = entity.getPaymentType();
+        // 刷卡支付
+        if (paymentType == PaymentType.UserWallet) {
+
+            CardInfo cardInfo = cardInfoDao.findByCode(entity.getCardNo());
+            if (ObjectUtils.isNotEmpty(cardInfo)) {
+                entity.setCardInfo(cardInfo);
+                entity.setUserId(cardInfo.getUserId());
+            }
+
+            // 验证卡片
+            if (ObjectUtils.isEmpty(cardInfo)) {
+                entity.setVerifyParamIsSuccess(Boolean.FALSE);
+                entity.setVerifyParamMsg("卡片未注册");
+                return;
+            }
+            // 判断卡片是否可用
+            if (cardInfo.getCardState() != CardState.Enable) {
+                entity.setVerifyParamIsSuccess(Boolean.FALSE);
+                entity.setVerifyParamMsg(String.format("卡片", cardInfo.getCardState().getRemark()));
+                return;
+            }
+
+            ConsumTransactionsModel iotParam = (ConsumTransactionsModel) entity.getParam();
+            if (iotParam.getMode() != 0 && iotParam.getPayType() != 0) {
+                entity.setVerifyParamIsSuccess(Boolean.FALSE);
+                entity.setVerifyParamMsg("消费模式不支持");
+                return;
+            }
+        }
+
+        if (StringUtils.isNotEmpty(entity.getUserId())) {
+            entity.setVerifyParamIsSuccess(Boolean.FALSE);
+            entity.setVerifyParamMsg("订单未找到用户");
+            return;
         }
 
+        UserAccount userAccount = userCountDao.findTopByUserId(entity.getUserId());
+        if (ObjectUtils.isEmpty(userAccount)) {
+            entity.setVerifyParamIsSuccess(Boolean.FALSE);
+            entity.setVerifyParamMsg("用户未注册");
+            return;
+        }
         if (userAccount.getState() == UserState.Locked) {
-            entity.setIsPaySuccess(Boolean.FALSE);
-            entity.setPayRemark("账号已锁定");
-            entity.setPaymentStatus("支付失败");
-            expenseFlowDao.save(entity);
-            return ResultContent.buildSuccess(entity);
+            entity.setVerifyParamIsSuccess(Boolean.FALSE);
+            entity.setVerifyParamMsg("用户已锁定");
+            return;
         }
         entity.setUserName(userAccount.getName());
-        entity.setUserId(userId);
+        entity.setUserAccount(userAccount);
+
+        // 个人钱包
+        if (paymentType == PaymentType.UserWallet) {
+            // 得到钱包的金额
+            BigDecimal amount = entity.getPayAmount();
+            // 钱包信息
+            Wallet wallet = walletService.getUserWalletByUserId(entity.getUserId());
+            if (wallet.getDataState() != DataState.Enable) {
+                entity.setVerifyParamIsSuccess(Boolean.FALSE);
+                entity.setVerifyParamMsg(String.format("支付失败钱包%s", wallet.getDataState().getRemark()));
+                return;
+            }
 
-        String deviceId = entity.getDeviceId();
-        if (deviceId == null) {
-            deviceId = "";
+            // 检查
+            if (wallet.getAmount().compareTo(amount) < 0) {
+                entity.setVerifyParamIsSuccess(Boolean.FALSE);
+                entity.setVerifyParamMsg("余额不足");
+                return;
+            }
         }
+
+        // 验证设备
         DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
         if (ObjectUtils.isEmpty(deviceInfo)) {
-            entity.setIsPaySuccess(Boolean.FALSE);
-            entity.setPayRemark("业务设备未注册");
-            entity.setPaymentStatus("支付失败");
-            expenseFlowDao.save(entity);
-            return ResultContent.buildSuccess(entity);
+            entity.setVerifyParamIsSuccess(Boolean.FALSE);
+            entity.setVerifyParamMsg("业务设备未注册");
+            return;
         }
-
         // 消费设备信息
         if (deviceInfo.getDeviceType() != null) {
             entity.setPayType(deviceInfo.getDeviceType().getRemark());
         } else {
             entity.setPayType("消费");
         }
+        if (entity.getPaymentType() == null) {
+            entity.setVerifyParamIsSuccess(Boolean.FALSE);
+            entity.setVerifyParamMsg("支付方式不支持");
+            return;
+        }
+    }
+
+    /**
+     * 消费机 B扫C的支付
+     *
+     * @param entity
+     * @return
+     */
+    @Transactional
+    public ResultContent<ExpenseFlow> expendPayQrCode(ExpenseFlow entity) {
+        if (entity.getVerifyParamIsSuccess() == null || !entity.getVerifyParamIsSuccess()) {
+            // 参数失败
+            entity.setIsPaySuccess(Boolean.FALSE);
+            entity.setPayRemark(entity.getVerifyParamMsg());
+            entity.setPaymentStatus("支付失败");
+            expenseFlowDao.save(entity);
+            return ResultContent.buildSuccess(entity);
+        }
+
+        PaymentType paymentType = entity.getPaymentType();
         // 调用微信支付
         QRCodeTransactionModel payParam = (QRCodeTransactionModel) entity.getParam();
+        // 微信支付
         String url = "https://jupan.5xryd.com//wxapi/pay/createQrCodeOrder";
-
+        if (paymentType == PaymentType.ZfbQrCode) {
+            // 支付宝支付
+            url = "https://jupan.5xryd.com//wxapi/pay/createAliQrCodeOrder";
+        }
         APIResponseModel apiResponseModel = apiRequestService.sendWxRequest(url, payParam);
         entity.setPayResult(apiResponseModel);
         log.info("支付结果:{}", apiResponseModel);

+ 0 - 12
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/payment/HxzService.java

@@ -78,12 +78,6 @@ public class HxzService extends SuperService {
         ConsumTransactionsResult resultModel = new ConsumTransactionsResult();
         // 创建订单
         ResultContent<ExpenseFlow> createResult = expenseFlowService.createExpenseFlowByHxz(param);
-        if (createResult.isFailed()) {
-            resultModel.setFailed(createResult.getMsg());
-            requestInfoService.addRequestInfo(param, resultModel);
-            result.setModel(resultModel);
-            return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
-        }
         ExpenseFlow expenseFlow = createResult.getContent();
 
         // 支付
@@ -130,12 +124,6 @@ public class HxzService extends SuperService {
 
         // 创建订单
         ResultContent<ExpenseFlow> createResult = expenseFlowService.createExpenseFlowByHxz(param);
-        if (createResult.isFailed()) {
-            model.setFailed(createResult.getMsg());
-            requestInfoService.addRequestInfo(param, model);
-            result.setModel(model);
-            return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
-        }
         ExpenseFlow expenseFlow = createResult.getContent();
 
         // 扣款支付订单

+ 45 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/util/PaymentUtil.java

@@ -0,0 +1,45 @@
+package com.zhongshu.card.server.core.util;
+
+import com.github.microservice.models.type.PaymentType;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+
+/**
+ * @author TRX
+ * @date 2024/7/3
+ */
+public class PaymentUtil {
+
+    // 微信付款码开头
+    public static List<String> wxStartList = List.of("10", "11", "12", "13", "14", "15");
+
+    // 支付宝付款码开头
+    public static List<String> zfbStartList = List.of("25", "26", "27", "28", "29", "30");
+
+    /**
+     * 根据B扫C 扫码内容判断是支付宝 还是微信支付
+     *
+     * @param qr
+     * @return
+     */
+    public static PaymentType getPaymentTypeByQr(String qr) {
+        PaymentType paymentType = null;
+        if (StringUtils.isNotEmpty(qr)) {
+            int len = qr.length();
+            for (String str : wxStartList) {
+                if (qr.startsWith(str) && len == 18) {
+                    return PaymentType.WxQrCode;
+                }
+            }
+
+            for (String str : zfbStartList) {
+                if (qr.startsWith(str)) {
+                    return PaymentType.ZfbQrCode;
+                }
+            }
+        }
+        return paymentType;
+    }
+
+}