-
Notifications
You must be signed in to change notification settings - Fork 232
feat(driver): Add 115 QR Code #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
62d275c
Add 115 QR Code
BrandonStudio b768fe3
Remove argument from refreshQRCode
BrandonStudio f3b6796
Potential fix for pull request finding
PIKACHUIM 4a41608
Merge branch 'main' into dev/115qr
PIKACHUIM 4e90a5b
Update src/driver/115cloud_qr.ts
PIKACHUIM 317c8f5
Update public/static/115qr.js
PIKACHUIM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /** | ||
| * @typedef {import('../../src/driver/115cloud_qr.ts').QRCodeResponse} QRCodeResponse | ||
| */ | ||
|
|
||
| async function start115CloudQRLogin() { | ||
| try { | ||
| // 显示模态框 | ||
| document.getElementById('qr-modal').style.display = 'block'; | ||
| setQRStatus('正在生成二维码...', 'waiting'); | ||
|
|
||
| // 生成二维码 - 向后端发送请求 | ||
| const response = await fetch(`/115cloud_qr/get_qr`); | ||
| if (response.ok) { | ||
| /** @type {QRCodeResponse} */ | ||
| const result = await response.json(); | ||
| showQRCode(result.qrcode); | ||
|
|
||
| setQRStatus('请使用115 App扫描二维码', 'waiting'); | ||
|
|
||
| checkQRStatus = () => check115CloudQRStatus(result); | ||
|
|
||
| // qr115CheckInterval = setInterval(() => check115CloudQRStatus(result), 2000); | ||
| } else { | ||
| setQRStatus(response.statusText || '生成二维码失败', 'error'); | ||
| document.getElementById('refresh-qr-btn').style.display = 'inline-block'; | ||
| } | ||
| } catch (error) { | ||
| setQRStatus('网络错误,请重试', 'error'); | ||
| document.getElementById('refresh-qr-btn').style.display = 'inline-block'; | ||
| console.error('生成二维码失败:', error); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param {QRCodeResponse} body | ||
| */ | ||
| async function check115CloudQRStatus(body) { | ||
| try { | ||
| const response = await fetch('/115cloud_qr/check_status', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json' | ||
| }, | ||
| body: JSON.stringify(body), | ||
| }); | ||
| /** @type {HTMLButtonElement} */ | ||
| const refreshBtn = document.getElementById('refresh-qr-btn'); | ||
| if (response.ok) { | ||
| const status = await response.text(); | ||
| switch (status) { | ||
| case '0': | ||
| setQRStatus('等待扫描二维码', 'waiting'); | ||
| break; | ||
| case '1': | ||
| setQRStatus('二维码已扫描,请在手机上确认登录', 'waiting'); | ||
| break; | ||
| case '2': | ||
| setQRStatus('登录成功', 'success'); | ||
| // clearInterval(qr115CheckInterval); | ||
| document.getElementById("access-token").value = body.uid; | ||
|
BrandonStudio marked this conversation as resolved.
PIKACHUIM marked this conversation as resolved.
|
||
| closeQRModal(); | ||
| break; | ||
| case '-1': | ||
| setQRStatus('二维码已过期,请刷新重试', 'error'); | ||
| refreshBtn.style.display = 'inline-block'; | ||
| break; | ||
| case '-2': | ||
| setQRStatus('登录已取消,请重试', 'error'); | ||
| refreshBtn.style.display = 'inline-block'; | ||
| break; | ||
| default: | ||
| setQRStatus(`未知状态: ${status}`, 'info'); | ||
| } | ||
| } else { | ||
| setQRStatus('检查登录状态失败', 'error'); | ||
| } | ||
| } catch (error) { | ||
| setQRStatus('网络错误,请重试', 'error'); | ||
| console.error('检查登录状态失败:', error); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // 显示二维码 | ||
| function showQRCode(qrUrl) { | ||
| const qrApiUrl = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodeURIComponent(qrUrl)}`; | ||
| document.getElementById('qr-code-display').innerHTML = `<img src="${qrApiUrl}" alt="二维码" class="qr-code-img">`; | ||
| document.getElementById('qr-code-container').style.display = 'block'; | ||
|
PIKACHUIM marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // 设置状态 | ||
| function setQRStatus(message, type) { | ||
| const statusEl = document.getElementById('qr-status'); | ||
| statusEl.textContent = message; | ||
| statusEl.className = `qr-status ${type}`; | ||
| statusEl.style.display = 'block'; | ||
| } | ||
|
|
||
| /** @type {() => Promise<void> | null} */ | ||
| var checkQRStatus = null; | ||
|
|
||
| /** | ||
| * @summary 刷新二维码 | ||
| */ | ||
| async function refreshQRCode() { | ||
| document.getElementById('refresh-qr-btn').style.display = 'none'; | ||
| // 清理旧会话 | ||
| switch (driver_txt) { | ||
| case 'alicloud_cs': | ||
| if (alicloud2SessionId) { | ||
| try { | ||
| await fetchWithFingerprint(`/alicloud2/logout?session_id=${alicloud2SessionId}`); | ||
| } catch (e) { | ||
| // console.log('清理旧会话失败:', e); | ||
| } | ||
| alicloud2SessionId = null; | ||
| } | ||
| await startAlicloud2Login(); | ||
| break; | ||
| case '115cloud_qr': | ||
| await start115CloudQRLogin(); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| // 关闭模态框 | ||
| function closeQRModal() { | ||
| document.getElementById('qr-modal').style.display = 'none'; | ||
| switch (driver_txt) { | ||
| case 'alicloud_cs': | ||
| stopAliQRStatusCheck(); | ||
|
|
||
| // 清理会话 | ||
| if (alicloud2SessionId) { | ||
| fetchWithFingerprint(`/alicloud2/logout?session_id=${alicloud2SessionId}`); | ||
| alicloud2SessionId = null; | ||
| } | ||
| break; | ||
| case '115cloud_qr': | ||
|
|
||
| break; | ||
| } | ||
|
PIKACHUIM marked this conversation as resolved.
|
||
|
|
||
| // 重置界面 | ||
| document.getElementById('qr-code-container').style.display = 'none'; | ||
| document.getElementById('qr-status').style.display = 'none'; | ||
| document.getElementById('refresh-qr-btn').style.display = 'none'; | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.