bilingfeng пре 9 месеци
родитељ
комит
22ad06ba2f

+ 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) {
     public static void main(String[] args) {
         SpringApplication.run(SDKApplication.class, args);
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <回传金额降档兼容> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <解决切账号token锁的问题> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +
                 "\\ `--.| | | | |/ / \n" +

+ 18 - 11
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/UserTokenServiceImpl.java

@@ -301,20 +301,27 @@ public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken
     }
     }
 
 
     private UserToken tokenSave(Long userId, String token, Integer deviceType) {
     private UserToken tokenSave(Long userId, String token, Integer deviceType) {
+        String lockKey = RedisKeyConstant.TOKEN_CREATE_LOCK + userId + "_" + deviceType;
         //上锁
         //上锁
-        if (!distributedLockComponent.doLock(RedisKeyConstant.TOKEN_CREATE_LOCK + userId + "_" + deviceType, 0L, 3L, TimeUnit.MINUTES)) {
+        if (!distributedLockComponent.doLock(lockKey, 0L, 3L, TimeUnit.MINUTES)) {
             throw new BaseException("token创建中, 请勿重复请求!");
             throw new BaseException("token创建中, 请勿重复请求!");
         }
         }
-        UserToken userToken = UserToken.builder()
-                .userId(userId)
-                .token(token)
-                .deviceType(deviceType)
-                .createTime(LocalDateTime.now())
-                .updateTime(LocalDateTime.now())
-                .expireTime(DateUtils.localDateTimeToSecond(LocalDateTime.now()) + ExpireTimeEnum.ONE_WEEK.getTime())
-                .build();
-        super.save(userToken);
-        return userToken;
+        try {
+            UserToken userToken = UserToken.builder()
+                    .userId(userId)
+                    .token(token)
+                    .deviceType(deviceType)
+                    .createTime(LocalDateTime.now())
+                    .updateTime(LocalDateTime.now())
+                    .expireTime(DateUtils.localDateTimeToSecond(LocalDateTime.now()) + ExpireTimeEnum.ONE_WEEK.getTime())
+                    .build();
+            super.save(userToken);
+            return userToken;
+        } catch (Exception e) {
+            throw new BaseException("创建token异常!");
+        } finally {
+            distributedLockComponent.unlock(lockKey);
+        }
     }
     }
 
 
     @Override
     @Override