Skip to content

Commit

Permalink
fix: 修正client中sign Provider的实现
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Dec 25, 2024
1 parent c5bcded commit c0bbd0d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
18 changes: 17 additions & 1 deletion client/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions client/sign/provider.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package sign

import "github.com/LagrangeDev/LagrangeGo/client/auth"

type Response struct {
Platform string `json:"platform"`
Version string `json:"version"`
Expand All @@ -15,4 +17,5 @@ type Provider interface {
AddRequestHeader(header map[string]string)
AddSignServer(signServers ...string)
GetSignServer() []string
SetAppInfo(app *auth.AppInfo)
}
18 changes: 11 additions & 7 deletions client/sign/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit c0bbd0d

Please sign in to comment.