feat(cms): 增加内部接口以激活站点状态
- 新增 /internal/activate POST接口,通过X-Internal-Key进行鉴权 - 实现根据请求体更新站点状态和运行标志 - 更新成功后清除对应站点缓存,保证状态及时同步 - 添加配置项 internal.key 用于内部接口密钥校验 - 处理鉴权失败和参数缺失的异常响应 - 采用日志记录缓存清理异常信息
This commit is contained in:
@@ -22,6 +22,7 @@ import com.gxwebsoft.common.system.entity.User;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -52,6 +53,9 @@ public class CmsWebsiteController extends BaseController {
|
||||
@Resource
|
||||
private CmsWebsiteSettingService cmsWebsiteSettingService;
|
||||
|
||||
@Value("${internal.key:websopy-internal-2025}")
|
||||
private String internalKey;
|
||||
|
||||
private static final String SITE_INFO_KEY_PREFIX = "SiteInfo:";
|
||||
private static final String MP_INFO_KEY_PREFIX = "MpInfo:";
|
||||
private static final String SELECT_PAYMENT_KEY_PREFIX = "SelectPayment:";
|
||||
@@ -679,5 +683,47 @@ public class CmsWebsiteController extends BaseController {
|
||||
return success(cmsWebsiteService.pageReviews(param));
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部接口:由 websopy 支付回调在服务端调用,将站点置为「运行中(1)」。
|
||||
* 通过 X-Internal-Key 头做简单鉴权(仅限内网/可信服务调用,密钥与 websopy 端保持一致)。
|
||||
*/
|
||||
@PostMapping("/internal/activate")
|
||||
public ApiResult<?> activateInternal(
|
||||
@RequestHeader(value = "X-Internal-Key", required = false) String key,
|
||||
@RequestBody Map<String, Object> body) {
|
||||
if (key == null || !key.equals(internalKey)) {
|
||||
return fail("非法请求");
|
||||
}
|
||||
Integer websiteId = body.get("websiteId") instanceof Number
|
||||
? ((Number) body.get("websiteId")).intValue() : null;
|
||||
if (websiteId == null) {
|
||||
return fail("websiteId 不能为空");
|
||||
}
|
||||
Integer status = body.get("status") instanceof Number
|
||||
? ((Number) body.get("status")).intValue() : 1;
|
||||
Integer running = body.get("running") instanceof Number
|
||||
? ((Number) body.get("running")).intValue() : 0;
|
||||
|
||||
CmsWebsite site = new CmsWebsite();
|
||||
site.setWebsiteId(websiteId);
|
||||
site.setStatus(status);
|
||||
site.setRunning(running);
|
||||
if (cmsWebsiteService.updateById(site)) {
|
||||
// 失效站点缓存,保证后台/公开站尽快读到新状态
|
||||
try {
|
||||
CmsWebsite exist = cmsWebsiteService.getOne(new LambdaQueryWrapper<CmsWebsite>()
|
||||
.eq(CmsWebsite::getWebsiteId, websiteId).last("limit 1"));
|
||||
if (exist != null && ObjectUtil.isNotEmpty(exist.getTenantId())) {
|
||||
redisUtil.delete(SITE_INFO_KEY_PREFIX.concat(exist.getTenantId().toString()));
|
||||
redisUtil.delete(MP_INFO_KEY_PREFIX.concat(exist.getTenantId().toString()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("清除站点缓存失败: {}", e.getMessage());
|
||||
}
|
||||
return success("站点已激活");
|
||||
}
|
||||
return fail("激活失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user