Skip to content

Commit

Permalink
refactor: 更接近miraigo的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Nov 12, 2024
1 parent 1d91b44 commit 42b7313
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
35 changes: 25 additions & 10 deletions client/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,26 @@ import (
)

// NewClient 创建一个新的 QQ Client
func NewClient(uin uint32, password string, appInfo *auth.AppInfo, signURL ...string) *QQClient {
return NewClientMD5(uin, md5.Sum([]byte(password)), appInfo, signURL...)
func NewClient(uin uint32, password string) *QQClient {
return NewClientMD5(uin, md5.Sum([]byte(password)))
}

func NewClientMD5(uin uint32, passwordMD5 [16]byte, appInfo *auth.AppInfo, signURL ...string) *QQClient {
func NewClientEmpty() *QQClient {
return NewClientMD5(0, [16]byte{})
}

func NewClientMD5(uin uint32, passwordMD5 [16]byte) *QQClient {
cookieContainer, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List})
client := &QQClient{
Uin: uin,
oicq: oicq.NewCodec(int64(uin)),
passwordMD5: passwordMD5,
highwaySession: highway.Session{
AppID: uint32(appInfo.AppID),
SubAppID: uint32(appInfo.SubAppID),
},
ticket: &TicketService{
client: &http.Client{Jar: cookieContainer},
sKey: &keyInfo{},
},
alive: true,
UA: "LagrangeGo qq/" + appInfo.PackageSign,
}
client.signProvider = sign.NewSigner(appInfo, client.debug, signURL...)
client.transport.Version = appInfo
client.transport.Sig.D2Key = make([]byte, 0, 16)
client.highwaySession.Uin = &client.transport.Sig.Uin
client.Online.Store(false)
Expand Down Expand Up @@ -132,6 +129,24 @@ type QQClient struct {
DisconnectedEvent EventHandle[*DisconnectedEvent]
}

// AddSignServer 设置签名服务器url
func (c *QQClient) AddSignServer(signServers ...string) {
c.signProvider.AddSignServer(signServers...)
}

// AddSignHeader 设置签名服务器签名时的额外http header
func (c *QQClient) AddSignHeader(header map[string]string) {
c.signProvider.AddRequestHeader(header)
}

func (c *QQClient) UseVersion(app *auth.AppInfo) {
c.transport.Version = app
c.highwaySession.AppID = uint32(app.AppID)
c.highwaySession.SubAppID = uint32(app.SubAppID)
c.UA = "LagrangeGo qq/" + app.PackageSign
c.signProvider = sign.NewSigner(app, c.debug)
}

func (c *QQClient) version() *auth.AppInfo {
return c.transport.Version
}
Expand Down
3 changes: 3 additions & 0 deletions client/sign/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ type Response struct {

type Provider interface {
Sign(cmd string, seq uint32, data []byte) (*Response, error)
AddRequestHeader(header map[string]string)
AddSignServer(signServers ...string)
GetSignServer() []string
}
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ func main() {
KernelVersion: "10.0.22631",
}

qqclient := client.NewClient(0, "", appInfo, "https://sign.lagrangecore.org/api/sign/25765")
qqclient := client.NewClient(0, "")
qqclient.SetLogger(protocolLogger{})
qqclient.UseVersion(appInfo)
qqclient.AddSignServer("https://sign.lagrangecore.org/api/sign/25765")
qqclient.UseDevice(deviceInfo)
data, err := os.ReadFile("sig.bin")
if err != nil {
Expand Down

0 comments on commit 42b7313

Please sign in to comment.