From 539cc28f348ba687eb49a106098ee67c99559a03 Mon Sep 17 00:00:00 2001 From: KomeiDiSanXian <2211213431@qq.com> Date: Thu, 20 Jul 2023 19:17:55 +0800 Subject: [PATCH 1/8] =?UTF-8?q?add:=20=E7=AD=89=E5=BE=85=E7=AD=BE=E5=90=8D?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E5=90=AF=E5=8A=A8=E4=BB=A5=E5=90=8E?= =?UTF-8?q?=E5=86=8D=E8=BF=9B=E8=A1=8C=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/gocq/login.go | 38 ++++++++++++++++++++++++++++++++++++++ cmd/gocq/main.go | 2 ++ 2 files changed, 40 insertions(+) diff --git a/cmd/gocq/login.go b/cmd/gocq/login.go index 8b1976845..067d259c6 100644 --- a/cmd/gocq/login.go +++ b/cmd/gocq/login.go @@ -7,9 +7,12 @@ import ( "fmt" "image" "image/png" + "net" "net/http" + "net/url" "os" "strings" + "sync" "time" "github.com/Mrs4s/MiraiGo/client" @@ -340,3 +343,38 @@ func register(uin int64, androidID, guid []byte, qimei36, key string) { } log.Infof("注册QQ实例 %v 成功: %v", uin, msg) } + +func listenPort(wg *sync.WaitGroup) { + defer wg.Done() + for { + err := dailPort() + if err != nil { + log.Warnf("连接到签名服务器出现错误: %v", err) + // 连接失败,每5秒检测一次 + time.Sleep(5 * time.Second) + } else { + break + } + } +} + +func dailPort() error { + u, err := url.Parse(base.SignServer) + if err != nil { + return err + } + conn, err := net.Dial("tcp", u.Host) + if err != nil { + return err + } + conn.Close() + return nil +} + +func waitForConnection() { + var wg sync.WaitGroup + wg.Add(1) + go listenPort(&wg) + wg.Wait() + log.Infof("连接至签名服务器: %s", base.SignServer) +} diff --git a/cmd/gocq/main.go b/cmd/gocq/main.go index 506186595..4112f9f13 100644 --- a/cmd/gocq/main.go +++ b/cmd/gocq/main.go @@ -166,6 +166,8 @@ func LoginInteract() { if base.SignServer != "-" && base.SignServer != "" { log.Infof("使用服务器 %s 进行数据包签名", base.SignServer) + // 等待签名服务器直到连接成功 + waitForConnection() register(base.Account.Uin, device.AndroidId, device.Guid, device.QImei36, base.Key) wrapper.DandelionEnergy = energy wrapper.FekitGetSign = sign From ceedf0e0ceb253d5b7a7e0250fbf2024569dcf27 Mon Sep 17 00:00:00 2001 From: KomeiDiSanXian <2211213431@qq.com> Date: Thu, 20 Jul 2023 19:21:14 +0800 Subject: [PATCH 2/8] =?UTF-8?q?add:=20=E6=94=AF=E6=8C=81=E7=AD=BE=E5=90=8D?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E8=87=AA=E5=8A=A8=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/gocq/login.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/gocq/login.go b/cmd/gocq/login.go index 067d259c6..bd9582695 100644 --- a/cmd/gocq/login.go +++ b/cmd/gocq/login.go @@ -275,7 +275,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, hex.EncodeToString(device.AndroidId), hex.EncodeToString(device.Guid)), } if base.IsBelow110 { req.URL = signServer + "custom_energy" + fmt.Sprintf("?data=%v&salt=%v", id, hex.EncodeToString(salt)) @@ -304,7 +305,7 @@ func sign(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []b } response, err := download.Request{ Method: http.MethodPost, - URL: signServer + "sign", + URL: signServer + "sign"+fmt.Sprintf("?), 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)))), }.Bytes() From 49fedae3de6b52b894ed92a6ab24d450cd0d4446 Mon Sep 17 00:00:00 2001 From: KomeiDiSanXian <2211213431@qq.com> Date: Thu, 20 Jul 2023 19:27:45 +0800 Subject: [PATCH 3/8] fix --- cmd/gocq/login.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/gocq/login.go b/cmd/gocq/login.go index a3a6855e1..d556700c9 100644 --- a/cmd/gocq/login.go +++ b/cmd/gocq/login.go @@ -17,14 +17,13 @@ import ( "github.com/Mrs4s/MiraiGo/client" "github.com/Mrs4s/MiraiGo/utils" + "github.com/Mrs4s/go-cqhttp/internal/base" "github.com/mattn/go-colorable" "github.com/pkg/errors" log "github.com/sirupsen/logrus" "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/download" ) @@ -306,7 +305,7 @@ func sign(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []b } response, err := download.Request{ Method: http.MethodPost, - URL: signServer + "sign"+fmt.Sprintf("?), + URL: signServer + "sign" + fmt.Sprintf("?android_id=%v&guid=%v", hex.EncodeToString(device.AndroidId), hex.EncodeToString(device.Guid)), 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)))), }.Bytes() From 8bb10631613e6bbdd461984ca110b2b2323b1ab2 Mon Sep 17 00:00:00 2001 From: KomeiDiSanXian <2211213431@qq.com> Date: Fri, 21 Jul 2023 01:45:23 +0800 Subject: [PATCH 4/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?sign=20=E6=97=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/gocq/login.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/gocq/login.go b/cmd/gocq/login.go index d556700c9..7f377a4c5 100644 --- a/cmd/gocq/login.go +++ b/cmd/gocq/login.go @@ -305,9 +305,10 @@ func sign(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []b } response, err := download.Request{ Method: http.MethodPost, - URL: signServer + "sign" + fmt.Sprintf("?android_id=%v&guid=%v", hex.EncodeToString(device.AndroidId), hex.EncodeToString(device.Guid)), + 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), hex.EncodeToString(device.AndroidId), hex.EncodeToString(device.Guid)))), }.Bytes() if err != nil { log.Warnf("获取sso sign时出现错误: %v server: %v", err, signServer) From 8405c478b37036a4d1358b79d480b0d1e31015a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 1 Aug 2023 09:07:48 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/gocq/login.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/gocq/login.go b/cmd/gocq/login.go index 7f377a4c5..f0aea7e0f 100644 --- a/cmd/gocq/login.go +++ b/cmd/gocq/login.go @@ -17,7 +17,6 @@ import ( "github.com/Mrs4s/MiraiGo/client" "github.com/Mrs4s/MiraiGo/utils" - "github.com/Mrs4s/go-cqhttp/internal/base" "github.com/mattn/go-colorable" "github.com/pkg/errors" log "github.com/sirupsen/logrus" @@ -25,6 +24,7 @@ import ( "gopkg.ilharper.com/x/isatty" "github.com/Mrs4s/go-cqhttp/global" + "github.com/Mrs4s/go-cqhttp/internal/base" "github.com/Mrs4s/go-cqhttp/internal/download" ) @@ -276,7 +276,7 @@ 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&android_id=%v&guid=%v", - id, hex.EncodeToString(salt), uin, hex.EncodeToString(device.AndroidId), hex.EncodeToString(device.Guid)), + 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)) @@ -308,7 +308,7 @@ func sign(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []b 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&android_id=%v&guid=%v", - uin, qua, cmd, seq, hex.EncodeToString(buff), hex.EncodeToString(device.AndroidId), hex.EncodeToString(device.Guid)))), + 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) @@ -332,7 +332,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, hex.EncodeToString(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) From 93fb227e544c33d59b54f6827d23a5b6baf01b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 1 Aug 2023 09:28:43 +0800 Subject: [PATCH 6/8] Update login.go --- cmd/gocq/login.go | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/cmd/gocq/login.go b/cmd/gocq/login.go index f0aea7e0f..f0eda2c15 100644 --- a/cmd/gocq/login.go +++ b/cmd/gocq/login.go @@ -346,37 +346,27 @@ func register(uin int64, androidID, guid []byte, qimei36, key string) { log.Infof("注册QQ实例 %v 成功: %v", uin, msg) } -func listenPort(wg *sync.WaitGroup) { - defer wg.Done() - for { - err := dailPort() +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) - // 连接失败,每5秒检测一次 - time.Sleep(5 * time.Second) - } else { - break + continue } + r := utils.RunTCPPingLoop(u.Host, 4) + if r.PacketsLoss > 0 { + log.Warnf("连接到签名服务器出现错误: 丢包%d/%d 时延%dms", r.PacketsLoss, r.PacketsSent, r.AvgTimeMill) + continue + } + break } -} - -func dailPort() error { - u, err := url.Parse(base.SignServer) - if err != nil { - return err - } - conn, err := net.Dial("tcp", u.Host) - if err != nil { - return err - } - conn.Close() - return nil -} - -func waitForConnection() { - var wg sync.WaitGroup - wg.Add(1) - go listenPort(&wg) - wg.Wait() log.Infof("连接至签名服务器: %s", base.SignServer) + return true } From f9ec605c5c42a4c43580646d55fe918788ce330a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 1 Aug 2023 09:30:03 +0800 Subject: [PATCH 7/8] Update main.go --- cmd/gocq/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/gocq/main.go b/cmd/gocq/main.go index 4112f9f13..606fae82b 100644 --- a/cmd/gocq/main.go +++ b/cmd/gocq/main.go @@ -167,7 +167,9 @@ func LoginInteract() { if base.SignServer != "-" && base.SignServer != "" { log.Infof("使用服务器 %s 进行数据包签名", base.SignServer) // 等待签名服务器直到连接成功 - waitForConnection() + if !waitSignServer() { + log.Fatalf("连接签名服务器失败") + } register(base.Account.Uin, device.AndroidId, device.Guid, device.QImei36, base.Key) wrapper.DandelionEnergy = energy wrapper.FekitGetSign = sign From d589254cbbc4317cbc14ad8f5107b4b93d44ca1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 1 Aug 2023 09:36:43 +0800 Subject: [PATCH 8/8] Update login.go --- cmd/gocq/login.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmd/gocq/login.go b/cmd/gocq/login.go index f0eda2c15..51d9626d2 100644 --- a/cmd/gocq/login.go +++ b/cmd/gocq/login.go @@ -7,12 +7,10 @@ import ( "fmt" "image" "image/png" - "net" "net/http" "net/url" "os" "strings" - "sync" "time" "github.com/Mrs4s/MiraiGo/client"