Skip to content

Commit e09a33e

Browse files
committed
chore: sync upstream
2 parents 6976c1e + 9c1390c commit e09a33e

File tree

22 files changed

+78
-1066
lines changed

22 files changed

+78
-1066
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ WORKDIR /data
4242
VOLUME [ "/data" ]
4343

4444
ENTRYPOINT [ "/docker-entrypoint.sh" ]
45+
CMD [ "/app/cqhttp" ]

cmd/gocq/login.go

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,19 @@ import (
1414

1515
"github.com/Mrs4s/MiraiGo/client"
1616
"github.com/Mrs4s/MiraiGo/utils"
17-
"github.com/Mrs4s/MiraiGo/wrapper"
17+
"github.com/Mrs4s/go-cqhttp/internal/base"
1818
"github.com/mattn/go-colorable"
1919
"github.com/pkg/errors"
2020
log "github.com/sirupsen/logrus"
2121
"github.com/tidwall/gjson"
2222
"gopkg.ilharper.com/x/isatty"
2323

2424
"github.com/Mrs4s/go-cqhttp/global"
25-
"github.com/Mrs4s/go-cqhttp/internal/base"
2625
"github.com/Mrs4s/go-cqhttp/internal/download"
27-
"github.com/Mrs4s/go-cqhttp/internal/encryption"
28-
_ "github.com/Mrs4s/go-cqhttp/internal/encryption/t544" // side effect
2926
)
3027

3128
var console = bufio.NewReader(os.Stdin)
3229

33-
func init() {
34-
wrapper.DandelionEnergy = energy
35-
}
36-
3730
func readLine() (str string) {
3831
str, _ = console.ReadString('\n')
3932
str = strings.TrimSpace(str)
@@ -222,9 +215,8 @@ func loginResponseProcessor(res *client.LoginResponse) error {
222215
log.Warnf("设备信息被封禁, 请删除 device.json 后重试.")
223216
case 237:
224217
log.Warnf("登录过于频繁, 请在手机QQ登录并根据提示完成认证后等一段时间重试")
225-
case 45: // 在提供 t544 后还是出现45错误是需要强行升级到最新客户端或被限制非常用设备
226-
log.Warnf("你的账号涉嫌违规被限制在非常用设备登录, 请在手机QQ登录并根据提示完成认证")
227-
log.Warnf("或使用 -update-protocol 升级到最新协议后重试")
218+
case 45:
219+
log.Warnf("你的账号被限制登录, 请配置 SignServer 后重试")
228220
}
229221
log.Infof("按 Enter 继续....")
230222
readLine()
@@ -274,32 +266,47 @@ func fetchCaptcha(id string) string {
274266
}
275267

276268
func energy(uin uint64, id string, appVersion string, salt []byte) ([]byte, error) {
277-
if localSigner, ok := encryption.T544Signer[appVersion]; ok {
278-
log.Debugf("use local T544Signer v%s", appVersion)
279-
result := localSigner(time.Now().UnixMicro(), salt)
280-
log.Debugf("t544 sign result: %x", result)
281-
return result, nil
282-
}
283-
log.Debugf("fallback to remote T544Signer v%s", appVersion)
284-
signServer := "https://captcha.go-cqhttp.org/sdk/dandelion/energy"
285-
if base.SignServerOverwrite != "" {
286-
signServer = base.SignServerOverwrite
269+
signServer := base.SignServer
270+
if !strings.HasSuffix(signServer, "/") {
271+
signServer += "/"
287272
}
288273
response, err := download.Request{
289-
Method: http.MethodPost,
290-
URL: signServer,
291-
Header: map[string]string{"Content-Type": "application/x-www-form-urlencoded"},
292-
Body: bytes.NewReader([]byte(fmt.Sprintf("uin=%v&id=%s&salt=%s&version=%s", uin, id, hex.EncodeToString(salt), appVersion))),
274+
Method: http.MethodGet,
275+
URL: signServer + "custom_energy" + fmt.Sprintf("?data=%v&salt=%v", id, hex.EncodeToString(salt)),
293276
}.Bytes()
294277
if err != nil {
295-
log.Errorf("获取T544时出现问题: %v", err)
278+
log.Warnf("获取T544 sign时出现错误: %v server: %v", err, signServer)
296279
return nil, err
297280
}
298-
sign, err := hex.DecodeString(gjson.GetBytes(response, "result").String())
299-
if err != nil || len(sign) == 0 {
300-
log.Errorf("获取T544时出现问题: %v", err)
281+
data, err := hex.DecodeString(gjson.GetBytes(response, "data").String())
282+
if err != nil {
283+
log.Warnf("获取T544 sign时出现错误: %v", err)
301284
return nil, err
302285
}
303-
log.Debugf("t544 sign result: %x", sign)
304-
return sign, nil
286+
if len(data) == 0 {
287+
log.Warnf("获取T544 sign时出现错误: %v", "data is empty")
288+
return nil, errors.New("data is empty")
289+
}
290+
return data, nil
291+
}
292+
293+
func sign(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []byte, extra []byte, token []byte, err error) {
294+
signServer := base.SignServer
295+
if !strings.HasSuffix(signServer, "/") {
296+
signServer += "/"
297+
}
298+
response, err := download.Request{
299+
Method: http.MethodPost,
300+
URL: signServer + "sign",
301+
Header: map[string]string{"Content-Type": "application/x-www-form-urlencoded"},
302+
Body: bytes.NewReader([]byte(fmt.Sprintf("uin=%v&qua=%s&cmd=%s&seq=%v&buffer=%v", uin, qua, cmd, seq, hex.EncodeToString(buff)))),
303+
}.Bytes()
304+
if err != nil {
305+
log.Warnf("获取sso sign时出现错误: %v server: %v", err, signServer)
306+
return nil, nil, nil, err
307+
}
308+
sign, _ = hex.DecodeString(gjson.GetBytes(response, "data.sign").String())
309+
extra, _ = hex.DecodeString(gjson.GetBytes(response, "data.extra").String())
310+
token, _ = hex.DecodeString(gjson.GetBytes(response, "data.token").String())
311+
return sign, extra, token, nil
305312
}

cmd/gocq/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/Mrs4s/MiraiGo/binary"
1616
"github.com/Mrs4s/MiraiGo/client"
17+
"github.com/Mrs4s/MiraiGo/wrapper"
1718
para "github.com/fumiama/go-hide-param"
1819
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
1920
"github.com/pkg/errors"
@@ -163,6 +164,14 @@ func LoginInteract() {
163164
}
164165
}
165166

167+
if base.SignServer != "-" && base.SignServer != "" {
168+
log.Infof("使用服务器 %s 进行数据包签名", base.SignServer)
169+
wrapper.DandelionEnergy = energy
170+
wrapper.FekitGetSign = sign
171+
} else {
172+
log.Warnf("警告: 未配置签名服务器, 这可能会导致登录 45 错误码或发送消息被风控")
173+
}
174+
166175
if base.Account.Encrypt {
167176
if !global.PathExists("password.encrypt") {
168177
if base.Account.Password == "" {

coolq/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ func (bot *CQBot) CQUploadPrivateFile(userID int64, file, name string) global.MS
617617
log.Warnf("上传私聊文件 %v 失败: %+v", file, err)
618618
return Failed(100, "OPEN_FILE_ERROR", "打开文件失败")
619619
}
620+
defer func() { _ = fileBody.Close() }()
620621
localFile := &client.LocalFile{
621622
FileName: name,
622623
Body: fileBody,

coolq/converter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (bot *CQBot) formatGroupMessage(m *message.GroupMessage) *event {
9292
"name": m.Sender.AnonymousInfo.AnonymousNick,
9393
}
9494
gm["sender"].(global.MSG)["nickname"] = "匿名消息"
95-
gm["sub_type"] = "anonymous"
95+
typ = "message/group/anonymous"
9696
} else {
9797
group := bot.Client.FindGroup(m.GroupCode)
9898
mem := group.FindMember(m.Sender.Uin)

coolq/cqcode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ func (bot *CQBot) ConvertElement(spec *onebot.Spec, elem msg.Element, sourceType
713713
MusicType: message.CloudMusic,
714714
Title: info.Get("name").String(),
715715
Summary: artistName,
716-
Url: "https://y.music.163.com/m/song/" + id,
716+
Url: "https://music.163.com/song/?id=" + id,
717717
PictureUrl: info.Get("album.picUrl").String(),
718718
MusicUrl: "https://music.163.com/song/media/outer/url?id=" + id,
719719
}, nil

docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ chown -R ${UID}:${GID} /app /data
1717
chmod +x /app/cqhttp
1818

1919
echo "Starting..."
20-
su-exec ${USER} /app/cqhttp
20+
su-exec ${USER} "$@"

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.20
55
require (
66
github.com/FloatTech/sqlite v1.5.7
77
github.com/Microsoft/go-winio v0.6.0
8-
github.com/Mrs4s/MiraiGo v0.0.0-20230401072048-f8d9841755b5
8+
github.com/Mrs4s/MiraiGo v0.0.0-20230627090859-19e3d172596e
99
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e
1010
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc
1111
github.com/fumiama/go-base16384 v1.6.1
@@ -69,4 +69,4 @@ require (
6969

7070
replace github.com/remyoudompheng/bigfft => github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b
7171

72-
replace github.com/Mrs4s/MiraiGo => github.com/CodeLaboratory/MiraiGo v0.0.0-20230413080504-8adea49c27b5
72+
replace github.com/Mrs4s/MiraiGo => github.com/CodeLaboratory/MiraiGo v0.0.0-20230705011024-9614424df4d3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/CodeLaboratory/MiraiGo v0.0.0-20230413080504-8adea49c27b5 h1:hRvl9EnHdL/smNj2mAShoiOuRALHDRy/4WePSOdOOBw=
2-
github.com/CodeLaboratory/MiraiGo v0.0.0-20230413080504-8adea49c27b5/go.mod h1:mU3fBFU+7eO0kaGes7YRKtzIDtwIU84nSSwTV7NK2b0=
1+
github.com/CodeLaboratory/MiraiGo v0.0.0-20230705011024-9614424df4d3 h1:xyUZGz1lyQS2UIRd/znddBlreKepD/M/TnT2BmqiK9Y=
2+
github.com/CodeLaboratory/MiraiGo v0.0.0-20230705011024-9614424df4d3/go.mod h1:mU3fBFU+7eO0kaGes7YRKtzIDtwIU84nSSwTV7NK2b0=
33
github.com/FloatTech/sqlite v1.5.7 h1:Bvo4LSojcZ6dVtbHrkqvt6z4v8e+sj0G5PSUIvdawsk=
44
github.com/FloatTech/sqlite v1.5.7/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY=
55
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b h1:tvciXWq2nuvTbFeJGLDNIdRX3BI546D3O7k7vrVueZw=

internal/base/flag.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var (
3838
FastStart bool // 是否为快速启动
3939
AllowTempSession bool // 是否允许发送临时会话信息
4040
UpdateProtocol bool // 是否更新协议
41-
SignServerOverwrite string // 使用特定的服务器进行签名
41+
SignServer string // 使用特定的服务器进行签名
4242
HTTPTimeout int
4343

4444
PostFormat string // 上报格式 string or array
@@ -64,7 +64,6 @@ func Parse() {
6464
d := flag.Bool("D", false, "debug mode")
6565
flag.BoolVar(&FastStart, "faststart", false, "skip waiting 5 seconds")
6666
flag.BoolVar(&UpdateProtocol, "update-protocol", false, "update protocol")
67-
flag.StringVar(&SignServerOverwrite, "sign-server", "", "use special server to sign tlv")
6867
flag.Parse()
6968

7069
if *d {
@@ -89,6 +88,7 @@ func Init() {
8988
ReportSelfMessage = conf.Message.ReportSelfMessage
9089
UseSSOAddress = conf.Account.UseSSOAddress
9190
AllowTempSession = conf.Account.AllowTempSession
91+
SignServer = conf.Account.SignServer
9292
HTTPTimeout = conf.Message.HTTPTimeout
9393
}
9494
{ // others

0 commit comments

Comments
 (0)