一、简单说明
使用聚合数据提供的免费全国彩票开奖结果查询
接口服务,目前支持双色球、大乐透、七乐彩、七星彩、福彩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);
}
想要了解更多内容,请持续关注码农资源网,一起探索发现编程世界的无限可能!
本站部分资源来源于网络,仅限用于学习和研究目的,请勿用于其他用途。
如有侵权请发送邮件至1943759704@qq.com删除
码农资源网 » 全国彩票开奖结果查询-PHP版
本站部分资源来源于网络,仅限用于学习和研究目的,请勿用于其他用途。
如有侵权请发送邮件至1943759704@qq.com删除
码农资源网 » 全国彩票开奖结果查询-PHP版