广告
返回顶部
首页 > 资讯 > 后端开发 > PHP编程 >全国彩票开奖结果查询-PHP版
  • 856
分享到

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

2024-04-02 19:04:59 856人浏览 安东尼
摘要

一、简单说明 使用聚合数据提供的免费全国彩票开奖结果查询接口服务,目前支持双色球、大乐透、七乐彩、七星彩、福彩3D、排列3、排列5,数据来源于网络公开,开奖结果获取可能会有一定的延时。 官网接口文档地址:https://www.juhe.c

一、简单说明

使用聚合数据提供的免费全国彩票开奖结果查询接口服务,目前支持双色球、大乐透、七乐彩、七星彩、福彩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);
}

--结束END--

本文标题: 全国彩票开奖结果查询-PHP版

本文链接: https://www.lsjlt.com/news/99285.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 全国彩票开奖结果查询-PHP版
    一、简单说明 使用聚合数据提供的免费全国彩票开奖结果查询接口服务,目前支持双色球、大乐透、七乐彩、七星彩、福彩3D、排列3、排列5,数据来源于网络公开,开奖结果获取可能会有一定的延时。 官网接口文档地址:https://www.juhe.c...
    99+
    2022-10-22
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作