+1
-4
@@ -8,10 +8,7 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "jayucloud-salon.privacy.content-moderation")
|
||||
public class ContentModerationProperties {
|
||||
private String provider = "disabled";
|
||||
private String callbackUrl;
|
||||
private String callbackToken;
|
||||
private String encodingAesKey;
|
||||
private Boolean allowMock = false;
|
||||
private Integer scene = 2;
|
||||
private Integer imageUrlExpireMinutes = 5;
|
||||
private Integer requestTimeoutMillis = 8000;
|
||||
|
||||
-2
@@ -1,13 +1,11 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.privacy.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(prefix = "jayucloud-salon.privacy.content-moderation", name = "provider", havingValue = "wechat")
|
||||
public class WechatContentModerationHttpConfig {
|
||||
@Bean("wechatContentModerationRestTemplate")
|
||||
public RestTemplate wechatContentModerationRestTemplate(ContentModerationProperties properties) {
|
||||
|
||||
+19
-11
@@ -3,11 +3,11 @@ package com.xiaowang.jayucloud.salon.core.modules.privacy.controller.front;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.config.WechatMiniProperties;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.config.ContentModerationProperties;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.service.ContentModerationService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.support.WechatCallbackCrypto;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.secure.ModerationRuntimeConfig;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.service.SecureIntegrationConfigService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -22,9 +22,8 @@ import java.nio.charset.StandardCharsets;
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/integration/wechat/content-moderation")
|
||||
@ConditionalOnProperty(prefix = "jayucloud-salon.privacy.content-moderation", name = "provider", havingValue = "wechat")
|
||||
public class WechatContentModerationCallbackController {
|
||||
private final ContentModerationProperties properties;
|
||||
private final SecureIntegrationConfigService secureIntegrationConfigService;
|
||||
private final WechatMiniProperties wechatProperties;
|
||||
private final WechatCallbackCrypto crypto;
|
||||
private final ContentModerationService contentModerationService;
|
||||
@@ -37,14 +36,14 @@ public class WechatContentModerationCallbackController {
|
||||
@RequestParam(value = "signature", required = false) String signature,
|
||||
@RequestParam(value = "encrypt_type", required = false) String encryptType,
|
||||
@RequestParam("echostr") String echoString) {
|
||||
ModerationRuntimeConfig config = requireWechatConfig();
|
||||
if ("aes".equalsIgnoreCase(encryptType)) {
|
||||
if (!StringUtils.hasText(properties.getEncodingAesKey())
|
||||
|| !crypto.verify(properties.getCallbackToken(), timestamp, nonce, echoString, messageSignature)) {
|
||||
if (!crypto.verify(config.getCallbackToken(), timestamp, nonce, echoString, messageSignature)) {
|
||||
throw new IllegalArgumentException("微信审核回调 AES 握手校验失败");
|
||||
}
|
||||
return crypto.decrypt(echoString, properties.getEncodingAesKey(), wechatProperties.getAppId());
|
||||
return crypto.decrypt(echoString, config.getEncodingAesKey(), wechatProperties.getAppId());
|
||||
}
|
||||
if (!crypto.verifyPlain(properties.getCallbackToken(), timestamp, nonce, signature)) {
|
||||
if (!crypto.verifyPlain(config.getCallbackToken(), timestamp, nonce, signature)) {
|
||||
throw new IllegalArgumentException("微信审核回调明文握手校验失败");
|
||||
}
|
||||
return echoString;
|
||||
@@ -57,16 +56,17 @@ public class WechatContentModerationCallbackController {
|
||||
@RequestParam(value = "signature", required = false) String signature,
|
||||
@RequestParam(value = "encrypt_type", required = false) String encryptType,
|
||||
@org.springframework.web.bind.annotation.RequestBody String body) throws Exception {
|
||||
ModerationRuntimeConfig config = requireWechatConfig();
|
||||
String encrypted = crypto.encryptedValue(body);
|
||||
String expectedSignature = "aes".equalsIgnoreCase(encryptType) ? messageSignature : signature;
|
||||
if (!crypto.verify(properties.getCallbackToken(), timestamp, nonce,
|
||||
if (!crypto.verify(config.getCallbackToken(), timestamp, nonce,
|
||||
"aes".equalsIgnoreCase(encryptType) ? encrypted : "", expectedSignature)) {
|
||||
throw new IllegalArgumentException("微信审核回调签名校验失败");
|
||||
}
|
||||
if (!"aes".equalsIgnoreCase(encryptType) || !StringUtils.hasText(properties.getEncodingAesKey())) {
|
||||
if (!"aes".equalsIgnoreCase(encryptType) || !StringUtils.hasText(config.getEncodingAesKey())) {
|
||||
throw new IllegalArgumentException("微信审核回调仅接受 AES 加密消息");
|
||||
}
|
||||
String decoded = crypto.decrypt(encrypted, properties.getEncodingAesKey(), wechatProperties.getAppId());
|
||||
String decoded = crypto.decrypt(encrypted, config.getEncodingAesKey(), wechatProperties.getAppId());
|
||||
String taskId;
|
||||
String suggest;
|
||||
String reason;
|
||||
@@ -96,4 +96,12 @@ public class WechatContentModerationCallbackController {
|
||||
for (String value : values) if (StringUtils.hasText(value)) return value;
|
||||
return null;
|
||||
}
|
||||
|
||||
private ModerationRuntimeConfig requireWechatConfig() {
|
||||
ModerationRuntimeConfig config = secureIntegrationConfigService.getModerationRuntimeConfig();
|
||||
if (config == null || !config.isReady() || !"WECHAT".equals(config.getProvider())) {
|
||||
throw new IllegalStateException("微信内容审核回调尚未启用或配置不完整");
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
||||
-6
@@ -1,14 +1,8 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.privacy.moderation;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ConditionalOnProperty(
|
||||
prefix = "jayucloud-salon.privacy.content-moderation",
|
||||
name = "provider",
|
||||
havingValue = "mock"
|
||||
)
|
||||
public class LocalMockContentModerationProvider implements ContentModerationProvider {
|
||||
@Override
|
||||
public String providerName() {
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.privacy.moderation;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.secure.ModerationRuntimeConfig;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.service.SecureIntegrationConfigService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Primary
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class RoutingContentModerationProvider implements ContentModerationProvider {
|
||||
private final SecureIntegrationConfigService secureIntegrationConfigService;
|
||||
private final LocalMockContentModerationProvider mockProvider;
|
||||
private final UnconfiguredContentModerationProvider unconfiguredProvider;
|
||||
private final WechatContentModerationProvider wechatProvider;
|
||||
|
||||
@Override
|
||||
public String providerName() {
|
||||
return resolveProvider().providerName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModerationOutcome reviewText(String contentType, String content, String openId) {
|
||||
return resolveProvider().reviewText(contentType, content, openId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModerationOutcome submitImage(String contentType, String imageUrl, String openId) {
|
||||
return resolveProvider().submitImage(contentType, imageUrl, openId);
|
||||
}
|
||||
|
||||
private ContentModerationProvider resolveProvider() {
|
||||
try {
|
||||
ModerationRuntimeConfig config = secureIntegrationConfigService.getModerationRuntimeConfig();
|
||||
if (config == null || !config.isReady()) return unconfiguredProvider;
|
||||
if ("MOCK".equals(config.getProvider())) return mockProvider;
|
||||
if ("WECHAT".equals(config.getProvider())) return wechatProvider;
|
||||
} catch (RuntimeException exception) {
|
||||
log.warn("无法读取内容审核安全配置,保持失败关闭", exception);
|
||||
}
|
||||
return unconfiguredProvider;
|
||||
}
|
||||
}
|
||||
-7
@@ -1,15 +1,8 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.privacy.moderation;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@ConditionalOnProperty(
|
||||
prefix = "jayucloud-salon.privacy.content-moderation",
|
||||
name = "provider",
|
||||
havingValue = "disabled",
|
||||
matchIfMissing = true
|
||||
)
|
||||
public class UnconfiguredContentModerationProvider implements ContentModerationProvider {
|
||||
@Override
|
||||
public String providerName() {
|
||||
|
||||
+2
-2
@@ -5,7 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.integration.service.WechatMiniClientService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.config.ContentModerationProperties;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -19,7 +20,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@ConditionalOnProperty(prefix = "jayucloud-salon.privacy.content-moderation", name = "provider", havingValue = "wechat")
|
||||
public class WechatContentModerationProvider implements ContentModerationProvider {
|
||||
private static final String TEXT_CHECK_URL = "https://api.weixin.qq.com/wxa/msg_sec_check";
|
||||
private static final String IMAGE_CHECK_URL = "https://api.weixin.qq.com/wxa/media_check_async";
|
||||
|
||||
+1
@@ -107,6 +107,7 @@ public final class SecurityAuditActions {
|
||||
public static final String CAMPAIGN_PUBLISH = "CAMPAIGN_PUBLISH";
|
||||
public static final String ANALYTICS_VIEW = "ANALYTICS_VIEW";
|
||||
public static final String PERFORMANCE_VIEW = "PERFORMANCE_VIEW";
|
||||
public static final String SECURE_CONFIG_UPDATE = "SECURE_CONFIG_UPDATE";
|
||||
|
||||
private SecurityAuditActions() {
|
||||
}
|
||||
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.system.controller.admin;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.annotation.OperationGuard;
|
||||
import com.xiaowang.jayucloud.salon.core.annotation.RequirePermission;
|
||||
import com.xiaowang.jayucloud.salon.core.common.Result;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.security.support.SecurityAuditActions;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.security.support.SecurityAuditSupport;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.dto.SecureIntegrationConfigDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.service.SecureIntegrationConfigService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.vo.SecureIntegrationConfigVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/admin/system-settings/secure-integration")
|
||||
public class AdminSecureIntegrationConfigController {
|
||||
private final SecureIntegrationConfigService secureIntegrationConfigService;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
private final SecurityAuditSupport securityAuditSupport;
|
||||
|
||||
@GetMapping
|
||||
@RequirePermission("messagehub:config:manage")
|
||||
public Result<SecureIntegrationConfigVO> getConfig(HttpServletRequest request) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(secureIntegrationConfigService.getAdminConfig(currentUser));
|
||||
}
|
||||
|
||||
@GetMapping("/map-runtime")
|
||||
@RequirePermission("messagehub:config:manage")
|
||||
public Result<Map<String, String>> getMapRuntimeConfig(HttpServletRequest request) {
|
||||
adminScopeHelper.getCurrentUser(request);
|
||||
return Result.success(secureIntegrationConfigService.getMapRuntimeConfig());
|
||||
}
|
||||
|
||||
@PostMapping("/map")
|
||||
@RequirePermission("messagehub:config:manage")
|
||||
@OperationGuard(action = "secure-map-config-save", ttlSeconds = 5, message = "地图设置正在保存,请勿重复提交")
|
||||
public Result<SecureIntegrationConfigVO> saveMapConfig(HttpServletRequest request,
|
||||
@Valid @RequestBody SecureIntegrationConfigDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
try {
|
||||
secureIntegrationConfigService.saveMapConfig(currentUser, dto);
|
||||
securityAuditSupport.success(request, SecurityAuditActions.SECURE_CONFIG_UPDATE, "section=MAP");
|
||||
return Result.success(secureIntegrationConfigService.getAdminConfig(currentUser));
|
||||
} catch (RuntimeException exception) {
|
||||
securityAuditSupport.fail(request, SecurityAuditActions.SECURE_CONFIG_UPDATE, "section=MAP");
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/content-moderation")
|
||||
@RequirePermission("messagehub:config:manage")
|
||||
@OperationGuard(action = "secure-moderation-config-save", ttlSeconds = 5, message = "内容审核设置正在保存,请勿重复提交")
|
||||
public Result<SecureIntegrationConfigVO> saveModerationConfig(HttpServletRequest request,
|
||||
@Valid @RequestBody SecureIntegrationConfigDTO dto) {
|
||||
UserDO currentUser = adminScopeHelper.getCurrentUser(request);
|
||||
try {
|
||||
secureIntegrationConfigService.saveModerationConfig(currentUser, dto);
|
||||
securityAuditSupport.success(request, SecurityAuditActions.SECURE_CONFIG_UPDATE, "section=CONTENT_MODERATION");
|
||||
return Result.success(secureIntegrationConfigService.getAdminConfig(currentUser));
|
||||
} catch (RuntimeException exception) {
|
||||
securityAuditSupport.fail(request, SecurityAuditActions.SECURE_CONFIG_UPDATE, "section=CONTENT_MODERATION");
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
-28
@@ -58,34 +58,6 @@ public class SystemParameterConfigController {
|
||||
return Result.success(configService.saveConfig(currentUser, dto));
|
||||
}
|
||||
|
||||
@GetMapping("/admin/tencent-map")
|
||||
/**
|
||||
* Purpose: getTencentMapKey supports SystemParameterConfigController.java by holding or executing the get tencent map key business role.
|
||||
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
public Result<Map<String, String>> getTencentMapKey(HttpServletRequest request) {
|
||||
adminScopeHelper.getCurrentUser(request);
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("key", configService.getEnabledValue("MAP", "TENCENT_MAP_KEY"));
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
@GetMapping("/admin/map-config")
|
||||
/**
|
||||
* Purpose: getMapConfig supports SystemParameterConfigController.java by holding or executing the get map config business role.
|
||||
* Usage: reference this method from the owning layer and pass validated inputs before reading or updating related state.
|
||||
*/
|
||||
public Result<Map<String, String>> getMapConfig(HttpServletRequest request) {
|
||||
adminScopeHelper.getCurrentUser(request);
|
||||
Map<String, String> result = new HashMap<>();
|
||||
String provider = configService.getEnabledValue("MAP", "MAP_PROVIDER");
|
||||
result.put("provider", "AMAP".equalsIgnoreCase(provider) ? "AMAP" : "TENCENT");
|
||||
result.put("tencentWebKey", configService.getEnabledValue("MAP", "TENCENT_MAP_KEY"));
|
||||
result.put("amapWebKey", configService.getEnabledValue("MAP", "AMAP_WEB_KEY"));
|
||||
result.put("amapMiniKey", configService.getEnabledValue("MAP", "AMAP_MINI_KEY"));
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
@GetMapping("/admin/user-default-password")
|
||||
@RequirePermission("user:create")
|
||||
public Result<Map<String, String>> getUserDefaultPassword(HttpServletRequest request) {
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.system.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SecureIntegrationConfigDTO {
|
||||
private String mapProvider;
|
||||
private Boolean mapEnabled;
|
||||
private String tencentWebKey;
|
||||
private String amapWebKey;
|
||||
private String amapMiniKey;
|
||||
private Boolean clearTencentWebKey;
|
||||
private Boolean clearAmapWebKey;
|
||||
private Boolean clearAmapMiniKey;
|
||||
|
||||
private String moderationProvider;
|
||||
private String moderationCallbackUrl;
|
||||
private String moderationCallbackToken;
|
||||
private String moderationEncodingAesKey;
|
||||
private Boolean clearModerationCallbackToken;
|
||||
private Boolean clearModerationEncodingAesKey;
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.xiaowang.jayucloud.salon.core.common.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("t_secure_integration_config")
|
||||
public class SecureIntegrationConfigDO extends BaseEntity {
|
||||
@TableField("config_group")
|
||||
private String configGroup;
|
||||
|
||||
@TableField("config_key")
|
||||
private String configKey;
|
||||
|
||||
@TableField("config_value")
|
||||
private String configValue;
|
||||
|
||||
@TableField("is_secret")
|
||||
private Integer secret;
|
||||
|
||||
@TableField("enabled")
|
||||
private Integer enabled;
|
||||
|
||||
@TableField("updated_by")
|
||||
private Long updatedBy;
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.entity.SecureIntegrationConfigDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SecureIntegrationConfigMapper extends BaseMapper<SecureIntegrationConfigDO> {
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.system.secure;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ModerationRuntimeConfig {
|
||||
private String provider;
|
||||
private String callbackUrl;
|
||||
private String callbackToken;
|
||||
private String encodingAesKey;
|
||||
private boolean ready;
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.system.secure;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.GCMParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
|
||||
@Component
|
||||
public class SecureConfigEncryptionService {
|
||||
private static final String PREFIX = "v1:";
|
||||
private static final int NONCE_LENGTH = 12;
|
||||
private static final int TAG_LENGTH_BITS = 128;
|
||||
private static final SecureRandom RANDOM = new SecureRandom();
|
||||
|
||||
private final String encodedMasterKey;
|
||||
|
||||
public SecureConfigEncryptionService(
|
||||
@Value("${SALON_SECURE_CONFIG_MASTER_KEY:}") String encodedMasterKey) {
|
||||
this.encodedMasterKey = encodedMasterKey;
|
||||
}
|
||||
|
||||
public boolean isConfigured() {
|
||||
try {
|
||||
decodeKey();
|
||||
return true;
|
||||
} catch (IllegalStateException exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public String encrypt(String value) {
|
||||
if (!StringUtils.hasText(value)) return null;
|
||||
byte[] nonce = new byte[NONCE_LENGTH];
|
||||
RANDOM.nextBytes(nonce);
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
||||
cipher.init(Cipher.ENCRYPT_MODE, decodeKey(), new GCMParameterSpec(TAG_LENGTH_BITS, nonce));
|
||||
byte[] encrypted = cipher.doFinal(value.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
byte[] payload = new byte[nonce.length + encrypted.length];
|
||||
System.arraycopy(nonce, 0, payload, 0, nonce.length);
|
||||
System.arraycopy(encrypted, 0, payload, nonce.length, encrypted.length);
|
||||
return PREFIX + Base64.getEncoder().encodeToString(payload);
|
||||
} catch (GeneralSecurityException exception) {
|
||||
throw new IllegalStateException("安全配置加密失败", exception);
|
||||
}
|
||||
}
|
||||
|
||||
public String decrypt(String value) {
|
||||
if (!StringUtils.hasText(value)) return "";
|
||||
if (!value.startsWith(PREFIX)) throw new IllegalStateException("安全配置密文版本不受支持");
|
||||
byte[] payload;
|
||||
try {
|
||||
payload = Base64.getDecoder().decode(value.substring(PREFIX.length()));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
throw new IllegalStateException("安全配置密文格式错误", exception);
|
||||
}
|
||||
if (payload.length <= NONCE_LENGTH) throw new IllegalStateException("安全配置密文长度错误");
|
||||
byte[] nonce = Arrays.copyOfRange(payload, 0, NONCE_LENGTH);
|
||||
byte[] ciphertext = Arrays.copyOfRange(payload, NONCE_LENGTH, payload.length);
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, decodeKey(), new GCMParameterSpec(TAG_LENGTH_BITS, nonce));
|
||||
return new String(cipher.doFinal(ciphertext), java.nio.charset.StandardCharsets.UTF_8);
|
||||
} catch (GeneralSecurityException exception) {
|
||||
throw new IllegalStateException("安全配置无法解密,请检查环境主密钥是否与写入时一致", exception);
|
||||
}
|
||||
}
|
||||
|
||||
private SecretKeySpec decodeKey() {
|
||||
if (!StringUtils.hasText(encodedMasterKey)) {
|
||||
throw new IllegalStateException("尚未配置安全接入加密主密钥");
|
||||
}
|
||||
try {
|
||||
byte[] key = Base64.getDecoder().decode(encodedMasterKey.trim());
|
||||
if (key.length != 32) throw new IllegalStateException("安全接入加密主密钥必须是 Base64 编码的 32 字节密钥");
|
||||
return new SecretKeySpec(key, "AES");
|
||||
} catch (IllegalArgumentException exception) {
|
||||
throw new IllegalStateException("安全接入加密主密钥必须是有效的 Base64 字符串", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.system.service;
|
||||
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.dto.SecureIntegrationConfigDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.secure.ModerationRuntimeConfig;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.vo.SecureIntegrationConfigVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface SecureIntegrationConfigService {
|
||||
SecureIntegrationConfigVO getAdminConfig(UserDO currentUser);
|
||||
|
||||
void saveMapConfig(UserDO currentUser, SecureIntegrationConfigDTO dto);
|
||||
|
||||
void saveModerationConfig(UserDO currentUser, SecureIntegrationConfigDTO dto);
|
||||
|
||||
Map<String, String> getMapRuntimeConfig();
|
||||
|
||||
ModerationRuntimeConfig getModerationRuntimeConfig();
|
||||
|
||||
void migrateLegacyMapConfig();
|
||||
}
|
||||
+308
@@ -0,0 +1,308 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.integration.service.WechatMiniClientService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.privacy.config.ContentModerationProperties;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.security.support.AdminScopeHelper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.dto.SecureIntegrationConfigDTO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.entity.SecureIntegrationConfigDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.entity.SystemParameterConfigDO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.mapper.SecureIntegrationConfigMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.mapper.SystemParameterConfigMapper;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.secure.ModerationRuntimeConfig;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.secure.SecureConfigEncryptionService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.service.SecureIntegrationConfigService;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.system.vo.SecureIntegrationConfigVO;
|
||||
import com.xiaowang.jayucloud.salon.core.modules.user.entity.UserDO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SecureIntegrationConfigServiceImpl implements SecureIntegrationConfigService {
|
||||
private static final String MAP = "MAP";
|
||||
private static final String MODERATION = "CONTENT_MODERATION";
|
||||
private static final String SYSTEM = "SYSTEM";
|
||||
private static final String LEGACY_MAP_MIGRATED = "LEGACY_MAP_MIGRATED";
|
||||
private static final List<String> MAP_SECRET_KEYS = Arrays.asList(
|
||||
"TENCENT_WEB_KEY", "AMAP_WEB_KEY", "AMAP_MINI_KEY");
|
||||
|
||||
private final SecureIntegrationConfigMapper secureConfigMapper;
|
||||
private final SystemParameterConfigMapper systemParameterConfigMapper;
|
||||
private final SecureConfigEncryptionService encryptionService;
|
||||
private final AdminScopeHelper adminScopeHelper;
|
||||
private final ContentModerationProperties moderationProperties;
|
||||
private final WechatMiniClientService wechatMiniClientService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public SecureIntegrationConfigVO getAdminConfig(UserDO currentUser) {
|
||||
adminScopeHelper.requirePlatformAdmin(currentUser, "仅平台管理员可以管理安全接入配置");
|
||||
migrateLegacyMapConfig();
|
||||
SecureIntegrationConfigVO result = new SecureIntegrationConfigVO();
|
||||
result.setEncryptionKeyConfigured(encryptionService.isConfigured());
|
||||
result.setMapLegacyMigrationPending(hasLegacyMapValues() && !isLegacyMapMigrationComplete());
|
||||
result.setMapProvider(readValue(MAP, "PROVIDER", "TENCENT"));
|
||||
result.setMapEnabled(Boolean.parseBoolean(readValue(MAP, "ENABLED", "false")));
|
||||
result.setTencentWebKeyConfigured(hasStoredValue(MAP, "TENCENT_WEB_KEY"));
|
||||
result.setAmapWebKeyConfigured(hasStoredValue(MAP, "AMAP_WEB_KEY"));
|
||||
result.setAmapMiniKeyConfigured(hasStoredValue(MAP, "AMAP_MINI_KEY"));
|
||||
|
||||
String moderationProvider = normalizedProvider(readValue(MODERATION, "PROVIDER", defaultModerationProvider()));
|
||||
boolean tokenConfigured = hasStoredValue(MODERATION, "CALLBACK_TOKEN");
|
||||
boolean aesConfigured = hasStoredValue(MODERATION, "ENCODING_AES_KEY");
|
||||
boolean callbackConfigured = hasText(readValue(MODERATION, "CALLBACK_URL", ""));
|
||||
boolean appConfigured = StringUtils.hasText(wechatMiniClientService.getConfiguredAppId());
|
||||
boolean moderationReady = "MOCK".equals(moderationProvider)
|
||||
? isMockAllowed()
|
||||
: "WECHAT".equals(moderationProvider) && tokenConfigured && aesConfigured && callbackConfigured && appConfigured;
|
||||
|
||||
result.setModerationProvider(moderationProvider);
|
||||
result.setModerationCallbackUrl(readValue(MODERATION, "CALLBACK_URL", ""));
|
||||
result.setModerationCallbackTokenConfigured(tokenConfigured);
|
||||
result.setModerationEncodingAesKeyConfigured(aesConfigured);
|
||||
result.setModerationReady(moderationReady);
|
||||
result.setWechatMiniAppConfigured(appConfigured);
|
||||
result.setMockProviderAllowed(isMockAllowed());
|
||||
result.setUpdatedAt(latestUpdateTime());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveMapConfig(UserDO currentUser, SecureIntegrationConfigDTO dto) {
|
||||
adminScopeHelper.requirePlatformAdmin(currentUser, "仅平台管理员可以管理安全接入配置");
|
||||
requireEncryptionKey();
|
||||
migrateLegacyMapConfig();
|
||||
|
||||
String provider = upper(dto.getMapProvider(), "TENCENT");
|
||||
if (!"TENCENT".equals(provider) && !"AMAP".equals(provider)) {
|
||||
throw new IllegalArgumentException("地图渠道仅支持腾讯地图或高德地图");
|
||||
}
|
||||
updateSecret(MAP, "TENCENT_WEB_KEY", dto.getTencentWebKey(), dto.getClearTencentWebKey(), currentUser.getId());
|
||||
updateSecret(MAP, "AMAP_WEB_KEY", dto.getAmapWebKey(), dto.getClearAmapWebKey(), currentUser.getId());
|
||||
updateSecret(MAP, "AMAP_MINI_KEY", dto.getAmapMiniKey(), dto.getClearAmapMiniKey(), currentUser.getId());
|
||||
|
||||
boolean enabled = Boolean.TRUE.equals(dto.getMapEnabled());
|
||||
if (enabled) {
|
||||
String selectedKey = "AMAP".equals(provider)
|
||||
? resolveUpdatedSecret(MAP, "AMAP_WEB_KEY", dto.getAmapWebKey(), dto.getClearAmapWebKey())
|
||||
: resolveUpdatedSecret(MAP, "TENCENT_WEB_KEY", dto.getTencentWebKey(), dto.getClearTencentWebKey());
|
||||
if (!StringUtils.hasText(selectedKey)) {
|
||||
throw new IllegalArgumentException("请先填写当前地图渠道对应的 Web Key,或关闭地图服务");
|
||||
}
|
||||
}
|
||||
writeValue(MAP, "PROVIDER", provider, false, currentUser.getId());
|
||||
writeValue(MAP, "ENABLED", String.valueOf(enabled), false, currentUser.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveModerationConfig(UserDO currentUser, SecureIntegrationConfigDTO dto) {
|
||||
adminScopeHelper.requirePlatformAdmin(currentUser, "仅平台管理员可以管理安全接入配置");
|
||||
requireEncryptionKey();
|
||||
|
||||
String provider = normalizedProvider(dto.getModerationProvider());
|
||||
if (!Arrays.asList("DISABLED", "WECHAT", "MOCK").contains(provider)) {
|
||||
throw new IllegalArgumentException("内容审核渠道不受支持");
|
||||
}
|
||||
if ("MOCK".equals(provider) && !isMockAllowed()) {
|
||||
throw new IllegalArgumentException("当前环境不允许启用模拟审核");
|
||||
}
|
||||
|
||||
String callbackUrl = StringUtils.trimWhitespace(dto.getModerationCallbackUrl());
|
||||
if (StringUtils.hasText(callbackUrl)) {
|
||||
writeValue(MODERATION, "CALLBACK_URL", callbackUrl, false, currentUser.getId());
|
||||
}
|
||||
updateSecret(MODERATION, "CALLBACK_TOKEN", dto.getModerationCallbackToken(),
|
||||
dto.getClearModerationCallbackToken(), currentUser.getId());
|
||||
updateSecret(MODERATION, "ENCODING_AES_KEY", dto.getModerationEncodingAesKey(),
|
||||
dto.getClearModerationEncodingAesKey(), currentUser.getId());
|
||||
|
||||
String token = resolveUpdatedSecret(MODERATION, "CALLBACK_TOKEN", dto.getModerationCallbackToken(),
|
||||
dto.getClearModerationCallbackToken());
|
||||
String aesKey = resolveUpdatedSecret(MODERATION, "ENCODING_AES_KEY", dto.getModerationEncodingAesKey(),
|
||||
dto.getClearModerationEncodingAesKey());
|
||||
String effectiveCallbackUrl = StringUtils.hasText(callbackUrl)
|
||||
? callbackUrl : readValue(MODERATION, "CALLBACK_URL", "");
|
||||
if ("WECHAT".equals(provider)) {
|
||||
if (!StringUtils.hasText(token) || token.length() < 3 || token.length() > 32) {
|
||||
throw new IllegalArgumentException("微信回调 Token 需要填写 3-32 个字符");
|
||||
}
|
||||
if (!StringUtils.hasText(aesKey) || !aesKey.matches("[A-Za-z0-9+/]{43}")) {
|
||||
throw new IllegalArgumentException("微信 EncodingAESKey 需要填写 43 位密钥");
|
||||
}
|
||||
if (!StringUtils.hasText(effectiveCallbackUrl) || !effectiveCallbackUrl.startsWith("https://")) {
|
||||
throw new IllegalArgumentException("微信回调地址必须是公网可访问的 HTTPS 地址");
|
||||
}
|
||||
if (!StringUtils.hasText(wechatMiniClientService.getConfiguredAppId())) {
|
||||
throw new IllegalArgumentException("当前环境未配置微信小程序 AppID,请先完成环境配置");
|
||||
}
|
||||
}
|
||||
writeValue(MODERATION, "PROVIDER", provider, false, currentUser.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Map<String, String> getMapRuntimeConfig() {
|
||||
migrateLegacyMapConfig();
|
||||
String provider = upper(readValue(MAP, "PROVIDER", "TENCENT"), "TENCENT");
|
||||
boolean enabled = Boolean.parseBoolean(readValue(MAP, "ENABLED", "false"));
|
||||
String keyName = "AMAP".equals(provider) ? "AMAP_WEB_KEY" : "TENCENT_WEB_KEY";
|
||||
String key = enabled && encryptionService.isConfigured() ? readValue(MAP, keyName, "") : "";
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("provider", provider);
|
||||
result.put("enabled", String.valueOf(enabled));
|
||||
result.put("key", key);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModerationRuntimeConfig getModerationRuntimeConfig() {
|
||||
if (!encryptionService.isConfigured()) {
|
||||
return new ModerationRuntimeConfig("DISABLED", "", "", "", false);
|
||||
}
|
||||
String provider = normalizedProvider(readValue(MODERATION, "PROVIDER", defaultModerationProvider()));
|
||||
String callbackUrl = readValue(MODERATION, "CALLBACK_URL", "");
|
||||
String token = readValue(MODERATION, "CALLBACK_TOKEN", "");
|
||||
String aesKey = readValue(MODERATION, "ENCODING_AES_KEY", "");
|
||||
boolean allowedMock = !"MOCK".equals(provider) || isMockAllowed();
|
||||
boolean configured = "MOCK".equals(provider)
|
||||
? isMockAllowed()
|
||||
: "WECHAT".equals(provider) && StringUtils.hasText(token) && StringUtils.hasText(aesKey)
|
||||
&& StringUtils.hasText(callbackUrl) && StringUtils.hasText(wechatMiniClientService.getConfiguredAppId());
|
||||
if (!allowedMock) provider = "DISABLED";
|
||||
return new ModerationRuntimeConfig(provider, callbackUrl, token, aesKey, configured);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void migrateLegacyMapConfig() {
|
||||
if (!encryptionService.isConfigured() || isLegacyMapMigrationComplete()) return;
|
||||
List<SystemParameterConfigDO> legacyConfigs = systemParameterConfigMapper.selectList(
|
||||
new LambdaQueryWrapper<SystemParameterConfigDO>()
|
||||
.eq(SystemParameterConfigDO::getConfigGroup, MAP)
|
||||
.eq(SystemParameterConfigDO::getIsDelete, 0));
|
||||
Map<String, SystemParameterConfigDO> legacyByKey = new HashMap<>();
|
||||
for (SystemParameterConfigDO legacy : legacyConfigs) {
|
||||
legacyByKey.put(upper(legacy.getConfigKey(), ""), legacy);
|
||||
}
|
||||
moveLegacyValue(legacyByKey, "MAP_PROVIDER", MAP, "PROVIDER", false);
|
||||
moveLegacyValue(legacyByKey, "TENCENT_MAP_KEY", MAP, "TENCENT_WEB_KEY", true);
|
||||
moveLegacyValue(legacyByKey, "AMAP_WEB_KEY", MAP, "AMAP_WEB_KEY", true);
|
||||
moveLegacyValue(legacyByKey, "AMAP_MINI_KEY", MAP, "AMAP_MINI_KEY", true);
|
||||
SystemParameterConfigDO oldProvider = legacyByKey.get("MAP_PROVIDER");
|
||||
if (oldProvider != null) {
|
||||
String enabled = Integer.valueOf(1).equals(oldProvider.getEnabled()) ? "true" : "false";
|
||||
writeValue(MAP, "ENABLED", enabled, false, null);
|
||||
}
|
||||
for (SystemParameterConfigDO legacy : legacyConfigs) {
|
||||
legacy.setConfigValue("");
|
||||
legacy.setEnabled(0);
|
||||
systemParameterConfigMapper.updateById(legacy);
|
||||
}
|
||||
writeValue(SYSTEM, LEGACY_MAP_MIGRATED, "true", false, null);
|
||||
}
|
||||
|
||||
private void moveLegacyValue(Map<String, SystemParameterConfigDO> legacyByKey, String oldKey,
|
||||
String group, String newKey, boolean secret) {
|
||||
SystemParameterConfigDO legacy = legacyByKey.get(oldKey);
|
||||
if (legacy == null || !StringUtils.hasText(legacy.getConfigValue()) || hasStoredValue(group, newKey)) return;
|
||||
writeValue(group, newKey, legacy.getConfigValue(), secret, null);
|
||||
}
|
||||
|
||||
private void updateSecret(String group, String key, String submittedValue, Boolean clear, Long updatedBy) {
|
||||
if (Boolean.TRUE.equals(clear)) {
|
||||
writeValue(group, key, "", true, updatedBy);
|
||||
} else if (StringUtils.hasText(submittedValue)) {
|
||||
writeValue(group, key, submittedValue.trim(), true, updatedBy);
|
||||
}
|
||||
}
|
||||
|
||||
private String resolveUpdatedSecret(String group, String key, String submittedValue, Boolean clear) {
|
||||
if (Boolean.TRUE.equals(clear)) return "";
|
||||
return StringUtils.hasText(submittedValue) ? submittedValue.trim() : readValue(group, key, "");
|
||||
}
|
||||
|
||||
private void writeValue(String group, String key, String value, boolean secret, Long updatedBy) {
|
||||
SecureIntegrationConfigDO record = select(group, key);
|
||||
if (record == null) {
|
||||
record = new SecureIntegrationConfigDO();
|
||||
record.setConfigGroup(group);
|
||||
record.setConfigKey(key);
|
||||
}
|
||||
record.setConfigValue(StringUtils.hasText(value) ? encryptionService.encrypt(value) : null);
|
||||
record.setSecret(secret ? 1 : 0);
|
||||
record.setEnabled(StringUtils.hasText(value) ? 1 : 0);
|
||||
record.setUpdatedBy(updatedBy);
|
||||
if (record.getId() == null) secureConfigMapper.insert(record);
|
||||
else secureConfigMapper.updateById(record);
|
||||
}
|
||||
|
||||
private String readValue(String group, String key, String fallback) {
|
||||
SecureIntegrationConfigDO record = select(group, key);
|
||||
if (record == null || !Integer.valueOf(1).equals(record.getEnabled())
|
||||
|| !StringUtils.hasText(record.getConfigValue()) || !encryptionService.isConfigured()) return fallback;
|
||||
return encryptionService.decrypt(record.getConfigValue());
|
||||
}
|
||||
|
||||
private boolean hasStoredValue(String group, String key) {
|
||||
SecureIntegrationConfigDO record = select(group, key);
|
||||
return record != null && Integer.valueOf(1).equals(record.getEnabled()) && StringUtils.hasText(record.getConfigValue());
|
||||
}
|
||||
|
||||
private SecureIntegrationConfigDO select(String group, String key) {
|
||||
return secureConfigMapper.selectOne(new LambdaQueryWrapper<SecureIntegrationConfigDO>()
|
||||
.eq(SecureIntegrationConfigDO::getConfigGroup, group)
|
||||
.eq(SecureIntegrationConfigDO::getConfigKey, key)
|
||||
.last("LIMIT 1"));
|
||||
}
|
||||
|
||||
private boolean hasLegacyMapValues() {
|
||||
return systemParameterConfigMapper.selectCount(new LambdaQueryWrapper<SystemParameterConfigDO>()
|
||||
.eq(SystemParameterConfigDO::getConfigGroup, MAP)
|
||||
.eq(SystemParameterConfigDO::getIsDelete, 0)
|
||||
.apply("config_value IS NOT NULL AND config_value <> ''")) > 0;
|
||||
}
|
||||
|
||||
private boolean isLegacyMapMigrationComplete() {
|
||||
return "true".equalsIgnoreCase(readValue(SYSTEM, LEGACY_MAP_MIGRATED, "false"));
|
||||
}
|
||||
|
||||
private java.time.LocalDateTime latestUpdateTime() {
|
||||
List<SecureIntegrationConfigDO> rows = secureConfigMapper.selectList(new LambdaQueryWrapper<SecureIntegrationConfigDO>()
|
||||
.orderByDesc(SecureIntegrationConfigDO::getUpdateTime).last("LIMIT 1"));
|
||||
return rows == null || rows.isEmpty() ? null : rows.get(0).getUpdateTime();
|
||||
}
|
||||
|
||||
private void requireEncryptionKey() {
|
||||
if (!encryptionService.isConfigured()) {
|
||||
throw new IllegalStateException("安全接入加密主密钥未配置,请先由部署维护人员设置 SALON_SECURE_CONFIG_MASTER_KEY 并重启 Core");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isMockAllowed() {
|
||||
return Boolean.TRUE.equals(moderationProperties.getAllowMock());
|
||||
}
|
||||
|
||||
private String defaultModerationProvider() {
|
||||
return isMockAllowed() ? "MOCK" : "DISABLED";
|
||||
}
|
||||
|
||||
private String normalizedProvider(String value) {
|
||||
return upper(value, "DISABLED");
|
||||
}
|
||||
|
||||
private String upper(String value, String fallback) {
|
||||
return StringUtils.hasText(value) ? value.trim().toUpperCase(Locale.ROOT) : fallback;
|
||||
}
|
||||
}
|
||||
+10
@@ -16,6 +16,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Collections;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@@ -40,12 +41,17 @@ public class SystemParameterConfigServiceImpl implements SystemParameterConfigSe
|
||||
*/
|
||||
public List<SystemParameterConfigVO> listConfigs(UserDO currentUser, String configGroup) {
|
||||
ensurePlatformAdmin(currentUser);
|
||||
if (StringUtils.hasText(configGroup) && "MAP".equalsIgnoreCase(configGroup.trim())) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
LambdaQueryWrapper<SystemParameterConfigDO> wrapper = new LambdaQueryWrapper<SystemParameterConfigDO>()
|
||||
.eq(SystemParameterConfigDO::getIsDelete, 0)
|
||||
.orderByAsc(SystemParameterConfigDO::getConfigGroup)
|
||||
.orderByAsc(SystemParameterConfigDO::getConfigKey);
|
||||
if (StringUtils.hasText(configGroup)) {
|
||||
wrapper.eq(SystemParameterConfigDO::getConfigGroup, normalize(configGroup));
|
||||
} else {
|
||||
wrapper.ne(SystemParameterConfigDO::getConfigGroup, "MAP");
|
||||
}
|
||||
return configMapper.selectList(wrapper).stream().map(this::toVO).collect(Collectors.toList());
|
||||
}
|
||||
@@ -60,6 +66,9 @@ public class SystemParameterConfigServiceImpl implements SystemParameterConfigSe
|
||||
ensurePlatformAdmin(currentUser);
|
||||
String group = normalize(dto.getConfigGroup());
|
||||
String key = normalize(dto.getConfigKey());
|
||||
if ("MAP".equals(group)) {
|
||||
throw new IllegalArgumentException("地图密钥已迁移至安全接入配置,不允许通过通用参数接口读写");
|
||||
}
|
||||
if (AdminDefaultPasswordSupport.isDefaultPasswordConfig(group, key)) {
|
||||
AdminDefaultPasswordSupport.validateDefaultPassword(dto.getConfigValue());
|
||||
}
|
||||
@@ -98,6 +107,7 @@ public class SystemParameterConfigServiceImpl implements SystemParameterConfigSe
|
||||
if (!StringUtils.hasText(configGroup) || !StringUtils.hasText(configKey)) {
|
||||
return "";
|
||||
}
|
||||
if ("MAP".equalsIgnoreCase(configGroup.trim())) return "";
|
||||
SystemParameterConfigDO config = configMapper.selectOne(new LambdaQueryWrapper<SystemParameterConfigDO>()
|
||||
.eq(SystemParameterConfigDO::getConfigGroup, normalize(configGroup))
|
||||
.eq(SystemParameterConfigDO::getConfigKey, normalize(configKey))
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.xiaowang.jayucloud.salon.core.modules.system.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class SecureIntegrationConfigVO {
|
||||
private String mapProvider;
|
||||
private Boolean mapEnabled;
|
||||
private Boolean tencentWebKeyConfigured;
|
||||
private Boolean amapWebKeyConfigured;
|
||||
private Boolean amapMiniKeyConfigured;
|
||||
private Boolean mapLegacyMigrationPending;
|
||||
|
||||
private String moderationProvider;
|
||||
private String moderationCallbackUrl;
|
||||
private Boolean moderationCallbackTokenConfigured;
|
||||
private Boolean moderationEncodingAesKeyConfigured;
|
||||
private Boolean moderationReady;
|
||||
private Boolean wechatMiniAppConfigured;
|
||||
private Boolean mockProviderAllowed;
|
||||
|
||||
private Boolean encryptionKeyConfigured;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE TABLE IF NOT EXISTS t_secure_integration_config (
|
||||
id BIGINT NOT NULL COMMENT '主键ID',
|
||||
config_group VARCHAR(64) NOT NULL COMMENT '安全配置分组',
|
||||
config_key VARCHAR(100) NOT NULL COMMENT '安全配置键',
|
||||
config_value LONGTEXT NULL COMMENT 'AES-GCM 加密后的配置值',
|
||||
is_secret TINYINT NOT NULL DEFAULT 0 COMMENT '是否为密钥类配置',
|
||||
enabled TINYINT NOT NULL DEFAULT 1 COMMENT '是否启用',
|
||||
updated_by BIGINT NULL COMMENT '最后修改管理员ID',
|
||||
create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_secure_integration_config_group_key (config_group, config_key)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Salon安全接入配置';
|
||||
@@ -1913,6 +1913,41 @@ export interface AdminDefaultPasswordResponse {
|
||||
password: string
|
||||
}
|
||||
|
||||
export interface SecureIntegrationConfigVO {
|
||||
mapProvider: 'TENCENT' | 'AMAP'
|
||||
mapEnabled: boolean
|
||||
tencentWebKeyConfigured: boolean
|
||||
amapWebKeyConfigured: boolean
|
||||
amapMiniKeyConfigured: boolean
|
||||
mapLegacyMigrationPending: boolean
|
||||
moderationProvider: 'DISABLED' | 'MOCK' | 'WECHAT'
|
||||
moderationCallbackUrl: string
|
||||
moderationCallbackTokenConfigured: boolean
|
||||
moderationEncodingAesKeyConfigured: boolean
|
||||
moderationReady: boolean
|
||||
wechatMiniAppConfigured: boolean
|
||||
mockProviderAllowed: boolean
|
||||
encryptionKeyConfigured: boolean
|
||||
updatedAt?: string
|
||||
}
|
||||
|
||||
export interface SecureIntegrationConfigUpdate {
|
||||
mapProvider?: 'TENCENT' | 'AMAP'
|
||||
mapEnabled?: boolean
|
||||
tencentWebKey?: string
|
||||
amapWebKey?: string
|
||||
amapMiniKey?: string
|
||||
clearTencentWebKey?: boolean
|
||||
clearAmapWebKey?: boolean
|
||||
clearAmapMiniKey?: boolean
|
||||
moderationProvider?: 'DISABLED' | 'MOCK' | 'WECHAT'
|
||||
moderationCallbackUrl?: string
|
||||
moderationCallbackToken?: string
|
||||
moderationEncodingAesKey?: string
|
||||
clearModerationCallbackToken?: boolean
|
||||
clearModerationEncodingAesKey?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: adminSystemParameterConfigApi supports admin.ts by holding or executing the admin system parameter config api page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
@@ -1924,17 +1959,18 @@ export const adminSystemParameterConfigApi = {
|
||||
saveConfig: (data: SystemParameterConfigVO) => {
|
||||
return adminApi.post<boolean>('/system-parameter-config/admin/save', data)
|
||||
},
|
||||
getTencentMapKey: () => {
|
||||
return adminApi.get<{ key: string }>('/system-parameter-config/admin/tencent-map') as unknown as Promise<{ key: string }>
|
||||
},
|
||||
getMapConfig: () => {
|
||||
return adminApi.get<{ provider: 'TENCENT' | 'AMAP'; tencentWebKey?: string; amapWebKey?: string; amapMiniKey?: string }>('/system-parameter-config/admin/map-config') as unknown as Promise<{ provider: 'TENCENT' | 'AMAP'; tencentWebKey?: string; amapWebKey?: string; amapMiniKey?: string }>
|
||||
},
|
||||
getUserDefaultPassword: () => {
|
||||
return adminApi.get<AdminDefaultPasswordResponse>('/system-parameter-config/admin/user-default-password') as unknown as Promise<AdminDefaultPasswordResponse>
|
||||
}
|
||||
}
|
||||
|
||||
export const adminSecureIntegrationConfigApi = {
|
||||
getConfig: () => adminApi.get<SecureIntegrationConfigVO>('/system-settings/secure-integration'),
|
||||
getMapRuntimeConfig: () => adminApi.get<{ provider: 'TENCENT' | 'AMAP'; enabled: string; key: string }>('/system-settings/secure-integration/map-runtime'),
|
||||
saveMapConfig: (data: SecureIntegrationConfigUpdate) => adminApi.post<SecureIntegrationConfigVO>('/system-settings/secure-integration/map', data),
|
||||
saveModerationConfig: (data: SecureIntegrationConfigUpdate) => adminApi.post<SecureIntegrationConfigVO>('/system-settings/secure-integration/content-moderation', data)
|
||||
}
|
||||
|
||||
export interface WorkbenchRegistrationApplication {
|
||||
id: IdType
|
||||
applicationNo: string
|
||||
|
||||
@@ -651,7 +651,7 @@ import { DEFAULT_SHOP_IMAGE } from '@/constants'
|
||||
* Purpose: Shop supports ShopsView.vue by holding or executing the shop page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
import { adminShopApi, adminFileApi, adminSystemParameterConfigApi, type Shop } from '@/api/admin'
|
||||
import { adminShopApi, adminFileApi, adminSecureIntegrationConfigApi, type Shop } from '@/api/admin'
|
||||
/**
|
||||
* Purpose: ChunkUploadTask supports ShopsView.vue by holding or executing the chunk upload task page or API role.
|
||||
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
@@ -1651,9 +1651,13 @@ const handleMapLocationMessage = (event: MessageEvent) => {
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const openMapLocationPicker = async () => {
|
||||
const response = await adminSystemParameterConfigApi.getMapConfig()
|
||||
const response = await adminSecureIntegrationConfigApi.getMapRuntimeConfig()
|
||||
const provider = response?.provider === 'AMAP' ? 'AMAP' : 'TENCENT'
|
||||
const key = provider === 'AMAP' ? (response?.amapWebKey || '') : (response?.tencentWebKey || '')
|
||||
const key = response?.key || ''
|
||||
if (response?.enabled === 'false') {
|
||||
message.warning('地图服务已停用,请先在系统设置中启用')
|
||||
return
|
||||
}
|
||||
if (!key) {
|
||||
message.warning(provider === 'AMAP'
|
||||
? '请先在系统设置的服务接入中配置高德 Web Key'
|
||||
|
||||
@@ -102,17 +102,17 @@
|
||||
<div class="pane-head">
|
||||
<div>
|
||||
<h2>服务接入</h2>
|
||||
<p>维护后台地图选点和短信验证码使用的服务渠道。</p>
|
||||
<p>维护加密保存的地图密钥、微信审核回调和短信服务渠道。</p>
|
||||
</div>
|
||||
<span />
|
||||
</div>
|
||||
|
||||
<div class="setting-group">
|
||||
<div class="setting-group__head setting-group__head--with-action"><strong>地图服务</strong><span>MAP</span><a-button size="small" type="primary" :loading="savingMap" @click="saveMapConfig">保存地图设置</a-button></div>
|
||||
<div class="setting-group__head setting-group__head--with-action"><strong>地图服务</strong><span>安全接入</span><a-button size="small" type="primary" :loading="savingMap" @click="saveMapConfig">保存地图设置</a-button></div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-copy"><strong>默认地图渠道</strong><span>店铺选点和后台地图展示使用的默认渠道。</span></div>
|
||||
<div class="setting-control"><a-select v-model:value="mapForms.provider.configValue" :options="mapProviderOptions" /></div>
|
||||
<span class="status-pill">{{ mapEnabled ? '已配置' : '停用' }}</span>
|
||||
<div class="setting-control"><a-select v-model:value="mapProvider" :options="mapProviderOptions" /></div>
|
||||
<span class="status-pill" :class="{ 'is-muted': !mapEnabled }">{{ mapEnabled ? '启用' : '停用' }}</span>
|
||||
</div>
|
||||
<div v-for="item in mapKeyRows" :key="item.key" class="setting-row">
|
||||
<div class="setting-copy">
|
||||
@@ -131,14 +131,65 @@
|
||||
</strong>
|
||||
<span>{{ item.description }}</span>
|
||||
</div>
|
||||
<div class="setting-control setting-control--password"><a-input-password v-model:value="mapForms[item.key].configValue" :placeholder="item.placeholder" /></div>
|
||||
<span class="status-pill" :class="{ 'is-muted': !mapForms[item.key].configValue }">{{ mapForms[item.key].configValue ? '已填写' : '待配置' }}</span>
|
||||
<div class="setting-control setting-control--password">
|
||||
<a-input-password v-model:value="mapSecrets[item.key]" :placeholder="item.placeholder" autocomplete="new-password" />
|
||||
<a-button v-if="mapConfigured(item.key)" size="small" type="text" danger @click="toggleMapSecretClear(item.key)">{{ clearMapSecrets[item.key] ? '撤销清除' : '清除' }}</a-button>
|
||||
</div>
|
||||
<span class="status-pill" :class="{ 'is-muted': !mapConfigured(item.key) || clearMapSecrets[item.key] }">{{ clearMapSecrets[item.key] ? '保存后清除' : mapConfigured(item.key) ? '已配置' : '待配置' }}</span>
|
||||
</div>
|
||||
<div class="setting-row setting-row--last">
|
||||
<div class="setting-copy"><strong>地图服务状态</strong><span>停用后店铺地图选点不会调用已保存的渠道。</span></div>
|
||||
<div class="setting-control"><a-switch v-model:checked="mapEnabled" checked-children="启用" un-checked-children="停用" /></div>
|
||||
<span :class="['status-pill', { 'is-muted': !mapEnabled }]">{{ mapEnabled ? '启用' : '停用' }}</span>
|
||||
</div>
|
||||
<p class="secure-note">密钥以 AES-256-GCM 加密保存在当前环境数据库,设置接口不回传密钥。地图打开时才通过管理员认证接口按当前渠道读取;Web Key 会在浏览器地图 SDK 请求中使用,请在地图开放平台限制可用域名,并为 DEV、SIT、PROD 分别创建 Key。<span v-if="secureStatus && !secureStatus.encryptionKeyConfigured" class="secure-note__warning">服务端加密主密钥尚未配置,需先由部署维护人员设置后才能保存。</span></p>
|
||||
</div>
|
||||
|
||||
<div class="setting-group">
|
||||
<div class="setting-group__head setting-group__head--with-action"><strong>微信内容审核</strong><span>安全回调</span><a-button size="small" type="primary" :loading="savingModeration" @click="saveModerationConfig">保存审核设置</a-button></div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-copy"><strong>审核渠道</strong><span>未启用或配置不完整时,内容保持隔离,不会自动放行。</span></div>
|
||||
<div class="setting-control"><a-select v-model:value="moderationProvider" :options="moderationProviderOptions" /></div>
|
||||
<span class="status-pill" :class="{ 'is-muted': !secureStatus?.moderationReady }">{{ secureStatus?.moderationReady ? '已就绪' : '待配置' }}</span>
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-copy"><strong>微信服务器回调 URL</strong><span>复制到微信公众平台「开发管理 → 开发设置 → 消息推送」的 URL。</span></div>
|
||||
<div class="setting-control setting-control--joined">
|
||||
<a-input v-model:value="moderationCallbackUrl" readonly />
|
||||
<a-button @click="copyCallbackUrl"><CopyOutlined />复制</a-button>
|
||||
</div>
|
||||
<span class="status-pill" :class="{ 'is-muted': !isPublicHttpsCallback }">{{ isPublicHttpsCallback ? '当前环境 HTTPS' : '本地地址不可验证' }}</span>
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-copy"><strong>回调 Token</strong><span>在微信消息推送配置中填写的 Token,留空表示不修改已保存值。</span></div>
|
||||
<div class="setting-control setting-control--password">
|
||||
<a-input-password v-model:value="moderationSecrets.callbackToken" autocomplete="new-password" placeholder="填写新的 Token,留空保持原值" />
|
||||
<a-button v-if="secureStatus?.moderationCallbackTokenConfigured" size="small" type="text" danger @click="toggleModerationSecretClear('callbackToken')">{{ clearModerationSecrets.callbackToken ? '撤销清除' : '清除' }}</a-button>
|
||||
</div>
|
||||
<span class="status-pill" :class="{ 'is-muted': !secureStatus?.moderationCallbackTokenConfigured || clearModerationSecrets.callbackToken }">{{ clearModerationSecrets.callbackToken ? '保存后清除' : secureStatus?.moderationCallbackTokenConfigured ? '已配置' : '待配置' }}</span>
|
||||
</div>
|
||||
<div class="setting-row setting-row--last">
|
||||
<div class="setting-copy"><strong>EncodingAESKey</strong><span>微信平台生成的 43 位密钥;消息加密方式必须选择「安全模式」。</span></div>
|
||||
<div class="setting-control setting-control--password">
|
||||
<a-input-password v-model:value="moderationSecrets.encodingAesKey" autocomplete="new-password" placeholder="填写 43 位 EncodingAESKey,留空保持原值" />
|
||||
<a-button v-if="secureStatus?.moderationEncodingAesKeyConfigured" size="small" type="text" danger @click="toggleModerationSecretClear('encodingAesKey')">{{ clearModerationSecrets.encodingAesKey ? '撤销清除' : '清除' }}</a-button>
|
||||
</div>
|
||||
<span class="status-pill" :class="{ 'is-muted': !secureStatus?.moderationEncodingAesKeyConfigured || clearModerationSecrets.encodingAesKey }">{{ clearModerationSecrets.encodingAesKey ? '保存后清除' : secureStatus?.moderationEncodingAesKeyConfigured ? '已配置' : '待配置' }}</span>
|
||||
</div>
|
||||
<div class="secure-guide">
|
||||
<strong>微信平台填写指引</strong>
|
||||
<ol>
|
||||
<li>进入小程序公众平台的「开发管理 → 开发设置 → 消息推送」,将上方 URL、Token、EncodingAESKey 填入对应项。</li>
|
||||
<li>消息加密方式选择「安全模式」,保存后使用微信平台的 URL 验证;确认审核用 AppID 与当前环境小程序一致。</li>
|
||||
<li>将此环境 Core 的公网出口 IP 加入小程序接口 IP 白名单;图片审核还要求对象存储签名 URL 可由微信公网 HTTPS 访问。</li>
|
||||
</ol>
|
||||
<div class="secure-guide__links">
|
||||
<a href="https://mp.weixin.qq.com/" target="_blank" rel="noopener noreferrer">打开微信公众平台 <ExportOutlined /></a>
|
||||
<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/message-push.html" target="_blank" rel="noopener noreferrer">消息推送配置说明 <ExportOutlined /></a>
|
||||
</div>
|
||||
<span v-if="!isPublicHttpsCallback" class="secure-note__warning">当前地址为本地或非 HTTPS 地址,不能用于微信服务器验证。请在对应环境的正式 HTTPS 域名后台填写。</span>
|
||||
<span v-if="secureStatus && !secureStatus.encryptionKeyConfigured" class="secure-note__warning">安全接入加密主密钥尚未配置,Token 与 AESKey 不会保存。</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="setting-group">
|
||||
@@ -185,11 +236,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { ApiOutlined, ExportOutlined, SettingOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
import { adminSystemParameterConfigApi, type SystemParameterConfigVO } from '@/api/admin'
|
||||
import { ApiOutlined, CopyOutlined, ExportOutlined, SettingOutlined, UserOutlined } from '@ant-design/icons-vue'
|
||||
import { adminSecureIntegrationConfigApi, adminSystemParameterConfigApi, type SecureIntegrationConfigVO, type SystemParameterConfigVO } from '@/api/admin'
|
||||
import { loadCachedAdminUserInfo } from '@/utils/admin-session'
|
||||
|
||||
type SettingsSection = 'runtime' | 'services' | 'account'
|
||||
@@ -203,12 +254,21 @@ const savingReviewNotice = ref(false)
|
||||
const savingManagerReviewMode = ref(false)
|
||||
const savingShopValidity = ref(false)
|
||||
const savingMap = ref(false)
|
||||
const savingModeration = ref(false)
|
||||
const savingSmsProvider = ref(false)
|
||||
const defaultPasswordEnabled = ref(true)
|
||||
const reviewNoticeEnabled = ref(true)
|
||||
const managerAutoApproveEnabled = ref(false)
|
||||
const shopDefaultValidDays = ref('30')
|
||||
const mapEnabled = ref(true)
|
||||
const mapProvider = ref<'TENCENT' | 'AMAP'>('TENCENT')
|
||||
const secureStatus = ref<SecureIntegrationConfigVO | null>(null)
|
||||
const mapSecrets = reactive<Record<MapKey, string>>({ tencentWeb: '', amapWeb: '', amapMini: '' })
|
||||
const clearMapSecrets = reactive<Record<MapKey, boolean>>({ tencentWeb: false, amapWeb: false, amapMini: false })
|
||||
const moderationProvider = ref<'DISABLED' | 'MOCK' | 'WECHAT'>('DISABLED')
|
||||
const moderationCallbackUrl = ref('')
|
||||
const moderationSecrets = reactive({ callbackToken: '', encodingAesKey: '' })
|
||||
const clearModerationSecrets = reactive({ callbackToken: false, encodingAesKey: false })
|
||||
const smsProviderOptions = [
|
||||
{ label: 'Spug 短信', value: 'SPUG' },
|
||||
{ label: '阿里云短信认证服务', value: 'ALIYUN_SMS_VERIFY' }
|
||||
@@ -217,15 +277,22 @@ const mapProviderOptions = [
|
||||
{ label: '腾讯地图', value: 'TENCENT' },
|
||||
{ label: '高德地图', value: 'AMAP' }
|
||||
]
|
||||
const moderationProviderOptions = computed(() => [
|
||||
{ label: '未启用(失败关闭)', value: 'DISABLED' },
|
||||
...(secureStatus.value?.mockProviderAllowed ? [{ label: '本地模拟审核', value: 'MOCK' as const }] : []),
|
||||
{ label: '微信内容安全审核', value: 'WECHAT' }
|
||||
])
|
||||
const isPublicHttpsCallback = computed(() => /^https:\/\//i.test(moderationCallbackUrl.value)
|
||||
&& !/localhost|127\.0\.0\.1/i.test(moderationCallbackUrl.value))
|
||||
const sections = [
|
||||
{ key: 'runtime' as const, label: '运行参数', icon: SettingOutlined },
|
||||
{ key: 'services' as const, label: '服务接入', icon: ApiOutlined },
|
||||
{ key: 'account' as const, label: '当前账号', icon: UserOutlined }
|
||||
]
|
||||
const mapKeyRows: Array<{ key: MapKey; label: string; description: string; placeholder: string; url: string }> = [
|
||||
{ key: 'tencentWeb', label: '腾讯 Web Key', description: '用于后台腾讯地图选点和 Web 展示。', placeholder: '填写腾讯 Web Key', url: 'https://lbs.qq.com/dev/console/key/manage' },
|
||||
{ key: 'amapWeb', label: '高德 Web Key', description: '用于后台高德地图选点和 Web 展示。', placeholder: '填写高德 Web Key', url: 'https://console.amap.com/dev/key/app' },
|
||||
{ key: 'amapMini', label: '高德小程序 Key', description: '供 Salon 小程序后续地图能力使用。', placeholder: '填写高德小程序 Key', url: 'https://console.amap.com/dev/key/app' }
|
||||
{ key: 'tencentWeb', label: '腾讯 Web Key', description: '用于后台腾讯地图选点。', placeholder: '填写腾讯 Web Key;留空保持原值', url: 'https://lbs.qq.com/dev/console/key/manage' },
|
||||
{ key: 'amapWeb', label: '高德 Web Key', description: '用于后台高德地图选点。', placeholder: '填写高德 Web Key;留空保持原值', url: 'https://console.amap.com/dev/key/app' },
|
||||
{ key: 'amapMini', label: '高德小程序 Key', description: '供 Salon 小程序地图能力使用。', placeholder: '填写高德小程序 Key;留空保持原值', url: 'https://console.amap.com/dev/key/app' }
|
||||
]
|
||||
|
||||
const defaultPasswordForm = reactive<SystemParameterConfigVO>({
|
||||
@@ -248,24 +315,28 @@ const smsProviderForm = reactive<SystemParameterConfigVO>({
|
||||
configGroup: 'SMS', configKey: 'SMS_PROVIDER', configName: '短信供应商', configValue: 'SPUG', enabled: 1,
|
||||
remark: '全局切换短信供应商时同步验证码模板和 MessageHub 通道'
|
||||
})
|
||||
const mapForms = reactive<Record<MapKey | 'provider', SystemParameterConfigVO>>({
|
||||
provider: { configGroup: 'MAP', configKey: 'MAP_PROVIDER', configName: '当前地图渠道', configValue: 'TENCENT', enabled: 1, remark: 'TENCENT 或 AMAP;决定后台店铺选点默认使用哪个地图渠道' },
|
||||
tencentWeb: { configGroup: 'MAP', configKey: 'TENCENT_MAP_KEY', configName: '腾讯 Web Key', configValue: '', enabled: 1, remark: '用于后台腾讯地图选点和 Web 展示' },
|
||||
amapWeb: { configGroup: 'MAP', configKey: 'AMAP_WEB_KEY', configName: '高德 Web Key', configValue: '', enabled: 1, remark: '用于后台高德地图选点和 Web 展示' },
|
||||
amapMini: { configGroup: 'MAP', configKey: 'AMAP_MINI_KEY', configName: '高德小程序 Key', configValue: '', enabled: 1, remark: '供 Salon 小程序地图能力使用' }
|
||||
})
|
||||
|
||||
const userInfo = ref(loadCachedAdminUserInfo())
|
||||
|
||||
const callbackPath = '/api/integration/wechat/content-moderation/callback'
|
||||
const defaultCallbackUrl = () => `${window.location.origin}${callbackPath}`
|
||||
const mapConfigured = (key: MapKey) => {
|
||||
if (clearMapSecrets[key]) return false
|
||||
if (mapSecrets[key]) return true
|
||||
if (!secureStatus.value) return false
|
||||
return key === 'tencentWeb' ? secureStatus.value.tencentWebKeyConfigured
|
||||
: key === 'amapWeb' ? secureStatus.value.amapWebKeyConfigured
|
||||
: secureStatus.value.amapMiniKeyConfigured
|
||||
}
|
||||
|
||||
const load = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const [userConfigs, smsConfigs, workbenchConfigs, shopConfigs, mapConfigs] = await Promise.all([
|
||||
const [userConfigs, smsConfigs, workbenchConfigs, shopConfigs, secureConfig] = await Promise.all([
|
||||
adminSystemParameterConfigApi.listConfigs('USER'),
|
||||
adminSystemParameterConfigApi.listConfigs('SMS'),
|
||||
adminSystemParameterConfigApi.listConfigs('WORKBENCH'),
|
||||
adminSystemParameterConfigApi.listConfigs('SHOP'),
|
||||
adminSystemParameterConfigApi.listConfigs('MAP')
|
||||
adminSecureIntegrationConfigApi.getConfig()
|
||||
])
|
||||
const defaultPassword = userConfigs.find(item => item.configKey === 'DEFAULT_PASSWORD')
|
||||
if (defaultPassword) {
|
||||
@@ -289,13 +360,16 @@ const load = async () => {
|
||||
Object.assign(shopValidityForm, shopValidity)
|
||||
shopDefaultValidDays.value = String(shopValidity.configValue || '30')
|
||||
}
|
||||
const mapByKey = Object.fromEntries(mapConfigs.map(item => [item.configKey, item])) as Record<string, SystemParameterConfigVO | undefined>
|
||||
if (mapByKey.MAP_PROVIDER) Object.assign(mapForms.provider, mapByKey.MAP_PROVIDER)
|
||||
if (mapByKey.TENCENT_MAP_KEY) Object.assign(mapForms.tencentWeb, mapByKey.TENCENT_MAP_KEY)
|
||||
if (mapByKey.AMAP_WEB_KEY) Object.assign(mapForms.amapWeb, mapByKey.AMAP_WEB_KEY)
|
||||
if (mapByKey.AMAP_MINI_KEY) Object.assign(mapForms.amapMini, mapByKey.AMAP_MINI_KEY)
|
||||
mapForms.provider.configValue = mapForms.provider.configValue === 'AMAP' ? 'AMAP' : 'TENCENT'
|
||||
mapEnabled.value = mapForms.provider.enabled === 1
|
||||
secureStatus.value = secureConfig
|
||||
mapProvider.value = secureConfig.mapProvider === 'AMAP' ? 'AMAP' : 'TENCENT'
|
||||
mapEnabled.value = Boolean(secureConfig.mapEnabled)
|
||||
moderationProvider.value = secureConfig.moderationProvider || 'DISABLED'
|
||||
moderationCallbackUrl.value = secureConfig.moderationCallbackUrl || defaultCallbackUrl()
|
||||
mapSecrets.tencentWeb = ''
|
||||
mapSecrets.amapWeb = ''
|
||||
mapSecrets.amapMini = ''
|
||||
moderationSecrets.callbackToken = ''
|
||||
moderationSecrets.encodingAesKey = ''
|
||||
userInfo.value = loadCachedAdminUserInfo()
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '系统设置加载失败')
|
||||
@@ -379,18 +453,82 @@ const saveShopValidity = async () => {
|
||||
const saveMapConfig = async () => {
|
||||
savingMap.value = true
|
||||
try {
|
||||
await adminSystemParameterConfigApi.saveConfig({ ...mapForms.provider, configValue: String(mapForms.provider.configValue).toUpperCase(), enabled: mapEnabled.value ? 1 : 0 })
|
||||
await adminSystemParameterConfigApi.saveConfig({ ...mapForms.tencentWeb, enabled: mapEnabled.value ? 1 : 0 })
|
||||
await adminSystemParameterConfigApi.saveConfig({ ...mapForms.amapWeb, enabled: mapEnabled.value ? 1 : 0 })
|
||||
await adminSystemParameterConfigApi.saveConfig({ ...mapForms.amapMini, enabled: mapEnabled.value ? 1 : 0 })
|
||||
message.success('地图配置已保存')
|
||||
const result = await adminSecureIntegrationConfigApi.saveMapConfig({
|
||||
mapProvider: mapProvider.value,
|
||||
mapEnabled: mapEnabled.value,
|
||||
tencentWebKey: mapSecrets.tencentWeb,
|
||||
amapWebKey: mapSecrets.amapWeb,
|
||||
amapMiniKey: mapSecrets.amapMini,
|
||||
clearTencentWebKey: clearMapSecrets.tencentWeb,
|
||||
clearAmapWebKey: clearMapSecrets.amapWeb,
|
||||
clearAmapMiniKey: clearMapSecrets.amapMini
|
||||
})
|
||||
secureStatus.value = result
|
||||
Object.keys(mapSecrets).forEach(key => { mapSecrets[key as MapKey] = '' })
|
||||
Object.keys(clearMapSecrets).forEach(key => { clearMapSecrets[key as MapKey] = false })
|
||||
message.success('地图密钥已加密保存')
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '地图配置保存失败')
|
||||
message.error(error instanceof Error ? error.message : '安全地图配置保存失败')
|
||||
} finally {
|
||||
savingMap.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const saveModerationConfig = async () => {
|
||||
if (moderationProvider.value === 'WECHAT') {
|
||||
if (!isPublicHttpsCallback.value) {
|
||||
message.warning('微信审核回调必须使用公网可访问的 HTTPS 地址')
|
||||
return
|
||||
}
|
||||
if (moderationSecrets.callbackToken && (moderationSecrets.callbackToken.length < 3 || moderationSecrets.callbackToken.length > 32)) {
|
||||
message.warning('微信回调 Token 需要为 3-32 个字符')
|
||||
return
|
||||
}
|
||||
if (moderationSecrets.encodingAesKey && !/^[A-Za-z0-9+/]{43}$/.test(moderationSecrets.encodingAesKey)) {
|
||||
message.warning('EncodingAESKey 需要为 43 位字符')
|
||||
return
|
||||
}
|
||||
const hasToken = secureStatus.value?.moderationCallbackTokenConfigured && !clearModerationSecrets.callbackToken
|
||||
const hasAesKey = secureStatus.value?.moderationEncodingAesKeyConfigured && !clearModerationSecrets.encodingAesKey
|
||||
if ((!hasToken && !moderationSecrets.callbackToken) || (!hasAesKey && !moderationSecrets.encodingAesKey)) {
|
||||
message.warning('启用微信审核前,请填写回调 Token 和 EncodingAESKey')
|
||||
return
|
||||
}
|
||||
}
|
||||
savingModeration.value = true
|
||||
try {
|
||||
secureStatus.value = await adminSecureIntegrationConfigApi.saveModerationConfig({
|
||||
moderationProvider: moderationProvider.value,
|
||||
moderationCallbackUrl: moderationCallbackUrl.value,
|
||||
moderationCallbackToken: moderationSecrets.callbackToken,
|
||||
moderationEncodingAesKey: moderationSecrets.encodingAesKey,
|
||||
clearModerationCallbackToken: clearModerationSecrets.callbackToken,
|
||||
clearModerationEncodingAesKey: clearModerationSecrets.encodingAesKey
|
||||
})
|
||||
moderationSecrets.callbackToken = ''
|
||||
moderationSecrets.encodingAesKey = ''
|
||||
clearModerationSecrets.callbackToken = false
|
||||
clearModerationSecrets.encodingAesKey = false
|
||||
message.success('内容审核接入设置已保存')
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '内容审核设置保存失败')
|
||||
} finally {
|
||||
savingModeration.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const toggleMapSecretClear = (key: MapKey) => { clearMapSecrets[key] = !clearMapSecrets[key] }
|
||||
const toggleModerationSecretClear = (key: 'callbackToken' | 'encodingAesKey') => { clearModerationSecrets[key] = !clearModerationSecrets[key] }
|
||||
|
||||
const copyCallbackUrl = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(moderationCallbackUrl.value)
|
||||
message.success('回调 URL 已复制')
|
||||
} catch {
|
||||
message.error('复制失败,请手动选择并复制回调 URL')
|
||||
}
|
||||
}
|
||||
|
||||
const saveSmsProvider = async () => {
|
||||
const confirmed = window.confirm('保存后会同步全部短信验证码场景的模板、通道和发送方式,确认切换吗?')
|
||||
if (!confirmed) return
|
||||
@@ -448,6 +586,9 @@ onMounted(() => {
|
||||
.setting-control > :deep(.ant-select) { width: 100%; }
|
||||
.setting-control--password > :deep(.ant-input-affix-wrapper) { flex: 1; width: auto; min-width: 100px; }
|
||||
.setting-control--password { min-width: 0; }
|
||||
.setting-control--joined { min-width: 0; }
|
||||
.setting-control--joined > :deep(.ant-input) { flex: 1; min-width: 0; }
|
||||
.setting-control--joined > :deep(.ant-btn) { flex: 0 0 auto; }
|
||||
.setting-control--number { width: min(220px, 100%); }
|
||||
.control-note { color: var(--admin-mobile-muted); font-size: 11px; white-space: nowrap; }
|
||||
.setting-row > .control-note { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
|
||||
@@ -458,6 +599,16 @@ onMounted(() => {
|
||||
.status-pill.is-muted::before { background: var(--admin-mobile-muted); }
|
||||
.warning-note { display: inline-flex; align-items: center; gap: 5px; color: #a66d22; font-size: 11px; white-space: nowrap; }
|
||||
.warning-note::before { content: '!'; display: inline-flex; align-items: center; justify-content: center; width: 14px; height: 14px; border-radius: 50%; background: #fff3d9; font-size: 10px; font-weight: 800; }
|
||||
.secure-note { margin: 0; padding: 12px 14px; color: var(--admin-mobile-muted); font-size: 12px; line-height: 1.65; background: color-mix(in srgb, var(--theme-primary) 7%, var(--theme-card-bg)); }
|
||||
.secure-note__warning { display: block; margin-top: 6px; color: #8a4b0d; font-weight: 650; }
|
||||
.secure-guide { margin: 0 12px 12px; padding: 14px 16px; background: color-mix(in srgb, var(--admin-mobile-accent-soft) 55%, var(--theme-card-bg)); color: var(--admin-mobile-ink); font-size: 12px; line-height: 1.65; }
|
||||
.secure-guide > strong { font-size: 13px; }
|
||||
.secure-guide ol { margin: 8px 0 10px; padding-left: 19px; color: var(--admin-mobile-muted); }
|
||||
.secure-guide li + li { margin-top: 4px; }
|
||||
.secure-guide__links { display: flex; flex-wrap: wrap; gap: 14px; }
|
||||
.secure-guide__links a { display: inline-flex; align-items: center; gap: 5px; color: var(--theme-primary-action); text-decoration: none; }
|
||||
.secure-guide__links a:hover { text-decoration: underline; }
|
||||
.secure-guide__links a:focus-visible { outline: 2px solid color-mix(in srgb, var(--theme-primary) 55%, transparent); outline-offset: 2px; }
|
||||
.section-footnote { margin: 12px 2px 0; color: var(--admin-mobile-muted); font-size: 11px; }
|
||||
@media (max-width: 760px) {
|
||||
.settings-header { align-items: flex-start; }
|
||||
|
||||
@@ -47,9 +47,8 @@ jayucloud-salon:
|
||||
manager-register-shop-description: 甲屿店务注册店铺
|
||||
privacy:
|
||||
content-moderation:
|
||||
# 仅开发环境使用确定性本地 mock;未命中模拟标记时默认通过,接入微信平台前不得晋级到 SIT/生产。
|
||||
provider: mock
|
||||
callback-url: ""
|
||||
# 仅 DEV 允许在后台设置中使用本地模拟审核;SIT/PROD 继续失败关闭。
|
||||
allow-mock: true
|
||||
scene: 2
|
||||
image-url-expire-minutes: 5
|
||||
request-timeout-millis: 8000
|
||||
|
||||
@@ -34,7 +34,3 @@ jayucloud-salon:
|
||||
index-key: "4/wLgcudBE8XNVBjnUle1A2H1L0ePV0rKUbX3VFeAzU="
|
||||
backfill-enabled: false
|
||||
backfill-page-size: 500
|
||||
content-moderation:
|
||||
# 接入微信审核前保持为空;不要把真实密钥提交到仓库。
|
||||
callback-token: ""
|
||||
encoding-aes-key: ""
|
||||
|
||||
@@ -47,8 +47,8 @@ jayucloud-salon:
|
||||
privacy:
|
||||
content-moderation:
|
||||
# 微信审核平台接入前失败关闭,内容进入隔离/人工复核,不自动放行。
|
||||
provider: disabled
|
||||
callback-url: ""
|
||||
# 仅 DEV 允许模拟审核;生产默认失败关闭,正式启用需在后台完成微信接入。
|
||||
allow-mock: false
|
||||
scene: 2
|
||||
image-url-expire-minutes: 5
|
||||
request-timeout-millis: 8000
|
||||
|
||||
@@ -35,6 +35,3 @@ jayucloud-salon:
|
||||
index-key: "01lUBIigsJL/GW/SeYLigYC4ngiY9ntknX+ScDeuNzQ="
|
||||
backfill-enabled: false
|
||||
backfill-page-size: 500
|
||||
content-moderation:
|
||||
callback-token: ""
|
||||
encoding-aes-key: ""
|
||||
|
||||
@@ -46,9 +46,8 @@ jayucloud-salon:
|
||||
manager-register-shop-description: 甲屿店务注册店铺
|
||||
privacy:
|
||||
content-moderation:
|
||||
# 微信审核平台接入前失败关闭,内容进入隔离/人工复核,不自动放行。
|
||||
provider: disabled
|
||||
callback-url: ""
|
||||
# 仅 DEV 允许模拟审核;SIT 必须在后台配置微信审核并保持失败关闭。
|
||||
allow-mock: false
|
||||
scene: 2
|
||||
image-url-expire-minutes: 5
|
||||
request-timeout-millis: 8000
|
||||
|
||||
@@ -39,6 +39,3 @@ jayucloud-salon:
|
||||
index-key: "bEQkH9PtYIMbe1SnO5z0lntr7esGl1ZrxI4Yg+XkFY8="
|
||||
backfill-enabled: false
|
||||
backfill-page-size: 500
|
||||
content-moderation:
|
||||
callback-token: ""
|
||||
encoding-aes-key: ""
|
||||
|
||||
Reference in New Issue
Block a user