升级至8069版本:版本号更新/代理配置系统/红包计时埋点/长连接重构/回调修复
This commit is contained in:
+67
-4
@@ -12,6 +12,7 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
"xiawan/wx/db/table"
|
||||
"xiawan/wx/protobuf/wechat"
|
||||
|
||||
"github.com/lunny/log"
|
||||
@@ -60,8 +61,17 @@ func GenerateSignature(payload []byte, key string) string {
|
||||
func SendMessageCallback(msg *wechat.AddMsg, uuid string) {
|
||||
// 获取回调配置
|
||||
config, err := GetMessageCallbackConfig(uuid)
|
||||
if err != nil || config == nil || !config.Enabled {
|
||||
return // 没有配置或未启用回调,直接返回
|
||||
if err != nil {
|
||||
log.Errorf("获取回调配置失败 [UUID: %s]: %v", uuid, err)
|
||||
return
|
||||
}
|
||||
if config == nil {
|
||||
log.Debugf("[回调调试] 未找到回调配置 [UUID: %s]", uuid)
|
||||
return
|
||||
}
|
||||
if !config.Enabled {
|
||||
log.Debugf("[回调调试] 回调未启用 [UUID: %s]", uuid)
|
||||
return
|
||||
}
|
||||
|
||||
// 使用消息包装器包含UUID信息
|
||||
@@ -104,6 +114,59 @@ func SendMessageCallback(msg *wechat.AddMsg, uuid string) {
|
||||
return
|
||||
}
|
||||
|
||||
// 记录回调结果
|
||||
log.Infof("Message callback sent to %s for message %d, status: %d", config.CallbackURL, msg.GetMsgId(), resp.StatusCode)
|
||||
}
|
||||
|
||||
// TestMessageCallback 测试消息回调配置
|
||||
func TestMessageCallback(config *table.MessageCallbackConfig) (bool, string) {
|
||||
// 构造测试消息
|
||||
testPayload := map[string]interface{}{
|
||||
"uuid": config.UUID,
|
||||
"type": "test",
|
||||
"data": map[string]interface{}{
|
||||
"message": "这是一条测试回调消息",
|
||||
"timestamp": time.Now().Unix(),
|
||||
},
|
||||
}
|
||||
|
||||
jsonBytes, err := json.Marshal(testPayload)
|
||||
if err != nil {
|
||||
return false, fmt.Sprintf("序列化测试数据失败: %v", err)
|
||||
}
|
||||
|
||||
// 创建HTTP请求
|
||||
req, err := http.NewRequest("POST", config.CallbackURL, bytes.NewBuffer(jsonBytes))
|
||||
if err != nil {
|
||||
return false, fmt.Sprintf("创建请求失败: %v", err)
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("X-Timestamp", fmt.Sprintf("%d", time.Now().Unix()))
|
||||
req.Header.Set("X-Test", "true")
|
||||
|
||||
// 发送请求
|
||||
client := &http.Client{
|
||||
Timeout: 5 * time.Second,
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return false, fmt.Sprintf("发送请求失败: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
// 读取响应
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return false, fmt.Sprintf("读取响应失败: %v", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
log.Infof("✓ 测试回调成功 [UUID: %s] -> %s, 状态码: %d",
|
||||
config.UUID, config.CallbackURL, resp.StatusCode)
|
||||
return true, fmt.Sprintf("状态码: %d, 响应: %s", resp.StatusCode, string(body))
|
||||
} else {
|
||||
log.Warnf("✗ 测试回调失败 [UUID: %s] -> %s, 状态码: %d",
|
||||
config.UUID, config.CallbackURL, resp.StatusCode)
|
||||
return false, fmt.Sprintf("状态码: %d, 响应: %s", resp.StatusCode, string(body))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user