足球特殊指数api接口示例

分享下足球特殊指数数据,单双、总进球数、半全场赔率api接口示例,详情查看在线文档接口返回的是Json数据,可以使用fastjson来解析。

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.List;

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

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

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

        // 设置接口参数
        String type = "6003";              // 赔率类型,4 位数字编号,单双、总进球数、半全场赔率为6003
        String token = "mytoken";          // 通信令牌,【替换为分配给自己的token】
        String format = "json";            // 返回格式,默认为json

        String url = "http://api.shenlu88.com/data/lottery/result/list";
        url += "?type=" + type;
        url += "&token=" + token;
        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<Odds> odds;

        public List<Odds> getOdds() {
            return odds;
        }

        public void setOdds(List<Odds> odds) {
            this.odds = odds;
        }
    }

    public static class GoalsOddsItem{
        @JSONField(name = "MoreThanSix")
        private String moreThanSix;

        @JSONField(name = "TwoToThree")
        private String twoToThree;

        @JSONField(name = "ZeroToOne")
        private String zeroToOne;

        @JSONField(name = "FourToSix")
        private String fourToSix;

        public String getMoreThanSix() {
            return moreThanSix;
        }

        public void setMoreThanSix(String moreThanSix) {
            this.moreThanSix = moreThanSix;
        }

        public String getTwoToThree() {
            return twoToThree;
        }

        public void setTwoToThree(String twoToThree) {
            this.twoToThree = twoToThree;
        }

        public String getZeroToOne() {
            return zeroToOne;
        }

        public void setZeroToOne(String zeroToOne) {
            this.zeroToOne = zeroToOne;
        }

        public String getFourToSix() {
            return fourToSix;
        }

        public void setFourToSix(String fourToSix) {
            this.fourToSix = fourToSix;
        }

        @Override
        public String toString() {
            return "GoalsOddsItem{" +
                    "moreThanSix='" + moreThanSix + '\'' +
                    ", twoToThree='" + twoToThree + '\'' +
                    ", zeroToOne='" + zeroToOne + '\'' +
                    ", fourToSix='" + fourToSix + '\'' +
                    '}';
        }
    }

    public static class  HalfTotalOddsItem{
        @JSONField(name = "half_status")
        private String halfStatus;

        @JSONField(name = "total_status")
        private String totalStatus;

        @JSONField(name = "ratio")
        private String ratio;

        public String getHalfStatus() {
            return halfStatus;
        }

        public void setHalfStatus(String halfStatus) {
            this.halfStatus = halfStatus;
        }

        public String getTotalStatus() {
            return totalStatus;
        }

        public void setTotalStatus(String totalStatus) {
            this.totalStatus = totalStatus;
        }

        public String getRatio() {
            return ratio;
        }

        public void setRatio(String ratio) {
            this.ratio = ratio;
        }

        @Override
        public String toString() {
            return "HalfTotalOddsItem{" +
                    "halfStatus='" + halfStatus + '\'' +
                    ", totalStatus='" + totalStatus + '\'' +
                    ", ratio='" + ratio + '\'' +
                    '}';
        }
    }

    public static class OddsItem {
        @JSONField(name = "single_ratio")
        private String singleRatio;
        @JSONField(name = "double_ratio")
        private String doubleRatio;
        @JSONField(name = "goals_odds")
        private List<GoalsOddsItem> goalsOdds;
        @JSONField(name = "half_total_odds")
        private List<HalfTotalOddsItem> halfTotalOdds;
        @JSONField(name = "is_stop")
        private Boolean isStop;

        public String getSingleRatio() {
            return singleRatio;
        }

        public void setSingleRatio(String singleRatio) {
            this.singleRatio = singleRatio;
        }

        public String getDoubleRatio() {
            return doubleRatio;
        }

        public void setDoubleRatio(String doubleRatio) {
            this.doubleRatio = doubleRatio;
        }

        public List<GoalsOddsItem> getGoalsOdds() {
            return goalsOdds;
        }

        public void setGoalsOdds(List<GoalsOddsItem> goalsOdds) {
            this.goalsOdds = goalsOdds;
        }

        public List<HalfTotalOddsItem> getHalfTotalOdds() {
            return halfTotalOdds;
        }

        public void setHalfTotalOdds(List<HalfTotalOddsItem> halfTotalOdds) {
            this.halfTotalOdds = halfTotalOdds;
        }

        public Boolean getStop() {
            return isStop;
        }

        public void setStop(Boolean stop) {
            isStop = stop;
        }

        @Override
        public String toString() {
            return "OddsItem{" +
                    "singleRatio='" + singleRatio + '\'' +
                    ", doubleRatio='" + doubleRatio + '\'' +
                    ", goalsOdds=" + goalsOdds +
                    ", halfTotalOdds=" + halfTotalOdds +
                    ", isStop=" + isStop +
                    '}';
        }
    }

    public static class Odds {
        @JSONField(name = "match_id")
        private String matchId;
        @JSONField(name = "company_id")
        private String companyId;
        @JSONField(name = "odds")
        private List<OddsItem> odds;
        @JSONField(name = "modify_time")
        private String modifyTime;

        public String getMatchId() {
            return matchId;
        }

        public void setMatchId(String matchId) {
            this.matchId = matchId;
        }

        public String getCompanyId() {
            return companyId;
        }

        public void setCompanyId(String companyId) {
            this.companyId = companyId;
        }

        public List<OddsItem> getOdds() {
            return odds;
        }

        public void setOdds(List<OddsItem> odds) {
            this.odds = odds;
        }

        public String getModifyTime() {
            return modifyTime;
        }

        public void setModifyTime(String modifyTime) {
            this.modifyTime = modifyTime;
        }

        @Override
        public String toString() {
            return "Odds{" +
                    "matchId=" + matchId +
                    ", companyId=" + companyId +
                    ", odds=" + odds +
                    ", modifyTime=" + modifyTime +
                    '}';
        }
    }
}

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

Odds{matchId=352677614, companyId=133, odds=[OddsItem{singleRatio='1.95', doubleRatio='1.92', goalsOdds=[GoalsOddsItem{moreThanSix='', twoToThree='', zeroToOne='', fourToSix=''}], halfTotalOdds=[HalfTotalOddsItem{halfStatus='WIN', totalStatus='WIN', ratio=''}, HalfTotalOddsItem{halfStatus='WIN', totalStatus='DRAW', ratio=''}, HalfTotalOddsItem{halfStatus='WIN', totalStatus='LOSE', ratio=''}, HalfTotalOddsItem{halfStatus='DRAW', totalStatus='WIN', ratio=''}, HalfTotalOddsItem{halfStatus='DRAW', totalStatus='DRAW', ratio=''}, HalfTotalOddsItem{halfStatus='DRAW', totalStatus='LOSE', ratio=''}, HalfTotalOddsItem{halfStatus='LOSE', totalStatus='WIN', ratio=''}, HalfTotalOddsItem{halfStatus='LOSE', totalStatus='DRAW', ratio=''}, HalfTotalOddsItem{halfStatus='LOSE', totalStatus='LOSE', ratio=''}], isStop=null}], modifyTime=1571909999}
Odds{matchId=372677616, companyId=133, odds=[OddsItem{singleRatio='1.96', doubleRatio='1.91', goalsOdds=[GoalsOddsItem{moreThanSix='', twoToThree='', zeroToOne='', fourToSix=''}], halfTotalOdds=[HalfTotalOddsItem{halfStatus='WIN', totalStatus='WIN', ratio=''}, HalfTotalOddsItem{halfStatus='WIN', totalStatus='DRAW', ratio=''}, HalfTotalOddsItem{halfStatus='WIN', totalStatus='LOSE', ratio=''}, HalfTotalOddsItem{halfStatus='DRAW', totalStatus='WIN', ratio=''}, HalfTotalOddsItem{halfStatus='DRAW', totalStatus='DRAW', ratio=''}, HalfTotalOddsItem{halfStatus='DRAW', totalStatus='LOSE', ratio=''}, HalfTotalOddsItem{halfStatus='LOSE', totalStatus='WIN', ratio=''}, HalfTotalOddsItem{halfStatus='LOSE', totalStatus='DRAW', ratio=''}, HalfTotalOddsItem{halfStatus='LOSE', totalStatus='LOSE', ratio=''}], isStop=null}], modifyTime=1571909999}
Odds{matchId=392677618, companyId=133, odds=[OddsItem{singleRatio='1.93', doubleRatio='1.94', goalsOdds=[GoalsOddsItem{moreThanSix='', twoToThree='', zeroToOne='', fourToSix=''}], halfTotalOdds=[HalfTotalOddsItem{halfStatus='WIN', totalStatus='WIN', ratio=''}, HalfTotalOddsItem{halfStatus='WIN', totalStatus='DRAW', ratio=''}, HalfTotalOddsItem{halfStatus='WIN', totalStatus='LOSE', ratio=''}, HalfTotalOddsItem{halfStatus='DRAW', totalStatus='WIN', ratio=''}, HalfTotalOddsItem{halfStatus='DRAW', totalStatus='DRAW', ratio=''}, HalfTotalOddsItem{halfStatus='DRAW', totalStatus='LOSE', ratio=''}, HalfTotalOddsItem{halfStatus='LOSE', totalStatus='WIN', ratio=''}, HalfTotalOddsItem{halfStatus='LOSE', totalStatus='DRAW', ratio=''}, HalfTotalOddsItem{halfStatus='LOSE', totalStatus='LOSE', ratio=''}], isStop=null}], modifyTime=1571909999}
原文链接:segmentfault.com

上一篇:[译]如何设计出访问性更佳的搜索栏
下一篇:前端模拟数据jsonServer 和 npm 命令执行合并包

相关推荐

  • 高阶组件 + New Context API = ?

    1. 前言 继上次小试牛刀(https://github.com/SmallStoneSK/Blog/issues/6)尝到高价组件的甜头之后,现已深陷其中无法自拔。。。

    2 年前
  • 重构 - 设计API的扩展机制

    1.前言 上篇文章,主要介绍了重构的一些概念和一些简单的实例。这一次,详细的说下项目中的一个重构场景给API设计扩展机制。目的就是为了方便以后能灵活应对需求的改变。

    2 年前
  • 重新开坑,在 react 中使用 composition API

    emmm大家好,那个,虽然最近新型肺炎,搞的人心惶惶,没啥动力写码 其实我也没啥可写的了,但是闲着也是闲着,然后记起来 smox 弃坑了还有一堆星星,想着怎么重新开坑 背景 smox 弃坑,不是我任性...

    6 个月前
  • 通过简单的示例来理解React Hook

    This hook makes it easy to dynamically change the appearance of your app using CSS variables. You si...

    1 年前
  • 通过示例演示 TypeScript 的高级类型

    原文地址: levelup.gitconnected.com/advancedty… 译文地址:github.com/xiaoT/note… 本文版权归原作者所有,翻译仅用于学习。

    2 个月前
  • 通过示例教你如何打造一个组件库

    2020年大家的flag里有没有造轮子这一项呢?最近终于有空了,打算对组件库下手。 这次重点放在了如何搭建一个组件库上,内容涉及到开源组件库必备的文档、代码规范控制、工程化、编译、单测等各个环节。

    6 个月前
  • 这次,彻底弄懂接口及抽象类

    LoulanPlan(https://img.javascriptcn.com/74c2e8562152e35142b54b56e367a0ca "LoulanPlan") 作者:伯特 出处:g...

    2 年前
  • 软件需要的接口短信功能有哪些?

    很多软件平台需要进行手机验证,需要收取短信验证码,随着科技的发展,手机短信验证码平台行业的发展迅速,而也有很多用户会恶意攻击短信验证码接口,那么对于手机短信验证码平台接口被恶意攻击,该怎么处理呢? ...

    1 年前
  • 足球冠军指数 api接口示例

    分享下足球冠军指数API数据,接口示例如下,可查看在线文档(https://www.shenlu88.com/doc.... 接口返回的是Json数据,可以使用fastjson来解析 API...

    5 个月前
  • 超火js库: Lodash API例子 (持续更新~~~)

    lodash.js是一款超火的js库,在npm上平均周下载量达到了惊人的,github start大量框架都用到了lodash,包括拥有start的vue 本文对比英文文档,加上一些小栗子和个...

    2 年前

官方社区

扫码加入 JavaScript 社区