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

update: support sign sever up to v1.1.3 #2283

Merged
merged 2 commits into from
Jul 10, 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
38 changes: 34 additions & 4 deletions cmd/gocq/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,19 @@ func fetchCaptcha(id string) string {
return ""
}

func energy(uin uint64, id string, appVersion string, salt []byte) ([]byte, error) {
func energy(uin uint64, id string, _ string, salt []byte) ([]byte, error) {
signServer := base.SignServer
if !strings.HasSuffix(signServer, "/") {
signServer += "/"
}
response, err := download.Request{
req := download.Request{
Method: http.MethodGet,
URL: signServer + "custom_energy" + fmt.Sprintf("?data=%v&salt=%v", id, hex.EncodeToString(salt)),
}.Bytes()
URL: signServer + "custom_energy" + fmt.Sprintf("?data=%v&salt=%v&uin=%v", id, hex.EncodeToString(salt), uin),
}
if base.IsBelow110 {
req.URL = signServer + "custom_energy" + fmt.Sprintf("?data=%v&salt=%v", id, hex.EncodeToString(salt))
}
response, err := req.Bytes()
if err != nil {
log.Warnf("获取T544 sign时出现错误: %v server: %v", err, signServer)
return nil, err
Expand Down Expand Up @@ -310,3 +314,29 @@ func sign(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []b
token, _ = hex.DecodeString(gjson.GetBytes(response, "data.token").String())
return sign, extra, token, nil
}

func register(uin int64, androidID, guid []byte, qimei36, key string) {
if base.IsBelow110 {
log.Warn("签名服务器版本低于1.1.0, 跳过实例注册")
return
}
signServer := base.SignServer
if !strings.HasSuffix(signServer, "/") {
signServer += "/"
}
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),
}.Bytes()
if err != nil {
log.Warnf("注册QQ实例时出现错误: %v server: %v", err, signServer)
return
}
msg := gjson.GetBytes(resp, "msg")
if gjson.GetBytes(resp, "code").Int() != 0 {
log.Warnf("注册QQ实例时出现错误: %v server: %v", msg, signServer)
return
}
log.Infof("注册QQ实例 %v 成功: %v", uin, msg)
}
1 change: 1 addition & 0 deletions cmd/gocq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func LoginInteract() {

if base.SignServer != "-" && base.SignServer != "" {
log.Infof("使用服务器 %s 进行数据包签名", base.SignServer)
register(base.Account.Uin, device.AndroidId, device.Guid, device.QImei36, base.Key)
wrapper.DandelionEnergy = energy
wrapper.FekitGetSign = sign
} else {
Expand Down
4 changes: 4 additions & 0 deletions internal/base/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ var (
AllowTempSession bool // 是否允许发送临时会话信息
UpdateProtocol bool // 是否更新协议
SignServer string // 使用特定的服务器进行签名
Key string // 签名服务器密钥
IsBelow110 bool // 签名服务器版本是否低于1.1.0及以下
HTTPTimeout int

PostFormat string // 上报格式 string or array
Expand Down Expand Up @@ -89,6 +91,8 @@ func Init() {
UseSSOAddress = conf.Account.UseSSOAddress
AllowTempSession = conf.Account.AllowTempSession
SignServer = conf.Account.SignServer
Key = conf.Account.Key
IsBelow110 = conf.Account.IsBelow110
HTTPTimeout = conf.Message.HTTPTimeout
}
{ // others
Expand Down
2 changes: 2 additions & 0 deletions modules/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Account struct {
UseSSOAddress bool `yaml:"use-sso-address"`
AllowTempSession bool `yaml:"allow-temp-session"`
SignServer string `yaml:"sign-server"`
Key string `yaml:"key"`
IsBelow110 bool `yaml:"is-below-110"`
}

// Config 总配置文件
Expand Down
5 changes: 5 additions & 0 deletions modules/config/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ account: # 账号相关
# sign-server: 'https://signserver.example.com' # 线上签名服务器
# 服务器可使用docker在本地搭建或者使用他人开放的服务
sign-server: '-'
# 如果签名服务器的版本在1.1.0及以下, 请将下面的参数改成true
is-below-110: false
# 签名服务器所需要的apikey, 如果签名服务器的版本在1.1.0及以下则此项无效
# 本地部署的默认为114514
key: '114514'

heartbeat:
# 心跳频率, 单位秒
Expand Down