From 5f73c505a03a8d2992d388866c97920c670b532a Mon Sep 17 00:00:00 2001 From: QLHazyCoder <2825305047@qq.com> Date: Mon, 25 May 2026 12:10:46 +0800 Subject: [PATCH 1/2] feat: add PayPal hosted checkout proxy support --- .../background/steps/create-plus-checkout.js | 240 +++++++++++++++- flows/openai/content/paypal-flow.js | 101 +++++++ tests/paypal-flow-content.test.js | 54 ++++ tests/plus-checkout-create-wait.test.js | 256 ++++++++++++++++++ 4 files changed, 647 insertions(+), 4 deletions(-) diff --git a/flows/openai/background/steps/create-plus-checkout.js b/flows/openai/background/steps/create-plus-checkout.js index a912624a..135693da 100644 --- a/flows/openai/background/steps/create-plus-checkout.js +++ b/flows/openai/background/steps/create-plus-checkout.js @@ -10,6 +10,11 @@ const PLUS_PAYMENT_METHOD_PAYPAL_HOSTED = 'paypal-hosted'; const PLUS_PAYMENT_METHOD_GOPAY = 'gopay'; const PLUS_PAYMENT_METHOD_GPC_HELPER = 'gpc-helper'; + const LOCAL_CHECKOUT_PROXY_HEALTH_URL = 'http://127.0.0.1:21988/health'; + const LOCAL_CHECKOUT_PROXY_URL = 'socks5://127.0.0.1:21987'; + const LOCAL_CHECKOUT_PROXY_SETTINGS_SCOPE = 'regular'; + const LOCAL_CHECKOUT_PROXY_TIMEOUT_MS = 1200; + const LOCAL_CHECKOUT_PROXY_SETTLE_MS = 350; const DEFAULT_GPC_HELPER_API_URL = 'https://gpc.qlhazycoder.top'; const GPC_HELPER_PHONE_MODE_AUTO = 'auto'; const GPC_HELPER_PHONE_MODE_MANUAL = 'manual'; @@ -24,6 +29,7 @@ const PAYPAL_HOSTED_STAGE_LOGIN = 'pay_login'; const PAYPAL_HOSTED_STAGE_GUEST_CHECKOUT = 'guest_checkout'; const PAYPAL_HOSTED_STAGE_CREATE_ACCOUNT = 'create_account'; + const PAYPAL_HOSTED_STAGE_SECURITY_CODE = 'security_code'; const PAYPAL_HOSTED_STAGE_REVIEW = 'review_consent'; const PAYPAL_HOSTED_STAGE_APPROVAL = 'approval'; const PAYPAL_HOSTED_STAGE_UNKNOWN = 'unknown'; @@ -58,6 +64,7 @@ sleepWithStop, waitForTabCompleteUntilStopped, waitForTabUrlMatchUntilStopped = null, + withCheckoutCreationProxy = null, throwIfStopped = () => {}, } = deps; @@ -78,6 +85,194 @@ }); } + function parseSocks5Endpoint(proxyUrl = '') { + const text = String(proxyUrl || '').trim(); + if (!text) { + return null; + } + let parsed = null; + try { + parsed = new URL(text); + } catch { + return null; + } + if (String(parsed.protocol || '').replace(/:$/, '').toLowerCase() !== 'socks5') { + return null; + } + const host = String(parsed.hostname || '').replace(/^\[|\]$/g, '').trim(); + const port = Number.parseInt(String(parsed.port || ''), 10); + if (!host || !Number.isInteger(port) || port <= 0 || port > 65535) { + return null; + } + return { host, port }; + } + + function buildCheckoutCreationPacScript(endpoint) { + const proxyHost = String(endpoint?.host || '').replace(/\\/g, '\\\\').replace(/"/g, '\\"'); + const port = Number.parseInt(String(endpoint?.port || ''), 10); + return ` +function FindProxyForURL(url, host) { + host = String(host || '').toLowerCase(); + if (host === 'chatgpt.com' || dnsDomainIs(host, '.chatgpt.com')) { + return "SOCKS5 ${proxyHost}:${port}"; + } + return "DIRECT"; +}`.trim(); + } + + function callChromeProxySettings(method, details = {}) { + const proxySettings = chrome?.proxy?.settings; + if (!proxySettings || typeof proxySettings[method] !== 'function') { + return Promise.reject(new Error('当前浏览器不支持扩展代理 API')); + } + return new Promise((resolve, reject) => { + proxySettings[method](details, (value) => { + const lastError = chrome?.runtime?.lastError; + if (lastError) { + reject(new Error(lastError.message || String(lastError))); + return; + } + resolve(value); + }); + }); + } + + function canControlProxySettings(details = {}) { + const level = String(details?.levelOfControl || '').trim(); + return !level || level === 'controlled_by_this_extension' || level === 'controllable_by_this_extension'; + } + + async function readProxySettingsSnapshot() { + return callChromeProxySettings('get', { incognito: false }); + } + + async function restoreProxySettingsSnapshot(snapshot = null) { + const value = snapshot?.value; + const level = String(snapshot?.levelOfControl || '').trim(); + if (level === 'controlled_by_this_extension' && value && typeof value === 'object') { + await callChromeProxySettings('set', { + value, + scope: LOCAL_CHECKOUT_PROXY_SETTINGS_SCOPE, + }); + return; + } + await callChromeProxySettings('clear', { + scope: LOCAL_CHECKOUT_PROXY_SETTINGS_SCOPE, + }); + } + + async function fetchLocalCheckoutProxyHealth() { + if (typeof fetchImpl !== 'function') { + return null; + } + const controller = typeof AbortController === 'function' ? new AbortController() : null; + let timer = null; + try { + timer = controller + ? setTimeout(() => controller.abort(), LOCAL_CHECKOUT_PROXY_TIMEOUT_MS) + : null; + const response = await fetchImpl(`${LOCAL_CHECKOUT_PROXY_HEALTH_URL}?t=${Date.now()}`, { + method: 'GET', + cache: 'no-store', + headers: { Accept: 'application/json,text/plain,*/*' }, + ...(controller ? { signal: controller.signal } : {}), + }); + if (!response?.ok) { + return null; + } + const payload = await response.json().catch(() => ({})); + if (!payload?.ok) { + return null; + } + const endpoint = parseSocks5Endpoint(payload.localProxy || LOCAL_CHECKOUT_PROXY_URL); + return endpoint ? { endpoint, payload } : null; + } catch { + return null; + } finally { + if (timer) { + clearTimeout(timer); + } + } + } + + async function applyTemporaryCheckoutProxy(endpoint) { + const pacScript = buildCheckoutCreationPacScript(endpoint); + await callChromeProxySettings('set', { + value: { + mode: 'pac_script', + pacScript: { + data: pacScript, + mandatory: true, + }, + }, + scope: LOCAL_CHECKOUT_PROXY_SETTINGS_SCOPE, + }); + } + + async function runWithLocalCheckoutCreationProxy(action) { + if (typeof withCheckoutCreationProxy === 'function') { + return withCheckoutCreationProxy({ + healthUrl: LOCAL_CHECKOUT_PROXY_HEALTH_URL, + localProxyUrl: LOCAL_CHECKOUT_PROXY_URL, + }, action); + } + if (!chrome?.proxy?.settings || typeof fetchImpl !== 'function') { + return action(); + } + + const health = await fetchLocalCheckoutProxyHealth(); + if (!health?.endpoint) { + return action(); + } + + let snapshot = null; + let applied = false; + let result = null; + let proxyError = null; + let restoreFailed = false; + try { + try { + snapshot = await readProxySettingsSnapshot(); + } catch (error) { + return action(); + } + if (!canControlProxySettings(snapshot)) { + return action(); + } + await applyTemporaryCheckoutProxy(health.endpoint); + applied = true; + await sleepWithStop(LOCAL_CHECKOUT_PROXY_SETTLE_MS); + result = await action(); + if (result?.error && !result?.stopped) { + proxyError = new Error(result.error); + } + } catch (error) { + if (!applied) { + return action(); + } + proxyError = error; + } finally { + if (applied) { + try { + await restoreProxySettingsSnapshot(snapshot); + await sleepWithStop(LOCAL_CHECKOUT_PROXY_SETTLE_MS); + } catch (error) { + restoreFailed = true; + } + } + } + if (result && !proxyError) { + return result; + } + if (proxyError) { + if (restoreFailed) { + throw proxyError; + } + return action(); + } + return null; + } + function normalizePlusPaymentMethod(value = '') { const rootScope = typeof self !== 'undefined' ? self : globalThis; if (rootScope.GoPayUtils?.normalizePlusPaymentMethod) { @@ -589,6 +784,16 @@ return result || {}; } + async function submitHostedPayPalSecurityCode(tabId, config = {}, stepKey = PAYPAL_HOSTED_STEP_CREATE_ACCOUNT) { + const stepNumber = getHostedStepNumber(stepKey); + const verificationCode = await pollHostedVerificationCode(config.verificationUrl); + await addHostedStepLog(stepKey, `步骤 ${stepNumber}:已获取 PayPal 手机验证码,正在填写。`, 'info'); + return runHostedPayPalStep(tabId, { + expectedStage: PAYPAL_HOSTED_STAGE_SECURITY_CODE, + securityCode: verificationCode, + }); + } + function getHostedStageOrder(stage = '') { switch (stage) { case PAYPAL_HOSTED_STAGE_LOGIN: @@ -597,6 +802,8 @@ return 2; case PAYPAL_HOSTED_STAGE_CREATE_ACCOUNT: return 3; + case PAYPAL_HOSTED_STAGE_SECURITY_CODE: + return 3.5; case PAYPAL_HOSTED_STAGE_REVIEW: return 4; case PAYPAL_HOSTED_STAGE_OUTSIDE: @@ -634,7 +841,7 @@ try { const pageState = await getHostedPayPalState(tabId); lastStage = pageState?.hostedStage || lastStage; - if (predicate(pageState)) { + if (await predicate(pageState)) { return pageState; } } catch (error) { @@ -934,6 +1141,19 @@ } const pageState = await getHostedPayPalState(tabId); + const config = await getHostedCheckoutRuntimeConfig(state); + if (pageState.hostedStage === PAYPAL_HOSTED_STAGE_SECURITY_CODE) { + await submitHostedPayPalSecurityCode(tabId, config, stepKey); + const nextState = await waitForHostedPayPalStage( + tabId, + (stateInfo) => stateInfo?.hostedStage && stateInfo.hostedStage !== PAYPAL_HOSTED_STAGE_SECURITY_CODE, + { label: `步骤 ${stepNumber}:等待 PayPal 验证码提交后跳转` } + ); + await completeHostedStep(stepKey, tabId, { + plusHostedCheckoutLastStage: nextState.hostedStage || '', + }); + return; + } if (isHostedStageAtOrAfter(pageState.hostedStage, PAYPAL_HOSTED_STAGE_REVIEW) && pageState.hostedStage !== PAYPAL_HOSTED_STAGE_CREATE_ACCOUNT) { await addHostedStepLog(stepKey, `步骤 ${stepNumber}:当前 PayPal 已进入后续页面(${pageState.hostedStage}),创建确认节点直接完成。`, 'info'); @@ -952,7 +1172,13 @@ }); const nextState = await waitForHostedPayPalStage( tabId, - (stateInfo) => stateInfo?.hostedStage && stateInfo.hostedStage !== PAYPAL_HOSTED_STAGE_CREATE_ACCOUNT, + async (stateInfo) => { + if (stateInfo?.hostedStage === PAYPAL_HOSTED_STAGE_SECURITY_CODE) { + await submitHostedPayPalSecurityCode(tabId, config, stepKey); + return false; + } + return stateInfo?.hostedStage && stateInfo.hostedStage !== PAYPAL_HOSTED_STAGE_CREATE_ACCOUNT; + }, { label: `步骤 ${stepNumber}:等待 PayPal 创建确认页跳转` } ); await completeHostedStep(stepKey, tabId, { @@ -1392,7 +1618,9 @@ const paymentMethodLabel = getPlusPaymentMethodLabel(paymentMethod); const checkoutModeLabel = getCheckoutModeLabel(state); await addLog(`步骤 6:正在打开新的 ChatGPT 会话,准备创建${checkoutModeLabel}...`, 'info'); - const tabId = await openFreshChatGptTabForCheckoutCreate(); + let tabId = 0; + const createCheckout = async () => { + tabId = await openFreshChatGptTabForCheckoutCreate(); await waitForTabCompleteUntilStopped(tabId); await sleepWithStop(1000); @@ -1402,11 +1630,15 @@ logMessage: '步骤 6:正在等待 ChatGPT 页面完成加载,再继续创建订阅页...', }); - const result = await sendTabMessageUntilStopped(tabId, PLUS_CHECKOUT_SOURCE, { + return sendTabMessageUntilStopped(tabId, PLUS_CHECKOUT_SOURCE, { type: 'CREATE_PLUS_CHECKOUT', source: 'background', payload: { paymentMethod }, }); + }; + const result = paymentMethod === PLUS_PAYMENT_METHOD_PAYPAL_HOSTED + ? await runWithLocalCheckoutCreationProxy(createCheckout) + : await createCheckout(); if (result?.error) { throw new Error(result.error); diff --git a/flows/openai/content/paypal-flow.js b/flows/openai/content/paypal-flow.js index 8f899439..613a5f75 100644 --- a/flows/openai/content/paypal-flow.js +++ b/flows/openai/content/paypal-flow.js @@ -8,6 +8,7 @@ const PAYPAL_HOSTED_STAGE_OUTSIDE = 'outside_paypal'; const PAYPAL_HOSTED_STAGE_LOGIN = 'pay_login'; const PAYPAL_HOSTED_STAGE_GUEST_CHECKOUT = 'guest_checkout'; const PAYPAL_HOSTED_STAGE_CREATE_ACCOUNT = 'create_account'; +const PAYPAL_HOSTED_STAGE_SECURITY_CODE = 'security_code'; const PAYPAL_HOSTED_STAGE_REVIEW = 'review_consent'; const PAYPAL_HOSTED_STAGE_APPROVAL = 'approval'; const PAYPAL_HOSTED_STAGE_UNKNOWN = 'unknown'; @@ -15,6 +16,7 @@ const PAYPAL_HOSTED_STEP_KEYS = { [PAYPAL_HOSTED_STAGE_LOGIN]: 'paypal-hosted-email', [PAYPAL_HOSTED_STAGE_GUEST_CHECKOUT]: 'paypal-hosted-card', [PAYPAL_HOSTED_STAGE_CREATE_ACCOUNT]: 'paypal-hosted-create-account', + [PAYPAL_HOSTED_STAGE_SECURITY_CODE]: 'paypal-hosted-create-account', [PAYPAL_HOSTED_STAGE_REVIEW]: 'paypal-hosted-review', }; @@ -308,10 +310,63 @@ function findHostedReviewConsentButton() { ]); } +function getHostedSecurityCodeInputs() { + const pageText = normalizeText(document.body?.innerText || document.body?.textContent || ''); + const pageLooksLikeSecurityCode = /enter\s+(?:your\s+)?code|6[-\s]*digit\s+code|security\s+code|verification\s+code|we\s+sent\s+a\s+6[-\s]*digit\s+code/i.test(pageText); + const visibleInputs = getVisibleControls('input') + .filter((input) => { + const type = String(input.getAttribute?.('type') || input.type || '').trim().toLowerCase(); + return isEnabledControl(input) + && !['hidden', 'checkbox', 'radio', 'submit', 'button', 'file'].includes(type); + }); + const candidates = visibleInputs + .filter((input) => { + const maxLength = Number(input.getAttribute?.('maxlength') || input.maxLength || 0); + const metadata = getActionText(input); + return maxLength === 1 || /otp|code|verification|security|one[-\s]*time/i.test(metadata); + }); + if (candidates.length < 6 && pageLooksLikeSecurityCode && visibleInputs.length >= 6) { + return visibleInputs.slice(0, 6); + } + const singleDigitInputs = candidates.filter((input) => { + const maxLength = Number(input.getAttribute?.('maxlength') || input.maxLength || 0); + const valueLength = String(input.value || '').length; + return maxLength === 1 || valueLength <= 1; + }); + return singleDigitInputs.length >= 6 ? singleDigitInputs.slice(0, 6) : candidates; +} + +function getHostedSecurityCodeSingleInput() { + return getVisibleControls('input').find((input) => { + const type = String(input.getAttribute?.('type') || input.type || '').trim().toLowerCase(); + const maxLength = Number(input.getAttribute?.('maxlength') || input.maxLength || 0); + const metadata = getActionText(input); + return isEnabledControl(input) + && !['hidden', 'checkbox', 'radio', 'submit', 'button', 'file'].includes(type) + && maxLength >= 6 + && /otp|code|verification|security|one[-\s]*time/i.test(metadata); + }) || null; +} + +function findHostedSecurityCodeSubmitButton() { + return findClickableByText([ + /submit|continue|next|verify|confirm|done/i, + ]); +} + +function isHostedSecurityCodePage() { + const pageText = normalizeText(document.body?.innerText || document.body?.textContent || ''); + const hasSecurityText = /enter\s+(?:your\s+)?code|6[-\s]*digit\s+code|security\s+code|verification\s+code|we\s+sent\s+a\s+6[-\s]*digit\s+code/i.test(pageText); + return hasSecurityText && (getHostedSecurityCodeInputs().length >= 6 || Boolean(getHostedSecurityCodeSingleInput())); +} + function detectPayPalHostedStage() { if (!/paypal\./i.test(String(location?.host || ''))) { return PAYPAL_HOSTED_STAGE_OUTSIDE; } + if (isHostedSecurityCodePage()) { + return PAYPAL_HOSTED_STAGE_SECURITY_CODE; + } if (isHostedGuestCheckoutPage()) { return PAYPAL_HOSTED_STAGE_GUEST_CHECKOUT; } @@ -465,6 +520,48 @@ function verifyHostedPhoneBeforeSubmit(expectedPhone = '') { }; } +function normalizeHostedSecurityCode(value = '') { + const code = String(value || '').replace(/\D/g, '').slice(0, 6); + return /^\d{6}$/.test(code) ? code : ''; +} + +async function submitHostedSecurityCode(payload = {}) { + await waitForDocumentComplete(); + const code = normalizeHostedSecurityCode(payload.securityCode || payload.verificationCode || payload.code || ''); + if (!code) { + throw new Error('PayPal hosted checkout 验证码为空或不是 6 位数字。'); + } + const digitInputs = getHostedSecurityCodeInputs(); + const singleInput = getHostedSecurityCodeSingleInput(); + if (digitInputs.length >= 6) { + digitInputs.slice(0, 6).forEach((input, index) => { + fillInput(input, code[index]); + }); + } else if (singleInput) { + fillInput(singleInput, code); + } else { + throw new Error('PayPal hosted checkout 未找到验证码输入框。'); + } + + const submitButton = findHostedSecurityCodeSubmitButton(); + if (submitButton && isVisibleElement(submitButton) && isEnabledControl(submitButton)) { + await performPayPalOperationWithDelay({ + stepKey: getHostedStepKey(PAYPAL_HOSTED_STAGE_SECURITY_CODE), + kind: 'click', + label: 'hosted-paypal-security-code-submit', + }, async () => { + simulateClick(submitButton); + }); + } + await sleep(1000); + return { + stage: PAYPAL_HOSTED_STAGE_SECURITY_CODE, + securityCodeSubmitted: true, + submitted: Boolean(submitButton), + inputCount: digitInputs.length >= 6 ? 6 : 1, + }; +} + async function clickHostedCreateAccount(payload = {}) { await waitForDocumentComplete(); const button = await waitUntil(() => { @@ -640,6 +737,9 @@ async function runPayPalHostedCheckoutStep(payload = {}) { if (stage === PAYPAL_HOSTED_STAGE_CREATE_ACCOUNT) { return clickHostedCreateAccount(payload); } + if (stage === PAYPAL_HOSTED_STAGE_SECURITY_CODE) { + return submitHostedSecurityCode(payload); + } if (stage === PAYPAL_HOSTED_STAGE_REVIEW) { return clickHostedReviewConsent(); } @@ -659,6 +759,7 @@ function inspectPayPalHostedState() { hostedStage: stage, hasGuestCardFields: Boolean(document.getElementById('cardNumber')), hasHostedEmailInput: Boolean(document.getElementById('email') || findEmailInput()), + securityCodeVisible: stage === PAYPAL_HOSTED_STAGE_SECURITY_CODE, createAccountReady: Boolean(createAccountButton && isVisibleElement(createAccountButton) && isEnabledControl(createAccountButton)), reviewConsentReady: Boolean(findHostedReviewConsentButton()), approveReady: Boolean(findApproveButton()), diff --git a/tests/paypal-flow-content.test.js b/tests/paypal-flow-content.test.js index db41f5c8..ea0ae8b8 100644 --- a/tests/paypal-flow-content.test.js +++ b/tests/paypal-flow-content.test.js @@ -413,6 +413,16 @@ function createHostedPayPalHarness(options = {}) { id: 'btnNext', text: '下一页', }); + const securityCodeInputs = Array.from({ length: 6 }, (_value, index) => createDomElement({ + tagName: 'INPUT', + id: `securityCode${index + 1}`, + type: 'text', + })); + const securityCodeContinueButton = createDomElement({ + tagName: 'BUTTON', + id: 'securityCodeContinue', + text: 'Continue', + }); function setElements(nextElements) { elements = nextElements; @@ -464,6 +474,15 @@ function createHostedPayPalHarness(options = {}) { setElements([emailInput, nextButton, createAccountButton]); } + function showSecurityCode() { + location.href = 'https://www.paypal.com/checkoutweb/security-code'; + location.host = 'www.paypal.com'; + location.pathname = '/checkoutweb/security-code'; + body.innerText = 'Enter your code We sent a 6-digit code to (835) 253-1607 Resend'; + body.textContent = body.innerText; + setElements([...securityCodeInputs, securityCodeContinueButton]); + } + const context = { console: { log() {}, warn() {}, error() {}, info() {} }, location, @@ -558,6 +577,7 @@ function createHostedPayPalHarness(options = {}) { showPayEmail, showCreateAccount, showGuestCheckout, + showSecurityCode, }; } @@ -687,3 +707,37 @@ test('PayPal hosted create account page is detected and handled as its own step' [{ stepKey: 'paypal-hosted-create-account', kind: 'click', label: 'hosted-paypal-create-account' }] ); }); + +test('PayPal hosted security code page fills six digit code inputs', async () => { + const harness = createHostedPayPalHarness(); + harness.showSecurityCode(); + + const state = await harness.send({ + type: 'PAYPAL_HOSTED_GET_STATE', + source: 'test', + payload: {}, + }); + assert.equal(state.ok, true); + assert.equal(state.hostedStage, 'security_code'); + assert.equal(state.securityCodeVisible, true); + + const result = await harness.send({ + type: 'PAYPAL_RUN_HOSTED_CHECKOUT_STEP', + source: 'test', + payload: { + expectedStage: 'security_code', + securityCode: '921714', + }, + }); + + assert.equal(result.ok, true); + assert.equal(result.stage, 'security_code'); + assert.equal(result.securityCodeSubmitted, true); + assert.deepEqual( + harness.events + .filter((event) => event.type === 'fill' && /^securityCode/.test(event.id)) + .map((event) => event.value), + ['9', '2', '1', '7', '1', '4'] + ); + assert.equal(harness.events.some((event) => event.type === 'click' && event.id === 'securityCodeContinue'), true); +}); diff --git a/tests/plus-checkout-create-wait.test.js b/tests/plus-checkout-create-wait.test.js index 06ae2f26..f4d2eb6e 100644 --- a/tests/plus-checkout-create-wait.test.js +++ b/tests/plus-checkout-create-wait.test.js @@ -259,6 +259,7 @@ test('Plus checkout create does not wait 20 seconds after opening checkout page' test('GoPay plus checkout create forwards gopay payment method to the checkout content script', async () => { const events = []; + let proxyCallCount = 0; const executor = api.createPlusCheckoutCreateExecutor({ addLog: async () => {}, chrome: { @@ -281,11 +282,183 @@ test('GoPay plus checkout create forwards gopay payment method to the checkout c setState: async () => {}, sleepWithStop: async () => {}, waitForTabCompleteUntilStopped: async () => {}, + withCheckoutCreationProxy: async () => { + proxyCallCount += 1; + throw new Error('gopay checkout should not use the checkout proxy wrapper'); + }, }); await executor.executePlusCheckoutCreate({ plusPaymentMethod: 'gopay' }); assert.deepStrictEqual(events[0]?.payload, { paymentMethod: 'gopay' }); + assert.equal(proxyCallCount, 0); +}); + +test('PayPal no-card binding creates checkout inside the local checkout proxy wrapper', async () => { + const events = []; + const executor = api.createPlusCheckoutCreateExecutor({ + addLog: async () => {}, + chrome: { + tabs: { + create: async () => ({ id: 77, url: 'https://chatgpt.com/', status: 'complete' }), + update: async () => {}, + get: async () => ({ id: 77, url: 'https://www.paypal.com/pay?token=BA-wrapper', status: 'complete' }), + }, + }, + completeNodeFromBackground: async () => {}, + ensureContentScriptReadyOnTabUntilStopped: async () => {}, + fetch: async () => ({ + ok: true, + status: 200, + json: async () => ({ + address: { + Address: '1 Main St', + City: 'New York', + State: 'New York', + Zip_Code: '10001', + }, + }), + }), + getState: async () => ({ + hostedCheckoutPhoneNumber: '4155551234', + }), + registerTab: async () => {}, + sendTabMessageUntilStopped: async (_tabId, _source, message) => { + events.push({ type: 'tab-message', message, inProxy: events.some((event) => event.type === 'proxy-enter') && !events.some((event) => event.type === 'proxy-exit') }); + if (message.type === 'CREATE_PLUS_CHECKOUT') { + return { + checkoutUrl: 'https://chatgpt.com/checkout/openai_llc/cs_hosted', + preferredCheckoutUrl: 'https://pay.openai.com/c/pay/cs_hosted', + hostedCheckoutUrl: 'https://pay.openai.com/c/pay/cs_hosted', + country: 'US', + currency: 'USD', + }; + } + if (message.type === 'RUN_PAYPAL_HOSTED_OPENAI_CHECKOUT_STEP') { + return { clicked: true }; + } + throw new Error(`unexpected message type ${message.type}`); + }, + setState: async () => {}, + sleepWithStop: async () => {}, + waitForTabCompleteUntilStopped: async () => {}, + withCheckoutCreationProxy: async (config, action) => { + events.push({ type: 'proxy-enter', config }); + const result = await action(); + events.push({ type: 'proxy-exit' }); + return result; + }, + }); + + await executor.executePlusCheckoutCreate({ + plusPaymentMethod: 'paypal-hosted', + plusHostedCheckoutOauthDelaySeconds: 0, + }); + + assert.deepStrictEqual(events.find((event) => event.type === 'proxy-enter')?.config, { + healthUrl: 'http://127.0.0.1:21988/health', + localProxyUrl: 'socks5://127.0.0.1:21987', + }); + assert.equal( + events.find((event) => event.type === 'tab-message' && event.message.type === 'CREATE_PLUS_CHECKOUT')?.inProxy, + true + ); +}); + +test('PayPal no-card binding falls back to direct checkout when local helper proxy fails', async () => { + const events = []; + let createAttempts = 0; + const proxySettings = { + get(details, callback) { + events.push({ type: 'proxy-get', details }); + callback({ + levelOfControl: 'controllable_by_this_extension', + value: { mode: 'system' }, + }); + }, + set(details, callback) { + events.push({ type: 'proxy-set', details }); + callback(); + }, + clear(details, callback) { + events.push({ type: 'proxy-clear', details }); + callback(); + }, + }; + const executor = api.createPlusCheckoutCreateExecutor({ + addLog: async () => {}, + chrome: { + runtime: {}, + proxy: { + settings: proxySettings, + }, + tabs: { + create: async () => ({ id: 78, url: 'https://chatgpt.com/', status: 'complete' }), + update: async () => {}, + get: async () => ({ id: 78, url: 'https://www.paypal.com/pay?token=BA-direct', status: 'complete' }), + }, + }, + completeNodeFromBackground: async () => {}, + ensureContentScriptReadyOnTabUntilStopped: async () => {}, + fetch: async (url) => { + events.push({ type: 'fetch', url }); + if (String(url).startsWith('http://127.0.0.1:21988/health')) { + return { + ok: true, + status: 200, + json: async () => ({ ok: true, localProxy: 'socks5://127.0.0.1:21987' }), + }; + } + return { + ok: true, + status: 200, + json: async () => ({ + address: { + Address: '1 Main St', + City: 'New York', + State: 'New York', + Zip_Code: '10001', + }, + }), + }; + }, + getState: async () => ({ + hostedCheckoutPhoneNumber: '4155551234', + }), + registerTab: async () => {}, + sendTabMessageUntilStopped: async (_tabId, _source, message) => { + events.push({ type: 'tab-message', message }); + if (message.type === 'CREATE_PLUS_CHECKOUT') { + createAttempts += 1; + if (createAttempts === 1) { + return { error: 'proxy connect failed' }; + } + return { + checkoutUrl: 'https://chatgpt.com/checkout/openai_llc/cs_hosted', + preferredCheckoutUrl: 'https://www.paypal.com/pay?token=BA-direct', + hostedCheckoutUrl: 'https://www.paypal.com/pay?token=BA-direct', + country: 'US', + currency: 'USD', + }; + } + if (message.type === 'RUN_PAYPAL_HOSTED_OPENAI_CHECKOUT_STEP') { + return { clicked: true }; + } + throw new Error(`unexpected message type ${message.type}`); + }, + setState: async () => {}, + sleepWithStop: async () => {}, + waitForTabCompleteUntilStopped: async () => {}, + }); + + await executor.executePlusCheckoutCreate({ + plusPaymentMethod: 'paypal-hosted', + plusHostedCheckoutOauthDelaySeconds: 0, + }); + + assert.equal(createAttempts, 2); + assert.equal(events.some((event) => event.type === 'proxy-set' && event.details?.value?.mode === 'pac_script'), true); + assert.equal(events.some((event) => event.type === 'proxy-clear' && event.details?.scope === 'regular'), true); }); test('PayPal no-card binding create opens and submits hosted OpenAI checkout before completing', async () => { @@ -554,6 +727,89 @@ test('PayPal hosted email node completes when Next navigation drops the content ); }); +test('PayPal hosted create account node submits PayPal security code from SMS text payload', async () => { + const events = []; + let stage = 'create_account'; + const executor = api.createPlusCheckoutCreateExecutor({ + addLog: async (message, level = 'info', options = {}) => events.push({ type: 'log', message, level, options }), + chrome: { + tabs: { + get: async (tabId) => ({ id: tabId, url: 'https://www.paypal.com/checkoutweb/create-account', status: 'complete' }), + }, + }, + completeNodeFromBackground: async (step, payload) => events.push({ type: 'complete', step, payload }), + ensureContentScriptReadyOnTabUntilStopped: async (source, tabId, options) => events.push({ type: 'ready', source, tabId, options }), + fetch: async (url) => { + events.push({ type: 'fetch', url }); + if (url === 'https://www.meiguodizhi.com/api/v1/dz') { + return { + ok: true, + status: 200, + json: async () => ({ + address: { + Address: '1 Main St', + City: 'New York', + State: 'New York', + Zip_Code: '10001', + }, + }), + }; + } + assert.equal(String(url).startsWith('https://otp.example.test/latest?t='), true); + return { + ok: true, + status: 200, + text: async () => JSON.stringify({ + code: 1, + msg: 'ok', + data: { + code: "PayPal: 921714 is your security code. Don't share it.", + code_time: '2026-05-25 01:41:22', + expired_date: '2026-08-15 00:00:00', + }, + }), + }; + }, + getState: async () => ({ + hostedCheckoutVerificationUrl: 'https://otp.example.test/latest', + hostedCheckoutPhoneNumber: '8352531607', + }), + registerTab: async (source, tabId) => events.push({ type: 'register', source, tabId }), + sendTabMessageUntilStopped: async (tabId, source, message) => { + events.push({ type: 'tab-message', tabId, source, message }); + if (message.type === 'PAYPAL_HOSTED_GET_STATE') { + return { hostedStage: stage }; + } + if (message.type === 'PAYPAL_RUN_HOSTED_CHECKOUT_STEP' && message.payload.expectedStage === 'create_account') { + stage = 'security_code'; + return { clicked: true, submitted: true, stage: 'create_account' }; + } + if (message.type === 'PAYPAL_RUN_HOSTED_CHECKOUT_STEP' && message.payload.expectedStage === 'security_code') { + stage = 'review_consent'; + return { securityCodeSubmitted: true, stage: 'security_code' }; + } + throw new Error(`unexpected message type ${message.type}`); + }, + setState: async (payload) => events.push({ type: 'set-state', payload }), + sleepWithStop: async (ms) => events.push({ type: 'sleep', ms }), + waitForTabCompleteUntilStopped: async () => events.push({ type: 'tab-complete' }), + }); + + await executor.executePayPalHostedCreateAccount({ + plusCheckoutTabId: 55, + plusPaymentMethod: 'paypal-hosted', + }); + + assert.deepStrictEqual( + events.find((event) => event.type === 'tab-message' && event.message?.payload?.expectedStage === 'security_code')?.message?.payload, + { + expectedStage: 'security_code', + securityCode: '921714', + } + ); + assert.equal(events.some((event) => event.type === 'complete' && event.step === 'paypal-hosted-create-account'), true); +}); + test('Plus checkout content routes billing operations through the operation delay gate', async () => { const { checkoutEvents, send } = createCheckoutContentHarness(); From 7fe46cee31c7972bb1493d7682a356c87626601a Mon Sep 17 00:00:00 2001 From: qqqasdwx <673179458@qq.com> Date: Sat, 23 May 2026 10:15:13 +0000 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20Cloudflare=20T?= =?UTF-8?q?emp=20Email=20=E5=9B=BA=E5=AE=9A=E5=AD=90=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- background.js | 26 ++++- background/generated-email-helpers.js | 16 ++- cloudflare-temp-email-utils.js | 25 +++++ ...77\347\224\250\346\225\231\347\250\213.md" | 2 +- ...46\345\206\231\346\250\241\346\235\277.md" | 2 +- ...77\347\224\250\350\257\264\346\230\216.md" | 35 +++++- sidepanel/sidepanel.html | 19 ++++ sidepanel/sidepanel.js | 104 +++++++++++++++++- ...und-cloudflare-temp-email-settings.test.js | 31 +++++- .../background-generated-email-module.test.js | 78 +++++++++++++ tests/cloudflare-temp-email-utils.test.js | 34 ++++++ ...dflare-temp-email-random-subdomain.test.js | 49 ++++++++- tests/sidepanel-contribution-mode.test.js | 3 + tests/sidepanel-icloud-provider.test.js | 7 ++ tests/sidepanel-mail2925-base-email.test.js | 3 + ...epanel-phone-verification-settings.test.js | 3 + ...76\350\267\257\350\257\264\346\230\216.md" | 5 +- ...23\346\236\204\350\257\264\346\230\216.md" | 9 +- 18 files changed, 424 insertions(+), 27 deletions(-) diff --git a/background.js b/background.js index 02ef4c82..7799ffb6 100644 --- a/background.js +++ b/background.js @@ -371,6 +371,7 @@ const { } = self.LuckMailUtils; const { DEFAULT_MAIL_PAGE_SIZE: CLOUDFLARE_TEMP_EMAIL_DEFAULT_PAGE_SIZE, + buildCloudflareTempEmailEffectiveDomain, buildCloudflareTempEmailHeaders, getCloudflareTempEmailAddressFromResponse, joinCloudflareTempEmailUrl, @@ -379,6 +380,7 @@ const { normalizeCloudflareTempEmailDomain, normalizeCloudflareTempEmailDomains, normalizeCloudflareTempEmailMailApiMessages, + normalizeCloudflareTempEmailSubdomainPrefix, } = self.CloudflareTempEmailUtils; const { DEFAULT_MAIL_PAGE_SIZE: CLOUD_MAIL_DEFAULT_PAGE_SIZE, @@ -1428,6 +1430,8 @@ const PERSISTED_SETTING_DEFAULTS = { cloudflareTempEmailLookupMode: DEFAULT_CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE, cloudflareTempEmailReceiveMailbox: '', cloudflareTempEmailUseRandomSubdomain: false, + cloudflareTempEmailUseFixedSubdomain: false, + cloudflareTempEmailSubdomainPrefix: '', cloudflareTempEmailDomain: '', cloudflareTempEmailDomains: [], cloudMailBaseUrl: '', @@ -2899,16 +2903,25 @@ function getHotmailServiceSettings(state = {}) { } function getCloudflareTempEmailConfig(state = {}) { - return { + const useFixedSubdomain = Boolean(state.cloudflareTempEmailUseFixedSubdomain); + const subdomainPrefix = normalizeCloudflareTempEmailSubdomainPrefix(state.cloudflareTempEmailSubdomainPrefix); + const domain = normalizeCloudflareTempEmailDomain(state.cloudflareTempEmailDomain); + const config = { baseUrl: normalizeCloudflareTempEmailBaseUrl(state.cloudflareTempEmailBaseUrl), adminAuth: String(state.cloudflareTempEmailAdminAuth || ''), customAuth: String(state.cloudflareTempEmailCustomAuth || ''), lookupMode: normalizeCloudflareTempEmailLookupMode(state.cloudflareTempEmailLookupMode), receiveMailbox: normalizeCloudflareTempEmailReceiveMailbox(state.cloudflareTempEmailReceiveMailbox), - useRandomSubdomain: Boolean(state.cloudflareTempEmailUseRandomSubdomain), - domain: normalizeCloudflareTempEmailDomain(state.cloudflareTempEmailDomain), + useRandomSubdomain: useFixedSubdomain ? false : Boolean(state.cloudflareTempEmailUseRandomSubdomain), + useFixedSubdomain, + subdomainPrefix, + domain, domains: normalizeCloudflareTempEmailDomains(state.cloudflareTempEmailDomains), }; + return { + ...config, + effectiveDomain: buildCloudflareTempEmailEffectiveDomain(config), + }; } function normalizeCloudflareTempEmailReceiveMailbox(value = '') { @@ -3402,6 +3415,7 @@ function normalizePersistentSettingValue(key, value) { case 'autoDeleteUsedIcloudAlias': case 'accountRunHistoryTextEnabled': case 'cloudflareTempEmailUseRandomSubdomain': + case 'cloudflareTempEmailUseFixedSubdomain': return Boolean(value); case 'icloudHostPreference': return normalizeIcloudHost(value) || 'auto'; @@ -3455,6 +3469,8 @@ function normalizePersistentSettingValue(key, value) { return normalizeCloudflareTempEmailLookupMode(value); case 'cloudflareTempEmailReceiveMailbox': return normalizeCloudflareTempEmailReceiveMailbox(value); + case 'cloudflareTempEmailSubdomainPrefix': + return normalizeCloudflareTempEmailSubdomainPrefix(value); case 'cloudflareTempEmailDomain': return normalizeCloudflareTempEmailDomain(value); case 'cloudflareTempEmailDomains': @@ -3613,6 +3629,9 @@ function buildPersistentSettingsPayload(input = {}, options = {}) { } payload.cloudflareTempEmailDomains = domains; } + if (payload.cloudflareTempEmailUseFixedSubdomain) { + payload.cloudflareTempEmailUseRandomSubdomain = false; + } if (payload.cloudMailDomains) { const domains = normalizeCloudMailDomains(payload.cloudMailDomains); if (payload.cloudMailDomain && !domains.includes(payload.cloudMailDomain)) { @@ -11840,6 +11859,7 @@ function getCurrentPayPalAccount(state = null) { const generatedEmailHelpers = self.MultiPageGeneratedEmailHelpers?.createGeneratedEmailHelpers({ addLog, buildGeneratedAliasEmail, + buildCloudflareTempEmailEffectiveDomain, buildCloudflareTempEmailHeaders, CLOUDFLARE_TEMP_EMAIL_GENERATOR, CUSTOM_EMAIL_POOL_GENERATOR, diff --git a/background/generated-email-helpers.js b/background/generated-email-helpers.js index 81367d5c..e6f6ddb3 100644 --- a/background/generated-email-helpers.js +++ b/background/generated-email-helpers.js @@ -5,6 +5,7 @@ const { addLog, buildGeneratedAliasEmail, + buildCloudflareTempEmailEffectiveDomain, buildCloudflareTempEmailHeaders, CLOUDFLARE_TEMP_EMAIL_GENERATOR, CUSTOM_EMAIL_POOL_GENERATOR, @@ -92,6 +93,12 @@ if (requireDomain && !config.domain) { throw new Error('Cloudflare Temp Email 域名为空或格式无效。'); } + if (config.useFixedSubdomain && !config.effectiveDomain && typeof buildCloudflareTempEmailEffectiveDomain === 'function') { + config.effectiveDomain = buildCloudflareTempEmailEffectiveDomain(config); + } + if (requireDomain && config.useFixedSubdomain && !config.effectiveDomain) { + throw new Error('Cloudflare Temp Email 固定子域前缀为空或格式无效。'); + } return config; } @@ -159,11 +166,16 @@ requireDomain: true, }); const requestedName = String(options.localPart || options.name || '').trim().toLowerCase() || generateCloudflareAliasLocalPart(); + const effectiveDomain = config.effectiveDomain || ( + typeof buildCloudflareTempEmailEffectiveDomain === 'function' + ? buildCloudflareTempEmailEffectiveDomain(config) + : config.domain + ); const payload = { enablePrefix: true, - enableRandomSubdomain: Boolean(config.useRandomSubdomain), + enableRandomSubdomain: config.useFixedSubdomain ? false : Boolean(config.useRandomSubdomain), name: requestedName, - domain: config.domain, + domain: effectiveDomain, }; const result = await requestCloudflareTempEmailJson(config, '/admin/new_address', { method: 'POST', diff --git a/cloudflare-temp-email-utils.js b/cloudflare-temp-email-utils.js index 08f63eb0..ed6371d8 100644 --- a/cloudflare-temp-email-utils.js +++ b/cloudflare-temp-email-utils.js @@ -58,6 +58,29 @@ return domains; } + function normalizeCloudflareTempEmailSubdomainPrefix(rawValue = '') { + let value = String(rawValue || '').trim().toLowerCase(); + if (!value) return ''; + value = value.replace(/^@+/, ''); + value = value.replace(/^https?:\/\//, ''); + value = value.replace(/\/.*$/, ''); + value = value.replace(/^\.+|\.+$/g, ''); + if (!/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(value)) { + return ''; + } + return value; + } + + function buildCloudflareTempEmailEffectiveDomain(config = {}) { + const domain = normalizeCloudflareTempEmailDomain(config.domain); + if (!domain) return ''; + const useFixedSubdomain = Boolean(config.useFixedSubdomain); + const subdomainPrefix = normalizeCloudflareTempEmailSubdomainPrefix(config.subdomainPrefix); + if (!useFixedSubdomain) return domain; + if (!subdomainPrefix) return ''; + return `${subdomainPrefix}.${domain}`; + } + function buildCloudflareTempEmailHeaders(config = {}, options = {}) { const headers = {}; const adminAuth = firstNonEmptyString([config.adminAuth, config.cloudflareTempEmailAdminAuth]); @@ -563,6 +586,7 @@ return { DEFAULT_MAIL_PAGE_SIZE, + buildCloudflareTempEmailEffectiveDomain, buildCloudflareTempEmailHeaders, getCloudflareTempEmailAddressFromResponse, joinCloudflareTempEmailUrl, @@ -572,5 +596,6 @@ normalizeCloudflareTempEmailDomains, normalizeCloudflareTempEmailMailApiMessages, normalizeCloudflareTempEmailMessage, + normalizeCloudflareTempEmailSubdomainPrefix, }; }); diff --git "a/docs/\344\275\277\347\224\250\346\225\231\347\250\213/\344\275\277\347\224\250\346\225\231\347\250\213.md" "b/docs/\344\275\277\347\224\250\346\225\231\347\250\213/\344\275\277\347\224\250\346\225\231\347\250\213.md" index 831e7aed..ec4741a5 100644 --- "a/docs/\344\275\277\347\224\250\346\225\231\347\250\213/\344\275\277\347\224\250\346\225\231\347\250\213.md" +++ "b/docs/\344\275\277\347\224\250\346\225\231\347\250\213/\344\275\277\347\224\250\346\225\231\347\250\213.md" @@ -22,7 +22,7 @@ |---|---|---|---| | 01 | 相关项目地址与部署说明 | `cpa`、`sub2api`、项目地址、部署前提、部署环境 | `docs/使用教程/分部分/01-相关项目地址与部署说明.md` | | 02 | 更新扩展 | `git pull`、`GitHub Desktop`、手动覆盖更新、扩展重新加载 | `docs/使用教程/分部分/02-更新扩展.md` | -| 03 | Cloudflare Temp Email 使用说明 | `Cloudflare Temp Email`、`Admin Auth`、`Custom Auth`、随机子域、邮件接收 | `docs/使用教程/分部分/03-Cloudflare-Temp-Email-使用说明.md` | +| 03 | Cloudflare Temp Email 使用说明 | `Cloudflare Temp Email`、`Admin Auth`、`Custom Auth`、随机子域、固定子域、邮件接收 | `docs/使用教程/分部分/03-Cloudflare-Temp-Email-使用说明.md` | | 04 | iCloud 隐私邮箱使用方法 | `iCloud+`、`隐藏邮件地址`、Apple ID、转发邮箱、刷新隐私邮箱 | `docs/使用教程/分部分/04-iCloud-隐私邮箱使用方法.md` | | 05 | QQ 邮箱切换邮箱使用教程 | `QQ 邮箱`、英文邮箱、`Foxmail`、删除后重建 | `docs/使用教程/分部分/05-QQ-邮箱切换邮箱使用教程.md` | | 06 | PayPal 注册与绑卡使用教程 | `PayPal`、注册、绑卡、钱包、身份认证、右上角通知 | `docs/使用教程/分部分/06-PayPal-注册与绑卡使用教程.md` | diff --git "a/docs/\344\275\277\347\224\250\346\225\231\347\250\213/\344\275\277\347\224\250\346\225\231\347\250\213\344\271\246\345\206\231\346\250\241\346\235\277.md" "b/docs/\344\275\277\347\224\250\346\225\231\347\250\213/\344\275\277\347\224\250\346\225\231\347\250\213\344\271\246\345\206\231\346\250\241\346\235\277.md" index 7feb77c4..1908ccae 100644 --- "a/docs/\344\275\277\347\224\250\346\225\231\347\250\213/\344\275\277\347\224\250\346\225\231\347\250\213\344\271\246\345\206\231\346\250\241\346\235\277.md" +++ "b/docs/\344\275\277\347\224\250\346\225\231\347\250\213/\344\275\277\347\224\250\346\225\231\347\250\213\344\271\246\345\206\231\346\250\241\346\235\277.md" @@ -72,7 +72,7 @@ AI 维护时默认按下面的范围归类: |---|---|---|---| | 01 | 相关项目地址与部署说明 | `cpa`、`sub2api`、项目地址、部署前提、部署环境 | `docs/使用教程/分部分/01-相关项目地址与部署说明.md` | | 02 | 更新扩展 | `git pull`、`GitHub Desktop`、手动覆盖更新、扩展重新加载 | `docs/使用教程/分部分/02-更新扩展.md` | -| 03 | Cloudflare Temp Email 使用说明 | `Cloudflare Temp Email`、`Admin Auth`、`Custom Auth`、随机子域、邮件接收 | `docs/使用教程/分部分/03-Cloudflare-Temp-Email-使用说明.md` | +| 03 | Cloudflare Temp Email 使用说明 | `Cloudflare Temp Email`、`Admin Auth`、`Custom Auth`、随机子域、固定子域、邮件接收 | `docs/使用教程/分部分/03-Cloudflare-Temp-Email-使用说明.md` | | 04 | iCloud 隐私邮箱使用方法 | `iCloud+`、`隐藏邮件地址`、Apple ID、转发邮箱、刷新隐私邮箱 | `docs/使用教程/分部分/04-iCloud-隐私邮箱使用方法.md` | | 05 | QQ 邮箱切换邮箱使用教程 | `QQ 邮箱`、英文邮箱、`Foxmail`、删除后重建 | `docs/使用教程/分部分/05-QQ-邮箱切换邮箱使用教程.md` | | 06 | PayPal 注册与绑卡使用教程 | `PayPal`、注册、绑卡、钱包、身份认证、右上角通知 | `docs/使用教程/分部分/06-PayPal-注册与绑卡使用教程.md` | diff --git "a/docs/\344\275\277\347\224\250\346\225\231\347\250\213/\345\210\206\351\203\250\345\210\206/03-Cloudflare-Temp-Email-\344\275\277\347\224\250\350\257\264\346\230\216.md" "b/docs/\344\275\277\347\224\250\346\225\231\347\250\213/\345\210\206\351\203\250\345\210\206/03-Cloudflare-Temp-Email-\344\275\277\347\224\250\350\257\264\346\230\216.md" index ad332320..82465d2a 100644 --- "a/docs/\344\275\277\347\224\250\346\225\231\347\250\213/\345\210\206\351\203\250\345\210\206/03-Cloudflare-Temp-Email-\344\275\277\347\224\250\350\257\264\346\230\216.md" +++ "b/docs/\344\275\277\347\224\250\346\225\231\347\250\213/\345\210\206\351\203\250\345\210\206/03-Cloudflare-Temp-Email-\344\275\277\347\224\250\350\257\264\346\230\216.md" @@ -3,7 +3,7 @@ ## 部分信息 - `section_slug`: `cloudflare-temp-email` -- `适用主题`: `Cloudflare Temp Email`、`Admin Auth`、`Custom Auth`、随机子域、邮件接收 +- `适用主题`: `Cloudflare Temp Email`、`Admin Auth`、`Custom Auth`、随机子域、固定子域、邮件接收 - `维护方式`: `直接更新本文件` ## 适用场景 @@ -16,6 +16,7 @@ - 一个可用的 `Cloudflare Temp Email` 后端地址 - 如果要使用随机子域,对应域名解析已经提前配置好 +- 如果要使用固定子域,后端已经开启 `ENABLE_CREATE_ADDRESS_SUBDOMAIN_MATCH` - 后端的 `admin auth` - 如果站点额外设置了访问密码,对应的访问认证信息 - 一个真正用于接收转发邮件的收件邮箱 @@ -52,23 +53,39 @@ ### 第五步:配置 `Temp 域名` -这里填写允许创建邮箱的基础域名。 -即使你开启了 `随机子域`,这里仍然填写基础域名,而不是随机出来的子域名。 +这里选择允许创建邮箱的基础域名。 +即使你开启了 `随机子域` 或 `固定子域`,这里仍然选择基础域名,而不是最终子域名。 ### 第六步:按需开启 `随机子域` 只有在 `邮箱生成 = Cloudflare Temp Email` 时,这一项才会生效。 +`随机子域` 与 `固定子域` 互斥,只能开启其中一个。 启用前需要先确认: - 后端已经配置 `RANDOM_SUBDOMAIN_DOMAINS` - Cloudflare DNS 已经设置 `MX *` -### 第七步:作为 `邮箱服务` 时填写 `邮件接收` +### 第七步:按需开启 `固定子域` + +只有在 `邮箱生成 = Cloudflare Temp Email` 时,这一项才会生效。 +开启 `固定子域` 后再填写 `子域前缀`,例如: + +- `子域前缀 = a` +- `Temp 域名 = b.com` +- 最终提交给后端的域名是 `a.b.com` + +切换 `Temp 域名` 后,子域前缀会继续复用。例如选择 `c.com` 后会生成 `xxx@a.c.com`。 +启用前需要先确认: + +- 后端已经开启 `ENABLE_CREATE_ADDRESS_SUBDOMAIN_MATCH` +- 目标子域名的邮件解析已经准备好,或通配 MX 可以覆盖该子域 + +### 第八步:作为 `邮箱服务` 时填写 `邮件接收` 如果 `邮箱服务` 也选了 `Cloudflare Temp Email`,还需要填写真正的收件邮箱。 后续转发邮件会送到这里。 -### 第八步:查看后端搭建参考 +### 第九步:查看后端搭建参考 如果你还没有部署后端,可以参考: @@ -88,8 +105,14 @@ 通常是因为后端没有配置 `RANDOM_SUBDOMAIN_DOMAINS`,或者 Cloudflare DNS 没有完成 `MX *` 设置。 +### 为什么固定子域没有生效? + +通常是因为后端没有开启 `ENABLE_CREATE_ADDRESS_SUBDOMAIN_MATCH`,或者 `子域前缀` 不符合单段 DNS label 规则。 +前缀只能使用小写字母、数字和中横线,不能包含点号、下划线,也不能以中横线开头或结尾。 + ## 注意事项 - 如果同时把它用作 `邮箱生成` 和 `邮箱服务`,要把两边相关字段都检查一遍 - `Custom Auth` 只有额外访问密码场景才需要填写 -- 开启随机子域前,先确认后端和 DNS 已经准备好 +- `随机子域` 与 `固定子域` 互斥,开启固定子域时会自动关闭随机子域 +- 开启随机子域或固定子域前,先确认后端和 DNS 已经准备好 diff --git a/sidepanel/sidepanel.html b/sidepanel/sidepanel.html index 401a97f2..c4fcec89 100644 --- a/sidepanel/sidepanel.html +++ b/sidepanel/sidepanel.html @@ -826,6 +826,25 @@ 依赖后端 RANDOM_SUBDOMAIN_DOMAINS + +