分享下足球特殊指数数据,单双、总进球数、半全场赔率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}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。