mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-04 19:17:37 +08:00
尝试修复首次登录时容易出现 code -10005 和 packet timed out 的问题 (#2463)
* try to fix: code -10005 and packet timed out (first login) * 此问题猜测可能是成功登录前无法向服务器发送sso packet并获取结果。 在有callback之前似乎没有出现这个问题,怀疑是这里的问题。 等待 100s 后(以等待完成过滑块)再提交初始化包以尝试解决 * sign submit 内容改为仅在debug模式下打印 * impl #2455 * 在“群消息发送失败: 账号可能被风控”的时候提供group_id * optimize: sign callback wait until online * 等待至 bot 在线再发包,而不是简单地等待 100s
This commit is contained in:
parent
517d323953
commit
bd785d3894
@ -186,13 +186,15 @@ func energy(uin uint64, id string, _ string, salt []byte) ([]byte, error) {
|
|||||||
// 提交回调 buffer
|
// 提交回调 buffer
|
||||||
func signSubmit(uin string, cmd string, callbackID int64, buffer []byte, t string) {
|
func signSubmit(uin string, cmd string, callbackID int64, buffer []byte, t string) {
|
||||||
buffStr := hex.EncodeToString(buffer)
|
buffStr := hex.EncodeToString(buffer)
|
||||||
tail := 64
|
if base.Debug {
|
||||||
endl := "..."
|
tail := 64
|
||||||
if len(buffStr) < tail {
|
endl := "..."
|
||||||
tail = len(buffStr)
|
if len(buffStr) < tail {
|
||||||
endl = "."
|
tail = len(buffStr)
|
||||||
|
endl = "."
|
||||||
|
}
|
||||||
|
log.Debugf("submit (%v): uin=%v, cmd=%v, callbackID=%v, buffer=%v%s", t, uin, cmd, callbackID, buffStr[:tail], endl)
|
||||||
}
|
}
|
||||||
log.Infof("submit (%v): uin=%v, cmd=%v, callbackID=%v, buffer=%v%s", t, uin, cmd, callbackID, buffStr[:tail], endl)
|
|
||||||
|
|
||||||
signServer, _, err := requestSignServer(
|
signServer, _, err := requestSignServer(
|
||||||
http.MethodGet,
|
http.MethodGet,
|
||||||
@ -208,6 +210,12 @@ func signSubmit(uin string, cmd string, callbackID int64, buffer []byte, t strin
|
|||||||
// signCallback
|
// signCallback
|
||||||
// 刷新 token 和签名的回调
|
// 刷新 token 和签名的回调
|
||||||
func signCallback(uin string, results []gjson.Result, t string) {
|
func signCallback(uin string, results []gjson.Result, t string) {
|
||||||
|
for { // 等待至在线
|
||||||
|
if cli.Online.Load() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
cmd := result.Get("cmd").String()
|
cmd := result.Get("cmd").String()
|
||||||
callbackID := result.Get("callbackId").Int()
|
callbackID := result.Get("callbackId").Int()
|
||||||
|
@ -759,7 +759,7 @@ func (bot *CQBot) CQSendGroupMessage(groupID int64, m gjson.Result, autoEscape b
|
|||||||
} else {
|
} else {
|
||||||
str := m.String()
|
str := m.String()
|
||||||
if str == "" {
|
if str == "" {
|
||||||
log.Warn("群消息发送失败: 信息为空.")
|
log.Warnf("群 %v 消息发送失败: 信息为空.", groupID)
|
||||||
return Failed(100, "EMPTY_MSG_ERROR", "消息为空")
|
return Failed(100, "EMPTY_MSG_ERROR", "消息为空")
|
||||||
}
|
}
|
||||||
if autoEscape {
|
if autoEscape {
|
||||||
@ -981,7 +981,7 @@ func (bot *CQBot) CQSendGroupForwardMessage(groupID int64, m gjson.Result) globa
|
|||||||
}
|
}
|
||||||
ret := bot.Client.SendGroupForwardMessage(groupID, fe)
|
ret := bot.Client.SendGroupForwardMessage(groupID, fe)
|
||||||
if ret == nil || ret.Id == -1 {
|
if ret == nil || ret.Id == -1 {
|
||||||
log.Warnf("合并转发(群)消息发送失败: 账号可能被风控.")
|
log.Warnf("合并转发(群 %v)消息发送失败: 账号可能被风控.", groupID)
|
||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
|
||||||
}
|
}
|
||||||
mid := bot.InsertGroupMessage(ret, source)
|
mid := bot.InsertGroupMessage(ret, source)
|
||||||
@ -1007,7 +1007,7 @@ func (bot *CQBot) CQSendPrivateForwardMessage(userID int64, m gjson.Result) glob
|
|||||||
}
|
}
|
||||||
mid := bot.SendPrivateMessage(userID, 0, &message.SendingMessage{Elements: []message.IMessageElement{fe}})
|
mid := bot.SendPrivateMessage(userID, 0, &message.SendingMessage{Elements: []message.IMessageElement{fe}})
|
||||||
if mid == -1 {
|
if mid == -1 {
|
||||||
log.Warnf("合并转发(好友)消息发送失败: 账号可能被风控.")
|
log.Warnf("合并转发(好友 %v)消息发送失败: 账号可能被风控.", userID)
|
||||||
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
|
return Failed(100, "SEND_MSG_API_ERROR", "请参考 go-cqhttp 端输出")
|
||||||
}
|
}
|
||||||
log.Infof("发送好友 %v(%v) 的合并转发消息: %v (%v)", userID, userID, limitedString(m.String()), mid)
|
log.Infof("发送好友 %v(%v) 的合并转发消息: %v (%v)", userID, userID, limitedString(m.String()), mid)
|
||||||
|
@ -297,14 +297,14 @@ func (bot *CQBot) SendGroupMessage(groupID int64, m *message.SendingMessage) (in
|
|||||||
newElem = append(newElem, e)
|
newElem = append(newElem, e)
|
||||||
}
|
}
|
||||||
if len(newElem) == 0 {
|
if len(newElem) == 0 {
|
||||||
log.Warnf("群消息发送失败: 消息为空.")
|
log.Warnf("群 %v 消息发送失败: 消息为空.", groupID)
|
||||||
return -1, errors.New("empty message")
|
return -1, errors.New("empty message")
|
||||||
}
|
}
|
||||||
m.Elements = newElem
|
m.Elements = newElem
|
||||||
bot.checkMedia(newElem, groupID)
|
bot.checkMedia(newElem, groupID)
|
||||||
ret := bot.Client.SendGroupMessage(groupID, m)
|
ret := bot.Client.SendGroupMessage(groupID, m)
|
||||||
if ret == nil || ret.Id == -1 {
|
if ret == nil || ret.Id == -1 {
|
||||||
log.Warnf("群消息发送失败: 账号可能被风控.")
|
log.Warnf("群 %v 发送消息失败: 账号可能被风控.", groupID)
|
||||||
return -1, errors.New("send group message failed: blocked by server")
|
return -1, errors.New("send group message failed: blocked by server")
|
||||||
}
|
}
|
||||||
return bot.InsertGroupMessage(ret, source), nil
|
return bot.InsertGroupMessage(ret, source), nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user