Skip to content

Commit

Permalink
fix: 我再修
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Jul 24, 2024
1 parent b575ba0 commit 4d4678c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 3 additions & 1 deletion client/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import (
func (c *QQClient) uniPacket(command string, body []byte) (uint32, []byte) {
seq := c.getAndIncreaseSequence()
var sign map[string]string
var err error
// todo: 实现自动选择sign
if len(c.signProvider) != 0 {
for _, signProvider := range c.signProvider {
if sign = signProvider(command, seq, body); sign == nil {
sign, err = signProvider(command, seq, body)
if err != nil {
continue
} else {
break
Expand Down
13 changes: 7 additions & 6 deletions client/sign/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,27 @@ func NewProviderURL(log func(msg string), rawUrls ...string) []Provider {
}
providers := make([]Provider, len(rawUrls))
for i, rawUrl := range rawUrls {
providers[i] = func(cmd string, seq uint32, buf []byte) map[string]string {
localRawUrl := rawUrl
providers[i] = func(cmd string, seq uint32, buf []byte) (map[string]string, error) {
if !containSignPKG(cmd) {
return nil
return nil, nil
}
startTime := time.Now().UnixMilli()
resp := signResponse{}
sb := strings.Builder{}
sb.WriteString(`{"cmd":"` + cmd + `",`)
sb.WriteString(`"seq":` + strconv.Itoa(int(seq)) + `,`)
sb.WriteString(`"src":"` + fmt.Sprintf("%x", buf) + `"}`)
err := httpPost(rawUrl, bytes.NewReader(utils.S2B(sb.String())), 8*time.Second, &resp)
err := httpPost(localRawUrl, bytes.NewReader(utils.S2B(sb.String())), 8*time.Second, &resp)
if err != nil || resp.Value.Sign == "" {
err := httpGet(rawUrl, map[string]string{
err := httpGet(localRawUrl, map[string]string{
"cmd": cmd,
"seq": strconv.Itoa(int(seq)),
"src": fmt.Sprintf("%x", buf),
}, 8*time.Second, &resp)
if err != nil {
log(err.Error())
return nil
return nil, err
}
}

Expand All @@ -106,7 +107,7 @@ func NewProviderURL(log func(msg string), rawUrls ...string) []Provider {
"sign": resp.Value.Sign,
"extra": resp.Value.Extra,
"token": resp.Value.Token,
}
}, nil
}
}
return providers
Expand Down
2 changes: 1 addition & 1 deletion client/sign/provider.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package sign

type Provider func(string, uint32, []byte) map[string]string
type Provider func(string, uint32, []byte) (map[string]string, error)

0 comments on commit 4d4678c

Please sign in to comment.