Update GoPay helper API URL to new domain and enhance cookie cleanup functionality

This commit is contained in:
QLHazyCoder
2026-05-07 16:31:58 +08:00
parent 43982825e1
commit 428e23d66a
17 changed files with 364 additions and 84 deletions
@@ -159,7 +159,7 @@ const self = {
};
const PERSISTED_SETTING_DEFAULTS = {
autoStepDelaySeconds: null,
gopayHelperApiUrl: 'https://gpc.leftcode.xyz',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top',
mailProvider: '163',
};
function normalizePanelMode(value) { return value === 'sub2api' ? 'sub2api' : (value === 'codex2api' ? 'codex2api' : 'cpa'); }
@@ -194,18 +194,18 @@ return {
assert.equal(api.normalizePersistentSettingValue('plusPaymentMethod', 'paypal'), 'paypal');
assert.equal(api.normalizePersistentSettingValue('plusPaymentMethod', 'unknown'), 'paypal');
assert.equal(
api.normalizePersistentSettingValue('gopayHelperApiUrl', ' https://gpc.leftcode.xyz/api/checkout/start '),
'https://gpc.leftcode.xyz'
api.normalizePersistentSettingValue('gopayHelperApiUrl', ' https://gpc.qlhazycoder.top/api/checkout/start '),
'https://gpc.qlhazycoder.top'
);
assert.equal(
api.normalizePersistentSettingValue('gopayHelperApiUrl', ' https://gpc.leftcode.xyz/api/gp/tasks/task_1/pin '),
'https://gpc.leftcode.xyz'
api.normalizePersistentSettingValue('gopayHelperApiUrl', ' https://gpc.qlhazycoder.top/api/gp/tasks/task_1/pin '),
'https://gpc.qlhazycoder.top'
);
assert.equal(
api.normalizePersistentSettingValue('gopayHelperApiUrl', ' https://gpc.leftcode.xyz/api/gp/balance '),
'https://gpc.leftcode.xyz'
api.normalizePersistentSettingValue('gopayHelperApiUrl', ' https://gpc.qlhazycoder.top/api/gp/balance '),
'https://gpc.qlhazycoder.top'
);
assert.equal(api.normalizePersistentSettingValue('gopayHelperApiUrl', ''), 'https://gpc.leftcode.xyz');
assert.equal(api.normalizePersistentSettingValue('gopayHelperApiUrl', ''), 'https://gpc.qlhazycoder.top');
assert.equal(api.normalizePersistentSettingValue('gopayHelperApiKey', ' gpc-123 '), 'gpc-123');
assert.equal(api.normalizePersistentSettingValue('gopayHelperCountryCode', ' 86 '), '+86');
assert.equal(api.normalizePersistentSettingValue('gopayHelperPhoneNumber', ' +86 138-0013-8000 '), '+8613800138000');
@@ -32,6 +32,63 @@ test('step 6 waits for registration success and completes from background', asyn
assert.ok(events.logs.some(({ message }) => /等待 20 /.test(message)));
});
test('step 6 only clears cookies when cleanup switch is enabled', async () => {
const source = fs.readFileSync('background/steps/wait-registration-success.js', 'utf8');
const globalScope = {};
const api = new Function('self', `${source}; return self.MultiPageBackgroundStep6;`)(globalScope);
const events = {
removedCookies: [],
browsingDataCalls: [],
completedSteps: [],
};
const chromeApi = {
cookies: {
getAllCookieStores: async () => [{ id: 'store-a' }],
getAll: async () => [
{ domain: '.chatgpt.com', path: '/auth', name: 'session', storeId: 'store-a' },
{ domain: '.example.com', path: '/', name: 'keep', storeId: 'store-a' },
],
remove: async (details) => {
events.removedCookies.push(details);
return details;
},
},
browsingData: {
removeCookies: async (details) => {
events.browsingDataCalls.push(details);
},
},
};
const executor = api.createStep6Executor({
addLog: async () => {},
chrome: chromeApi,
completeStepFromBackground: async (step) => {
events.completedSteps.push(step);
},
sleepWithStop: async () => {},
});
await executor.executeStep6({ step6CookieCleanupEnabled: false });
assert.deepStrictEqual(events.removedCookies, []);
assert.deepStrictEqual(events.browsingDataCalls, []);
await executor.executeStep6({ step6CookieCleanupEnabled: true });
assert.deepStrictEqual(events.completedSteps, [6, 6]);
assert.deepStrictEqual(events.removedCookies, [
{
url: 'https://chatgpt.com/auth',
name: 'session',
storeId: 'store-a',
},
]);
assert.equal(events.browsingDataCalls.length, 1);
assert.ok(events.browsingDataCalls[0].origins.includes('https://chatgpt.com'));
});
test('step 7 retries up to configured limit and then fails', async () => {
const source = fs.readFileSync('background/steps/oauth-login.js', 'utf8');
const globalScope = {};
+11 -11
View File
@@ -26,35 +26,35 @@ test('GoPay utils keeps GPC helper payment method distinct', () => {
test('GoPay utils builds GPC queue task and balance URLs from helper endpoints', () => {
const api = loadGoPayUtils();
assert.equal(api.DEFAULT_GPC_HELPER_API_URL, 'https://gpc.leftcode.xyz');
assert.equal(api.normalizeGpcHelperBaseUrl(''), 'https://gpc.leftcode.xyz');
assert.equal(api.DEFAULT_GPC_HELPER_API_URL, 'https://gpc.qlhazycoder.top');
assert.equal(api.normalizeGpcHelperBaseUrl(''), 'https://gpc.qlhazycoder.top');
assert.equal(
api.buildGpcHelperApiUrl('', '/api/checkout/start'),
'https://gpc.leftcode.xyz/api/checkout/start'
'https://gpc.qlhazycoder.top/api/checkout/start'
);
assert.equal(
api.buildGpcApiKeyBalanceUrl('http://localhost:18473/'),
'http://localhost:18473/api/gp/balance'
);
assert.equal(
api.buildGpcCardBalanceUrl('https://gpc.leftcode.xyz/api/gp/balance'),
'https://gpc.leftcode.xyz/api/gp/balance'
api.buildGpcCardBalanceUrl('https://gpc.qlhazycoder.top/api/gp/balance'),
'https://gpc.qlhazycoder.top/api/gp/balance'
);
assert.deepEqual(
api.buildGpcApiKeyHeaders(' gpc-123 ', { Accept: 'application/json' }),
{ Accept: 'application/json', 'X-API-Key': 'gpc-123' }
);
assert.equal(
api.buildGpcTaskCreateUrl('https://gpc.leftcode.xyz/api/checkout/start'),
'https://gpc.leftcode.xyz/api/gp/tasks'
api.buildGpcTaskCreateUrl('https://gpc.qlhazycoder.top/api/checkout/start'),
'https://gpc.qlhazycoder.top/api/gp/tasks'
);
assert.equal(
api.buildGpcTaskQueryUrl('https://gpc.leftcode.xyz/api/gp/tasks/task_old?card_key=old', 'task/1'),
'https://gpc.leftcode.xyz/api/gp/tasks/task%2F1'
api.buildGpcTaskQueryUrl('https://gpc.qlhazycoder.top/api/gp/tasks/task_old?card_key=old', 'task/1'),
'https://gpc.qlhazycoder.top/api/gp/tasks/task%2F1'
);
assert.equal(
api.buildGpcTaskActionUrl('https://gpc.leftcode.xyz/api/gp/tasks/task_old/stop', 'task_1', 'pin'),
'https://gpc.leftcode.xyz/api/gp/tasks/task_1/pin'
api.buildGpcTaskActionUrl('https://gpc.qlhazycoder.top/api/gp/tasks/task_old/stop', 'task_1', 'pin'),
'https://gpc.qlhazycoder.top/api/gp/tasks/task_1/pin'
);
});
@@ -833,7 +833,7 @@ test('GPC billing polls queue task, submits WhatsApp OTP then PIN, and waits unt
getState: async () => currentState,
fetchImpl: async (url, options = {}) => {
fetchCalls.push({ url, options });
if (url === 'https://gpc.leftcode.xyz/api/gp/tasks/task_123') {
if (url === 'https://gpc.qlhazycoder.top/api/gp/tasks/task_123') {
pollCount += 1;
if (pollCount === 1) {
return {
@@ -877,7 +877,7 @@ test('GPC billing polls queue task, submits WhatsApp OTP then PIN, and waits unt
plusPaymentMethod: 'gpc-helper',
plusCheckoutSource: 'gpc-helper',
gopayHelperTaskId: 'task_123',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/api/gp/tasks/task_old/otp',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/api/gp/tasks/task_old/otp',
gopayHelperPin: '654321',
gopayHelperApiKey: 'gpc_billing_123',
});
@@ -893,7 +893,7 @@ test('GPC billing polls queue task, submits WhatsApp OTP then PIN, and waits unt
await run;
assert.equal(fetchCalls[0].url, 'https://gpc.leftcode.xyz/api/gp/tasks/task_123');
assert.equal(fetchCalls[0].url, 'https://gpc.qlhazycoder.top/api/gp/tasks/task_123');
assert.equal(fetchCalls[0].options.headers['X-API-Key'], 'gpc_billing_123');
const otpCall = fetchCalls.find((call) => call.url.endsWith('/api/gp/tasks/task_123/otp'));
const pinCall = fetchCalls.find((call) => call.url.endsWith('/api/gp/tasks/task_123/pin'));
@@ -923,7 +923,7 @@ test('GPC billing reads SMS OTP from local helper for sms_otp_wait', async () =>
json: async () => ({ ok: true, otp: '654321', message_id: 'sms-1' }),
};
}
if (url === 'https://gpc.leftcode.xyz/api/gp/tasks/task_sms') {
if (url === 'https://gpc.qlhazycoder.top/api/gp/tasks/task_sms') {
pollCount += 1;
if (pollCount === 1) {
return {
@@ -967,7 +967,7 @@ test('GPC billing reads SMS OTP from local helper for sms_otp_wait', async () =>
plusPaymentMethod: 'gpc-helper',
plusCheckoutSource: 'gpc-helper',
gopayHelperTaskId: 'task_sms',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
gopayHelperPin: '654321',
gopayHelperApiKey: 'gpc_sms',
gopayHelperOtpChannel: 'sms',
@@ -1008,7 +1008,7 @@ test('GPC billing can read WhatsApp OTP from local helper when enabled', async (
json: async () => ({ ok: true, otp: '765432', message_id: 'wa-1' }),
};
}
if (url === 'https://gpc.leftcode.xyz/api/gp/tasks/task_wa') {
if (url === 'https://gpc.qlhazycoder.top/api/gp/tasks/task_wa') {
pollCount += 1;
if (pollCount === 1) {
return {
@@ -1052,7 +1052,7 @@ test('GPC billing can read WhatsApp OTP from local helper when enabled', async (
plusPaymentMethod: 'gpc-helper',
plusCheckoutSource: 'gpc-helper',
gopayHelperTaskId: 'task_wa',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
gopayHelperPin: '654321',
gopayHelperApiKey: 'gpc_wa',
gopayHelperOtpChannel: 'whatsapp',
@@ -1088,8 +1088,8 @@ test('GPC billing helper mode does not open OTP dialog when helper has no code a
json: async () => ({ ok: true, status: 'waiting', otp: '', message: '未查询到验证码' }),
};
}
if (url === 'https://gpc.leftcode.xyz/api/gp/tasks/task_timeout') {
const queryCount = fetchCalls.filter((call) => call.url === 'https://gpc.leftcode.xyz/api/gp/tasks/task_timeout').length;
if (url === 'https://gpc.qlhazycoder.top/api/gp/tasks/task_timeout') {
const queryCount = fetchCalls.filter((call) => call.url === 'https://gpc.qlhazycoder.top/api/gp/tasks/task_timeout').length;
return {
ok: true,
status: 200,
@@ -1118,7 +1118,7 @@ test('GPC billing helper mode does not open OTP dialog when helper has no code a
plusPaymentMethod: 'gpc-helper',
plusCheckoutSource: 'gpc-helper',
gopayHelperTaskId: 'task_timeout',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
gopayHelperPin: '654321',
gopayHelperApiKey: 'gpc_timeout',
gopayHelperOtpChannel: 'whatsapp',
@@ -1153,7 +1153,7 @@ test('GPC billing helper mode requests newer OTP after invalid OTP error', async
json: async () => ({ ok: true, otp: helperCallCount === 1 ? '111111' : '222222', message_id: `sms-${helperCallCount}` }),
};
}
if (url === 'https://gpc.leftcode.xyz/api/gp/tasks/task_retry') {
if (url === 'https://gpc.qlhazycoder.top/api/gp/tasks/task_retry') {
taskPollCount += 1;
if (taskPollCount === 1) {
return { ok: true, status: 200, json: async () => createGpcTaskResponse({ task_id: 'task_retry', status: 'active', remote_stage: 'sms_otp_wait', api_waiting_for: 'otp' }) };
@@ -1181,7 +1181,7 @@ test('GPC billing helper mode requests newer OTP after invalid OTP error', async
plusPaymentMethod: 'gpc-helper',
plusCheckoutSource: 'gpc-helper',
gopayHelperTaskId: 'task_retry',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
gopayHelperPin: '654321',
gopayHelperApiKey: 'gpc_retry',
gopayHelperOtpChannel: 'sms',
@@ -1222,7 +1222,7 @@ test('GPC billing manual OTP wrong input opens next dialog only after previous o
getState: async () => currentState,
fetchImpl: async (url, options = {}) => {
fetchCalls.push({ url, options });
if (url === 'https://gpc.leftcode.xyz/api/gp/tasks/task_manual_retry') {
if (url === 'https://gpc.qlhazycoder.top/api/gp/tasks/task_manual_retry') {
pollCount += 1;
if (pollCount === 1) {
return { ok: true, status: 200, json: async () => createGpcTaskResponse({ task_id: 'task_manual_retry', status: 'active', remote_stage: 'whatsapp_otp_wait', api_waiting_for: 'otp' }) };
@@ -1263,7 +1263,7 @@ test('GPC billing manual OTP wrong input opens next dialog only after previous o
plusPaymentMethod: 'gpc-helper',
plusCheckoutSource: 'gpc-helper',
gopayHelperTaskId: 'task_manual_retry',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
gopayHelperPin: '654321',
gopayHelperApiKey: 'gpc_manual_retry',
});
@@ -1297,7 +1297,7 @@ test('GPC billing manual OTP cancel stops task and ends current round', async ()
getState: async () => currentState,
fetchImpl: async (url, options = {}) => {
fetchCalls.push({ url, options });
if (url === 'https://gpc.leftcode.xyz/api/gp/tasks/task_cancel') {
if (url === 'https://gpc.qlhazycoder.top/api/gp/tasks/task_cancel') {
return { ok: true, status: 200, json: async () => createGpcTaskResponse({ task_id: 'task_cancel', status: 'active', remote_stage: 'whatsapp_otp_wait', api_waiting_for: 'otp' }) };
}
if (url.endsWith('/api/gp/tasks/task_cancel/stop')) {
@@ -1311,7 +1311,7 @@ test('GPC billing manual OTP cancel stops task and ends current round', async ()
plusPaymentMethod: 'gpc-helper',
plusCheckoutSource: 'gpc-helper',
gopayHelperTaskId: 'task_cancel',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
gopayHelperPin: '654321',
gopayHelperApiKey: 'gpc_cancel',
});
@@ -1340,7 +1340,7 @@ test('GPC billing PIN failure ends task without retrying PIN', async () => {
stateByFrame: {},
fetchImpl: async (url, options = {}) => {
fetchCalls.push({ url, options });
if (url === 'https://gpc.leftcode.xyz/api/gp/tasks/task_pin_failed') {
if (url === 'https://gpc.qlhazycoder.top/api/gp/tasks/task_pin_failed') {
pollCount += 1;
if (pollCount === 1) {
return { ok: true, status: 200, json: async () => createGpcTaskResponse({ task_id: 'task_pin_failed', status: 'otp_ready', status_text: '等待 PIN', remote_stage: 'otp_ready', api_waiting_for: 'pin' }) };
@@ -1359,7 +1359,7 @@ test('GPC billing PIN failure ends task without retrying PIN', async () => {
plusPaymentMethod: 'gpc-helper',
plusCheckoutSource: 'gpc-helper',
gopayHelperTaskId: 'task_pin_failed',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
gopayHelperPin: '654321',
gopayHelperApiKey: 'gpc_pin_failed',
}),
@@ -1378,7 +1378,7 @@ for (const terminalStatus of ['failed', 'expired', 'discarded']) {
stateByFrame: {},
fetchImpl: async (url, options = {}) => {
fetchCalls.push({ url, options });
if (url === 'https://gpc.leftcode.xyz/api/gp/tasks/task_bad') {
if (url === 'https://gpc.qlhazycoder.top/api/gp/tasks/task_bad') {
return {
ok: true,
status: 200,
@@ -1399,7 +1399,7 @@ for (const terminalStatus of ['failed', 'expired', 'discarded']) {
plusPaymentMethod: 'gpc-helper',
plusCheckoutSource: 'gpc-helper',
gopayHelperTaskId: 'task_bad',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
gopayHelperPin: '654321',
gopayHelperApiKey: 'gpc_bad',
}),
@@ -1417,7 +1417,7 @@ test('GPC billing stops task best-effort when flow is interrupted before termina
stateByFrame: {},
fetchImpl: async (url, options = {}) => {
fetchCalls.push({ url, options });
if (url === 'https://gpc.leftcode.xyz/api/gp/tasks/task_stop') {
if (url === 'https://gpc.qlhazycoder.top/api/gp/tasks/task_stop') {
return {
ok: false,
status: 500,
@@ -1440,7 +1440,7 @@ test('GPC billing stops task best-effort when flow is interrupted before termina
plusPaymentMethod: 'gpc-helper',
plusCheckoutSource: 'gpc-helper',
gopayHelperTaskId: 'task_stop',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
gopayHelperPin: '654321',
gopayHelperApiKey: 'gpc_stop',
}),
+6 -6
View File
@@ -155,7 +155,7 @@ test('GPC checkout injects Plus script before reading ChatGPT session token and
await executor.executePlusCheckoutCreate({
email: 'Current.Round+GPC@Example.COM',
plusPaymentMethod: 'gpc-helper',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
gopayHelperPhoneNumber: '+8613800138000',
gopayPhone: '',
gopayHelperCountryCode: '+86',
@@ -173,7 +173,7 @@ test('GPC checkout injects Plus script before reading ChatGPT session token and
includeAccessToken: true,
});
assert.equal(fetchCalls.length, 1);
assert.equal(fetchCalls[0].url, 'https://gpc.leftcode.xyz/api/gp/tasks');
assert.equal(fetchCalls[0].url, 'https://gpc.qlhazycoder.top/api/gp/tasks');
const helperPayload = JSON.parse(fetchCalls[0].options.body);
assert.deepEqual(helperPayload, {
access_token: 'session-access-token',
@@ -233,7 +233,7 @@ test('GPC checkout forwards selected SMS OTP channel', async () => {
await executor.executePlusCheckoutCreate({
email: 'sms@example.com',
plusPaymentMethod: 'gpc-helper',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
gopayHelperPhoneNumber: '+8613800138000',
gopayHelperCountryCode: '+86',
gopayHelperPin: '123456',
@@ -285,7 +285,7 @@ test('GPC checkout surfaces unified queue API errors', async () => {
() => executor.executePlusCheckoutCreate({
email: 'paid@example.com',
plusPaymentMethod: 'gpc-helper',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
chatgptAccessToken: 'state-access-token',
gopayHelperPhoneNumber: '+8613800138000',
gopayHelperCountryCode: '+86',
@@ -326,7 +326,7 @@ test('GPC checkout does not fall back to browser GoPay phone fields', async () =
await assert.rejects(
() => executor.executePlusCheckoutCreate({
plusPaymentMethod: 'gpc-helper',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
chatgptAccessToken: 'state-access-token',
email: 'helper-phone-test@example.com',
gopayPhone: '+8613800138000',
@@ -366,7 +366,7 @@ test('GPC checkout rejects missing API Key before calling helper API', async ()
await assert.rejects(
() => executor.executePlusCheckoutCreate({
plusPaymentMethod: 'gpc-helper',
gopayHelperApiUrl: 'https://gpc.leftcode.xyz/',
gopayHelperApiUrl: 'https://gpc.qlhazycoder.top/',
chatgptAccessToken: 'state-access-token',
email: 'missing-card@example.com',
gopayHelperPhoneNumber: '+8613800138000',
+3 -1
View File
@@ -135,9 +135,11 @@ test('sidepanel html exposes Plus mode, PayPal, and GoPay settings', () => {
assert.match(html, /id="input-gopay-pin"/);
assert.match(html, /<option value="gpc-helper">GPC<\/option>/);
assert.match(html, /id="btn-gpc-card-key-purchase"/);
assert.match(html, />获取 API Key</);
assert.match(html, />购买卡密</);
assert.match(html, /GPC API/);
assert.match(html, /id="input-gpc-helper-api"/);
assert.match(html, /id="btn-gpc-helper-convert-api-key"/);
assert.match(html, />转换 API Key</);
assert.match(html, /GPC API Key/);
assert.match(html, /id="input-gpc-helper-card-key"/);
assert.match(html, /id="btn-gpc-helper-balance"/);