最先/最后进球指数 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 GoalOrderOdds {
    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 = "6002";              // 赔率类型,4 位数字编号,最先/最后进球赔率为6002
        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;

        public List getOdds() {
            return odds;
        }

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

    public static class OddsItems {
        @JSONField(name = "first_is_home_ratio")
        private String firstIsHomeRatio;
        @JSONField(name = "first_is_away_ratio")
        private String firstIsAwayRatio;
        @JSONField(name = "last_is_home_ratio")
        private String lastIsHomeRatio;
        @JSONField(name = "last_is_away_ratio")
        private String lastIsAwayRatio;
        @JSONField(name = "no_goal_ratio")
        private String noGoalRatio;

        public String getFirstIsHomeRatio() {
            return firstIsHomeRatio;
        }

        public void setFirstIsHomeRatio(String firstIsHomeRatio) {
            this.firstIsHomeRatio = firstIsHomeRatio;
        }

        public String getFirstIsAwayRatio() {
            return firstIsAwayRatio;
        }

        public void setFirstIsAwayRatio(String firstIsAwayRatio) {
            this.firstIsAwayRatio = firstIsAwayRatio;
        }

        public String getLastIsHomeRatio() {
            return lastIsHomeRatio;
        }

        public void setLastIsHomeRatio(String lastIsHomeRatio) {
            this.lastIsHomeRatio = lastIsHomeRatio;
        }

        public String getLastIsAwayRatio() {
            return lastIsAwayRatio;
        }

        public void setLastIsAwayRatio(String lastIsAwayRatio) {
            this.lastIsAwayRatio = lastIsAwayRatio;
        }

        public String getNoGoalRatio() {
            return noGoalRatio;
        }

        public void setNoGoalRatio(String noGoalRatio) {
            this.noGoalRatio = noGoalRatio;
        }

        @Override
        public String toString() {
            return "{" +
                    "firstIsHomeRatio='" + firstIsHomeRatio + '\'' +
                    ", firstIsAwayRatio=" + firstIsAwayRatio +
                    ", lastIsHomeRatio=" + lastIsHomeRatio +
                    ", lastIsAwayRatio=" + lastIsAwayRatio +
                    ", noGoalRatio=" + noGoalRatio +
                    '}';
        }
    }

    public static class Odds {
        @JSONField(name = "match_id")
        private String matchId;
        @JSONField(name = "company_id")
        private String companyId;
        @JSONField(name = "odds")
        private List 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 getOdds() {
            return odds;
        }

        public void setOdds(List 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=281243716, companyId=133, odds=[{firstIsHomeRatio='1.9', firstIsAwayRatio=1.85, lastIsHomeRatio=1.9, lastIsAwayRatio=1.85, noGoalRatio=18.5}], modifyTime=1571591064}
Odds{matchId=397712714, companyId=133, odds=[{firstIsHomeRatio='1.99', firstIsAwayRatio=1.84, lastIsHomeRatio=1.99, lastIsAwayRatio=1.84, noGoalRatio=13.5}], modifyTime=1571573896}
Odds{matchId=241243712, companyId=133, odds=[{firstIsHomeRatio='2.22', firstIsAwayRatio=1.63, lastIsHomeRatio=2.22, lastIsAwayRatio=1.63, noGoalRatio=17.5}], modifyTime=1571596475}
Odds{matchId=376436714, companyId=133, odds=[{firstIsHomeRatio='1.86', firstIsAwayRatio=2.02, lastIsHomeRatio=1.86, lastIsAwayRatio=2.02, noGoalRatio=11.5}], modifyTime=1570102937}
Odds{matchId=376436714, companyId=111, odds=[{firstIsHomeRatio='1.88', firstIsAwayRatio=1.94, lastIsHomeRatio=0, lastIsAwayRatio=0, noGoalRatio=13}], modifyTime=1569850871}

你可能感兴趣的:(javascript,jquery,html5)