升级至8069版本:版本号更新/代理配置系统/红包计时埋点/长连接重构/回调修复

This commit is contained in:
2026-02-26 10:44:13 +08:00
parent 7cbd3d061d
commit 40a74d2ea7
38 changed files with 3639 additions and 235 deletions
+19 -7
View File
@@ -15,6 +15,7 @@ import (
"xiawan/wx/clientsdk/mmtls"
"xiawan/wx/db"
"xiawan/wx/srv"
"xiawan/wx/srv/srvconfig"
"xiawan/wx/srv/websrv"
"xiawan/wx/srv/wxface"
)
@@ -235,10 +236,9 @@ func (wxconn *WXConnect) StartShortReader() {
return
}
forCount := 0
// 最大重试次数
const maxLongRetries = 5
// 最小重试间隔 (秒)
const minRetryInterval = 60
// 从配置获取最大重试次数和重试间隔
maxLongRetries := srvconfig.GlobalSetting.ProxyConfig.MaxLongRetryTimes
minRetryInterval := int64(srvconfig.GlobalSetting.ProxyConfig.LongRetryInterval)
for {
// 判断是否重复启动 for 循环
@@ -311,8 +311,11 @@ func (wxconn *WXConnect) StartShortReader() {
shouldRetry := (currentTime-wxconn.lastLongRetryTime >= minRetryInterval) &&
(wxconn.longRetryCount < maxLongRetries)
// 如果重试计数器已达上限,但已经过去了更长时间(比如10分钟),重置计数器
// 如果重试计数器已达上限,但已经过去了更长时间(比如10倍间隔),重置计数器
if wxconn.longRetryCount >= maxLongRetries && (currentTime-wxconn.lastLongRetryTime >= minRetryInterval*10) {
log.Printf("[%s],[%s] 重置长连接重试计数器(已过去足够长时间)\n",
wxconn.GetWXAccount().GetUserInfo().GetUserName(),
wxconn.GetWXAccount().GetUserInfo().NickName)
wxconn.longRetryCount = 0
shouldRetry = true
}
@@ -369,10 +372,11 @@ func (wxconn *WXConnect) StartShortReader() {
} else if wxconn.longRetryCount >= maxLongRetries {
// 只有在第一次达到最大重试次数时记录日志
if wxconn.longRetryCount == maxLongRetries {
log.Printf("[%s],[%s] 已达到最大重试次数(%d),暂停长连接恢复尝试\n",
log.Printf("[%s],[%s] 已达到最大重试次数(%d),暂停长连接恢复尝试(将在%d秒后重置)\n",
wxconn.GetWXAccount().GetUserInfo().GetUserName(),
wxconn.GetWXAccount().GetUserInfo().NickName,
maxLongRetries)
maxLongRetries,
minRetryInterval*10)
wxconn.longRetryCount++ // 增加一次以避免重复打印
}
}
@@ -597,6 +601,14 @@ func (wxconn *WXConnect) startLongLink() error {
}
tmpMMInfo.Dialer = dialer
// 设置代理配置到MMInfo
tmpMMInfo.LongConnTimeout = srvconfig.GlobalSetting.ProxyConfig.LongConnTimeout
tmpMMInfo.LongConnReadTimeout = srvconfig.GlobalSetting.ProxyConfig.LongConnReadTimeout
tmpMMInfo.LongConnRetryTimes = srvconfig.GlobalSetting.ProxyConfig.LongConnRetryTimes
tmpMMInfo.LongConnRetryInterval = srvconfig.GlobalSetting.ProxyConfig.LongConnRetryInterval
tmpMMInfo.ShortConnTimeout = srvconfig.GlobalSetting.ProxyConfig.ShortConnTimeout
tmpMMInfo.AllowDirectOnProxyFail = srvconfig.GlobalSetting.ProxyConfig.AllowDirectOnProxyFail
wxconn.setConnected(true)
userInfo.MMInfo = tmpMMInfo
// 启动长链接发送接收协程(创建新的定时器)
+40 -2
View File
@@ -1480,7 +1480,9 @@ func (wxqi *WXReqInvoker) SendOpenRedEnvelopesRequest(hbItem *baseinfo.HongBaoIt
hongBaoReceiverItem.InWay = baseinfo.MMHongBaoReqInAwayPersonal
}
// 发送接收红包请求
recvReqStartMs := time.Now().UnixMilli()
packHeader, err := clientsdk.SendReceiveWxHB(wxqi.wxconn.GetWXAccount().GetUserInfo(), hongBaoReceiverItem)
recvReqEndMs := time.Now().UnixMilli()
if err != nil {
if packHeader != nil && packHeader.RetCode == baseinfo.MMRequestRetSessionTimeOut {
// token登陆
@@ -1489,25 +1491,52 @@ func (wxqi *WXReqInvoker) SendOpenRedEnvelopesRequest(hbItem *baseinfo.HongBaoIt
return nil, err
}
var hongbaoResp wechat.HongBaoRes
parseRespStartMs := time.Now().UnixMilli()
errs := clientsdk.ParseResponseData(tmpUserInfo, packHeader, &hongbaoResp)
parseRespEndMs := time.Now().UnixMilli()
if errs != nil {
return nil, errs
}
// 解析
retHongBaoReceiveResp := &baseinfo.HongBaoReceiverResp{}
unmarshalRecvStartMs := time.Now().UnixMilli()
err = json.Unmarshal(hongbaoResp.GetRetText().GetBuffer(), retHongBaoReceiveResp)
unmarshalRecvEndMs := time.Now().UnixMilli()
if err != nil {
return nil, err
}
// 发送给微信消息处理器 打开红包
openReqStartMs := time.Now().UnixMilli()
rsp, er := wxqi.SendOpenWxHBNewRequest(hbItem, retHongBaoReceiveResp.TimingIdentifier)
openReqEndMs := time.Now().UnixMilli()
if er != nil {
return nil, er
}
wxqi.SendOpenHBMsgToSelf(rsp, hbItem)
wxqi.ThanksHB(rsp)
var data RedPacket
if rsp != nil {
_ = json.Unmarshal(rsp.RetText.Buffer, &data)
}
nowMs := time.Now().UnixMilli()
if hbItem != nil && hbItem.RecvAtMs > 0 && data.Retcode == 0 && data.ReceiveStatus == 2 {
detectToEnqueue := hbItem.EnqueueAtMs - hbItem.RecvAtMs
enqueueToDequeue := hbItem.DequeueAtMs - hbItem.EnqueueAtMs
dequeueToRecvStart := recvReqStartMs - hbItem.DequeueAtMs
recvNet := recvReqEndMs - recvReqStartMs
parseResp := parseRespEndMs - parseRespStartMs
unmarshalRecv := unmarshalRecvEndMs - unmarshalRecvStartMs
openNet := openReqEndMs - openReqStartMs
openDoneMs := openReqEndMs - hbItem.RecvAtMs
totalMs := nowMs - hbItem.RecvAtMs
fmt.Printf("红包耗时 total=%dms open=%dms detect->enqueue=%dms enqueue->dequeue=%dms dequeue->recvStart=%dms recvNet=%dms parse=%dms recvUnmarshal=%dms openNet=%dms sendid=%s isGroup=%d fromUser=%s\n",
totalMs, openDoneMs, detectToEnqueue, enqueueToDequeue, dequeueToRecvStart, recvNet, parseResp, unmarshalRecv, openNet, data.SendId, hbItem.IsGroup, hbItem.FromUserName)
}
// go func() {
// wxqi.SendOpenHBMsgToSelf(rsp, hbItem)
// wxqi.ThanksHB(rsp)
// }()
return rsp, nil
}
@@ -2052,12 +2081,16 @@ func (wxqi *WXReqInvoker) SendOpenWxHBNewRequest(hbItem *baseinfo.HongBaoItem, t
var packHeader *baseinfo.PackHeader
var err error
openSendStartMs := time.Now().UnixMilli()
openPath := "openwxhb"
if hongBaoOpenItem.SceneID == 1005 {
hongBaoOpenItem.CgiCmd = 5148 // 这里是pb字段的cgicmd 抓包得到
packHeader, err = clientsdk.SendOpenUninoHB(wxqi.wxconn.GetWXAccount().GetUserInfo(), hongBaoOpenItem)
openPath = "openunionhb"
} else {
packHeader, err = clientsdk.SendOpenWxHB(wxqi.wxconn.GetWXAccount().GetUserInfo(), hongBaoOpenItem)
}
openSendEndMs := time.Now().UnixMilli()
if err != nil {
if packHeader != nil && packHeader.RetCode == baseinfo.MMRequestRetSessionTimeOut {
@@ -2069,12 +2102,17 @@ func (wxqi *WXReqInvoker) SendOpenWxHBNewRequest(hbItem *baseinfo.HongBaoItem, t
//wechat.HongBaoRes{}
// 解析获取联系人响应
resp := new(wechat.HongBaoRes)
openParseStartMs := time.Now().UnixMilli()
err = clientsdk.ParseResponseData(tmpUserInfo, packHeader, resp)
openParseEndMs := time.Now().UnixMilli()
if err != nil {
// token登陆
wxqi.wxconn.SendAutoAuthWaitingMinutes(4)
return nil, err
}
if hbItem != nil && hbItem.RecvAtMs > 0 {
fmt.Printf("红包open阶段 send=%dms parse=%dms path=%s cgi=%d scene=%d\n", openSendEndMs-openSendStartMs, openParseEndMs-openParseStartMs, openPath, hongBaoOpenItem.CgiCmd, hongBaoOpenItem.SceneID)
}
return resp, nil
}
+1 -2
View File
@@ -1,7 +1,6 @@
package wxcore
import (
"fmt"
"xiawan/wx/srv/wxface"
"xiawan/wx/srv/wxtask"
)
@@ -37,7 +36,7 @@ func NewWXTaskMgr(wxConn wxface.IWXConnect) wxface.IWXTaskMgr {
// Start 启动
func (wxtm *WXTaskMgr) Start() {
fmt.Println("启动微信任务管理器")
// fmt.Println("启动微信任务管理器")
//处理异常
// defer TryE("(wxtm *WXTaskMgr) Start()")
if wxtm.start {