Browse Source

各个客户单独jwt的token,并且新增校验

zyp 8 hours ago
parent
commit
dd57b96b92

+ 6 - 6
fs-service/src/main/resources/application-common.yml

@@ -14,12 +14,12 @@ fs:
   addressEnabled: false
   # 验证码类型 math 数组计算 char 字符验证
   captchaType: math
-  jwt:
-    # 加密秘钥
-    secret: f4e2e52034348f86b67cde581c0f9eb5
-    # token有效时长,7天,单位秒
-    expire: 31536000
-    header: AppToken
+#  jwt:
+#    # 加密秘钥
+#    secret: f4e2e52034348f86b67cde581c0f9eb5
+#    # token有效时长,7天,单位秒
+#    expire: 31536000
+#    header: AppToken
 # 开发环境配置
 server:
   servlet:

+ 6 - 0
fs-service/src/main/resources/application-config-druid-hdt.yml

@@ -65,6 +65,12 @@ watch:
 fs :
   commonApi: http://192.168.0.70:8010
   h5CommonApi: http://119.29.195.254:8010
+  jwt:
+    # 加密秘钥
+    secret: f4e2e52034348f86b67cde581c0f9eb6
+    # token有效时长,7天,单位秒
+    expire: 31536000
+    header: AppToken
 nuonuo:
   key: 10924508
   secret: A2EB20764D304D16

+ 6 - 0
fs-service/src/main/resources/application-config-druid-jnmy.yml

@@ -60,6 +60,12 @@ watch:
 fs :
   commonApi: http://192.168.0.18:7771
   h5CommonApi: http://192.168.0.18:7771
+  jwt:
+    # 加密秘钥
+    secret: f4e2e52034348f86b67cde581c0f9eb8
+    # token有效时长,7天,单位秒
+    expire: 31536000
+    header: AppToken
 nuonuo:
   key: 10924508
   secret: A2EB20764D304D16

+ 6 - 0
fs-service/src/main/resources/application-config-myhk.yml

@@ -65,6 +65,12 @@ watch:
 
 fs :
   commonApi: http://172.27.0.7:8010
+  jwt:
+    # 加密秘钥
+    secret: f4e2e52034348f86b67cde581c0f9e10
+    # token有效时长,7天,单位秒
+    expire: 31536000
+    header: AppToken
 nuonuo:
   key: 10924508
   secret: A2EB20764D304D16

+ 6 - 0
fs-service/src/main/resources/application-config-zkzh.yml

@@ -134,6 +134,12 @@ watch:
 
 fs:
   commonApi: http://172.21.76.167:8010
+  jwt:
+    # 加密秘钥
+    secret: f4e2e52034348f86b67cde581c0f9eb9
+    # token有效时长,7天,单位秒
+    expire: 31536000
+    header: AppToken
 nuonuo:
   key: 10924508
   secret: A2EB20764D304D16

+ 1 - 0
fs-user-app/src/main/java/com/fs/app/controller/course/CourseFsUserController.java

@@ -113,6 +113,7 @@ public class CourseFsUserController extends AppBaseController {
     @ApiOperation("答题")
     @PostMapping("/courseAnswer")
     @UserOperationLog(operationType = FsUserOperationEnum.ANSWER)
+    @RepeatSubmit
     public R courseAnswer(@RequestBody FsCourseQuestionAnswerUParam param){
         if (ObjectUtil.isEmpty(param.getUserId())){
             Long userId = Long.parseLong(getUserId());

+ 32 - 0
fs-user-app/src/main/java/com/fs/app/controller/course/CourseQwController.java

@@ -7,6 +7,7 @@ import com.fs.app.annotation.Login;
 import com.fs.app.controller.AppBaseController;
 import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.domain.R;
+import com.fs.common.utils.ServletUtils;
 import com.fs.common.utils.StringUtils;
 import com.fs.core.utils.OrderCodeUtils;
 import com.fs.course.config.CourseConfig;
@@ -24,6 +25,7 @@ import com.fs.system.service.ISysConfigService;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.hc.openapi.tool.fastjson.JSON;
+import io.jsonwebtoken.Claims;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
@@ -36,7 +38,9 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.Valid;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 @Api("企微看课接口")
 @RestController
@@ -413,4 +417,32 @@ public class CourseQwController extends AppBaseController {
         return R.ok().put("data",course);
     }
 
+
+    @ApiOperation("检测是否登录")
+    @GetMapping("/checkLogin")
+    public R checkLogin(){
+        try {
+            HttpServletRequest request = ServletUtils.getRequest();
+            //获取用户凭证
+            String token = request.getHeader(jwtUtils.getHeader());
+            if(StringUtils.isBlank(token)){
+                token = request.getParameter(jwtUtils.getHeader());
+            }
+            //检查token是否存在
+            if (StringUtils.isBlank(token)) {
+                return R.error(4001, "登录凭证不能为空,重新授权");
+            }
+            Claims claims=jwtUtils.getClaimByToken(token);
+            if(claims==null || jwtUtils.isTokenExpired(claims.getExpiration())){
+                return R.error(4004,"回传token校验失败,重新授权");
+            }
+            return R.ok();
+
+        }catch (Exception e){
+            logger.error("检测登录状态异常: {}", e.getMessage(), e);
+            return R.error("系统异常,请稍后重试");
+        }
+
+    }
+
 }

+ 1 - 1
fs-user-app/src/main/java/com/fs/app/utils/JwtUtils.java

@@ -49,7 +49,7 @@ public class JwtUtils {
                     .parseClaimsJws(token)
                     .getBody();
         }catch (Exception e){
-            logger.debug("validate is token error ", e);
+            logger.error("验证令牌错误", e);
             return null;
         }
     }