共计 3535 个字符,预计需要花费 9 分钟才能阅读完成。
一、简略阐明
应用聚合数据提供的收费 全国彩票开奖后果查问
接口服务,目前反对双色球、大乐透、七乐彩、七星彩、福彩 3D、排列 3、排列 5,数据来源于网络公开,开奖后果获取可能会有肯定的延时。
官网接口文档地址:https://www.juhe.cn/docs/api/id/300,注册申请即可取得接口申请 Key。
二、PHP 调用代码参考
Lottery.class.php
/**
* Class Lottery
*/
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;}
}
/**
* 获取彩票某一期开奖后果, 默认最新一期
* @param $lotteryId 彩票 ID
* @param string $lotteryNo 彩票期数,默认最新一期
* @return bool|mixed
*/
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;}
}
/**
* 获取历史开奖后果
* @param $lotteryId 彩票 ID
* @param int $pageSize 每页返回条数
* @param int $page 当前页数
*/
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;}
}
/**
* 中奖计算器 / 判断号码是否中奖
* @param $lotteryId 彩票 ID
* @param $lotteryRes 投注号码
* @param string $lotteryNo 投注期号,默认最新一期
* @return bool|mixed
*/
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;}
}
/**
* 发动接口网络申请
* @param $url
* @param bool $params
* @param int $ispost
* @return bool|mixed
*/
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);
}
正文完