🆕 支持转发消息到外部服务(暂时只支持socket)
All checks were successful
BuildImage / build-image (push) Successful in 1m30s
All checks were successful
BuildImage / build-image (push) Successful in 1m30s
This commit is contained in:
parent
81be5a0f70
commit
63d50b815c
@ -6,6 +6,9 @@ wechat:
|
||||
autoSetCallback: false
|
||||
# 回调IP,如果是Docker运行,本参数必填,如果Docker修改了映射,格式为 ip:port
|
||||
callback: 10.0.0.51
|
||||
# 转发到其他地址
|
||||
forward:
|
||||
- 10.0.0.247:4299
|
||||
|
||||
# 数据库
|
||||
mysql:
|
||||
@ -39,3 +42,9 @@ ai:
|
||||
baseUrl: https://sxxx
|
||||
# 人设
|
||||
personality: 你的名字叫张三,你是一个百科机器人,你的爱好是看电影,你的性格是开朗的,你的专长是讲故事,你的梦想是当一名童话故事作家。你对政治没有一点儿兴趣,也不会讨论任何与政治相关的话题,你甚至可以拒绝回答这一类话题。
|
||||
|
||||
# 资源配置(这玩意儿是机器人那个机器上的smb文件夹)
|
||||
# 暂时没用 - 2023-12-6
|
||||
resource:
|
||||
localPath: /files
|
||||
remotePath: D:\Share\
|
||||
|
@ -5,9 +5,10 @@ import "strings"
|
||||
// wxHelper
|
||||
// @description: 微信助手
|
||||
type wechat struct {
|
||||
Host string `json:"host" yaml:"host"` // 接口地址
|
||||
AutoSetCallback bool `json:"autoSetCallback" yaml:"autoSetCallback"` // 是否自动设置回调地址
|
||||
Callback string `json:"callback" yaml:"callback"` // 回调地址
|
||||
Host string `json:"host" yaml:"host"` // 接口地址
|
||||
AutoSetCallback bool `json:"autoSetCallback" yaml:"autoSetCallback"` // 是否自动设置回调地址
|
||||
Callback string `json:"callback" yaml:"callback"` // 回调地址
|
||||
Forward []string `json:"forward" yaml:"forward"` // 转发地址
|
||||
}
|
||||
|
||||
// Check
|
||||
|
25
tcpserver/forward.go
Normal file
25
tcpserver/forward.go
Normal file
@ -0,0 +1,25 @@
|
||||
package tcpserver
|
||||
|
||||
import (
|
||||
"go-wechat/config"
|
||||
"log"
|
||||
"net"
|
||||
)
|
||||
|
||||
// forward
|
||||
// @description: 转发消息
|
||||
func forward(msg []byte) {
|
||||
// 使用socket转发消息
|
||||
for _, s := range config.Conf.Wechat.Forward {
|
||||
conn, err := net.Dial("tcp", s)
|
||||
if err != nil {
|
||||
log.Printf("转发消息失败,错误信息: %v", err)
|
||||
continue
|
||||
}
|
||||
_, err = conn.Write(msg)
|
||||
if err != nil {
|
||||
log.Printf("转发消息失败,错误信息: %v", err)
|
||||
}
|
||||
_ = conn.Close()
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package tcpserver
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"go-wechat/config"
|
||||
"go-wechat/handler"
|
||||
"io"
|
||||
"log"
|
||||
@ -24,6 +25,11 @@ func process(conn net.Conn) {
|
||||
}
|
||||
log.Printf("[%s]数据长度: %d", conn.RemoteAddr(), buf.Len())
|
||||
go handler.Parse(conn.RemoteAddr(), buf.Bytes())
|
||||
|
||||
// 转发到其他地方去
|
||||
if len(config.Conf.Wechat.Forward) > 0 {
|
||||
go forward(buf.Bytes())
|
||||
}
|
||||
// 将接受到的数据返回给客户端
|
||||
if _, err := conn.Write([]byte("200 OK")); err != nil {
|
||||
log.Printf("[%s]返回数据失败,错误信息: %v", conn.RemoteAddr(), err)
|
||||
|
Loading…
Reference in New Issue
Block a user