@@ -405,14 +424,13 @@ $notice_text = $settings['notice_text'] ?? '欢迎使用全球接码平台!';
let currentCountry = null;
let currentService = null;
let activePolls = {};
- let activeTimers = {};
let searchTimeout = null;
document.addEventListener('DOMContentLoaded', () => {
loadCountries();
renderServices(popularServices);
loadActiveOrders();
- setInterval(loadActiveOrders, 30000);
+ setInterval(loadActiveOrders, 10000);
document.addEventListener('click', (e) => {
if (!e.target.closest('.custom-dropdown')) hideAllDropdowns();
@@ -445,14 +463,8 @@ $notice_text = $settings['notice_text'] ?? '欢迎使用全球接码平台!';
if (data.code === 0) {
allCountries = Array.isArray(data.data) ? data.data : [];
renderCountries();
- } else if (data.code === 401) {
- window.location.href = 'index.php';
- } else {
- listContainer.innerHTML = `
加载失败: ${data.msg || '未知API错误'}
`;
}
- } catch (e) {
- listContainer.innerHTML = '
网络连接超时,请刷新页面
';
- }
+ } catch (e) {}
}
function toggleDropdown(id, event) {
@@ -476,25 +488,15 @@ $notice_text = $settings['notice_text'] ?? '欢迎使用全球接码平台!';
if (!container) return;
container.innerHTML = '';
- if (!Array.isArray(allCountries) || allCountries.length === 0) {
- container.innerHTML = '
暂无可用国家数据
';
- return;
- }
-
const filtered = filter ? allCountries.filter(c =>
(c.name_zh && c.name_zh.includes(filter)) ||
(c.name_en && c.name_en.toLowerCase().includes(filter.toLowerCase()))
) : allCountries;
- if (filtered.length === 0) {
- container.innerHTML = '
未找到匹配的国家
';
- return;
- }
-
filtered.slice(0, 100).forEach(c => {
const div = document.createElement('div');
div.className = 'list-item';
- div.innerHTML = `
${c.name_zh || '未知'}${c.name_en || ''}
`;
+ div.innerHTML = `
${c.name_zh || '未知'}
`;
div.onclick = (e) => { e.stopPropagation(); selectCountry(c); };
container.appendChild(div);
});
@@ -504,16 +506,10 @@ $notice_text = $settings['notice_text'] ?? '欢迎使用全球接码平台!';
const container = document.getElementById('servicesList');
if (!container) return;
container.innerHTML = '';
-
- if (!Array.isArray(services) || services.length === 0) {
- container.innerHTML = '
暂无搜索结果
';
- return;
- }
-
services.forEach(s => {
const div = document.createElement('div');
div.className = 'list-item';
- div.innerHTML = `
${s.name}`;
+ div.innerHTML = `
${s.name}`;
div.onclick = (e) => { e.stopPropagation(); selectService(s); };
container.appendChild(div);
});
@@ -523,7 +519,6 @@ $notice_text = $settings['notice_text'] ?? '欢迎使用全球接码平台!';
function handleServiceInput() {
const q = document.getElementById('serviceSearch').value;
- const listContainer = document.getElementById('servicesList');
if (searchTimeout) clearTimeout(searchTimeout);
if (!q) { renderServices(popularServices); return; }
@@ -534,20 +529,12 @@ $notice_text = $settings['notice_text'] ?? '欢迎使用全球接码平台!';
if (data.code === 0) {
const unique = [];
const map = new Map();
- const services = Array.isArray(data.data) ? data.data : [];
- services.forEach(i => {
- if(i.service_name && !map.has(i.service_name)){
- map.set(i.service_name, true);
- unique.push({name: i.service_name});
- }
+ (data.data || []).forEach(i => {
+ if(i.service_name && !map.has(i.service_name)){ map.set(i.service_name, true); unique.push({name: i.service_name}); }
});
renderServices(unique);
- } else if (data.code === 401) {
- window.location.href = 'index.php';
}
- } catch (e) {
- console.error("Search error", e);
- }
+ } catch (e) {}
}, 400);
}
@@ -555,8 +542,7 @@ $notice_text = $settings['notice_text'] ?? '欢迎使用全球接码平台!';
currentCountry = c;
const l = document.getElementById('countryLabel');
l.textContent = c.name_zh;
- l.classList.remove('placeholder');
- l.classList.add('val');
+ l.classList.remove('placeholder'); l.classList.add('val');
hideAllDropdowns();
loadQuotation();
}
@@ -565,15 +551,14 @@ $notice_text = $settings['notice_text'] ?? '欢迎使用全球接码平台!';
currentService = s;
const l = document.getElementById('serviceLabel');
l.textContent = s.name;
- l.classList.remove('placeholder');
- l.classList.add('val');
+ l.classList.remove('placeholder'); l.classList.add('val');
hideAllDropdowns();
loadQuotation();
}
async function loadQuotation() {
const body = document.getElementById('quotationBody');
- body.innerHTML = '
';
+ body.innerHTML = '
';
const cP = currentCountry ? encodeURIComponent(currentCountry.name_zh) : '';
const sP = currentService ? encodeURIComponent(currentService.name) : '';
@@ -583,66 +568,31 @@ $notice_text = $settings['notice_text'] ?? '欢迎使用全球接码平台!';
const data = await res.json();
if (data.code === 0) {
body.innerHTML = '';
- const services = Array.isArray(data.data) ? data.data : [];
- if (!services.length) {
- body.innerHTML = '
';
- return;
- }
- services.forEach(s => {
+ (data.data || []).forEach(s => {
const item = document.createElement('div');
item.className = 'quotation-item';
- const isPop = popularServices.some(ps => ps.name === s.service_name);
item.innerHTML = `
-
- ${s.service_name}
- ${isPop ? '热门' : ''}
-
-
${s.country_name_zh || (currentCountry ? currentCountry.name_zh : '全球')}
-
-
-
-
+
${s.service_name}
+
${s.country_name_zh}
+
+
`;
body.appendChild(item);
});
- document.getElementById('lastUpdated').textContent = '更新时间: ' + new Date().toLocaleTimeString();
- } else if (data.code === 401) {
- window.location.href = 'index.php';
- } else {
- body.innerHTML = `
加载行情失败: ${data.msg || '未知接口错误'}
`;
}
- } catch (e) { body.innerHTML = '
行情数据连接失败,请检查网络
'; }
+ } catch (e) {}
}
async function getNumber(sid, sname, price, btn) {
showConfirm('购买确认', `确认扣费 $${price} 购买 ${sname} 号码?`, async () => {
- const originalText = btn.innerHTML;
- btn.disabled = true;
- btn.innerHTML = '
';
-
try {
- const cname = currentCountry ? currentCountry.name_zh : '全球';
- const res = await fetch(`${apiHandler}?action=get_number&service_id=${sid}&service_name=${encodeURIComponent(sname)}&country_name=${encodeURIComponent(cname)}&price=${price}`);
+ const res = await fetch(`${apiHandler}?action=get_number&service_id=${sid}&service_name=${encodeURIComponent(sname)}&country_name=${encodeURIComponent(currentCountry.name_zh)}&price=${price}`);
const data = await res.json();
- if (data.code === 0) {
- showToast('号码获取成功!');
- loadActiveOrders(); updateBalance(); window.scrollTo({top: 0, behavior: 'smooth'});
- } else if (data.code === 401) {
- window.location.href = 'index.php';
- } else {
- showToast(data.msg || '库存不足或接口超时', 'error');
- }
- } catch (e) {
- showToast('获取号码失败,请重试', 'error');
- } finally {
- btn.disabled = false;
- btn.innerHTML = originalText;
- }
+ if (data.code === 0) { showToast('获取成功!'); loadActiveOrders(); updateBalance(); }
+ else { showToast(data.msg || '获取失败', 'error'); }
+ } catch (e) { showToast('接口异常', 'error'); }
});
}
@@ -660,90 +610,68 @@ $notice_text = $settings['notice_text'] ?? '欢迎使用全球接码平台!';
const data = await res.json();
const body = document.getElementById('activeTasksBody');
const section = document.getElementById('activeTasksSection');
+ const latestArea = document.getElementById('latestOrderArea');
+ const latestContent = document.getElementById('latestOrderContent');
- Object.values(activeTimers).forEach(t => clearInterval(t));
- activeTimers = {};
-
if (data.code === 0 && Array.isArray(data.data) && data.data.length > 0) {
section.style.display = 'block';
body.innerHTML = '';
+
+ const receivedList = data.data.filter(o => o.status === 'received');
+ if (receivedList.length > 0) {
+ const latest = receivedList.sort((a,b) => new Date(b.created_at) - new Date(a.created_at))[0];
+ const now = new Date();
+ const rAt = new Date(latest.created_at.replace(/-/g, "/").replace(" ", "T") + "Z");
+ if ((now - rAt) / 1000 < 300) {
+ latestArea.style.display = 'block';
+ latestContent.innerHTML = `
+
项目: ${latest.service_name}
+
号码: ${latest.number}
+
短信: ${latest.sms_content}
+
+ `;
+ } else { latestArea.style.display = 'none'; }
+ } else { latestArea.style.display = 'none'; }
+
data.data.forEach(o => {
- const exp = new Date(o.expire_at.replace(/-/g, "/")).getTime();
- let tl = Math.floor((exp - new Date().getTime())/1000);
const row = document.createElement('tr');
row.innerHTML = `
-
- ${o.service_name}
- ${o.country_name}
- |
-
${o.number} |
-
- ${o.status === 'received' ? `${o.sms_content}` : `
- `}
- |
-
${formatTime(tl)} |
-
-
- |
+
${o.service_name} / ${o.country_name} |
+
${o.number} |
+
${o.status === 'received' ? o.sms_content : '等待中...'} |
+
${o.status} |
+
${o.expire_at} |
+
|
`;
body.appendChild(row);
- if (o.status !== 'received') { startPolling(o.request_id); startTimer(o.request_id, tl); }
+ if (o.status !== 'received' && !activePolls[o.request_id]) startPolling(o.request_id);
});
- } else { section.style.display = 'none'; }
+ } else { section.style.display = 'none'; latestArea.style.display = 'none'; }
} catch (e) {}
}
function startPolling(rid) {
- if (activePolls[rid]) return;
activePolls[rid] = setInterval(async () => {
try {
const res = await fetch(`${apiHandler}?action=check_sms&request_id=${rid}`);
const data = await res.json();
if (data.code === 0 && (data.msg === 'success' || data.sms_code)) {
- const el = document.getElementById(`sms-${rid}`);
- if (el) el.innerHTML = `
${data.sms_code}`;
- clearInterval(activePolls[rid]); delete activePolls[rid]; showSmsModal(data.sms_code);
- } else if (data.code === 400 || (data.code !== 0 && data.code !== 500)) {
- clearInterval(activePolls[rid]); delete activePolls[rid]; loadActiveOrders();
+ clearInterval(activePolls[rid]); delete activePolls[rid]; showSmsModal(data.sms_code); loadActiveOrders();
}
} catch (e) {}
}, 5000);
}
- function startTimer(id, s) {
- activeTimers[id] = setInterval(() => {
- s--;
- const el = document.getElementById('timer-' + id);
- if (s <= 0) { clearInterval(activeTimers[id]); loadActiveOrders(); }
- else if (el) el.textContent = formatTime(s);
- }, 1000);
- }
-
async function releaseNumber(id) {
- showConfirm('释放确认', '确定取消并释放此号码吗?', async () => {
- try {
- const res = await fetch(`${apiHandler}?action=release_number&request_id=${id}`);
- const data = await res.json();
- if (data.code === 0) { showToast('号码已取消!'); loadActiveOrders(); updateBalance(); } else { showToast(data.msg, 'error'); }
- } catch (e) { showToast('连接服务器失败', 'error'); }
- });
- }
-
- function formatTime(s) {
- if (s <= 0) return "00:00";
- const m = Math.floor(s/60), sec = s%60;
- return `${m.toString().padStart(2,'0')}:${sec.toString().padStart(2,'0')}`;
+ try {
+ const res = await fetch(`${apiHandler}?action=release_number&request_id=${id}`);
+ loadActiveOrders(); updateBalance();
+ } catch (e) {}
}
function showSmsModal(code) {
document.getElementById('modalSmsCode').textContent = code;
new bootstrap.Modal(document.getElementById('smsModal')).show();
- if(navigator.clipboard && navigator.clipboard.writeText) {
- navigator.clipboard.writeText(code).catch(e => {});
- }
}