Compare commits

..

3 Commits

Author SHA1 Message Date
ca42c72e0f 🐛修复微信通知bug 2024-12-05 11:25:21 +08:00
683e7b2cc3 🐛修复定时任务bug 2024-12-05 11:06:21 +08:00
accb060e27 🐛修复定时任务bug 2024-12-05 10:43:40 +08:00
2 changed files with 13 additions and 4 deletions

View File

@@ -49,13 +49,14 @@ func (c networkClient) ClientOfflineNotify() error {
// 查询一下通知配置 // 查询一下通知配置
code, err := service.Setting().GetByCode("WECHAT_NOTIFY") code, err := service.Setting().GetByCode("WECHAT_NOTIFY")
if err != nil { if err != nil {
log.Errorf("获取微信通知配置失败: %v", err.Error())
return err return err
} }
for _, peer := range connectedPeers { for _, peer := range connectedPeers {
var clientName string var clientName string
if !slices.ContainsFunc(clients, func(cli model.Client) bool { if !slices.ContainsFunc(clients, func(cli model.Client) bool {
isExist := peer.PublicKey.String() == jsoniter.Get([]byte(cli.Keys), "PublicKey").ToString() isExist := peer.PublicKey.String() == jsoniter.Get([]byte(cli.Keys), "publicKey").ToString()
if isExist { if isExist {
clientName = cli.Name clientName = cli.Name
} }
@@ -65,7 +66,7 @@ func (c networkClient) ClientOfflineNotify() error {
} }
// 如果存在,判断离线时间 // 如果存在,判断离线时间
if time.Since(peer.LastHandshakeTime) < 3 { if time.Since(peer.LastHandshakeTime).Minutes() < 3 {
var ipAllocation string var ipAllocation string
for _, iaip := range peer.AllowedIPs { for _, iaip := range peer.AllowedIPs {
ipAllocation += iaip.String() + "," ipAllocation += iaip.String() + ","

View File

@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"gitee.ltd/lxh/logger/log" "gitee.ltd/lxh/logger/log"
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
"strings"
"wireguard-ui/global/client" "wireguard-ui/global/client"
"wireguard-ui/model" "wireguard-ui/model"
) )
@@ -26,7 +27,7 @@ func WechatNotify(setting *model.Setting) wechatNotify {
Addr: sm["addr"], Addr: sm["addr"],
Path: sm["path"], Path: sm["path"],
Method: sm["method"], Method: sm["method"],
toUserId: sm["toUserId"], toUserId: sm["toUserWxId"],
} }
} }
@@ -36,6 +37,7 @@ func WechatNotify(setting *model.Setting) wechatNotify {
// @param msg // @param msg
// @return error // @return error
func (w wechatNotify) SendTextMessage(msg string) error { func (w wechatNotify) SendTextMessage(msg string) error {
log.Debugf("发送通知到微信: %v", msg)
req := client.HttpClient.R() req := client.HttpClient.R()
req.SetHeader("Content-Type", "application/json") req.SetHeader("Content-Type", "application/json")
@@ -43,7 +45,13 @@ func (w wechatNotify) SendTextMessage(msg string) error {
"wxid": w.toUserId, "wxid": w.toUserId,
"msg": msg, "msg": msg,
}) })
result, err := req.Post(fmt.Sprintf("%s:%s", w.Addr, w.Path))
req.URL = fmt.Sprintf("%s:%s", w.Addr, w.Path)
switch strings.ToUpper(w.Method) {
case "POST":
req.Method = "POST"
}
result, err := req.SetDebug(true).Send()
if err != nil { if err != nil {
return err return err
} }