release- 扫码登录新增已扫码未登录状态

release-2024-08-08
huangyawei 4 months ago
parent c6aa15cfe6
commit 183731df5d

@ -44,7 +44,6 @@ import java.util.concurrent.TimeUnit;
*
*
* @author Administrator
*
*/
@RestController
@CrossOrigin
@ -84,7 +83,7 @@ public class LoginController extends BaseController {
@PostMapping("/sendsms")
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 20)
public Result<Void> sendSms(@VerifyParam SendSmsReq sendSmsReq) {
if(sendSmsReq.getMobile().equals("18812345678")){
if (sendSmsReq.getMobile().equals("18812345678")) {
/**
*
*/
@ -112,7 +111,7 @@ public class LoginController extends BaseController {
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
public Result<String> appLogin(HttpServletRequest request,
@VerifyParam LoginReq loginReq) {
if("18812345678".equals(loginReq.getMobile())) {
if ("18812345678".equals(loginReq.getMobile())) {
UserInfo loginUserInfo = new UserInfo();
loginUserInfo.setMobile(loginReq.getMobile());
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
@ -139,9 +138,10 @@ public class LoginController extends BaseController {
redisTemplate.delete(redisMobileCheckCodeKey);
return Result.success(token);
}
@ApiOperation(value = "2.1 appleId登录/注册", notes = "成功后返回authorization")
@PostMapping("/appleIdLogin")
public Result<String> appleIdLogin(HttpServletRequest request,@VerifyParam AppleLoginReq appleLoginReq) {
public Result<String> appleIdLogin(HttpServletRequest request, @VerifyParam AppleLoginReq appleLoginReq) {
// 无手机号和验证码
@ -163,7 +163,7 @@ public class LoginController extends BaseController {
UserInfo loginUserInfo = new UserInfo();
// loginUserInfo.setMobile(appleLoginReq.getMobile());
loginUserInfo.setAppleId(appleLoginReq.getUserIdentifier());
loginUserInfo.setAppleEmail(playloadObj.get("email")+"");
loginUserInfo.setAppleEmail(playloadObj.get("email") + "");
loginUserInfo.setLastLoginIp(getIpAddr(request));
loginUserInfo.setLastUseDeviceId(appleLoginReq.getDeviceId());
loginUserInfo.setLastUseDeviceBrand(appleLoginReq.getDeviceBrand());
@ -173,15 +173,14 @@ public class LoginController extends BaseController {
return Result.success(token);
}
@ApiOperation(value = "2.2 微信wxId登录/注册", notes = "成功后返回authorization")
@PostMapping("/wxIdLogin")
public Result<String> wxIdLogin(HttpServletRequest request,@VerifyParam WeChatLoginReq weChatLoginReq) {
public Result<String> wxIdLogin(HttpServletRequest request, @VerifyParam WeChatLoginReq weChatLoginReq) {
// 如果有手机号,是首次微信登录时绑定流程
if(StringUtils.isNotEmpty(weChatLoginReq.getMobile())) {
if (StringUtils.isNotEmpty(weChatLoginReq.getMobile())) {
//得到缓存中的验证码
String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + weChatLoginReq.getDeviceId();
String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey);
@ -191,11 +190,11 @@ public class LoginController extends BaseController {
if (!redisMobileCheckCode.equals(weChatLoginReq.getMobileCheckCode())) {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
}
return weChatAouth2Service.register(weChatLoginReq,getIpAddr(request));
return weChatAouth2Service.register(weChatLoginReq, getIpAddr(request));
}
// 无手机号,非第一次微信登录场景,需要判断当前wxID在数据库中是否有记录如果有记录登录正常执行如果无记录返回状态到上面绑定手机号流程
return weChatAouth2Service.login(weChatLoginReq,getIpAddr(request));
return weChatAouth2Service.login(weChatLoginReq, getIpAddr(request));
}
@ -286,7 +285,6 @@ public class LoginController extends BaseController {
// }
/**
* authorization
*/
@ -303,7 +301,7 @@ public class LoginController extends BaseController {
*
*/
@ApiOperation(value = "4.获取图形验证码", notes = "4.三次短信验证失败后获取图形验证码有效期10分钟")
@ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "设备id", required = true) })
@ApiImplicitParams({@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)})
@GetMapping("/imageCheckCode/{deviceId}")
@GlobalInterceptor
public void imageCheckCode(HttpServletResponse response,
@ -318,12 +316,14 @@ public class LoginController extends BaseController {
redisTemplate.opsForValue().set(redisKey, code, 10, TimeUnit.MINUTES);
vCode.write(response.getOutputStream());
}
/**
* 4.1Base64
*
* @return
*/
@ApiOperation(value = "4.1获取图形验证码Base64", notes = "4.三次短信验证失败后获取图形验证码Base64有效期10分钟")
@ApiImplicitParams({ @ApiImplicitParam(name = "deviceId", value = "设备id", required = true) })
@ApiImplicitParams({@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)})
@GetMapping("/imageCheckCodeBase64/{deviceId}")
@GlobalInterceptor
public Result<String> imageCheckCodeBase64(HttpServletResponse response,
@ -349,15 +349,17 @@ public class LoginController extends BaseController {
public Result<List<CountryCodeDTO>> getSupportedCountryCode() {
return Result.success(DEFAULT_SUPPORTED_COUNTRY_CODES);
}
/**
* 退
*
* @param authorization
* @return
*/
@ApiOperation(value = "6.退出登录")
@PostMapping("/logout")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<Void> logout(@RequestHeader(value = "Authorization", required = true) String authorization){
public Result<Void> logout(@RequestHeader(value = "Authorization", required = true) String authorization) {
return Result.success();
}
@ -372,17 +374,17 @@ public class LoginController extends BaseController {
String userName = userNameLoginDto.getUserName();
String password = userNameLoginDto.getPassword();
UserInfo userInfo = userInfoService.findByUserNameAndPassword(userName, password);
if(ObjectUtils.notEqual(UserStatusEnum.ENABLE.getStatus(), userInfo.getStatus())){
if (ObjectUtils.notEqual(UserStatusEnum.ENABLE.getStatus(), userInfo.getStatus())) {
// 用户状态错误
throw new BizException(ErrorConstants.USER_STATUS_ERROR);
}
if (userInfo !=null) {
if (userInfo != null) {
//生成token
String token = jwtUtil.createJWT(userInfo.getId(),userInfo.getUserName(),"artist","");
String token = jwtUtil.createJWT(userInfo.getId(), userInfo.getUserName(), "artist", "");
Map<String, Object> map = new HashMap<>();
map.put("token",token);
map.put("roles","artist");
map.put("name",userInfo.getUserName());
map.put("token", token);
map.put("roles", "artist");
map.put("name", userInfo.getUserName());
return Result.success(map);
} else {
return Result.failed(StatusCode.USER_NAME_OR_PASSWORD_FAILED);
@ -404,7 +406,7 @@ public class LoginController extends BaseController {
return Result.success(uuid);
}
@ApiOperation(value = "9.2.校验uuid对应的请求认证状态", notes = "0是未完成,其余是已完成状态的token")
@ApiOperation(value = "9.2.校验uuid对应的请求认证状态", notes = "0-未完成 1-已扫码 other-token")
@GetMapping(value = "/check/qr")
public Result<String> getCountryCode(String uuid) {
return Result.success(redisTemplate.opsForValue().get(uuid).toString());
@ -412,7 +414,7 @@ public class LoginController extends BaseController {
@ApiOperation(value = "9.3.获取登录二维码、放入Token", notes = "前端获取二维码")
@GetMapping(value = "/getLoginQr")
public void createCodeImg(HttpServletRequest request, HttpServletResponse response, String uuid){
public void createCodeImg(HttpServletRequest request, HttpServletResponse response, String uuid) {
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
@ -425,14 +427,14 @@ public class LoginController extends BaseController {
if (o == null) {
throw new BizException("二维码失效!");
}
if(!String.valueOf(o).equals("0")) {
if (!String.valueOf(o).equals("0")) {
throw new BizException("登录认证已完成");
}
response.setHeader("uuid", uuid);
// 这里是开源工具类 hutool里的QrCodeUtil
// 网址http://hutool.mydoc.io/
QrCodeUtil.generate(uuid, 300, 300, "jpg",response.getOutputStream());
QrCodeUtil.generate(uuid, 300, 300, "jpg", response.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
@ -440,11 +442,13 @@ public class LoginController extends BaseController {
}
@ApiOperation(value = "9.4.确认身份接口:确定身份以及判断是否二维码过期等", notes = "确认身份接口:确定身份以及判断是否二维码过期等")
@PostMapping(value = "/bindUserIdAndToken")
public Result<String> bindUserIdAndToken(@RequestParam("token") String token ,
@RequestParam("userId") String userId){
@PostMapping(value = "/scanOrConfirm")
public Result<Void> scanOrConfirm(@RequestParam("token") String token,
@RequestParam("userId") String userId,
@RequestParam("type") Integer type) {
try {
return Result.success(userInfoService.bindUserIdAndToken(userId,token));
userInfoService.scan(userId, token, type);
return Result.success();
} catch (Exception e) {
throw new RuntimeException(e);
}

@ -710,7 +710,15 @@ public class UserInfoService {
userInfoDao.save(userInfoByUserName);
}
public String bindUserIdAndToken(String userId, String token) throws Exception {
/**
*
*
* @param userId id
* @param token uuid
* @param type 1- 2-
* @return token
*/
public void scan(String userId, String token, Integer type) throws Exception {
Object o = redisTemplate.opsForValue().get(token);
if (o == null) {
throw new BizException("二维码失效!");
@ -719,9 +727,15 @@ public class UserInfoService {
throw new BizException("登录认证已完成");
}
if(type == 1) {
// 扫码
redisTemplate.opsForValue().set(token, 1, 60, TimeUnit.SECONDS);
} else {
// 确认
UserInfo loginUserInfo = userInfoDao.findById(userId).get();
String authorization = loginOrRegister(loginUserInfo);
redisTemplate.opsForValue().set(token, authorization, 60, TimeUnit.SECONDS);
return authorization;
}
}
}

Loading…
Cancel
Save