From 89b3160a21845201ea4191285f9860930002f048 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Fri, 16 Oct 2026 16:31:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=AB=E7=A0=81=E8=BD=AE=E8=AF=A2?= =?UTF-8?q?=E6=94=B9=E7=94=A8=E7=BD=91=E7=AB=99=E6=8E=A5=E5=8F=97=E7=9A=84?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/unicom/client.go | 6 +++++- internal/unicom/live_test.go | 26 ++++++++++++++++++++++++++ internal/unicom/script_test.go | 12 +++++++++++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/internal/unicom/client.go b/internal/unicom/client.go index cfe901e..580ad1a 100644 --- a/internal/unicom/client.go +++ b/internal/unicom/client.go @@ -498,11 +498,15 @@ func (c *Client) land(ctx context.Context, raw string) error { } func (c *Client) loginURL(path string, q url.Values) string { - q.Set("callback", "cb") + q.Set("callback", jsonpCallback()) q.Set("_", milli()) 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) { body, _, err := c.do(ctx, http.MethodGet, rawURL, referer, nil, nil) return body, err diff --git a/internal/unicom/live_test.go b/internal/unicom/live_test.go index bcc623f..fb85353 100644 --- a/internal/unicom/live_test.go +++ b/internal/unicom/live_test.go @@ -37,3 +37,29 @@ func TestLiveDiscover(t *testing.T) { } 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) + } +} diff --git a/internal/unicom/script_test.go b/internal/unicom/script_test.go index ffd32c8..e94b970 100644 --- a/internal/unicom/script_test.go +++ b/internal/unicom/script_test.go @@ -1,6 +1,16 @@ 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) { quoted, err := parseJSONP(`cb({"resultCode":"false","ckCode":"2"});`)