分享使用 飞鲸体育数据 www.feijing88.com 接口调用的示例代码,DOTA2的【即时指数】接口。
import 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: 赔率信息
* @Website: https://www.feijing88.com
*/
public class DotaBet {
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();
}
}
/**
* 获取API返回内容
*
* Note: 这里为了方便测试我使用了一份本地文件,使用时应替换为真实接口返回内容
*/
private static String getContent() {
try {
StringBuilder builder = new StringBuilder();
List lines = Files.readAllLines(Paths.get("./src/main/resources/DotaBet.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
成功
Bet{betId='57277', matchId='X00009233', title='猜输赢', endTime=0, status=3, resultId='None-1', options=[Options{betItemId='None-1', teamId='79867', name='Chaos Esports Club', odds='1.95'}, Options{betItemId='None-2', teamId='79154', name='Team Aster', odds='1.95'}], betType=1, boardNum=0, typeDesc=''}
Bet{betId='387n07m7710jkm128mm7k1128m5m0njk', matchId='X00009233', title='全场获胜者', endTime=0, status=2, resultId='null', options=[Options{betItemId='732f02e2250bce563ee2c5563e9e0fbc-1', teamId='79154', name='Aster', odds='1.87'}, Options{betItemId='732f02e2250bce563ee2c5563e9e0fbc-2', teamId='79867', name='Chaos', odds='1.89'}], betType=1, boardNum=0, typeDesc=''}
Bet{betId='k18172792m4ik5j002ni5jm146770383', matchId='X00009233', title='第1局获胜者', endTime=0, status=2, resultId='null', options=[Options{betItemId='c53526246e8ac9b006fa9be581220737-1', teamId='79154', name='Aster', odds='8.5'}, Options{betItemId='c53526246e8ac9b006fa9be581220737-2', teamId='79867', name='Chaos', odds='1.05'}], betType=2, boardNum=1, typeDesc=''}
Bet{betId='1833n43l29jl6840nk3km65m0j4jn174', matchId='X00009233', title='第1局率先获得一血', endTime=0, status=2, resultId='null', options=[Options{betItemId='5377f87d64bd1380fc7ce19e0b8bf528-1', teamId='79154', name='Aster', odds='1.37'}, Options{betItemId='5377f87d64bd1380fc7ce19e0b8bf528-2', teamId='79867', name='Chaos', odds='2.28'}], betType=4, boardNum=1, typeDesc=''}
Bet{betId='41n0919i2571i7li4444in8273m598ln', matchId='X00009233', title='第1局率先获得十杀(+10)', endTime=0, status=2, resultId='null', options=[Options{betItemId='85f0454a6925a2da8888af3627e943df-1', teamId='79154', name='Aster', odds='1.74'}, Options{betItemId='85f0454a6925a2da8888af3627e943df-2', teamId='79867', name='Chaos', odds='1.96'}], betType=6, boardNum=1, typeDesc='+10'}
Bet{betId='0653n370j1lnk76nj3kl98mn19j270k1', matchId='X00009233', title='第2局获胜者', endTime=0, status=2, resultId='null', options=[Options{betItemId='0197f720b5dfc21fb7cd43ef54b620c5-1', teamId='79154', name='Aster', odds='2.03'}, Options{betItemId='0197f720b5dfc21fb7cd43ef54b620c5-2', teamId='79867', name='Chaos', odds='1.73'}], betType=2, boardNum=2, typeDesc=''}