全国彩票开奖结果查询-PHP版

韩瑶
• 阅读 563

一、简单说明

使用聚合数据提供的免费全国彩票开奖结果查询接口服务,目前支持双色球、大乐透、七乐彩、七星彩、福彩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);
}
点赞
收藏
评论区
推荐文章
不是海碗 不是海碗
2年前
原生JS + HTML + CSS 实现快递物流信息 API 的数据链式展示
全国快递物流查询API是一种提供实时、准确、可靠的快递物流信息查询服务的接口。它基于现有的物流信息系统,通过API接口的方式,向用户提供快递物流信息的查询、跟踪、统计等功能。
Wesley13 Wesley13
3年前
IP地址查询接口及调用方法
设计蜂巢IP地址查询接口:http://www.hujuntao.com/api/ip/ip.php腾讯IP地址查询接口:http://fw.qq.com/ipaddress新浪IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?formatjs搜狐I
Stella981 Stella981
3年前
Spring Cache缓存技术的介绍
缓存用于提升系统的性能,特别适用于一些对资源需求比较高的操作。本文介绍如何基于springbootcache技术,使用caffeine作为具体的缓存实现,对操作的结果进行缓存。demo场景本demo将创建一个web应用,提供两个Rest接口。一个接口用于接受查询请求,并有条件的缓存查询结果。另一个接口用于获取所有缓存的数据,用于监控
Stella981 Stella981
3年前
Python版的数据库查询构造器、ORM及动态迁移数据表。
OratorOrator提供一个简单和方便的数据库数据处理库。它的灵感来源于PHP的Laravel框架,借助其思想实现了python版的查询构造器和ORM。这是完整的文档:http://oratororm.com/docs(https://www.oschina.net/action/GoToLink?urlhttp%3A%2F
Stella981 Stella981
3年前
Python MySQL Order By
对结果排序可以使用ORDERBY语句,按升序或降序对结果排序。默认情况下,ORDERBY关键字按升序排列结果。要按降序排列,可使用DESC关键字。示例按name的字母顺序排列结果:importmysql.connectormydbmysql.connector.connect
Wesley13 Wesley13
3年前
mysql基础之查询缓存、存储引擎
一、查询缓存    “查询缓存”,就是将查询的结果缓存下载,如果查询语句完全相同,则直接返回缓存中的结果。  如果应用程序在某个场景中,需要经常执行大量的相同的查询,而且查询出的数据不会经常被更新,那么,使用查询缓存会有一定的性能提升。查看当前服务是否开启了查询缓存功能:!复制代码(https://oscimg.oschina.n
不是海碗 不是海碗
2年前
全国快递物流 API 实现快递单号自动识别的原理解析
概述全国快递物流API是一种提供快递物流单号查询的接口,涵盖了包括申通、顺丰、圆通、韵达、中通、汇通等600快递公司的数据。该API的目标是为快递公司、电商、物流平台等提供便捷、快速、准确的快递物流信息查询服务。数据采集和处理全国快递物流API的数据采集
E小媛同学 E小媛同学
1年前
APISpace 全国快递物流地图轨迹查询API接口案例代码
APISpace全国快递物流地图轨迹查询API接口案例代码
飞鹅官方账号 飞鹅官方账号
10个月前
五、飞鹅官网API接口文档
接口列表1.获取网站信息请求方法:GET请求URL:/api/site/getSiteInfo请求参数无返回结果json"code":1,"data":"id":1,//id"title":"SampleSiteName",//网站名称"intro":"T