彩票开奖结果查询
聚合数据 官方文档
目前支持双色球、大乐透、七乐彩、七星彩、福彩3D、排列3、排列5,数据来源于网络公开,开奖结果获取可能会有一定的延时
基本说明:
接口地址:http://apis.juhe.cn/lottery/types
返回格式:json
请求方式:get/post
请求示例:http://apis.juhe.cn/lottery/query
请求参数说明:
名称 类型 必填 说明
key string 必填 申请数据自动分配 扫码关注公众号
lottery_id string 必填 彩票ID
lottery_no string 选填 彩票期号,默认最新一期
返回参数说明:
名称 类型 说明
error_code int 返回码
reason string 返回说明
result string 返回结果集
lottery_id string 彩票ID
lottery_name string 彩票名称
lottery_res string 开奖结果
lottery_no string 开奖期号
lottery_date string 开奖日期
lottery_exdate string 兑奖截止日期
lottery_sale_amount string 本期销售额,可能为空
lottery_pool_amount string 奖池滚存,可能为空
lottery_prize array 开奖详情,可能为null
prize_name string 奖项名称
prize_num string 中奖数量,公布数据可能延时可能为空或--
prize_amount string 中奖金额
prize_require string 中奖条件
JSON返回示例:
{
	"reason": "查询成功",
	"result": {
		"lottery_id": "ssq",
		"lottery_name": "双色球",
		"lottery_res": "03,08,11,14,18,23,16",
		"lottery_no": "18028",
		"lottery_date": "2018-03-13",
		"lottery_exdate": "2018-05-11",
		"lottery_sale_amount": "352,015,830",
		"lottery_pool_amount": "578,094,167",
		"lottery_prize": [{
				"prize_name": "一等奖",
				"prize_num": "7",
				"prize_amount": "7,676,997",
				"prize_require": "6+1"
			},
			{
				"prize_name": "二等奖",
				"prize_num": "220",
				"prize_amount": "106,471",
				"prize_require": "6+0"
			},
			{
				"prize_name": "三等奖",
				"prize_num": "1869",
				"prize_amount": "3,000",
				"prize_require": "5+1"
			},
			{
				"prize_name": "四等奖",
				"prize_num": "82708",
				"prize_amount": "200",
				"prize_require": "5+0,4+1"
			},
			{
				"prize_name": "五等奖",
				"prize_num": "1493643",
				"prize_amount": "10",
				"prize_require": "4+0,3+1"
			},
			{
				"prize_name": "六等奖",
				"prize_num": "8341565",
				"prize_amount": "5",
				"prize_require": "2+1,1+1,0+1"
			}
		]
	},
	"error_code": 0
}
服务级错误码参照
错误码 说明
230001 彩票ID不存在/不能为空
230002 查询不到相关结果
230003 彩票号码格式不正确
230004 查询不到本期开奖结果
230005 暂不支持本彩票ID是否中奖判断
10001 错误的请求KEY
10002 该KEY无请求权限
10003 KEY过期
10004 错误的OPENID
10005 应用未审核超时,请提交认证
10007 未知的请求源
10008 被禁止的IP
10009 被禁止的KEY
10011 当前IP请求超过限制
10012 请求超过次数限制
10013 测试KEY超过请求限制
10014 系统内部异常(调用充值类业务时,请务必联系客服或通过订单查询接口检测订单,避免造成损失)
10020 接口维护
10021 接口停用
完整教学代码示例
<?php
class Lottery
{
    //接口提交地址
    private static $submitUrl = 'http://apis.juhe.cn/lottery';

    //申请的彩票接口AppKey
    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;
    }
}