浏览代码

-fix : 解决token重复重现的问题

bilingfeng 9 月之前
父节点
当前提交
d56ce1a83e

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java

@@ -23,7 +23,7 @@ public class SDKApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <游戏表新增字段> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <解决token重复重现的问题> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +

+ 2 - 4
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/UserTokenServiceImpl.java

@@ -303,8 +303,8 @@ public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken
     private UserToken tokenSave(Long userId, String token, Integer deviceType) {
         String lockKey = RedisKeyConstant.TOKEN_CREATE_LOCK + userId + "_" + deviceType;
         //上锁
-        if (!distributedLockComponent.doLock(lockKey, 0L, 3L, TimeUnit.MINUTES)) {
-            throw new BaseException("token创建中, 请勿重复请求!");
+        if (!distributedLockComponent.doLock(lockKey, 0L, 1L, TimeUnit.MINUTES)) {
+            throw new BaseException("操作频繁, 请1分钟后重试!");
         }
         try {
             UserToken userToken = UserToken.builder()
@@ -319,8 +319,6 @@ public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken
             return userToken;
         } catch (Exception e) {
             throw new BaseException("创建token异常!");
-        } finally {
-            distributedLockComponent.unlock(lockKey);
         }
     }