release- app扫码登录PC端

release-2024-08-08
pikaqiudeshujia 7 months ago
parent 2248fafdc4
commit 4f6ec1b1eb

@ -120,6 +120,20 @@
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.80</version> <version>1.2.80</version>
</dependency> </dependency>
<!-- tool -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.20</version>
</dependency>
<!-- zxing -->
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.5.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>app</finalName> <finalName>app</finalName>

@ -4,6 +4,7 @@ import annotation.GlobalInterceptor;
import annotation.VerifyParam; import annotation.VerifyParam;
import api.Result; import api.Result;
import api.StatusCode; import api.StatusCode;
import cn.hutool.extra.qrcode.QrCodeUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.luoo.user.dto.UserNameLoginDto; import com.luoo.user.dto.UserNameLoginDto;
import com.luoo.user.dto.request.*; import com.luoo.user.dto.request.*;
@ -365,7 +366,7 @@ public class LoginController extends BaseController {
* *
* @return * @return
*/ */
@ApiOperation(value = "通过用户名/密码登录") @ApiOperation(value = "7.通过用户名/密码登录")
@PostMapping("/login/username") @PostMapping("/login/username")
public Result loginByUserName(@Validated @RequestBody UserNameLoginDto userNameLoginDto) { public Result loginByUserName(@Validated @RequestBody UserNameLoginDto userNameLoginDto) {
String userName = userNameLoginDto.getUserName(); String userName = userNameLoginDto.getUserName();
@ -388,11 +389,55 @@ public class LoginController extends BaseController {
} }
} }
@ApiOperation(value = "修改密码") @ApiOperation(value = "8.修改密码")
@PostMapping("/changePassword") @PostMapping("/changePassword")
public Result<Void> changePassword(@Validated @RequestBody UserNameLoginDto changePasswordDto) { public Result<Void> changePassword(@Validated @RequestBody UserNameLoginDto changePasswordDto) {
userInfoService.changePassword(changePasswordDto.getUserName(), changePasswordDto.getPassword()); userInfoService.changePassword(changePasswordDto.getUserName(), changePasswordDto.getPassword());
return Result.success(); return Result.success();
} }
@ApiOperation(value = "9.1.获取UUID", notes = "获取UUID")
@GetMapping(value = "/uuid")
public Result<String> getUuid() {
String uuid = UUID.randomUUID().toString();
return Result.success(uuid);
}
@ApiOperation(value = "9.2.校验uuid对应的请求认证状态", notes = "0是未完成其余是已完成状态的token")
@GetMapping(value = "/check/qr")
public Result<String> getCountryCode(String uuid) {
return Result.success(redisTemplate.opsForValue().get(uuid).toString());
}
@ApiOperation(value = "9.3.获取登录二维码、放入Token", notes = "前端获取二维码")
@GetMapping(value = "/getLoginQr")
public void createCodeImg(HttpServletRequest request, HttpServletResponse response, String uuid){
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
try {
response.setHeader("uuid", uuid);
// 这里是开源工具类 hutool里的QrCodeUtil
// 网址http://hutool.mydoc.io/
QrCodeUtil.generate(uuid, 300, 300, "jpg",response.getOutputStream());
redisTemplate.opsForValue().set(uuid, 0, 60, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
}
@ApiOperation(value = "9.4.确认身份接口:确定身份以及判断是否二维码过期等", notes = "确认身份接口:确定身份以及判断是否二维码过期等")
@PostMapping(value = "/bindUserIdAndToken")
public Result<String> bindUserIdAndToken(@RequestParam("token") String token ,
@RequestParam("userId") String userId){
try {
return Result.success(userInfoService.bindUserIdAndToken(userId,token));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
} }

@ -709,4 +709,19 @@ public class UserInfoService {
userInfoByUserName.setPassword(encoder.encode(password)); userInfoByUserName.setPassword(encoder.encode(password));
userInfoDao.save(userInfoByUserName); userInfoDao.save(userInfoByUserName);
} }
public String bindUserIdAndToken(String userId, String token) throws Exception {
Object o = redisTemplate.opsForValue().get(token);
if (o == null) {
throw new BizException("二维码失效!");
}
if(!String.valueOf(0).equals("0")) {
throw new BizException("登录认证已完成");
}
UserInfo loginUserInfo = userInfoDao.findById(userId).get();
String authorization = loginOrRegister(loginUserInfo);
redisTemplate.opsForValue().set(token, authorization, 60, TimeUnit.SECONDS);
return authorization;
}
} }

Loading…
Cancel
Save