release: scanOrConfirm 新增鉴权

release-2024-08-08
huangyw 4 months ago
parent 61c9b1eb92
commit de00b21956

@ -17,6 +17,7 @@ import com.luoo.user.util.IOSTokenUtils;
import constants.Constants;
import constants.ErrorConstants;
import controller.BaseController;
import dto.UserLoginDto;
import enums.RequestFrequencyTypeEnum;
import enums.UserStatusEnum;
import exception.BizException;
@ -54,161 +55,161 @@ import java.util.concurrent.TimeUnit;
@Api(tags = "LoginController")
public class LoginController extends BaseController {
private static final List<CountryCodeDTO> DEFAULT_SUPPORTED_COUNTRY_CODES = Arrays
.asList(new CountryCodeDTO("中国", "+86"));
@Autowired
private UserInfoService userInfoService;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private WeChatAouth2Service weChatAouth2Service;
@Autowired
private JwtUtil jwtUtil;
@Value("${download.url}")
private String downloadUrl;
/**
*
*
* @param
* @return
*/
@PutMapping("/{userid}/{friendid}/{x}")
public void updatefanscountandfollowcount(@PathVariable String userid,
@PathVariable String friendid,
@PathVariable int x) {
userInfoService.updatefanscountandfollowcount(x, userid, friendid);
}
/**
*
*/
@ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟一个手机号一天内最多发送20个请求")
@PostMapping("/sendsms")
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 20)
public Result<Void> sendSms(@VerifyParam SendSmsReq sendSmsReq) {
if (sendSmsReq.getMobile().equals("18812345678")) {
/**
*
*/
return Result.success();
}
if (!StringTools.isEmpty(sendSmsReq.getImageCheckCode())) {
// 得到缓存中的验证码
String redisImageCheckCodeKey =
Constants.REDIS_KEY_IMAGE_CHECK_CODE + sendSmsReq.getDeviceId();
String redisImageCheckCode = (String) redisTemplate.opsForValue().get(redisImageCheckCodeKey);
if (StringTools.isEmpty(redisImageCheckCode)) {
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_EXPIRED);
}
if (!redisImageCheckCode.equalsIgnoreCase(sendSmsReq.getImageCheckCode())) {
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_MISMATCH);
}
redisTemplate.delete(redisImageCheckCodeKey);
private static final List<CountryCodeDTO> DEFAULT_SUPPORTED_COUNTRY_CODES = Arrays
.asList(new CountryCodeDTO("中国", "+86"));
@Autowired
private UserInfoService userInfoService;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private WeChatAouth2Service weChatAouth2Service;
@Autowired
private JwtUtil jwtUtil;
@Value("${download.url}")
private String downloadUrl;
/**
*
*
* @param
* @return
*/
@PutMapping("/{userid}/{friendid}/{x}")
public void updatefanscountandfollowcount(@PathVariable String userid,
@PathVariable String friendid,
@PathVariable int x) {
userInfoService.updatefanscountandfollowcount(x, userid, friendid);
}
userInfoService.sendSms(sendSmsReq.getDeviceId(), sendSmsReq.getMobile());
return Result.success();
}
@ApiOperation(value = "2.登录/注册", notes = "成功后返回authorization")
@PostMapping("/appLogin")
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
public Result<String> appLogin(HttpServletRequest request,
@VerifyParam LoginReq loginReq) {
if ("18812345678".equals(loginReq.getMobile())) {
UserInfo loginUserInfo = new UserInfo();
loginUserInfo.setMobile(loginReq.getMobile());
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());
loginUserInfo.setLastLoginIp(getIpAddr(request));
String token = userInfoService.loginOrRegister(loginUserInfo);
return Result.success(token);
}
// 得到缓存中的验证码
String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + loginReq.getDeviceId();
String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey);
if (StringTools.isEmpty(redisMobileCheckCode)) {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED);
/**
*
*/
@ApiOperation(value = "1.发送短信验证码", notes = "有效期15分钟一个手机号一天内最多发送20个请求")
@PostMapping("/sendsms")
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.DAY, requestFrequencyThreshold = 20)
public Result<Void> sendSms(@VerifyParam SendSmsReq sendSmsReq) {
if (sendSmsReq.getMobile().equals("18812345678")) {
/**
*
*/
return Result.success();
}
if (!StringTools.isEmpty(sendSmsReq.getImageCheckCode())) {
// 得到缓存中的验证码
String redisImageCheckCodeKey =
Constants.REDIS_KEY_IMAGE_CHECK_CODE + sendSmsReq.getDeviceId();
String redisImageCheckCode = (String) redisTemplate.opsForValue().get(redisImageCheckCodeKey);
if (StringTools.isEmpty(redisImageCheckCode)) {
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_EXPIRED);
}
if (!redisImageCheckCode.equalsIgnoreCase(sendSmsReq.getImageCheckCode())) {
return Result.failed(StatusCode.USER_IMAGE_VERIFICATION_CODE_MISMATCH);
}
redisTemplate.delete(redisImageCheckCodeKey);
}
userInfoService.sendSms(sendSmsReq.getDeviceId(), sendSmsReq.getMobile());
return Result.success();
}
if (!redisMobileCheckCode.equals(loginReq.getMobileCheckCode())) {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
@ApiOperation(value = "2.登录/注册", notes = "成功后返回authorization")
@PostMapping("/appLogin")
@GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
public Result<String> appLogin(HttpServletRequest request,
@VerifyParam LoginReq loginReq) {
if ("18812345678".equals(loginReq.getMobile())) {
UserInfo loginUserInfo = new UserInfo();
loginUserInfo.setMobile(loginReq.getMobile());
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());
loginUserInfo.setLastLoginIp(getIpAddr(request));
String token = userInfoService.loginOrRegister(loginUserInfo);
return Result.success(token);
}
// 得到缓存中的验证码
String redisMobileCheckCodeKey = Constants.REDIS_KEY_MOBILE_CHECK_CODE + loginReq.getDeviceId();
String redisMobileCheckCode = (String) redisTemplate.opsForValue().get(redisMobileCheckCodeKey);
if (StringTools.isEmpty(redisMobileCheckCode)) {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED);
}
if (!redisMobileCheckCode.equals(loginReq.getMobileCheckCode())) {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
}
UserInfo loginUserInfo = new UserInfo();
loginUserInfo.setMobile(loginReq.getMobile());
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());
loginUserInfo.setLastLoginIp(getIpAddr(request));
String token = userInfoService.loginOrRegister(loginUserInfo);
redisTemplate.delete(redisMobileCheckCodeKey);
return Result.success(token);
}
UserInfo loginUserInfo = new UserInfo();
loginUserInfo.setMobile(loginReq.getMobile());
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());
loginUserInfo.setLastLoginIp(getIpAddr(request));
String token = userInfoService.loginOrRegister(loginUserInfo);
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) {
// 无手机号和验证码
String identityToken = appleLoginReq.getIdentityToken();
// 解码后的消息体
JSONObject playloadObj = IOSTokenUtils.parserIdentityToken(identityToken);
Boolean success;
try {
success = IOSTokenUtils.verifyExc(identityToken, playloadObj);
} catch (Exception e) {
return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
@ApiOperation(value = "2.1 appleId登录/注册", notes = "成功后返回authorization")
@PostMapping("/appleIdLogin")
public Result<String> appleIdLogin(HttpServletRequest request,
@VerifyParam AppleLoginReq appleLoginReq) {
// 无手机号和验证码
String identityToken = appleLoginReq.getIdentityToken();
// 解码后的消息体
JSONObject playloadObj = IOSTokenUtils.parserIdentityToken(identityToken);
Boolean success;
try {
success = IOSTokenUtils.verifyExc(identityToken, playloadObj);
} catch (Exception e) {
return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
// throw new RuntimeException(e);
}
}
if (!success) {
// TODO 校验token失败具体操作
return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
}
UserInfo loginUserInfo = new UserInfo();
if (!success) {
// TODO 校验token失败具体操作
return Result.failed(StatusCode.APPLE_lOGIN_FAILED);
}
UserInfo loginUserInfo = new UserInfo();
// loginUserInfo.setMobile(appleLoginReq.getMobile());
loginUserInfo.setAppleId(appleLoginReq.getUserIdentifier());
loginUserInfo.setAppleEmail(playloadObj.get("email") + "");
loginUserInfo.setLastLoginIp(getIpAddr(request));
loginUserInfo.setLastUseDeviceId(appleLoginReq.getDeviceId());
loginUserInfo.setLastUseDeviceBrand(appleLoginReq.getDeviceBrand());
String token = userInfoService.appleLoginOrRegister(loginUserInfo);
return Result.success(token);
}
@ApiOperation(value = "2.2 微信wxId登录/注册", notes = "成功后返回authorization")
@PostMapping("/wxIdLogin")
public Result<String> wxIdLogin(HttpServletRequest request,
@VerifyParam WeChatLoginReq weChatLoginReq) {
// 如果有手机号,是首次微信登录时绑定流程
if (StringUtils.isNotEmpty(weChatLoginReq.getMobile())) {
//得到缓存中的验证码
String redisMobileCheckCodeKey =
Constants.REDIS_KEY_MOBILE_CHECK_CODE + weChatLoginReq.getDeviceId();
String redisMobileCheckCode = (String) redisTemplate.opsForValue()
.get(redisMobileCheckCodeKey);
if (StringTools.isEmpty(redisMobileCheckCode)) {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED);
}
if (!redisMobileCheckCode.equals(weChatLoginReq.getMobileCheckCode())) {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
}
return weChatAouth2Service.register(weChatLoginReq, getIpAddr(request));
loginUserInfo.setAppleId(appleLoginReq.getUserIdentifier());
loginUserInfo.setAppleEmail(playloadObj.get("email") + "");
loginUserInfo.setLastLoginIp(getIpAddr(request));
loginUserInfo.setLastUseDeviceId(appleLoginReq.getDeviceId());
loginUserInfo.setLastUseDeviceBrand(appleLoginReq.getDeviceBrand());
String token = userInfoService.appleLoginOrRegister(loginUserInfo);
return Result.success(token);
}
// 无手机号,非第一次微信登录场景,需要判断当前wxID在数据库中是否有记录如果有记录登录正常执行如果无记录返回状态到上面绑定手机号流程
return weChatAouth2Service.login(weChatLoginReq, getIpAddr(request));
@ApiOperation(value = "2.2 微信wxId登录/注册", notes = "成功后返回authorization")
@PostMapping("/wxIdLogin")
public Result<String> wxIdLogin(HttpServletRequest request,
@VerifyParam WeChatLoginReq weChatLoginReq) {
// 如果有手机号,是首次微信登录时绑定流程
if (StringUtils.isNotEmpty(weChatLoginReq.getMobile())) {
//得到缓存中的验证码
String redisMobileCheckCodeKey =
Constants.REDIS_KEY_MOBILE_CHECK_CODE + weChatLoginReq.getDeviceId();
String redisMobileCheckCode = (String) redisTemplate.opsForValue()
.get(redisMobileCheckCodeKey);
if (StringTools.isEmpty(redisMobileCheckCode)) {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_EXPIRED);
}
if (!redisMobileCheckCode.equals(weChatLoginReq.getMobileCheckCode())) {
return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH);
}
return weChatAouth2Service.register(weChatLoginReq, getIpAddr(request));
}
// 无手机号,非第一次微信登录场景,需要判断当前wxID在数据库中是否有记录如果有记录登录正常执行如果无记录返回状态到上面绑定手机号流程
return weChatAouth2Service.login(weChatLoginReq, getIpAddr(request));
}
}
// @ApiOperation(value = "2.1 appleId登录/注册", notes = "成功后返回authorization")
// @PostMapping("/appleIdLogin")
// @GlobalInterceptor(frequencyType = RequestFrequencyTypeEnum.HOUR, requestFrequencyThreshold = 12)
@ -296,173 +297,177 @@ public class LoginController extends BaseController {
// }
/**
* authorization
*/
@ApiOperation(value = "3.token续期", notes = "有效期7天")
@PostMapping("/autoLogin")
@GlobalInterceptor
public Result<String> autoLogin(HttpServletRequest request,
@RequestHeader(value = "Authorization", required = false) String authorization,
@VerifyParam TokenRefreshReq tokenRefreshReq) {
return Result.success(userInfoService.autoLogin(authorization, tokenRefreshReq.getDeviceId(),
tokenRefreshReq.getDeviceBrand(), getIpAddr(request)));
}
/**
*
*/
@ApiOperation(value = "4.获取图形验证码", notes = "4.三次短信验证失败后获取图形验证码有效期10分钟")
@ApiImplicitParams({@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)})
@GetMapping("/imageCheckCode/{deviceId}")
@GlobalInterceptor
public void imageCheckCode(HttpServletResponse response,
@VerifyParam(required = true) @PathVariable("deviceId") String deviceId) throws IOException {
CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
String code = vCode.getCode();
String redisKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
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)})
@GetMapping("/imageCheckCodeBase64/{deviceId}")
@GlobalInterceptor
public Result<String> imageCheckCodeBase64(HttpServletResponse response,
@VerifyParam(required = true) @PathVariable("deviceId") String deviceId) throws IOException {
CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
String code = vCode.getCode();
String redisKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
redisTemplate.opsForValue().set(redisKey, code, 10, TimeUnit.MINUTES);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
vCode.write(bos);
return Result.success(Base64.getEncoder().encodeToString(bos.toByteArray()));
}
/**
*
*/
@ApiOperation(value = "5.获取支持的手机号国家码", notes = "v1仅支持'+86'")
@GetMapping("/supportedCountryCode")
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) {
return Result.success();
}
/**
* /
*
* @return
*/
@ApiOperation(value = "7.通过用户名/密码登录")
@PostMapping("/login/username")
public Result loginByUserName(@Validated @RequestBody UserNameLoginDto userNameLoginDto) {
String userName = userNameLoginDto.getUserName();
String password = userNameLoginDto.getPassword();
UserInfo userInfo = userInfoService.findByUserNameAndPassword(userName, password);
if (ObjectUtils.notEqual(UserStatusEnum.ENABLE.getStatus(), userInfo.getStatus())) {
// 用户状态错误
throw new BizException(ErrorConstants.USER_STATUS_ERROR);
/**
* authorization
*/
@ApiOperation(value = "3.token续期", notes = "有效期7天")
@PostMapping("/autoLogin")
@GlobalInterceptor
public Result<String> autoLogin(HttpServletRequest request,
@RequestHeader(value = "Authorization", required = false) String authorization,
@VerifyParam TokenRefreshReq tokenRefreshReq) {
return Result.success(userInfoService.autoLogin(authorization, tokenRefreshReq.getDeviceId(),
tokenRefreshReq.getDeviceBrand(), getIpAddr(request)));
}
/**
*
*/
@ApiOperation(value = "4.获取图形验证码", notes = "4.三次短信验证失败后获取图形验证码有效期10分钟")
@ApiImplicitParams({@ApiImplicitParam(name = "deviceId", value = "设备id", required = true)})
@GetMapping("/imageCheckCode/{deviceId}")
@GlobalInterceptor
public void imageCheckCode(HttpServletResponse response,
@VerifyParam(required = true) @PathVariable("deviceId") String deviceId) throws IOException {
CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
String code = vCode.getCode();
String redisKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
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)})
@GetMapping("/imageCheckCodeBase64/{deviceId}")
@GlobalInterceptor
public Result<String> imageCheckCodeBase64(HttpServletResponse response,
@VerifyParam(required = true) @PathVariable("deviceId") String deviceId) throws IOException {
CreateImageCode vCode = new CreateImageCode(130, 38, 5, 10);
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
String code = vCode.getCode();
String redisKey = Constants.REDIS_KEY_IMAGE_CHECK_CODE + deviceId;
redisTemplate.opsForValue().set(redisKey, code, 10, TimeUnit.MINUTES);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
vCode.write(bos);
return Result.success(Base64.getEncoder().encodeToString(bos.toByteArray()));
}
/**
*
*/
@ApiOperation(value = "5.获取支持的手机号国家码", notes = "v1仅支持'+86'")
@GetMapping("/supportedCountryCode")
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) {
return Result.success();
}
/**
* /
*
* @return
*/
@ApiOperation(value = "7.通过用户名/密码登录")
@PostMapping("/login/username")
public Result loginByUserName(@Validated @RequestBody UserNameLoginDto userNameLoginDto) {
String userName = userNameLoginDto.getUserName();
String password = userNameLoginDto.getPassword();
UserInfo userInfo = userInfoService.findByUserNameAndPassword(userName, password);
if (ObjectUtils.notEqual(UserStatusEnum.ENABLE.getStatus(), userInfo.getStatus())) {
// 用户状态错误
throw new BizException(ErrorConstants.USER_STATUS_ERROR);
}
if (userInfo != null) {
//生成token
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());
return Result.success(map);
} else {
return Result.failed(StatusCode.USER_NAME_OR_PASSWORD_FAILED);
}
}
@ApiOperation(value = "8.修改密码")
@PostMapping("/changePassword")
public Result<Void> changePassword(@Validated @RequestBody UserNameLoginDto changePasswordDto) {
userInfoService.changePassword(changePasswordDto.getUserName(),
changePasswordDto.getPassword());
return Result.success();
}
if (userInfo != null) {
//生成token
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());
return Result.success(map);
} else {
return Result.failed(StatusCode.USER_NAME_OR_PASSWORD_FAILED);
@ApiOperation(value = "9.1.获取UUID", notes = "获取UUID")
@GetMapping(value = "/uuid")
public Result<String> getUuid() {
String uuid = UUID.randomUUID().toString();
redisTemplate.opsForValue().set(uuid, 0, 60, TimeUnit.SECONDS);
return Result.success(uuid);
}
}
@ApiOperation(value = "8.修改密码")
@PostMapping("/changePassword")
public Result<Void> changePassword(@Validated @RequestBody UserNameLoginDto changePasswordDto) {
userInfoService.changePassword(changePasswordDto.getUserName(),
changePasswordDto.getPassword());
return Result.success();
}
@ApiOperation(value = "9.1.获取UUID", notes = "获取UUID")
@GetMapping(value = "/uuid")
public Result<String> getUuid() {
String uuid = UUID.randomUUID().toString();
redisTemplate.opsForValue().set(uuid, 0, 60, TimeUnit.SECONDS);
return Result.success(uuid);
}
@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());
}
@ApiOperation(value = "9.3.获取登录二维码、放入Token", notes = "前端获取二维码")
@GetMapping(value = "/getLoginQr")
public Result<String> createCodeImg(HttpServletRequest request, HttpServletResponse response,
String uuid) {
try {
Object o = redisTemplate.opsForValue().get(uuid);
if (o == null) {
throw new BizException("二维码失效!");
}
if (!String.valueOf(o).equals("0")) {
throw new BizException("登录认证已完成");
}
} catch (Exception e) {
e.printStackTrace();
@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());
}
@ApiOperation(value = "9.3.获取登录二维码、放入Token", notes = "前端获取二维码")
@GetMapping(value = "/getLoginQr")
public Result<String> createCodeImg(HttpServletRequest request, HttpServletResponse response,
String uuid) {
try {
Object o = redisTemplate.opsForValue().get(uuid);
if (o == null) {
throw new BizException("二维码失效!");
}
if (!String.valueOf(o).equals("0")) {
throw new BizException("登录认证已完成");
}
} catch (Exception e) {
e.printStackTrace();
}
log.info(downloadUrl);
return Result.success(downloadUrl + "?code=" + uuid);
}
log.info(downloadUrl);
return Result.success(downloadUrl + "?code=" + uuid);
}
@ApiOperation(value = "9.4.确认身份接口:确定身份以及判断是否二维码过期等", notes = "确认身份接口:确定身份以及判断是否二维码过期等")
@PostMapping(value = "/scanOrConfirm")
@ApiImplicitParams({@ApiImplicitParam(name = "token", value = "扫码获得的code", required = true),
@ApiImplicitParam(name = "userId", value = "用户id", required = true),
@ApiImplicitParam(name = "type", value = "type 1-扫码 2-确认", required = true)})
public Result<Void> scanOrConfirm(@RequestParam("token") String token,
@RequestParam("userId") String userId,
@RequestParam("type") Integer type) {
try {
userInfoService.scan(userId, token, type);
return Result.success();
} catch (Exception e) {
throw new RuntimeException(e);
@ApiOperation(value = "9.4.确认身份接口:确定身份以及判断是否二维码过期等", notes = "确认身份接口确定身份以及判断是否二维码过期等仅APP用户可用")
@PostMapping(value = "/scanOrConfirm")
@GlobalInterceptor(checkAppUserLogin = true)
@ApiImplicitParams({
@ApiImplicitParam(name = "authorization", value = "Authorization", required = true),
@ApiImplicitParam(name = "token", value = "扫码获得的code", required = true),
@ApiImplicitParam(name = "type", value = "type 1-扫码 2-确认", required = true)})
public Result<Void> scanOrConfirm(
@RequestHeader(value = "Authorization", required = true) String authorization,
@RequestParam("token") String token,
@RequestParam("type") Integer type) {
try {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
userInfoService.scan(userLoginDto.getUserId(), token, type);
return Result.success();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}

Loading…
Cancel
Save