用java写了第二个login接口,其中在service类中,当用户名和密码都正确的时候,会生成一个token,token保存在user类中。当发送url请求的时候,添加一个拦截器,进行权限控制。
流程图
token的生成:
String token = JWT.create().withAudience(userInDB.getUserId()).withExpiresAt(calendar.getTime())
.sign(Algorithm.HMAC256(userInDB.getPassword()));复制代码
然后保存在user的token字段中,token的有效时间设置为1h。