Ver Fonte

fix:token校验限制

lileilei há 2 anos atrás
pai
commit
0c8306fda2

+ 28 - 0
src/main/java/com/yixin/ms/model/enums/TokenEnum.java

@@ -0,0 +1,28 @@
+package com.yixin.ms.model.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @author: lileilei
+ * @date: 2022/8/18 17:19
+ * @description:
+ */
+@AllArgsConstructor
+@Getter
+public enum TokenEnum {
+    INTERNAL_USE("hh_7cdf74cb7bd84b788a6bc8e0ba805e68");
+
+    private String token;
+
+    public static TokenEnum tokenOf(String token){
+        for(TokenEnum tokenEnum:values()){
+            if(tokenEnum.getToken().equals(token)){
+               return tokenEnum;
+            }
+        }
+
+        return null;
+    }
+
+}

+ 6 - 4
src/main/java/com/yixin/ms/service/impl/HealthCodeServiceImpl.java

@@ -101,10 +101,12 @@ public class HealthCodeServiceImpl implements HealthCodeService {
             throw new ServiceException(700, "token为空哦");
         }
 
-        if (StrUtil.isEmpty(shortTermDTO.getHealthCode())) {
-            if (StringUtils.isBlank(shortTermDTO.getIdNumber()) && StringUtils.isBlank(shortTermDTO.getName())) {
-                throw new ServiceException(701, "身份证和姓名为空哦");
-            }
+        if(TokenEnum.tokenOf(shortTermDTO.getToken()) == null){
+            throw new ServiceException(700, "token校验失败");
+        }
+
+        if (StringUtils.isBlank(shortTermDTO.getIdNumber())) {
+            throw new ServiceException(701, "身份证为空哦");
         }
 
         HealtCodeUserVO userVO = guizhouHealthServer.gzhHealthByIdCard(new GzhHealthDTO().setCardId(shortTermDTO.getIdNumber()));

+ 1 - 1
src/main/resources/application.yml

@@ -1,3 +1,3 @@
 spring:
   profiles:
-    active: test
+    active: prod