Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions golang/internal/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ type LoginOptions struct {
OnExpired func()
}

const (
maxQRRefreshCount = 3
fixedQRBaseURL = "https://ilinkai.weixin.qq.com"
)
const maxQRRefreshCount = 3

// Login performs QR code login, returning credentials.
// If stored credentials exist and Force is false, returns them directly.
Expand All @@ -105,7 +102,7 @@ func Login(ctx context.Context, client *protocol.Client, opts LoginOptions) (*Cr
return nil, fmt.Errorf("QR code expired %d times — login aborted", maxQRRefreshCount)
}

qr, err := client.GetQRCode(ctx, fixedQRBaseURL)
qr, err := client.GetQRCode(ctx, baseURL)
if err != nil {
return nil, fmt.Errorf("get QR code: %w", err)
}
Expand All @@ -117,7 +114,7 @@ func Login(ctx context.Context, client *protocol.Client, opts LoginOptions) (*Cr
}

lastStatus := ""
currentPollBaseURL := fixedQRBaseURL
currentPollBaseURL := baseURL
for {
status, err := client.PollQRStatus(ctx, currentPollBaseURL, qr.QRCode)
if err != nil {
Expand Down
8 changes: 3 additions & 5 deletions nodejs/src/auth/authenticator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import type { Credentials, QrLoginCallbacks } from './types.js'
const QR_POLL_INTERVAL_MS = 2_000
/** Maximum number of times to refresh the QR code before giving up. */
const MAX_QR_REFRESH_COUNT = 3
/** Fixed API base URL for QR code requests (matches npm package). */
const FIXED_QR_BASE_URL = 'https://ilinkai.weixin.qq.com'

/**
* Handles the entire QR login flow with credential persistence.
Expand Down Expand Up @@ -71,7 +69,7 @@ export class Authenticator {

/**
* Execute the QR code scanning login flow.
* - Uses fixed base URL for QR requests (consistent with npm package)
* - Uses configured base URL for QR requests (supports proxy hubs)
* - Handles `scaned_but_redirect` for IDC redirect
* - Limits QR refreshes to MAX_QR_REFRESH_COUNT
*/
Expand All @@ -85,7 +83,7 @@ export class Authenticator {
}

this.logger.info(`Requesting QR code... (${qrRefreshCount}/${MAX_QR_REFRESH_COUNT})`)
const qr = await this.api.getQrCode(FIXED_QR_BASE_URL)
const qr = await this.api.getQrCode(baseUrl)

// Pass QR URL to developer's callback — display is their responsibility
if (callbacks?.onQrUrl) {
Expand All @@ -96,7 +94,7 @@ export class Authenticator {

let lastStatus: string | undefined
// Current polling URL; may be updated on IDC redirect
let currentPollBaseUrl = FIXED_QR_BASE_URL
let currentPollBaseUrl = baseUrl

for (;;) {
const status = await this.api.pollQrStatus(currentPollBaseUrl, qr.qrcode)
Expand Down
5 changes: 2 additions & 3 deletions python/wechatbot/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
DEFAULT_CRED_PATH = DEFAULT_CRED_DIR / "credentials.json"
QR_POLL_INTERVAL = 2.0
MAX_QR_REFRESH_COUNT = 3
FIXED_QR_BASE_URL = "https://ilinkai.weixin.qq.com"


async def load_credentials(path: Path | None = None) -> Credentials | None:
Expand Down Expand Up @@ -81,7 +80,7 @@ async def login(
f"QR code expired {MAX_QR_REFRESH_COUNT} times — login aborted"
)

qr = await api.get_qr_code(FIXED_QR_BASE_URL)
qr = await api.get_qr_code(base_url)
qr_url = qr["qrcode_img_content"]

if on_qr_url:
Expand All @@ -90,7 +89,7 @@ async def login(
print(f"[wechatbot] Scan this URL in WeChat: {qr_url}", file=sys.stderr)

last_status = ""
current_poll_base_url = FIXED_QR_BASE_URL
current_poll_base_url = base_url
while True:
status = await api.poll_qr_status(current_poll_base_url, qr["qrcode"])
current = status["status"]
Expand Down
6 changes: 2 additions & 4 deletions rust/src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ impl WeChatBot {

/// Maximum number of QR code refresh attempts before giving up.
const MAX_QR_REFRESH: u32 = 3;
/// Fixed API base URL for QR code requests.
const FIXED_QR_BASE_URL: &'static str = "https://ilinkai.weixin.qq.com";

/// Login via QR code. Returns credentials on success.
pub async fn login(&self, force: bool) -> Result<Credentials> {
Expand All @@ -103,7 +101,7 @@ impl WeChatBot {
)));
}

let qr = self.client.get_qr_code(Self::FIXED_QR_BASE_URL).await?;
let qr = self.client.get_qr_code(&base_url).await?;

if let Some(ref cb) = self.on_qr_url {
cb(&qr.qrcode_img_content);
Expand All @@ -112,7 +110,7 @@ impl WeChatBot {
}

let mut last_status = String::new();
let mut current_poll_base_url = Self::FIXED_QR_BASE_URL.to_string();
let mut current_poll_base_url = base_url.clone();
loop {
let status = self
.client
Expand Down