浏览代码

刷新令牌

he2802 4 年之前
父节点
当前提交
bd9fd8bbcc

+ 1 - 1
zhongzheng-api/src/main/java/com/zhongzheng/controller/wx/WxLoginController.java

@@ -52,7 +52,7 @@ public class WxLoginController
     }
 
     @ApiOperation("刷新令牌")
-    @PostMapping("/refreshToken/{unionId}")
+    @GetMapping("/refreshToken/{unionId}")
     public AjaxResult refreshToken(@PathVariable("unionId") String unionId)
     {
         String token = wxLoginService.refreshToken(unionId);

+ 1 - 0
zhongzheng-framework/src/main/java/com/zhongzheng/framework/security/filter/JwtAuthenticationTokenFilter.java

@@ -42,6 +42,7 @@ public class JwtAuthenticationTokenFilter extends OncePerRequestFilter
         if(StringUtils.isNoneEmpty(wxToken)){
             ClientLoginUser clientLoginUser = wxTokenService.getLoginUser(request);
             if(clientLoginUser!=null){
+                wxTokenService.verifyToken(clientLoginUser);
                 UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(clientLoginUser, null,null);
                 authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
                 SecurityContextHolder.getContext().setAuthentication(authenticationToken);

+ 12 - 3
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/WxLoginService.java

@@ -6,12 +6,13 @@ import com.alibaba.fastjson.JSONObject;
 import com.zhongzheng.common.core.bo.WxLoginResultBo;
 import com.zhongzheng.common.exception.CustomException;
 
-import com.zhongzheng.common.utils.AES;
-import com.zhongzheng.common.utils.SnowflakeIdUtils;
-import com.zhongzheng.common.utils.TelPhoneUtils;
+import com.zhongzheng.common.utils.*;
+import com.zhongzheng.common.utils.ip.IpUtils;
+import com.zhongzheng.modules.course.mapper.CourseSectionMapper;
 import com.zhongzheng.modules.user.bo.UserAddBo;
 import com.zhongzheng.modules.user.domain.User;
 import com.zhongzheng.modules.user.entity.ClientLoginUser;
+import com.zhongzheng.modules.user.mapper.UserMapper;
 import com.zhongzheng.modules.user.service.IUserService;
 import com.zhongzheng.modules.wx.bo.WxLoginBody;
 import org.apache.commons.codec.binary.Base64;
@@ -47,6 +48,9 @@ public class WxLoginService
     @Autowired
     private IUserService iUserService;
 
+    @Autowired
+    private UserMapper userMapper;
+
     public String login(WxLoginBody loginBody) {
         String unionId = getWxUnionId(loginBody.getCode());
         User user = iUserService.queryByUnionId(unionId);
@@ -63,6 +67,9 @@ public class WxLoginService
         if(user==null){
             throw new CustomException("unionId不存在");
         }
+        user.setLastLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
+        user.setLastLoginTime(DateUtils.getNowTime());
+        userMapper.updateById(user);
         ClientLoginUser loginUser = new ClientLoginUser();
         loginUser.setUser(user);
         return wxTokenService.createToken(loginUser);
@@ -88,6 +95,8 @@ public class WxLoginService
         bo.setSex(1);
         bo.setStatus(1);
         bo.setRegisterPlat("1");
+        bo.setLastLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
+        bo.setLastLoginTime(DateUtils.getNowTime());
         return iUserService.insertByAddBo(bo);
     }
 

+ 4 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/bo/UserAddBo.java

@@ -91,4 +91,8 @@ public class UserAddBo {
     private String unionId;
     @ApiModelProperty("注册平台 1小程序")
     private String registerPlat;
+    @ApiModelProperty("最后登录IP")
+    private String lastLoginIp;
+    @ApiModelProperty("最后登录时间")
+    private Long lastLoginTime;
 }

+ 4 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/domain/User.java

@@ -103,4 +103,8 @@ private static final long serialVersionUID=1L;
 
     /** 注册平台 1小程序 */
     private String registerPlat;
+
+    private String lastLoginIp;
+
+    private Long lastLoginTime;
 }

+ 2 - 0
zhongzheng-system/src/main/resources/mapper/modules/user/UserMapper.xml

@@ -31,6 +31,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="status" column="status"/>
         <result property="unionId" column="union_id"/>
         <result property="registerPlat" column="register_plat"/>
+        <result property="lastLoginIp" column="last_login_ip"/>
+        <result property="lastLoginTime" column="last_login_time"/>
     </resultMap>