From c0bbd0d52d264f3e334b7df212800b9e9684b8f9 Mon Sep 17 00:00:00 2001 From: Redmomn <109732988+Redmomn@users.noreply.github.com> Date: Wed, 25 Dec 2024 16:21:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3client=E4=B8=ADsign=20?= =?UTF-8?q?Provider=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/base.go | 18 +++++++++++++++++- client/sign/provider.go | 3 +++ client/sign/sign.go | 18 +++++++++++------- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/client/base.go b/client/base.go index 9fe5d29..15d79ea 100644 --- a/client/base.go +++ b/client/base.go @@ -135,11 +135,17 @@ type QQClient struct { // AddSignServer 设置签名服务器url func (c *QQClient) AddSignServer(signServers ...string) { + if c.signProvider == nil { + c.UseSignProvider(sign.NewSigner(c.debug)) + } c.signProvider.AddSignServer(signServers...) } // AddSignHeader 设置签名服务器签名时的额外http header func (c *QQClient) AddSignHeader(header map[string]string) { + if c.signProvider == nil { + c.UseSignProvider(sign.NewSigner(c.debug)) + } c.signProvider.AddRequestHeader(header) } @@ -148,7 +154,17 @@ func (c *QQClient) UseVersion(app *auth.AppInfo) { 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) + if c.signProvider == nil { + c.signProvider = sign.NewSigner(c.debug) + } + c.signProvider.SetAppInfo(app) +} + +func (c *QQClient) UseSignProvider(p sign.Provider) { + c.signProvider = p + if c.version() != nil { + c.signProvider.SetAppInfo(c.version()) + } } func (c *QQClient) version() *auth.AppInfo { diff --git a/client/sign/provider.go b/client/sign/provider.go index 48749a2..184e640 100644 --- a/client/sign/provider.go +++ b/client/sign/provider.go @@ -1,5 +1,7 @@ package sign +import "github.com/LagrangeDev/LagrangeGo/client/auth" + type Response struct { Platform string `json:"platform"` Version string `json:"version"` @@ -15,4 +17,5 @@ type Provider interface { AddRequestHeader(header map[string]string) AddSignServer(signServers ...string) GetSignServer() []string + SetAppInfo(app *auth.AppInfo) } diff --git a/client/sign/sign.go b/client/sign/sign.go index 3df1d04..026148b 100644 --- a/client/sign/sign.go +++ b/client/sign/sign.go @@ -41,17 +41,14 @@ const ( var ErrVersionMismatch = errors.New("sign version mismatch") -func NewSigner(appinfo *auth.AppInfo, log func(string, ...any), signServers ...string) *Client { +func NewSigner(log func(string, ...any), signServers ...string) *Client { client := &Client{ instances: utils.Map(signServers, func(s string) *remote { return &remote{server: s} }), - app: appinfo, - httpClient: &http.Client{}, - extraHeaders: http.Header{ - "User-Agent": []string{"qq/" + appinfo.CurrentVersion}, - }, - log: log, + httpClient: &http.Client{}, + extraHeaders: http.Header{}, + log: log, } go client.test() return client @@ -81,6 +78,13 @@ func (c *Client) GetSignServer() []string { }) } +func (c *Client) SetAppInfo(app *auth.AppInfo) { + c.lock.Lock() + defer c.lock.Unlock() + c.app = app + c.extraHeaders.Set("User-Agent", "qq/"+app.CurrentVersion) +} + func (c *Client) getAvailableSign() *remote { c.lock.RLock() defer c.lock.RUnlock()