优先使用 state 获取全部彩种状态,需要查看更多历史时再使用 history,仅在确需持续实时更新时再接入 stream。同时这里保留了 open.html,并新增了 open.php 正式案例页,同时提供 open.rar 下载,便于直接测试效果与正式上线使用。
正式对外主要就是下面这三个接口。
一次返回全部彩种当前状态、模式、推送节奏与历史预览。普通接入、首页接入、整站采集,优先使用这一个接口。
按彩种读取历史数据,支持分页。适合历史页、查看更多记录、单独历史采集。
适合开奖高频阶段持续监听。浏览器端可直接使用 EventSource 实时接收状态。
调用 history 时,key 必须使用下面这些固定值。?ajax=history 不能直接访问,必须带上 key 参数。
香港六合彩
新澳门六合彩
老澳门六合彩
柬埔寨六合彩
菲律宾六合彩
澳门六合彩
新加坡六合彩
迪拜六合彩
| history 正确示例 | https://lottolive.net/index.php?ajax=history&key=hk&page=1&per_page=20 |
|---|---|
| 错误访问示例 | https://lottolive.net/index.php?ajax=history 会返回 {"ok":false,"message":"无效的彩种"},因为没有传 key。 |
| 全部可用 key | hk、newMacau、oldMacau、cambodia、philippines、macau、singapore、dubai |
保留原有 open.html 演示页,点击后可以直接打开看到效果。适合静态展示与常规前端对接。
新增 open.php 演示页,点击测试即可直接打开。适合需要服务端部署与正式上线使用的场景。
为了方便直接下载使用,下载文件名 open.rar。点击即可直接下载。
open.html 为原有 HTML 案例页面,点击即可直接看到实际效果。
open.php 为新增 PHP 案例页面,适合服务端正式部署使用。
open.rar 点击下载才会直接拿到压缩包。
正式上线时最常用的参数很少,按这里接即可,不需要额外乱拼。
| state | 默认无需参数,直接访问 https://lottolive.net/index.php?ajax=state 即可。 |
|---|---|
| history / key | 必填。必须使用本页给出的固定彩种 key,例如 hk、macau、newMacau。?ajax=history 不能直接访问,不带 key 会返回无效的彩种。 |
| history / page | 选填。页码,从 1 开始,默认 1。 |
| history / per_page | 选填。每页条数,默认 20,最大 100。 |
| stream | 浏览器端使用 EventSource 连接,监听 state、error、end 事件即可。 |
下面的示例都可以直接复制使用,展示顺序也按实际接入频率重新整理过。
fetch('https://lottolive.net/index.php?ajax=state')
.then(res => res.json())
.then(data => {
console.log(data.data.lotteries);
console.log(data.data.lotteries.hk.current);
});
fetch('https://lottolive.net/index.php?ajax=history&key=hk&page=1&per_page=20')
.then(res => res.json())
.then(data => {
console.log(data.history);
});
const source = new EventSource('https://lottolive.net/index.php?ajax=stream');
source.addEventListener('state', (event) => {
const payload = JSON.parse(event.data);
console.log(payload.data);
});
source.addEventListener('end', () => {
source.close();
});
<?php
$url = 'https://lottolive.net/index.php?ajax=state';
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 5,
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($response === false || $httpCode < 200 || $httpCode >= 300) {
exit('API 请求失败');
}
$data = json_decode($response, true);
print_r($data['data']['lotteries']['hk']['current']);
正式使用时建议按下面方式接,更稳也更省资源。
普通网站接入,优先用 state 做主接口,只有需要更多历史时再补 history。
如果调用过快触发限制,建议按返回里的 push_interval_ms 控制前端刷新节奏。
history 的 key 必须严格使用本页固定值,大小写不要改。
实时流收到 end 后,说明当前建议切回普通轮询,这样更稳。