Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ if __name__ == "__main__":
```

## 版本更新
### v39.3.3-1(2024.11.18)

* 新增消息转发正则白名单配置,只针对r#type为1的纯文本消息
未配置白名单,则默认转发所有消息
配置白名单,只有符合正则的消息才会转发
非文本消息,如好友消息,红包消息,卡片消息等默认转发

### v39.3.3(2024.11.15)

* 升级 WCF 至 v39.3.3
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wcfrust"
version = "39.3.3"
version = "39.3.3-1"
description = "A HTTP (Rust) client for WeChatFerry"
authors = ["Changhua"]
license = "MIT"
Expand Down Expand Up @@ -41,6 +41,7 @@ rand = "0.8.5"
ureq = { version = "2.10", features = ["json"] }
rust_socketio = {version = "0.6.0", features = ["async"] }
futures-util = "0.3.31"
regex = "1"

[features]
# this feature is used for production builds or when `devPath` points to the filesystem
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/config.json5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cburl":[],"http_server_port":10010,"wsurl":"","file_dir":"","front_msg_show":true}
{"cburl":[],"http_server_port":10010,"wsurl":"","file_dir":"","front_msg_show":true,"msg_filter_regexp":""}
30 changes: 24 additions & 6 deletions src-tauri/src/handler/message/http_message_handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use async_trait::async_trait;

use crate::{handler::event_entity::{Event, EventHandler}, service::global_service::GLOBAL};
use crate::{
handler::event_entity::{Event, EventHandler},
service::global_service::GLOBAL,
};

use regex::Regex;
use serde_json::json;

/// 配置 http 回调地址后,将调用设置的url,
Expand All @@ -14,13 +18,27 @@ impl EventHandler for HttpMessageHandler {
async fn handle(&mut self, event: Event) {
if let Event::ClientMessage(ref msg) = event {
let global = GLOBAL.get().unwrap();
let wechat_config = global.wechat_config.read().unwrap();
let cburl = wechat_config.cburl.clone();
let (cburl, msg_filter_regexp) = {
let config = global.wechat_config.read().unwrap();
(config.cburl.clone(), config.msg_filter_regexp.clone())
};
if cburl.is_empty() {
log::debug!("未配置回调地址,跳过处理");
return;
}

for url in cburl {
// 仅对文本消息做过滤,其他消息也默认转发,如好友消息,红包消息,链接消息等
if msg.r#type == 1 {
if let Some(ref regex_str) = msg_filter_regexp {
let regex = Regex::new(&regex_str).unwrap();
if !regex.is_match(&msg.content) {
log::debug!("消息被过滤,内容: {:?}", &msg.content);
return;
}
} else {
log::debug!("未配置正则过滤,所有消息转发")
}
}
for url in cburl {
log::debug!("http服务 {} 回调地址为: {:?}", self.id, url.clone());
if !url.starts_with("http") {
log::error!("http 转发消息失败,回调地址不合法");
Expand All @@ -38,7 +56,7 @@ impl EventHandler for HttpMessageHandler {
Err(e) => {
log::error!("转发消息失败:{}", e);
}
}
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/wechat_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ pub struct WechatConfig {
pub file_dir: String,
// 前端日志显示
pub front_msg_show: bool,
// 消息正则白名单过滤
pub msg_filter_regexp: Option<String>,
}
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"package": {
"productName": "WcfRust",
"version": "39.3.3"
"version": "39.3.3-1"
},
"tauri": {
"systemTray": {
Expand Down
6 changes: 6 additions & 0 deletions src/components/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ const submitForm = async () => {
<el-input v-model="configStore.wechatConfig.wsurl" />
</el-form-item>
</el-card>
<el-card class="w-full mt-4">
<template #header>消息过滤配置</template>
<el-form-item label="正则白名单过滤:">
<el-input v-model="configStore.wechatConfig.msg_filter_regexp" />
</el-form-item>
</el-card>
</el-form>
</el-main>
</el-container>
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const useConfigStore = defineStore('config', () => {
// 显示消息日志
front_msg_show: true,
file_dir: '',
msg_filter_regexp: '',
});

const update = async () => {
Expand Down
1 change: 1 addition & 0 deletions src/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export type WechatConfig = {
http_server_port: number,
front_msg_show: boolean,
file_dir: string;
msg_filter_regexp: string;
}