公益宣传 · 非商业 · 免费接入
给站长的一段代码

把公益广告
嵌进你的网站

这里的内容免费、非商业。复制一段代码放到你的页面里,就能多一块安全提醒的位置。不需要注册,不需要申请,也不用挂我们的链接。

广告接入

选择要接入的广告位,点击卡片查看教程。全部免费、非商业、免后端。

更多广告位 后续陆续开放

01 方案 A · 前端请求(接口无 CORS,已内置代理)

源接口没有返回跨域头,直连会被浏览器拦截。下面的代码把直连和公共代理一起发出,谁先成功用谁,复制即可使用。

const RAW = 'https://api.xunjinlu.fun/api/babygome/index.php?type=json';

// 直连 + 公共代理并发,谁先成功用谁
const WRAPPERS = [
  u => u,
  u => 'https://api.allorigins.win/raw?url=' + encodeURIComponent(u),
  u => 'https://api.codetabs.com/v1/proxy?quest=' + encodeURIComponent(u)
];

function fetchOne(wrap, target) {
  const ctrl = new AbortController();
  const timer = setTimeout(() => ctrl.abort(), 8000);   // 8 秒超时

  return fetch(wrap(target), { signal: ctrl.signal, cache: 'no-store' })
    .then(r => { if (!r.ok) throw new Error('HTTP ' + r.status); return r.text(); })
    .then(text => {
      const json = JSON.parse(text);
      if (json.code && Number(json.code) !== 200) throw new Error('状态码 ' + json.code);
      // 注意:data 是单个对象,不是数组
      const item = Array.isArray(json) ? json[0] : json.data;
      if (!item || !item.name) throw new Error('数据结构异常');
      return item;
    })
    .finally(() => clearTimeout(timer));
}

Promise.any(WRAPPERS.map(w => fetchOne(w, RAW + '&_=' + Date.now())))
  .then(item => console.log(item.name, item.lostAddress))
  .catch(() => console.warn('所有通道均失败'));

02 方案 B · 直连 JSON(需自行配好跨域)

有服务器的站长建议做反向代理并补上 CORS 头,前端就能直连,比公共代理稳得多。

# Nginx 反向代理
location /api/babygome {
    proxy_pass https://api.xunjinlu.fun/api/babygome/index.php?type=json;
    add_header Access-Control-Allow-Origin *;
}

// 前端直连自己的代理
const res  = await fetch('/api/babygome', { cache: 'no-store' });
const json = await res.json();
const item = json.data || {};
console.log(item.name, item.lostAddress);
字段:name 姓名、sex 性别、birthDay 出生日期、lostDay 走失日期、lostAddress 走失地点、 feature 特征、photoUrl 照片、detailUrl 详情页。