feat: AppKey 切换重新配置上线

This commit is contained in:
zuoqinbo 2023-11-02 16:02:08 +08:00
parent 0cbf09a20b
commit fb6e94eb81
2 changed files with 20 additions and 4 deletions

View File

@ -2,6 +2,8 @@ package cn.axzo.im.channel.netease;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; 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; import org.springframework.stereotype.Service;
/** /**
@ -13,11 +15,13 @@ import org.springframework.stereotype.Service;
* @date 2023/10/11 9:44 * @date 2023/10/11 9:44
*/ */
@Service("appKeyUtil") @Service("appKeyUtil")
@Configuration
@RefreshScope
public class AppKeyUtil { 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 * 网易云信IM配置appkey

View File

@ -21,6 +21,9 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; 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.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -59,6 +62,9 @@ public class AccountService {
private static final String DEFAULT_NICK_NAME = "普通IM用户_"; private static final String DEFAULT_NICK_NAME = "普通IM用户_";
@Autowired
private Environment environment;
/** /**
* 创建IM账户 * 创建IM账户
* *
@ -71,7 +77,8 @@ public class AccountService {
if (appTypeEnum == null) { if (appTypeEnum == null) {
throw new ServiceException("当前appType,服务器不支持该类型!!"); 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可能会更换普通用户通过userIdappTypeappKey维度来保证数据库唯一性 //后续AppKey可能会更换普通用户通过userIdappTypeappKey维度来保证数据库唯一性
UserAccountResp userAccountResp = createAccountRegister(userAccountReq.getUserId(), userIdWrapper, appType, UserAccountResp userAccountResp = createAccountRegister(userAccountReq.getUserId(), userIdWrapper, appType,
AccountTypeEnum.USER.getCode(), userAccountReq.getHeadImageUrl(), userAccountReq.getNickName()); AccountTypeEnum.USER.getCode(), userAccountReq.getHeadImageUrl(), userAccountReq.getNickName());
@ -117,7 +124,9 @@ public class AccountService {
if (StringUtils.isBlank(accountRegister.getImAccount())) { if (StringUtils.isBlank(accountRegister.getImAccount())) {
//2.重新注册账户,如果已注册就查询该账户信息 //2.重新注册账户,如果已注册就查询该账户信息
UserAccountResp accountResp = createNimAccount(userId, userIdWrapper, headImageUrl, nickName); 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.setImAccount(accountResp.getImAccount());
accountRegister.setToken(accountResp.getToken()); accountRegister.setToken(accountResp.getToken());
accountRegister.setAppKey(appKey); accountRegister.setAppKey(appKey);
@ -223,6 +232,9 @@ public class AccountService {
userAccountReq.setUserId(accountAbsentQuery.getPersonId()); userAccountReq.setUserId(accountAbsentQuery.getPersonId());
userAccountReq.setNickName(DEFAULT_NICK_NAME + accountAbsentQuery.getPersonId()); userAccountReq.setNickName(DEFAULT_NICK_NAME + accountAbsentQuery.getPersonId());
UserAccountResp accountResp = generateAccount(userAccountReq, iNotifyService); UserAccountResp accountResp = generateAccount(userAccountReq, iNotifyService);
if (StringUtils.isEmpty(accountResp.getToken())) {
continue;
}
accountResp.setAppType(appTypeEnum.getCode()); accountResp.setAppType(appTypeEnum.getCode());
userAccountAll.add(accountResp); userAccountAll.add(accountResp);
} }