地方彩票开奖api接口示例

地方彩票开奖接口示例,在线文档可查看下

package com.huaying.demo.shenlu;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.annotation.JSONField;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Arrays;
import java.util.List;


public class DFLottery {

    public static void main(String[] args) {
        try {
            String content = getContent();
            Respond rsp = new Respond();
            rsp.setLotteries(JSONArray.parseArray(content,Lottery.class));
            rsp.getLotteries().forEach(System.out::println);

        } catch (Throwable t) {
            t.printStackTrace();
        }
    }


    /**
     * 获取API返回内容
     */
    private static String getContent() {

        // 设置接口参数
        String type = "2002";              // 彩种类型,4 位数字编号,福建36选7为2002
        String token = "token";          // 通信令牌,【替换为分配给自己的token】
        String count = "3";                // 返回条数,默认为5
        String format = "json";            // 返回格式,默认为json

        String url = "http://api.shenlu88.com/data/lottery/result/list";
        url += "?type=" + type;
        url += "&token=" + token;
        url += "&count=" + count;
        url += "&format=" + format;

        // 调用神鹿数据 API 获取格式为 JSON 字符串的开奖结果
        String charset = "UTF-8";
        String jsonResult = get(url, charset);

        return jsonResult;
    }

    /**
     * @param url:请求接口
     * @param charset:字符编码
     * @return 返回json字符串
     */
    public static String get(String url, String charset) {
        BufferedReader reader = null;
        String result = null;
        StringBuffer sbf = new StringBuffer();
        String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
        try {
            URL newUrl = new URL(url);
            HttpURLConnection connection = (HttpURLConnection) newUrl.openConnection();
            connection.setRequestMethod("GET");
            connection.setReadTimeout(30000);
            connection.setConnectTimeout(30000);
            connection.setRequestProperty("User-agent", userAgent);
            connection.connect();
            InputStream is = connection.getInputStream();
            reader = new BufferedReader(new InputStreamReader(is, charset));
            String strRead = null;
            while ((strRead = reader.readLine()) != null) {
                sbf.append(strRead);
                sbf.append("\r\n");
            }
            reader.close();
            result = sbf.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }


    public static class Respond{
        @JSONField
        private List lotteries;

        public List getLotteries() {
            return lotteries;
        }

        public void setLotteries(List lotteries) {
            this.lotteries = lotteries;
        }
    }


    public static class Lottery {
        @JSONField(name = "period")
        private String period;
        @JSONField(name = "numbers")
        private String[] numbers;
        @JSONField(name = "special_numbers")
        private String[] special_numbers;
        @JSONField(name = "sales")
        private Long sales;
        @JSONField(name = "jackpot")
        private Long jackpot;
        @JSONField(name = "return_rate")
        private Long return_rate;
        @JSONField(name = "ball_set")
        private Integer ball_set;
        @JSONField(name = "open_date")
        private Long open_date;
        @JSONField(name = "awards")
        private Award[] awards;

        @Override
        public String toString() {
            return "Lottery{" +
                    "period='" + period + '\'' +
                    ", numbers=" + Arrays.toString(numbers) +
                    ", special_numbers=" + Arrays.toString(special_numbers) +
                    ", sales=" + sales +
                    ", jackpot=" + jackpot +
                    ", return_rate=" + return_rate +
                    ", ball_set=" + ball_set +
                    ", open_date=" + open_date +
                    ", awards=" + Arrays.toString(awards) +
                    '}';
        }

        public String getPeriod() {
            return period;
        }

        public void setPeriod(String period) {
            this.period = period;
        }

        public String[] getNumbers() {
            return numbers;
        }

        public void setNumbers(String[] numbers) {
            this.numbers = numbers;
        }

        public String[] getSpecial_numbers() {
            return special_numbers;
        }

        public void setSpecial_numbers(String[] special_numbers) {
            this.special_numbers = special_numbers;
        }

        public Long getSales() {
            return sales;
        }

        public void setSales(Long sales) {
            this.sales = sales;
        }

        public Long getJackpot() {
            return jackpot;
        }

        public void setJackpot(Long jackpot) {
            this.jackpot = jackpot;
        }

        public Long getReturn_rate() {
            return return_rate;
        }

        public void setReturn_rate(Long return_rate) {
            this.return_rate = return_rate;
        }

        public Integer getBall_set() {
            return ball_set;
        }

        public void setBall_set(Integer ball_set) {
            this.ball_set = ball_set;
        }

        public Long getOpen_date() {
            return open_date;
        }

        public void setOpen_date(Long open_date) {
            this.open_date = open_date;
        }

        public Award[] getAwards() {
            return awards;
        }

        public void setAwards(Award[] awards) {
            this.awards = awards;
        }
    }

    public static class Award{
        @JSONField(name = "name")
        private String name;
        @JSONField(name = "total_bonus")
        private Long total_bonus;
        @JSONField(name = "pot_bonus")
        private Long pot_bonus;
        @JSONField(name = "pot_count")
        private Long pot_count;
        @JSONField(name = "additional_bonus")
        private Long additional_bonus;
        @JSONField(name = "additional_pot_count")
        private Long additional_pot_count;
        @JSONField(name = "additional_pot_bonus")
        private Long additional_pot_bonus;

        @Override
        public String toString() {
            return "Award{" +
                    "name='" + name + '\'' +
                    ", total_bonus=" + total_bonus +
                    ", pot_bonus=" + pot_bonus +
                    ", pot_count=" + pot_count +
                    ", additional_bonus=" + additional_bonus +
                    ", additional_pot_count=" + additional_pot_count +
                    ", additional_pot_bonus=" + additional_pot_bonus +
                    '}';
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Long getTotal_bonus() {
            return total_bonus;
        }

        public void setTotal_bonus(Long total_bonus) {
            this.total_bonus = total_bonus;
        }

        public Long getPot_bonus() {
            return pot_bonus;
        }

        public void setPot_bonus(Long pot_bonus) {
            this.pot_bonus = pot_bonus;
        }

        public Long getPot_count() {
            return pot_count;
        }

        public void setPot_count(Long pot_count) {
            this.pot_count = pot_count;
        }

        public Long getAdditional_bonus() {
            return additional_bonus;
        }

        public void setAdditional_bonus(Long additional_bonus) {
            this.additional_bonus = additional_bonus;
        }

        public Long getAdditional_pot_count() {
            return additional_pot_count;
        }

        public void setAdditional_pot_count(Long additional_pot_count) {
            this.additional_pot_count = additional_pot_count;
        }

        public Long getAdditional_pot_bonus() {
            return additional_pot_bonus;
        }

        public void setAdditional_pot_bonus(Long additional_pot_bonus) {
            this.additional_pot_bonus = additional_pot_bonus;
        }
    }
}

API 返回数据如下(部分):

Lottery{period='19114', numbers=[01, 06, 09, 14, 16, 26, 35], special_numbers=[17], sales=99045800, jackpot=4281056040, return_rate=0, ball_set=0, open_date=1569670200000, awards=[Award{name='特等奖', total_bonus=0, pot_bonus=0, pot_count=0, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='一等奖', total_bonus=0, pot_bonus=0, pot_count=0, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='二等奖', total_bonus=0, pot_bonus=416000, pot_count=8, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='三等奖', total_bonus=0, pot_bonus=50000, pot_count=65, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='四等奖', total_bonus=0, pot_bonus=5000, pot_count=537, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='五等奖', total_bonus=0, pot_bonus=2000, pot_count=1064, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='六等奖', total_bonus=0, pot_bonus=600, pot_count=13625, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='幸运奖', total_bonus=0, pot_bonus=0, pot_count=0, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}]}
Lottery{period='19113', numbers=[06, 08, 10, 12, 14, 17, 20], special_numbers=[21], sales=113264000, jackpot=4251099630, return_rate=0, ball_set=0, open_date=1569497400000, awards=[Award{name='特等奖', total_bonus=0, pot_bonus=0, pot_count=0, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='一等奖', total_bonus=0, pot_bonus=1188800, pot_count=3, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='二等奖', total_bonus=0, pot_bonus=137100, pot_count=26, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='三等奖', total_bonus=0, pot_bonus=50000, pot_count=86, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='四等奖', total_bonus=0, pot_bonus=5000, pot_count=705, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='五等奖', total_bonus=0, pot_bonus=2000, pot_count=1086, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='六等奖', total_bonus=0, pot_bonus=600, pot_count=18281, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='幸运奖', total_bonus=0, pot_bonus=0, pot_count=0, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}]}
Lottery{period='19112', numbers=[01, 09, 13, 15, 22, 24, 33], special_numbers=[12], sales=116776000, jackpot=4222566510, return_rate=0, ball_set=0, open_date=1569324600000, awards=[Award{name='特等奖', total_bonus=0, pot_bonus=0, pot_count=0, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='一等奖', total_bonus=0, pot_bonus=1357400, pot_count=3, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='二等奖', total_bonus=0, pot_bonus=509000, pot_count=8, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='三等奖', total_bonus=0, pot_bonus=50000, pot_count=107, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='四等奖', total_bonus=0, pot_bonus=5000, pot_count=424, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='五等奖', total_bonus=0, pot_bonus=2000, pot_count=1002, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='六等奖', total_bonus=0, pot_bonus=600, pot_count=13649, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}, Award{name='幸运奖', total_bonus=0, pot_bonus=0, pot_count=0, additional_bonus=0, additional_pot_count=0, additional_pot_bonus=0}]}

你可能感兴趣的:(php,c++,c#)