fix: 扫码轮询改用网站接受的回调名

This commit is contained in:
Nixevol
2026-10-16 16:31:16 +08:00
parent bf308aee92
commit 89b3160a21
3 changed files with 42 additions and 2 deletions
+5 -1
View File
@@ -498,11 +498,15 @@ func (c *Client) land(ctx context.Context, raw string) error {
} }
func (c *Client) loginURL(path string, q url.Values) string { func (c *Client) loginURL(path string, q url.Values) string {
q.Set("callback", "cb") q.Set("callback", jsonpCallback())
q.Set("_", milli()) q.Set("_", milli())
return uacOrigin + path + "?" + q.Encode() return uacOrigin + path + "?" + q.Encode()
} }
func jsonpCallback() string {
return fmt.Sprintf("jQuery%d_%d", time.Now().UnixNano(), time.Now().UnixMilli())
}
func (c *Client) get(ctx context.Context, rawURL, referer string) ([]byte, error) { func (c *Client) get(ctx context.Context, rawURL, referer string) ([]byte, error) {
body, _, err := c.do(ctx, http.MethodGet, rawURL, referer, nil, nil) body, _, err := c.do(ctx, http.MethodGet, rawURL, referer, nil, nil)
return body, err return body, err
+26
View File
@@ -37,3 +37,29 @@ func TestLiveDiscover(t *testing.T) {
} }
t.Logf("captcha app %s fee %s plan %s", appID, fee, plan) t.Logf("captcha app %s fee %s plan %s", appID, fee, plan)
} }
func TestLiveQRPoll(t *testing.T) {
if os.Getenv("CU_LIVE") == "" {
t.Skip()
}
client, err := New()
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 40*time.Second)
defer cancel()
img, err := client.QRCode(ctx)
if err != nil {
t.Fatal(err)
}
if len(img) < 100 {
t.Fatalf("qr %d", len(img))
}
status, err := client.PollQR(ctx)
if err != nil {
t.Fatal(err)
}
if !status.Waiting {
t.Fatalf("status %#v", status)
}
}
+11 -1
View File
@@ -1,6 +1,16 @@
package unicom package unicom
import "testing" import (
"strings"
"testing"
)
func TestJSONPCallbackName(t *testing.T) {
name := jsonpCallback()
if !strings.HasPrefix(name, "jQuery") || !strings.Contains(name, "_") {
t.Fatal(name)
}
}
func TestParseJSONP(t *testing.T) { func TestParseJSONP(t *testing.T) {
quoted, err := parseJSONP(`cb({"resultCode":"false","ckCode":"2"});`) quoted, err := parseJSONP(`cb({"resultCode":"false","ckCode":"2"});`)