全国彩票开奖结果查询-PHP版
短信预约 -IT技能 免费直播动态提醒
一、简单说明
使用聚合数据提供的免费全国彩票开奖结果查询
接口服务,目前支持双色球、大乐透、七乐彩、七星彩、福彩3D、排列3、排列5,数据来源于网络公开,开奖结果获取可能会有一定的延时。
官网接口文档地址:https://www.juhe.cn/docs/api/id/300,注册申请即可获得接口请求Key。
二、PHP调用代码参考
Lottery.class.php
class Lottery
{
//接口提交地址
private static $submitUrl = 'http://apis.juhe.cn/lottery';
//申请的彩票接口请求Key
private static $appkey = '**********';
public static function getLotteryTypes()
{
$urlPath = '/types';
$params = [
'key' => self::$appkey
];
$paramsString = http_build_query($params);
$requestUrl = self::$submitUrl.$urlPath;
$content = self::juheCurl($requestUrl, $paramsString);
$result = json_decode($content, true);
if ($result) {
return $result;
} else {
return false;
}
}
public static function getLotteryRes($lotteryId, $lotteryNo = "")
{
$urlPath = '/query';
$params = [
'key' => self::$appkey,
'lottery_id' => $lotteryId,
'lottery_no' => $lotteryNo
];
$paramsString = http_build_query($params);
$requestUrl = self::$submitUrl.$urlPath;
$content = self::juheCurl($requestUrl, $paramsString);
$result = json_decode($content, true);
if ($result) {
return $result;
} else {
return false;
}
}
public static function getLotteryHistroyRes($lotteryId, $pageSize = 10, $page = 1)
{
$urlPath = '/history';
$params = [
'key' => self::$appkey,
'lottery_id' => $lotteryId,
'page_size' => $pageSize,
'page' => $page,
];
$paramsString = http_build_query($params);
$requestUrl = self::$submitUrl.$urlPath;
$content = self::juheCurl($requestUrl, $paramsString);
$result = json_decode($content, true);
if ($result) {
return $result;
} else {
return false;
}
}
public static function getBonus($lotteryId, $lotteryRes, $lotteryNo='')
{
$urlPath = '/bonus';
$params = [
'key' => self::$appkey,
'lottery_id' => $lotteryId,
'lottery_res' => $lotteryRes,
'lottery_no' => $lotteryNo,
];
$paramsString = http_build_query($params);
$requestUrl = self::$submitUrl.$urlPath;
$content = self::juheCurl($requestUrl, $paramsString);
$result = json_decode($content, true);
if ($result) {
return $result;
} else {
return false;
}
}
public static function juheCurl($url, $params = false, $ispost = 0)
{
$httpInfo = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 12);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($ispost) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, $url);
} else {
if ($params) {
curl_setopt($ch, CURLOPT_URL, $url.'?'.$params);
} else {
curl_setopt($ch, CURLOPT_URL, $url);
}
}
$response = curl_exec($ch);
if ($response === FALSE) {
return false;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$httpInfo = array_merge($httpInfo, curl_getinfo($ch));
curl_close($ch);
return $response;
}
}
index.php
include "Lottery.class.php";
$lotteryTypes = Lottery::getLotteryTypes();
if ($lotteryTypes) {
print_r($lotteryTypes);
}
$lotteryResult = Lottery::getLotteryRes('ssq', '18028');
if ($lotteryResult) {
print_r($lotteryResult);
}
$lotteryHistoryResult = Lottery::getLotteryHistroyRes('ssq', 10 ,1);
if ($lotteryHistoryResult) {
print_r($lotteryHistoryResult);
}
$lotteryBonusResult = Lottery::getBonus('ssq', '13,14,20,21,25,33@07', '18030');
if ($lotteryBonusResult) {
print_r($lotteryBonusResult);
}
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341