fix: align SMS Bower provider with documented API

This commit is contained in:
chick
2026-05-31 00:20:16 +08:00
parent b69490e632
commit 39af4f9ca4
2 changed files with 49 additions and 27 deletions
+23 -13
View File
@@ -4,7 +4,7 @@
})(typeof self !== 'undefined' ? self : globalThis, function createSmsBowerProviderModule() {
const PROVIDER_ID = 'sms-bower';
const DEFAULT_BASE_URL = 'https://smsbower.page/stubs/handler_api.php';
const DEFAULT_SERVICE_CODE = 'ot';
const DEFAULT_SERVICE_CODE = 'dr';
const DEFAULT_SERVICE_LABEL = 'OpenAI';
const DEFAULT_COUNTRY_ID = 6;
const DEFAULT_COUNTRY_LABEL = 'Indonesia';
@@ -160,8 +160,9 @@
throw error;
}
const message = describePayload(payload);
if (/^(BAD_KEY|BAD_ACTION|BAD_SERVICE|BAD_STATUS|NO_ACTIVATION|EARLY_CANCEL_DENIED|BAD_COUNTRY)\b/i.test(message)) {
const error = new Error(`${actionLabel}失败:${message}`);
const apiStatus = payload && typeof payload === 'object' && !Array.isArray(payload) ? Number(payload.status) : null;
if (apiStatus === 0 || /^(BAD_KEY|BAD_ACTION|BAD_SERVICE|BAD_STATUS|NO_ACTIVATION|EARLY_CANCEL_DENIED|BAD_COUNTRY)\b/i.test(message)) {
const error = new Error(`${actionLabel}失败:${message || 'SMS Bower API 返回失败状态'}`);
error.payload = payload;
throw error;
}
@@ -220,7 +221,7 @@
async function fetchPrices(state = {}, countryConfig = {}, deps = {}) {
const config = resolveConfig(state, deps);
return fetchPayload(config, {
action: 'getPrices',
action: 'getPricesV3',
service: config.serviceCode,
country: normalizeSmsBowerCountryId(countryConfig?.id ?? state.smsBowerCountryId, DEFAULT_COUNTRY_ID),
}, 'SMS Bower 查询价格');
@@ -232,12 +233,21 @@
return entries;
}
if (!payload || typeof payload !== 'object') return entries;
const cost = Number(payload.cost ?? payload.price ?? payload.Price);
if (Number.isFinite(cost) && cost >= 0) {
const count = Number(payload.count ?? payload.qty ?? payload.Qty);
entries.push({ cost, count: Number.isFinite(count) ? count : 0, inStock: !Number.isFinite(count) || count > 0 });
const directCount = Number(payload.count ?? payload.qty ?? payload.Qty);
const directPrice = Number(payload.cost ?? payload.price ?? payload.Price);
if (Number.isFinite(directPrice) && directPrice >= 0) {
entries.push({ cost: directPrice, count: Number.isFinite(directCount) ? directCount : 0, inStock: !Number.isFinite(directCount) || directCount > 0 });
}
Object.values(payload).forEach((entry) => collectPriceEntries(entry, entries));
Object.entries(payload).forEach(([key, entry]) => {
if (entry && typeof entry === 'object' && !Array.isArray(entry)) {
const keyedPrice = Number(key);
const keyedCount = Number(entry.count ?? entry.qty ?? entry.Qty);
if (/^\d+(?:\.\d+)?$/.test(String(key)) && String(key).includes('.') && Number.isFinite(keyedPrice) && keyedPrice >= 0 && !Number.isFinite(Number(entry.cost ?? entry.price ?? entry.Price))) {
entries.push({ cost: keyedPrice, count: Number.isFinite(keyedCount) ? keyedCount : 0, inStock: !Number.isFinite(keyedCount) || keyedCount > 0 });
}
}
collectPriceEntries(entry, entries);
});
return entries;
}
@@ -249,10 +259,10 @@
}
}
const source = payload && typeof payload === 'object' && !Array.isArray(payload) ? payload : {};
const activationId = normalizeText(source.activationId ?? source.id ?? fallback.activationId);
const phoneNumber = normalizeText(source.phoneNumber ?? source.phone ?? fallback.phoneNumber);
const activationId = normalizeText(source.activationId ?? source.activation_id ?? source.id ?? fallback.activationId);
const phoneNumber = normalizeText(source.phoneNumber ?? source.phone_number ?? source.phone ?? fallback.phoneNumber);
if (!activationId || !phoneNumber) return null;
const countryId = normalizeSmsBowerCountryId(source.countryId ?? source.country ?? fallback.countryId, DEFAULT_COUNTRY_ID);
const countryId = normalizeSmsBowerCountryId(source.countryId ?? source.country_id ?? source.countryCode ?? source.country ?? fallback.countryId, DEFAULT_COUNTRY_ID);
return {
activationId,
phoneNumber,
@@ -287,7 +297,7 @@
throw new Error(`SMS Bower 价格区间无效:最低购买价 ${range.minPriceLimit} 高于价格上限 ${range.maxPriceLimit}`);
}
return {
action: 'getNumber',
action: 'getNumberV2',
service: config.serviceCode,
country: normalizeSmsBowerCountryId(countryConfig.id, DEFAULT_COUNTRY_ID),
maxPrice: range.maxPriceLimit,