Рубрики
Uncategorized

Интерфейс API данных Csgo для электронного соревнования – пример кода [индекса реального времени] Вызов API

Автор оригинала: David Wong.

Пример вызова интерфейса API Csgo [индекс реального времени], просмотр онлайн-документов, необходимо зарегистрироваться

mport com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
 
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
 
/**
 *@ API: Odds information
 * @Website: https://www.feijing88.com
 */
public class CsgoBet {
 
 
    public static void main(String[] args) {
        try {
            String content = getContent();
            Respond rsp = JSON.parseObject(content, Respond.class);
            System.out.println(rsp.code);
            System.out.println(rsp.message);
            rsp.getData().forEach(System.out::println);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
 
    /**
     *Get API return content
     * 

*Note: in order to facilitate the test, I used a local file, which should be replaced with the real interface to return the content */ private static String getContent() { try { StringBuilder builder = new StringBuilder(); List lines = Files.readAllLines(Paths.get("./src/main/resources/CsgoBet.json"), StandardCharsets.UTF_8); lines.forEach(builder::append); return builder.toString(); } catch (Throwable t) { t.printStackTrace(); return ""; } } public static class Respond { @JSONField private int code; @JSONField private String message; @JSONField private List data; public int getCode() { return code; } public void setCode(int code) { this.code = code; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public List getData() { return data; } public void setData(List data) { this.data = data; } } public static class Bet { @JSONField private String betId; @JSONField private String matchId; @JSONField private String title; @JSONField private long endTime; @JSONField private int status; @JSONField private String resultId; @JSONField private List options; @JSONField private int betType; @JSONField private int boardNum; @JSONField private String typeDesc; @Override public String toString() { return "Bet{" + "betId='" + betId + '\'' + ", matchId='" + matchId + '\'' + ", title='" + title + '\'' + ", endTime=" + endTime + ", status=" + status + ", resultId='" + resultId + '\'' + ", options=" + options + ", betType=" + betType + ", boardNum=" + boardNum + ", typeDesc='" + typeDesc + '\'' + '}'; } public void setBetId(String betId) { this.betId = betId; } public void setMatchId(String matchId) { this.matchId = matchId; } public void setTitle(String title) { this.title = title; } public void setEndTime(long endTime) { this.endTime = endTime; } public void setStatus(int status) { this.status = status; } public void setResultId(String resultId) { this.resultId = resultId; } public void setOptions(List options) { this.options = options; } public void setBetType(int betType) { this.betType = betType; } public void setBoardNum(int boardNum) { this.boardNum = boardNum; } public void setTypeDesc(String typeDesc) { this.typeDesc = typeDesc; } } public static class Options { @JSONField private String betItemId; @JSONField private String teamId; @JSONField private String name; @JSONField private String odds; @Override public String toString() { return "Options{" + "betItemId='" + betItemId + '\'' + ", teamId='" + teamId + '\'' + ", name='" + name + '\'' + ", odds='" + odds + '\'' + '}'; } public void setBetItemId(String betItemId) { this.betItemId = betItemId; } public void setTeamId(String teamId) { this.teamId = teamId; } public void setName(String name) { this.name = name; } public void setOdds(String odds) { this.odds = odds; } } }

Данные, возвращаемые API, выглядят следующим образом (частично):

200
Success
Betid = 7887031-8 ', matchid = 7887031', title = 'win the whole field', Endtime = 15541848000000, status = 1, ResultID = null ', options = [options {betitemid = 23332075-3-1', teamid = 9966 ', name ='nip', ODS ='1 '}, options {betitemid = 23332075-3-2', teamid = 3202 ', name ='vici', oddds ='13.51 '}], betttype = 1, boardnum = 0, type = 0, type = 0, type = 0, type = 0, type = 0, type = 0, type = 0, type = 0, type = 0, type = 0, bodynumber = 0, type = 0, type = 0, type = 1'}], options {{, betitemid = 23332075-3-2 ', team pedesc =' '}
Betid = 7887031-62 ', matchid = 7887031', title = 'win the whole field', Endtime = 15541848000000, status = 1, ResultID = null ', options = [options {betitemid = 23320775-16-1', teamid = 9966 ', name ='nip', ODS ='1 '}, options {betitemid = 23320775-16-2', teamid = 3202 ', name ='vici', oddds ='13.51 '}], betttype = 1, boardnum = 0, type = 0, type = 0, type = 0, type type = 0, type = 0, type = 0, type = 0, type = 0, type = 1'}, options {{, betitemid = 23320775-16-2 ', teamid = 23320775-16-2', team id = 3202 ', name ='vici desc =' '}
Betid = 7887031-3 ', matchid = 7887031', title = 'win the whole field', Endtime = 15541848000000, status = 1, ResultID = null ', options = [options {betitemid = 23320775-7-1', teamid ='9966 ', name ='nip', ODS ='1.01 '}, options {betitemid = 23320775-7-2', teamid ='3202 ', name ='vici', oddds ='14 '}], betttype = 1, boardnum = 0, typetype = 0, type = 0, typetype = 0, type = 0, type = 0, type = 0, type = 0, type = 1, betttype = 1, bettype = 1, boardnum = 1, boardnum = 0, type = 0, type = 0, type = 0, type = 0, type = 0, type = 0, desc =' '}
Betid = 7887031-66 ', matchid = 7887031', title = 'win the whole field', Endtime = 15541848000000, status = 1, ResultID = null ', options = [options {betitemid = 23332075-11-1', teamid ='9966 ', name ='nip', ODS ='1.01 '}, options {betitemid = 23332075-11-2', teamid ='3202 ', name ='vici', ODS ='14 '}], betttype = 1, boardnum = 0, typetype = 0, typetype = 0, type = 0, type = 0, type = 0, type = 0, type = 0, type = 0, ODS ='1.01'}, options {{, betitemid = 23332075-11-2 ', teamid ='3202', team id ='3202 ', name ='vici', ODS ='desc = ''}
Betid = 7887031-69 ', matchid = 7887031', title = 'win the whole field', Endtime = 15541848000000, status = 1, ResultID = null ', options = [options {betitemid = 23332075-14-1', teamid = 9966 ', name ='nip', ODS ='1 '}, options {betitemid = 23320775-14-2', teamid = 3202 ', name ='vici', oddds ='11 '}], betttype = 1, boardnum = 0, typedesc = 0, typedesc = 0, typedesc = type = 1, type = 1, boardnum = 0, typedesc = 0, typedesc = 0, typedesc = 0, type = 1'}, options {[betitemid = 23332075-14-2 ', teamid = 23332075-14-2', = ''}
Betid = 7887031-2 ', matchid = 7887031', title = 'win the whole field', Endtime = 15541848000000, status = 1, ResultID = null ', options = [options {betitemid = 23332075-6-1', teamid = 9966 ', name ='nip', ODS = 1.22 '}, options {betitemid = 23332075-6-2', teamid = 3202 ', name ='vici', ODS ='4 '}], betttype = 1, boardnum = 0, typetype = 0, type = 0, type = 0, type = 0, type = 0, type = 0, type = 0, type = 0, ODS ='1.22'}, options {{, betitemid = 23332075-6-2 ', teamid = 3202', team id ='3202 ', name ='vici', ODS ='4 desc = ''}

Оригинал: “https://developpaper.com/csgo-data-api-interface-of-e-competition-example-code-of-real-time-index-api-call/”