diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index aa4b013..16e2674 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v2 with: - go-version: '1.20' + go-version: '1.21' - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 diff --git a/go.mod b/go.mod index 9b6c2e3..392ce10 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ProtobufBot/Go-Mirai-Client -go 1.20 +go 1.21 require ( github.com/BurntSushi/toml v1.3.2 @@ -15,7 +15,7 @@ require ( github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 github.com/sirupsen/logrus v1.9.3 github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 - github.com/tidwall/gjson v1.15.0 + github.com/tidwall/gjson v1.16.0 github.com/zserge/lorca v0.1.10 golang.org/x/mobile v0.0.0-20230531173138-3c911d8e3eda google.golang.org/grpc v1.57.0 diff --git a/go.sum b/go.sum index db9cab4..6254764 100644 --- a/go.sum +++ b/go.sum @@ -27,6 +27,7 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= @@ -42,8 +43,10 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g= +github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4= @@ -51,6 +54,7 @@ github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= @@ -91,6 +95,7 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY= +github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec= github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY= github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -108,8 +113,8 @@ github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gt github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk= github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA= -github.com/tidwall/gjson v1.15.0 h1:5n/pM+v3r5ujuNl4YLZLsQ+UE5jlkLVm7jMzT5Mpolw= -github.com/tidwall/gjson v1.15.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.16.0 h1:SyXa+dsSPpUlcwEDuKuEBJEz5vzTvOea+9rjyYodQFg= +github.com/tidwall/gjson v1.16.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= @@ -158,6 +163,7 @@ google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/pkg/bot/bot.go b/pkg/bot/bot.go index 80bca48..6079380 100644 --- a/pkg/bot/bot.go +++ b/pkg/bot/bot.go @@ -22,8 +22,25 @@ import ( //go:generate go run github.com/a8m/syncmap -o "gen_client_map.go" -pkg bot -name ClientMap "map[int64]*client.QQClient" //go:generate go run github.com/a8m/syncmap -o "gen_token_map.go" -pkg bot -name TokenMap "map[int64][]byte" var ( - Clients ClientMap - LoginTokens TokenMap + Clients ClientMap + LoginTokens TokenMap + EnergyCount = 0 + EnergyStop = false + SignCount = 0 + SignStop = false + RegisterSignCount = 0 + RegisterSignStop = false + SubmitRequestCallbackCount = 0 + SubmitRequestCallbackStop = false + RequestTokenCount = 0 + RequestTokenStop = false + DestoryInstanceCount = 0 + DestoryInstanceStop = false + RSR RequestSignResult + GTL *GMCLogin + SR SignRegister + IsRequestTokenAgain bool = false + TTI_i = 30 ) type Logger struct { @@ -64,16 +81,6 @@ type RequestSignResult struct { Data *RequestSignData } -var RSR RequestSignResult - -var GTL *GMCLogin - -var SR SignRegister - -var IsRequestTokenAgain bool = false - -var TTI_i = 30 - func GmcTokenLogin() (g GMCLogin, err error) { if PathExists("deviceInfo.toml") { _, err = toml.DecodeFile("deviceInfo.toml", >L) @@ -120,32 +127,37 @@ func InitLog(cli *client.QQClient) { func Login(cli *client.QQClient) (bool, error) { cli.AllowSlider = true - if GTL.ClientProtocol == 1 && GTL.SignServer != "" { + if (GTL.ClientProtocol == 1 || GTL.ClientProtocol == 6) && GTL.SignServer != "" { RegisterSign(uint64(cli.Uin), cli.Device().AndroidId, cli.Device().Guid, cli.Device().QImei36, GTL.SignServerKey) - wrapper.DandelionEnergy = Energy - wrapper.FekitGetSign = Sign + if !RegisterSignStop { + wrapper.DandelionEnergy = Energy + wrapper.FekitGetSign = Sign + } } else if GTL.SignServer != "" { log.Warn("SignServer 不支持该协议") } - rsp, err := cli.Login() - if rsp.Code == byte(45) && GTL.SignServer == "" { - log.Warn("您的账号被限制登录,请配置 SignServer 后重试") - } - if rsp.Code == byte(235) { - log.Warn("设备信息被封禁,请删除设备(device)文件夹里对应设备文件后重试") - } - if rsp.Code == byte(237) { - log.Warn("登录过于频繁,请在手机QQ登录并根据提示完成认证") - } - if err != nil { - return false, err - } + if !RegisterSignStop { + rsp, err := cli.Login() + if rsp.Code == byte(45) && GTL.SignServer == "" { + log.Warn("您的账号被限制登录,请配置 SignServer 后重试") + } + if rsp.Code == byte(235) { + log.Warn("设备信息被封禁,请删除设备(device)文件夹里对应设备文件后重试") + } + if rsp.Code == byte(237) { + log.Warn("登录过于频繁,请在手机QQ登录并根据提示完成认证") + } + if err != nil { + return false, err + } - ok, err := ProcessLoginRsp(cli, rsp) - if err != nil { - return false, err + ok, err := ProcessLoginRsp(cli, rsp) + if err != nil { + return false, err + } + return ok, nil } - return ok, nil + return false, fmt.Errorf("登录失败!") } func SetRelogin(cli *client.QQClient, retryInterval int, retryCount int) { @@ -222,54 +234,82 @@ func IsClientExist(uin int64) bool { } func Energy(uin uint64, id string, appVersion string, salt []byte) ([]byte, error) { - signServer := GTL.SignServer - if !strings.HasSuffix(signServer, "/") { - signServer += "/" - } - response, err := download.Request{ - Method: http.MethodGet, - URL: signServer + "custom_energy" + fmt.Sprintf("?uin=%v&data=%v&salt=%v", uin, id, hex.EncodeToString(salt)), - }.Bytes() - if err != nil { - log.Warnf("获取T544 sign时出现错误: %v server: %v", err, signServer) - return nil, err - } - data, err := hex.DecodeString(gjson.GetBytes(response, "data").String()) - if err != nil { - log.Warnf("获取T544 sign时出现错误: %v", err) - return nil, err - } - if len(data) == 0 { - log.Warnf("获取T544 sign时出现错误: %v", "data is empty") - return nil, errors.New("data is empty") + if !EnergyStop { + signServer := GTL.SignServer + if !strings.HasSuffix(signServer, "/") { + signServer += "/" + } + response, err := download.Request{ + Method: http.MethodGet, + URL: signServer + "custom_energy" + fmt.Sprintf("?uin=%v&data=%v&salt=%v", uin, id, hex.EncodeToString(salt)), + }.Bytes() + if err != nil { + log.Warnf("获取T544 sign时出现错误: %v server: %v", err, signServer) + EnergyCount++ + if EnergyCount > 2 { + EnergyStop = true + } + return nil, err + } + data, err := hex.DecodeString(gjson.GetBytes(response, "data").String()) + if err != nil { + log.Warnf("获取T544 sign时出现错误: %v", err) + EnergyCount++ + if EnergyCount > 2 { + EnergyStop = true + } + return nil, err + } + if len(data) == 0 { + log.Warnf("获取T544 sign时出现错误: %v", "data is empty") + EnergyCount++ + if EnergyCount > 2 { + EnergyStop = true + } + return nil, errors.New("data is empty") + } + return data, nil + } else { + log.Warn("Energy失败,请重试") + DestoryInstance(uint(uin), SR.Key) + return nil, fmt.Errorf("Energy失败,请重试") } - return data, nil } func Sign(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []byte, extra []byte, token []byte, err error) { - signServer := GTL.SignServer - if !strings.HasSuffix(signServer, "/") { - signServer += "/" - } - response, err := download.Request{ - 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)))), - }.Bytes() - if err != nil { - log.Warnf("获取sso sign时出现错误: %v server: %v", err, signServer) - return nil, nil, nil, err - } - sign, _ = hex.DecodeString(gjson.GetBytes(response, "data.sign").String()) - extra, _ = hex.DecodeString(gjson.GetBytes(response, "data.extra").String()) - token, _ = hex.DecodeString(gjson.GetBytes(response, "data.token").String()) + if !SignStop { + signServer := GTL.SignServer + if !strings.HasSuffix(signServer, "/") { + signServer += "/" + } + response, err := download.Request{ + 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)))), + }.Bytes() + if err != nil { + log.Warnf("获取sso sign时出现错误: %v server: %v", err, signServer) + SignCount++ + if SignCount > 2 { + SignStop = true + } + return nil, nil, nil, err + } + sign, _ = hex.DecodeString(gjson.GetBytes(response, "data.sign").String()) + extra, _ = hex.DecodeString(gjson.GetBytes(response, "data.extra").String()) + token, _ = hex.DecodeString(gjson.GetBytes(response, "data.token").String()) - json.Unmarshal(response, &RSR) - if len(RSR.Data.RequestCallback) > 1 { - log.Warn(RSR.Data.RequestCallback[0], RSR.Data.RequestCallback[1]) + json.Unmarshal(response, &RSR) + if len(RSR.Data.RequestCallback) > 1 { + log.Warn(RSR.Data.RequestCallback[0], RSR.Data.RequestCallback[1]) + } + return sign, extra, token, nil + } else { + log.Warn("Sign失败, 请重试") + DestoryInstance(uint(SR.Uin), SR.Key) + return nil, nil, nil, fmt.Errorf("Sign失败, 请重试") } - return sign, extra, token, nil } func RegisterSign(uin uint64, androidId []byte, guid []byte, Qimei36 string, signServerAuth string) { @@ -293,8 +333,13 @@ func RegisterSign(uin uint64, androidId []byte, guid []byte, Qimei36 string, sig }.Bytes() if err != nil { log.Warnf("初始化 Sign 失败\n", err) - time.Sleep(time.Second) - RegisterSign(SR.Uin, []byte(SR.AndroidId), []byte(SR.Guid), SR.Qimei36, signServerAuth) + if RegisterSignCount < 2 { + time.Sleep(time.Second * 5) + RegisterSign(SR.Uin, []byte(SR.AndroidId), []byte(SR.Guid), SR.Qimei36, signServerAuth) + RegisterSignCount++ + } else { + RegisterSignStop = true + } } else { log.Info("初始化 Sign 成功") log.Warn(gjson.GetBytes(response, "msg").String()) @@ -303,50 +348,72 @@ func RegisterSign(uin uint64, androidId []byte, guid []byte, Qimei36 string, sig // http://your.host:port/submit?uin=[QQ]&cmd=[CMD]&callback_id=[CALLBACK_ID]&buffer=[BUFFER] func SubmitRequestCallback(uin uint64, cmd string, callbackId int, buffer []byte) { - signServer := GTL.SignServer - if !strings.HasSuffix(signServer, "/") { - signServer += "/" - } - response, err := download.Request{ - Method: http.MethodGet, - URL: signServer + "submit" + fmt.Sprintf("?uin=%v&cmd=%s&callback_id=%v&buffer=%s", uin, cmd, callbackId, buffer), - }.Bytes() - if err != nil { - log.Warnf(cmd, " ", callbackId, "提交失败\n", err) - SubmitRequestCallback(uin, cmd, callbackId, buffer) + if !SubmitRequestCallbackStop { + signServer := GTL.SignServer + if !strings.HasSuffix(signServer, "/") { + signServer += "/" + } + response, err := download.Request{ + Method: http.MethodGet, + URL: signServer + "submit" + fmt.Sprintf("?uin=%v&cmd=%s&callback_id=%v&buffer=%s", uin, cmd, callbackId, buffer), + }.Bytes() + if err != nil { + log.Warnf(cmd, " ", callbackId, "提交失败\n", err) + if SubmitRequestCallbackCount < 2 { + time.Sleep(time.Second * 5) + SubmitRequestCallback(uin, cmd, callbackId, buffer) + SubmitRequestCallbackCount++ + } else { + SubmitRequestCallbackStop = true + } + } else { + log.Info(cmd, " ", callbackId, "提交成功") + log.Warn(string(response)) + log.Warn(gjson.GetBytes(response, "msg").String()) + } } else { - log.Info(cmd, " ", callbackId, "提交成功") - log.Warn(string(response)) - log.Warn(gjson.GetBytes(response, "msg").String()) + log.Warn("SubmitRequestCallback失败,请重试") + DestoryInstance(uint(SR.Uin), SR.Key) } } func RequestToken(uin uint64) { - signServer := GTL.SignServer - if !strings.HasSuffix(signServer, "/") { - signServer += "/" - } - response, err := download.Request{ - Method: http.MethodGet, - URL: signServer + "request_token" + fmt.Sprintf("?uin=%v", uin), - }.Bytes() - if err != nil || strings.HasPrefix(gjson.GetBytes(response, "msg").String(), "Uin") { // QSign - log.Warnf("请求 Token 失败\n", gjson.GetBytes(response, "msg").String(), err) - log.Info("正在重新注册 ", uin) - RegisterSign(SR.Uin, []byte(SR.AndroidId), []byte(SR.Guid), SR.Qimei36, SR.Key) - IsRequestTokenAgain = true - } else if strings.HasPrefix(gjson.GetBytes(response, "msg").String(), "QSign") { - log.Warn("QSign not initialized, unable to request_ Token, please submit the initialization package first.") - IsRequestTokenAgain = false + if !RequestTokenStop { + signServer := GTL.SignServer + if !strings.HasSuffix(signServer, "/") { + signServer += "/" + } + response, err := download.Request{ + Method: http.MethodGet, + URL: signServer + "request_token" + fmt.Sprintf("?uin=%v", uin), + }.Bytes() + if err != nil || strings.HasPrefix(gjson.GetBytes(response, "msg").String(), "Uin") { // QSign + log.Warnf("请求 Token 失败\n", gjson.GetBytes(response, "msg").String(), err) + log.Info("正在重新注册 ", uin) + if RequestTokenCount < 2 { + time.Sleep(time.Second * 5) + RegisterSign(SR.Uin, []byte(SR.AndroidId), []byte(SR.Guid), SR.Qimei36, SR.Key) + IsRequestTokenAgain = true + RequestTokenCount++ + } else { + RequestTokenStop = true + } + } else if strings.HasPrefix(gjson.GetBytes(response, "msg").String(), "QSign") { + log.Warn("QSign not initialized, unable to request_ Token, please submit the initialization package first.") + IsRequestTokenAgain = false + } else { + log.Info("请求 Token 成功") + log.Warn(string(response)) + log.Warn(gjson.GetBytes(response, "msg").String()) + } } else { - log.Info("请求 Token 成功") - log.Warn(string(response)) - log.Warn(gjson.GetBytes(response, "msg").String()) + log.Warn("RequestToken失败,请重试!") + DestoryInstance(uint(SR.Uin), SR.Key) } } // http://host:port/destroy?uin=[QQ]&key=[key] -func DestoryInstance(uin uint, key string){ +func DestoryInstance(uin uint, key string) { signServer := GTL.SignServer if !strings.HasSuffix(signServer, "/") { signServer += "/" @@ -356,7 +423,13 @@ func DestoryInstance(uin uint, key string){ URL: signServer + "destroy" + fmt.Sprintf("?uin=%v&key=%s", uin, key), }.Bytes() if err != nil { - DestoryInstance(uin, key) + if DestoryInstanceCount < 2 { + time.Sleep(time.Second * 5) + DestoryInstance(uin, key) + DestoryInstanceCount++ + } else { + DestoryInstanceStop = true + } } else { log.Warn(gjson.GetBytes(response, "msg").String()) } @@ -364,10 +437,14 @@ func DestoryInstance(uin uint, key string){ func TTIR(uin uint64) { for TTI_i >= 0 { + if RequestTokenStop { + break + } time.Sleep(time.Minute) if TTI_i == 0 { TTI_i = 30 RequestToken(uin) } + TTI_i-- } } diff --git a/pkg/gmc/handler/bot.go b/pkg/gmc/handler/bot.go index 350267e..5869451 100644 --- a/pkg/gmc/handler/bot.go +++ b/pkg/gmc/handler/bot.go @@ -447,9 +447,14 @@ func CreateBotImplMd5(uin int64, passwordMd5 [16]byte, deviceRandSeed int64, cli go bot.SubmitRequestCallback(uint64(uin), data.Cmd, data.CallBackId, []byte(data.Body)) } time.Sleep(time.Second * 3) - AfterLogin(cli) - accountToken := cli.GenToken() - _ = os.WriteFile("session.token", accountToken, 0o644) + if !bot.SubmitRequestCallbackStop { + log.Infof("登录成功") + AfterLogin(cli) + accountToken := cli.GenToken() + _ = os.WriteFile("session.token", accountToken, 0o644) + } else { + log.Warn("联网更新Token失败,请退出重登") + } } else { log.Infof("登录失败") }