From e812995138f372c1385b056c506f2083b2bcb0a3 Mon Sep 17 00:00:00 2001 From: Gary Date: Tue, 16 Jan 2024 18:15:24 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9user=20login=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=BF=94=E5=9B=9Emap,=202.nickName=20=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E4=B8=BAXX-XXXX-XXXX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luoo/user/controller/UserController.java | 18 +++++++++++++----- .../java/com/luoo/user/util/NickNameUtil.java | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/controller/UserController.java b/luoo_user/src/main/java/com/luoo/user/controller/UserController.java index 7ed7692..2cc61d7 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/UserController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/UserController.java @@ -107,8 +107,12 @@ public class UserController { return Result.failed(StatusCode.USER_MOBILE_VERIFICATION_CODE_MISMATCH); } User user = userService.loginOrRegister(mobile); + + String token = jwtUtil.createJWT(user.getId(),user.getNickname(),Constants.TOKEN_ROLE_APP_USER); - return Result.success(token); + Map map = new HashMap<>(); + map.put("token", token); + return Result.success(map); }finally { redisTemplate.delete(redisMobileCheckCodeKey); } @@ -117,10 +121,12 @@ public class UserController { @ApiOperation(value = "3.游客登录返回token", notes = "token中的subject和roles均为tourist") @GetMapping("/touristLogin") - public Result touristLogin() { + public Result> touristLogin() { String nickName="游客-"+NickNameUtil.getRandomNickName(); String token = jwtUtil.createJWT(String.valueOf(idWorker.nextId()),nickName,Constants.TOKEN_ROLE_TOURIST); - return Result.success(token); + Map map=new HashMap<>(); + map.put("token", token); + return Result.success(map); } /** @@ -140,8 +146,10 @@ public class UserController { @ApiOperation(value = "5.token续期", notes = "有效期7天") @PostMapping("/autoLogin") @GlobalInterceptor - public Result autoLogin(@RequestHeader(value = "token", required = false) String token) { - return Result.success(userService.autoLogin(token)); + public Result> autoLogin(@RequestHeader(value = "token", required = false) String token) { + Map map=new HashMap<>(); + map.put("token", userService.autoLogin(token)); + return Result.success(map); } /** diff --git a/luoo_user/src/main/java/com/luoo/user/util/NickNameUtil.java b/luoo_user/src/main/java/com/luoo/user/util/NickNameUtil.java index f65db86..5d2b08c 100644 --- a/luoo_user/src/main/java/com/luoo/user/util/NickNameUtil.java +++ b/luoo_user/src/main/java/com/luoo/user/util/NickNameUtil.java @@ -3,7 +3,21 @@ package com.luoo.user.util; import com.apifan.common.random.RandomSource; public class NickNameUtil { + /** + * 最终名为: 雀乐/游客-XXXX-XXXX,经分析用户量1000万时,重名率为0.000001% + * eg: + * 雀乐-冬力一柏.朋长 + * 雀乐-莹玲书蕊&贤秋 + * 雀乐-博应杨-沛道 + * 雀乐-石济$丁然自钧 + */ + private static String[] SPECIAL_CHARACTER = new String[] { "~", "`", "@", "$", "%", "^", "&", "*", "+", "-", "|", + ".", "<", ">" }; + public static String getRandomNickName() { - return RandomSource.personInfoSource().randomChineseNickName(4); + int index = RandomSource.numberSource().randomInt(0, SPECIAL_CHARACTER.length); + String character = SPECIAL_CHARACTER[index]; + return RandomSource.personInfoSource().randomChineseNickName(4) + character + + RandomSource.personInfoSource().randomChineseNickName(4); } }