From fb6e94eb81331eb22e0c6775b1712878f48ae902 Mon Sep 17 00:00:00 2001 From: zuoqinbo Date: Thu, 2 Nov 2023 16:02:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20AppKey=20=E5=88=87=E6=8D=A2=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E9=85=8D=E7=BD=AE=E4=B8=8A=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/axzo/im/channel/netease/AppKeyUtil.java | 8 ++++++-- .../java/cn/axzo/im/service/AccountService.java | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/im-center-server/src/main/java/cn/axzo/im/channel/netease/AppKeyUtil.java b/im-center-server/src/main/java/cn/axzo/im/channel/netease/AppKeyUtil.java index e0f52dd..24164a0 100644 --- a/im-center-server/src/main/java/cn/axzo/im/channel/netease/AppKeyUtil.java +++ b/im-center-server/src/main/java/cn/axzo/im/channel/netease/AppKeyUtil.java @@ -2,6 +2,8 @@ package cn.axzo.im.channel.netease; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; +import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Service; /** @@ -13,11 +15,13 @@ import org.springframework.stereotype.Service; * @date 2023/10/11 9:44 */ @Service("appKeyUtil") +@Configuration +@RefreshScope public class AppKeyUtil { - private static final String APP_KEY = "70c18b713812ae6e8038142f24c99f48"; + private static final String APP_KEY = "0f85615ab0972611ac59147fb79709ad"; - private static final String APP_SECRET = "784adefc4be7"; + private static final String APP_SECRET = "0d1ada41f74f"; /** * 网易云信IM配置appkey diff --git a/im-center-server/src/main/java/cn/axzo/im/service/AccountService.java b/im-center-server/src/main/java/cn/axzo/im/service/AccountService.java index 59bdff9..5178926 100644 --- a/im-center-server/src/main/java/cn/axzo/im/service/AccountService.java +++ b/im-center-server/src/main/java/cn/axzo/im/service/AccountService.java @@ -21,6 +21,9 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RestController; @@ -59,6 +62,9 @@ public class AccountService { private static final String DEFAULT_NICK_NAME = "普通IM用户_"; + @Autowired + private Environment environment; + /** * 创建IM账户 * @@ -71,7 +77,8 @@ public class AccountService { if (appTypeEnum == null) { throw new ServiceException("当前appType,服务器不支持该类型!!"); } - String userIdWrapper = userAccountReq.getUserId() + "_" + appTypeEnum.getCode(); + String env = environment.getProperty("spring.profiles.active"); + String userIdWrapper = env + userAccountReq.getUserId() + "_" + appTypeEnum.getCode(); //后续AppKey可能会更换,普通用户通过userId、appType、appKey维度来保证数据库唯一性 UserAccountResp userAccountResp = createAccountRegister(userAccountReq.getUserId(), userIdWrapper, appType, AccountTypeEnum.USER.getCode(), userAccountReq.getHeadImageUrl(), userAccountReq.getNickName()); @@ -117,7 +124,9 @@ public class AccountService { if (StringUtils.isBlank(accountRegister.getImAccount())) { //2.重新注册账户,如果已注册,就查询该账户信息 UserAccountResp accountResp = createNimAccount(userId, userIdWrapper, headImageUrl, nickName); - if (accountResp != null && StringUtils.isNotBlank(accountResp.getImAccount())) { + //重复注册的用户 会返回imaccount 不会返回token + if (accountResp != null && StringUtils.isNotBlank(accountResp.getImAccount()) + && StringUtils.isNotBlank(accountResp.getToken())) { accountRegister.setImAccount(accountResp.getImAccount()); accountRegister.setToken(accountResp.getToken()); accountRegister.setAppKey(appKey); @@ -223,6 +232,9 @@ public class AccountService { userAccountReq.setUserId(accountAbsentQuery.getPersonId()); userAccountReq.setNickName(DEFAULT_NICK_NAME + accountAbsentQuery.getPersonId()); UserAccountResp accountResp = generateAccount(userAccountReq, iNotifyService); + if (StringUtils.isEmpty(accountResp.getToken())) { + continue; + } accountResp.setAppType(appTypeEnum.getCode()); userAccountAll.add(accountResp); }