Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add waitSignServer #2311

Merged
merged 10 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions cmd/gocq/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"image"
"image/png"
"net/http"
"net/url"
"os"
"strings"
"time"
Expand All @@ -20,9 +21,8 @@ import (
"github.com/tidwall/gjson"
"gopkg.ilharper.com/x/isatty"

"github.com/Mrs4s/go-cqhttp/internal/base"

"github.com/Mrs4s/go-cqhttp/global"
"github.com/Mrs4s/go-cqhttp/internal/base"
"github.com/Mrs4s/go-cqhttp/internal/download"
)

Expand Down Expand Up @@ -273,7 +273,8 @@ func energy(uin uint64, id string, _ string, salt []byte) ([]byte, error) {
}
req := download.Request{
Method: http.MethodGet,
URL: signServer + "custom_energy" + fmt.Sprintf("?data=%v&salt=%v&uin=%v", id, hex.EncodeToString(salt), uin),
URL: signServer + "custom_energy" + fmt.Sprintf("?data=%v&salt=%v&uin=%v&android_id=%v&guid=%v",
id, hex.EncodeToString(salt), uin, utils.B2S(device.AndroidId), hex.EncodeToString(device.Guid)),
}
if base.IsBelow110 {
req.URL = signServer + "custom_energy" + fmt.Sprintf("?data=%v&salt=%v", id, hex.EncodeToString(salt))
Expand Down Expand Up @@ -304,7 +305,8 @@ func sign(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []b
Method: http.MethodPost,
URL: signServer + "sign",
Header: map[string]string{"Content-Type": "application/x-www-form-urlencoded"},
Body: bytes.NewReader([]byte(fmt.Sprintf("uin=%v&qua=%s&cmd=%s&seq=%v&buffer=%v", uin, qua, cmd, seq, hex.EncodeToString(buff)))),
Body: bytes.NewReader([]byte(fmt.Sprintf("uin=%v&qua=%s&cmd=%s&seq=%v&buffer=%v&android_id=%v&guid=%v",
uin, qua, cmd, seq, hex.EncodeToString(buff), utils.B2S(device.AndroidId), hex.EncodeToString(device.Guid)))),
}.Bytes()
if err != nil {
log.Warnf("获取sso sign时出现错误: %v server: %v", err, signServer)
Expand All @@ -328,7 +330,7 @@ func register(uin int64, androidID, guid []byte, qimei36, key string) {
resp, err := download.Request{
Method: http.MethodGet,
URL: signServer + "register" + fmt.Sprintf("?uin=%v&android_id=%v&guid=%v&qimei36=%v&key=%s",
uin, androidID, hex.EncodeToString(guid), qimei36, key),
uin, utils.B2S(androidID), hex.EncodeToString(guid), qimei36, key),
}.Bytes()
if err != nil {
log.Warnf("注册QQ实例时出现错误: %v server: %v", err, signServer)
Expand All @@ -341,3 +343,28 @@ func register(uin int64, androidID, guid []byte, qimei36, key string) {
}
log.Infof("注册QQ实例 %v 成功: %v", uin, msg)
}

func waitSignServer() bool {
t := time.NewTicker(time.Second*5)
defer t.Stop()
i := 0
for range t.C {
if i > 3 {
return false
}
i++
u, err := url.Parse(base.SignServer)
if err != nil {
log.Warnf("连接到签名服务器出现错误: %v", err)
continue
}
r := utils.RunTCPPingLoop(u.Host, 4)
if r.PacketsLoss > 0 {
log.Warnf("连接到签名服务器出现错误: 丢包%d/%d 时延%dms", r.PacketsLoss, r.PacketsSent, r.AvgTimeMill)
continue
}
break
}
log.Infof("连接至签名服务器: %s", base.SignServer)
return true
}
4 changes: 4 additions & 0 deletions cmd/gocq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"golang.org/x/crypto/pbkdf2"
"golang.org/x/term"

"github.com/Mrs4s/go-cqhttp/coolq"

Check failure on line 26 in cmd/gocq/main.go

View workflow job for this annotation

GitHub Actions / lint

could not import github.com/Mrs4s/go-cqhttp/coolq (-: # github.com/Mrs4s/go-cqhttp/coolq
"github.com/Mrs4s/go-cqhttp/db"
"github.com/Mrs4s/go-cqhttp/global"
"github.com/Mrs4s/go-cqhttp/global/terminal"
Expand Down Expand Up @@ -166,6 +166,10 @@

if base.SignServer != "-" && base.SignServer != "" {
log.Infof("使用服务器 %s 进行数据包签名", base.SignServer)
// 等待签名服务器直到连接成功
if !waitSignServer() {
log.Fatalf("连接签名服务器失败")
}
register(base.Account.Uin, device.AndroidId, device.Guid, device.QImei36, base.Key)
wrapper.DandelionEnergy = energy
wrapper.FekitGetSign = sign
Expand Down
Loading