From 3dfc112561daa3ac8ec59dbf4cc2d3e0e1052afb Mon Sep 17 00:00:00 2001 From: QLHazyCoder Date: Tue, 5 May 2026 05:32:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20GPC=20Helper=20API?= =?UTF-8?q?=20URL=20=E6=94=AF=E6=8C=81=E5=B9=B6=E6=9B=B4=E6=96=B0=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- background.js | 21 ++++++++++++------- background/steps/create-plus-checkout.js | 5 +++-- background/steps/fill-plus-checkout.js | 5 +++-- gopay-utils.js | 8 ++++--- sidepanel/sidepanel.html | 4 ---- sidepanel/sidepanel.js | 20 +++++++++++------- ...ackground-account-history-settings.test.js | 2 ++ tests/gopay-utils.test.js | 6 ++++++ tests/sidepanel-plus-payment-method.test.js | 4 ++-- tests/step-definitions-module.test.js | 2 ++ 10 files changed, 49 insertions(+), 28 deletions(-) diff --git a/background.js b/background.js index cf59b2d..8b6e64d 100644 --- a/background.js +++ b/background.js @@ -239,6 +239,7 @@ const SUB2API_STEP1_RESPONSE_TIMEOUT_MS = 90000; const SUB2API_STEP9_RESPONSE_TIMEOUT_MS = 120000; const DEFAULT_SUB2API_URL = 'https://sub2api.hisence.fun/admin/accounts'; const DEFAULT_CODEX2API_URL = 'http://localhost:8080/admin/accounts'; +const DEFAULT_GPC_HELPER_API_URL = 'https://gopay.hwork.pro'; const DEFAULT_SUB2API_GROUP_NAME = 'codex'; const DEFAULT_SUB2API_PROXY_NAME = ''; const CONTRIBUTION_SOURCE_CPA = 'cpa'; @@ -603,7 +604,7 @@ const PERSISTED_SETTING_DEFAULTS = { gopayPhone: '', gopayOtp: '', gopayPin: '', - gopayHelperApiUrl: '', + gopayHelperApiUrl: DEFAULT_GPC_HELPER_API_URL, gopayHelperCardKey: '', gopayHelperPhoneNumber: '', gopayHelperCountryCode: '+86', @@ -2213,9 +2214,13 @@ function normalizePersistentSettingValue(key, value) { ? self.GoPayUtils.normalizeGoPayCountryCode(value) : String(value || '+86').trim(); case 'gopayHelperApiUrl': - return self.GoPayUtils?.normalizeGpcHelperBaseUrl - ? self.GoPayUtils.normalizeGpcHelperBaseUrl(value) - : String(value || '').trim().replace(/\/+$/g, ''); + { + const defaultGpcHelperApiUrl = PERSISTED_SETTING_DEFAULTS.gopayHelperApiUrl + || (typeof DEFAULT_GPC_HELPER_API_URL !== 'undefined' ? DEFAULT_GPC_HELPER_API_URL : 'https://gopay.hwork.pro'); + return self.GoPayUtils?.normalizeGpcHelperBaseUrl + ? self.GoPayUtils.normalizeGpcHelperBaseUrl(value || defaultGpcHelperApiUrl) + : String(value || defaultGpcHelperApiUrl).trim().replace(/\/+$/g, ''); + } case 'gopayHelperCardKey': case 'gopayHelperReferenceId': case 'gopayHelperGoPayGuid': @@ -9387,13 +9392,13 @@ async function maybeSwitchIpProxyAfterAutoRunRoundSuccess(payload = {}) { function resolveGpcHelperBaseUrl(apiUrl = '') { if (self.GoPayUtils?.normalizeGpcHelperBaseUrl) { - return self.GoPayUtils.normalizeGpcHelperBaseUrl(apiUrl); + return self.GoPayUtils.normalizeGpcHelperBaseUrl(apiUrl || DEFAULT_GPC_HELPER_API_URL); } - let normalized = String(apiUrl || '').trim().replace(/\/+$/g, ''); + let normalized = String(apiUrl || DEFAULT_GPC_HELPER_API_URL).trim().replace(/\/+$/g, ''); normalized = normalized.replace(/\/api\/checkout\/start$/i, ''); normalized = normalized.replace(/\/api\/gopay\/(?:otp|pin)$/i, ''); normalized = normalized.replace(/\/api\/card\/balance(?:\?.*)?$/i, ''); - return normalized; + return normalized || DEFAULT_GPC_HELPER_API_URL; } function buildGpcCardBalanceRequestUrl(apiUrl = '', cardKey = '') { @@ -9423,7 +9428,7 @@ function formatGpcCardBalancePayload(payload = {}) { } async function refreshGpcCardBalance(state = {}, options = {}) { - const apiUrl = String(state?.gopayHelperApiUrl || '').trim(); + const apiUrl = resolveGpcHelperBaseUrl(state?.gopayHelperApiUrl || DEFAULT_GPC_HELPER_API_URL); const cardKey = String(state?.gopayHelperCardKey || state?.gpcCardKey || state?.cardKey || '').trim(); if (!apiUrl) { throw new Error('缺少 GPC API 地址。'); diff --git a/background/steps/create-plus-checkout.js b/background/steps/create-plus-checkout.js index e108a16..8e1b67b 100644 --- a/background/steps/create-plus-checkout.js +++ b/background/steps/create-plus-checkout.js @@ -7,6 +7,7 @@ const PLUS_PAYMENT_METHOD_PAYPAL = 'paypal'; const PLUS_PAYMENT_METHOD_GOPAY = 'gopay'; const PLUS_PAYMENT_METHOD_GPC_HELPER = 'gpc-helper'; + const DEFAULT_GPC_HELPER_API_URL = 'https://gopay.hwork.pro'; function createPlusCheckoutCreateExecutor(deps = {}) { const { @@ -200,11 +201,11 @@ if (rootScope.GoPayUtils?.normalizeGpcHelperBaseUrl) { return rootScope.GoPayUtils.normalizeGpcHelperBaseUrl(apiUrl); } - let normalized = String(apiUrl || '').trim().replace(/\/+$/g, ''); + let normalized = String(apiUrl || DEFAULT_GPC_HELPER_API_URL).trim().replace(/\/+$/g, ''); normalized = normalized.replace(/\/api\/checkout\/start$/i, ''); normalized = normalized.replace(/\/api\/gopay\/(?:otp|pin)$/i, ''); normalized = normalized.replace(/\/api\/card\/balance(?:\?.*)?$/i, ''); - return normalized; + return normalized || DEFAULT_GPC_HELPER_API_URL; } function buildGpcHelperApiUrl(apiUrl = '', path = '') { diff --git a/background/steps/fill-plus-checkout.js b/background/steps/fill-plus-checkout.js index 62f4778..692b2dd 100644 --- a/background/steps/fill-plus-checkout.js +++ b/background/steps/fill-plus-checkout.js @@ -10,6 +10,7 @@ const PLUS_PAYMENT_METHOD_PAYPAL = 'paypal'; const PLUS_PAYMENT_METHOD_GOPAY = 'gopay'; const PLUS_PAYMENT_METHOD_GPC_HELPER = 'gpc-helper'; + const DEFAULT_GPC_HELPER_API_URL = 'https://gopay.hwork.pro'; const PAYMENT_METHOD_CONFIGS = { [PLUS_PAYMENT_METHOD_PAYPAL]: { id: PLUS_PAYMENT_METHOD_PAYPAL, @@ -111,11 +112,11 @@ if (rootScope.GoPayUtils?.normalizeGpcHelperBaseUrl) { return rootScope.GoPayUtils.normalizeGpcHelperBaseUrl(apiUrl); } - let normalized = String(apiUrl || '').trim().replace(/\/+$/g, ''); + let normalized = String(apiUrl || DEFAULT_GPC_HELPER_API_URL).trim().replace(/\/+$/g, ''); normalized = normalized.replace(/\/api\/checkout\/start$/i, ''); normalized = normalized.replace(/\/api\/gopay\/(?:otp|pin)$/i, ''); normalized = normalized.replace(/\/api\/card\/balance(?:\?.*)?$/i, ''); - return normalized; + return normalized || DEFAULT_GPC_HELPER_API_URL; } async function fetchJsonWithTimeout(url, options = {}, timeoutMs = 30000) { diff --git a/gopay-utils.js b/gopay-utils.js index a24ef8d..462f034 100644 --- a/gopay-utils.js +++ b/gopay-utils.js @@ -4,6 +4,7 @@ const PLUS_PAYMENT_METHOD_PAYPAL = 'paypal'; const PLUS_PAYMENT_METHOD_GOPAY = 'gopay'; const PLUS_PAYMENT_METHOD_GPC_HELPER = 'gpc-helper'; + const DEFAULT_GPC_HELPER_API_URL = 'https://gopay.hwork.pro'; function normalizePlusPaymentMethod(value = '') { const normalized = String(value || '').trim().toLowerCase(); @@ -46,15 +47,15 @@ } function normalizeGpcHelperBaseUrl(apiUrl = '') { - let normalized = String(apiUrl || '').trim(); + let normalized = String(apiUrl || DEFAULT_GPC_HELPER_API_URL).trim(); if (!normalized) { - return ''; + return DEFAULT_GPC_HELPER_API_URL; } normalized = normalized.replace(/\/+$/g, ''); normalized = normalized.replace(/\/api\/checkout\/start$/i, ''); normalized = normalized.replace(/\/api\/gopay\/(?:otp|pin)$/i, ''); normalized = normalized.replace(/\/api\/card\/balance(?:\?.*)?$/i, ''); - return normalized; + return normalized || DEFAULT_GPC_HELPER_API_URL; } function buildGpcHelperApiUrl(apiUrl = '', path = '') { @@ -194,6 +195,7 @@ return { DEFAULT_GOPAY_COUNTRY_CODE, + DEFAULT_GPC_HELPER_API_URL, PLUS_PAYMENT_METHOD_GPC_HELPER, PLUS_PAYMENT_METHOD_GOPAY, PLUS_PAYMENT_METHOD_PAYPAL, diff --git a/sidepanel/sidepanel.html b/sidepanel/sidepanel.html index 11bf79f..a80d989 100644 --- a/sidepanel/sidepanel.html +++ b/sidepanel/sidepanel.html @@ -279,10 +279,6 @@ -