First / last goal index API interface example

Time:2020-1-23

Share the football special index data, first / last goal loss API interface examples, see the online documents for details
The interface returns JSON data, which can be parsed using 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();
        }
    }

    /**
     *Get API return content
     */
    private static String getContent() {

        //Set interface parameters
        String type = "6002"; // loss type, 4-digit number, the first / last goal loss is 6002
        String token = "mytoken"; // communication token, [replace with the token assigned to yourself]
        String format = "JSON"; // returns the format, which is JSON by default

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

        //Call shenlu data API to get the loss result in JSON string format
        String charset = "UTF-8";
        String jsonResult = get(url, charset);

        return jsonResult;
    }

    /**
     *@ param URL: request interface
     *@ param charset: character encoding
     *@ return returns the JSON string
     */
    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 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<OddsItems> 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<OddsItems> getOdds() {
            return odds;
        }

        public void setOdds(List<OddsItems> 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 return data is as follows (partial):

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}