feat: 根据OpenClaw dmPolicy重新设计配对规则

- 更新数据库表结构,添加dm_policy字段(pairing/allowlist/open/disabled)
- 添加allow_from字段用于白名单配置
- 添加openclaw_gateway_url和openclaw_gateway_token字段
- 更新Java实体类WeComBot,支持新的配对策略
- 更新测试数据,包含四种配对策略的示例
- 删除旧的pairing_mode字段,使用标准的OpenClaw dmPolicy
This commit is contained in:
2026-03-09 16:24:32 +08:00
parent 9e56eff874
commit f1737f3bf0
3 changed files with 205 additions and 525 deletions

View File

@@ -2,24 +2,12 @@ package com.wecom;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@RestController
@EnableScheduling
public class WeComMiddlewareApplication {
public static void main(String[] args) {
SpringApplication.run(WeComMiddlewareApplication.class, args);
}
@GetMapping("/")
public String home() {
return "WeCom Middleware Backend is running!";
}
@GetMapping("/api/system/health")
public String health() {
return "{\"status\":\"UP\"}";
}
}

View File

@@ -0,0 +1,86 @@
package com.wecom.entity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 企业微信Bot配置实体
*/
@Data
@TableName("wecom_bots")
public class WeComBot {
@TableId(type = IdType.AUTO)
private Long id;
@TableField("name")
private String name;
@TableField("bot_id")
private String botId;
@TableField("secret")
private String secret;
/**
* 配对策略:
* pairing - 默认:未知发送者会收到配对码;所有者必须批准
* allowlist - 仅允许 allowFrom或已配对的允许存储中的发送者
* open - 允许所有入站私聊
* disabled - 忽略所有入站私聊
*/
@TableField("dm_policy")
private String dmPolicy;
/**
* 允许列表(JSON数组)dm_policy=allowlist时使用
*/
@TableField("allow_from")
private String allowFrom;
/**
* 状态:
* active - 活跃
* inactive - 未激活
* error - 错误
*/
@TableField("status")
private String status;
@TableField("webhook_url")
private String webhookUrl;
@TableField("openclaw_gateway_url")
private String openclawGatewayUrl;
@TableField("openclaw_gateway_token")
private String openclawGatewayToken;
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createdAt;
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updatedAt;
// 枚举类
public static class PairingMode {
public static final String MANUAL = "manual";
public static final String AUTO = "auto";
public static final String RULE = "rule";
public static String[] getAll() {
return new String[]{MANUAL, AUTO, RULE};
}
}
public static class Status {
public static final String ACTIVE = "active";
public static final String INACTIVE = "inactive";
public static final String ERROR = "error";
public static String[] getAll() {
return new String[]{ACTIVE, INACTIVE, ERROR};
}
}
}