feat(main): 新增 websopy 内部服务调用密钥及默认域名初始化
- 在配置文件中添加内部服务调用密钥配置,支持环境变量覆盖 - ConfigProperties 添加 internalKey 属性用于读取密钥 - MainController 新增 initDefaultDomain 方法,调用 websopy 初始化租户默认域名 - 租户注册成功后调用默认域名初始化接口,失败时记录日志但不阻断流程 - TenantServiceImpl 内置超管账号时设置已安装标志,避免重复操作
This commit is contained in:
@@ -97,6 +97,11 @@ public class ConfigProperties {
|
||||
*/
|
||||
private String websopyUrl;
|
||||
|
||||
/**
|
||||
* 内部服务调用密钥(调用 websopy 等内部接口时使用)
|
||||
*/
|
||||
private String internalKey;
|
||||
|
||||
/**
|
||||
* 微信扫码H5页面访问地址(用于微信扫码登录跳转)
|
||||
*/
|
||||
|
||||
@@ -57,6 +57,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -69,6 +70,7 @@ import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
@@ -90,6 +92,8 @@ public class MainController extends BaseController {
|
||||
@Resource
|
||||
private ConfigProperties configProperties;
|
||||
@Resource
|
||||
private RestTemplate restTemplate;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@@ -1285,6 +1289,31 @@ public class MainController extends BaseController {
|
||||
return access_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 向 websopy 初始化租户默认域名并标记为已生效
|
||||
*/
|
||||
private void initDefaultDomain(Integer tenantId, String appCode) {
|
||||
String websopyUrl = configProperties.getWebsopyUrl();
|
||||
if (StrUtil.isBlank(websopyUrl)) {
|
||||
return;
|
||||
}
|
||||
String prefix = "site";
|
||||
String suffix = "sitelnk.cn";
|
||||
if ("mp".equals(appCode)) {
|
||||
prefix = "mp";
|
||||
suffix = "shoplnk.cn";
|
||||
} else if ("shop".equals(appCode)) {
|
||||
prefix = "shop";
|
||||
suffix = "shoplnk.cn";
|
||||
}
|
||||
String domain = prefix + "-" + tenantId + "." + suffix;
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("tenantId", tenantId);
|
||||
body.put("domain", domain);
|
||||
body.put("internalKey", configProperties.getInternalKey());
|
||||
restTemplate.postForObject(websopyUrl + "/api/app/user-sync/initDomain", body, String.class);
|
||||
}
|
||||
|
||||
@Operation(summary = "开发者短信验证码登录")
|
||||
@PostMapping("/loginByDeveloperSms")
|
||||
public ApiResult<LoginResult> loginByDeveloperSms(@RequestBody LoginParam param, HttpServletRequest request) {
|
||||
@@ -1448,9 +1477,6 @@ public class MainController extends BaseController {
|
||||
userParam.setTemplateId(user.getTemplateId());
|
||||
userParam.setTenantId(addCompany.getTenantId()); // 使用新创建的租户ID
|
||||
final User adminByPhone = userService.getAdminByPhone(userParam);
|
||||
// 注册即开通:标记该超管账号已安装(initialized)
|
||||
adminByPhone.setInstalled(true);
|
||||
userService.updateById(adminByPhone);
|
||||
|
||||
// 设置过期时间
|
||||
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||
@@ -1632,9 +1658,14 @@ public class MainController extends BaseController {
|
||||
userParam1.setTemplateId(user.getTemplateId());
|
||||
userParam1.setTenantId(addCompany.getTenantId()); // 使用新创建的租户ID
|
||||
final User adminByPhone = userService.getAdminByPhone(userParam1);
|
||||
// 注册即开通:标记该超管账号已安装(initialized)
|
||||
adminByPhone.setInstalled(true);
|
||||
userService.updateById(adminByPhone);
|
||||
|
||||
// 在 websopy 初始化默认域名(site-租户ID.sitelnk.cn)并标记为已生效
|
||||
try {
|
||||
initDefaultDomain(addCompany.getTenantId(), "site");
|
||||
} catch (Exception e) {
|
||||
log.error("注册后初始化默认域名失败: tenantId={}", addCompany.getTenantId(), e);
|
||||
// 域名初始化失败不阻断注册流程
|
||||
}
|
||||
|
||||
// 设置过期时间
|
||||
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||
|
||||
@@ -146,6 +146,7 @@ import java.util.stream.Collectors;
|
||||
superAdmin.setPassword(userService.encodePassword(company.getPassword()));
|
||||
}
|
||||
superAdmin.setTenantId(company.getTid());
|
||||
superAdmin.setInstalled(true);
|
||||
if(company.getTemplateId() != null){
|
||||
superAdmin.setTemplateId(company.getTemplateId());
|
||||
}
|
||||
|
||||
@@ -53,6 +53,9 @@ config:
|
||||
# websopy 服务地址(用于同步用户数据)
|
||||
websopyUrl: https://websopy-api.websoft.top
|
||||
|
||||
# 内部服务调用密钥(调用 websopy 等内部接口时使用,请务必与 websopy 端保持一致)
|
||||
internal-key: ${INTERNAL_KEY:websopy-internal-2025}
|
||||
|
||||
# 生产环境证书配置
|
||||
certificate:
|
||||
# 生产环境使用挂载卷模式
|
||||
|
||||
@@ -119,6 +119,9 @@ config:
|
||||
# websopy 服务地址(用于同步用户数据)
|
||||
websopyUrl: https://websopy-api.websoft.top
|
||||
|
||||
# 内部服务调用密钥(调用 websopy 等内部接口时使用,请务必与 websopy 端保持一致)
|
||||
internal-key: ${INTERNAL_KEY:websopy-internal-2025}
|
||||
|
||||
# 阿里云OSS云存储
|
||||
endpoint: https://oss-cn-shenzhen.aliyuncs.com
|
||||
accessKeyId: LTAI5tGXuJku8MK7TA6gQMZw
|
||||
|
||||
Reference in New Issue
Block a user