当前位置: 首页 > 后端技术 > PHP

如何获得足球比赛的实时赔率?

时间:2023-03-30 01:45:47 PHP

在线接口调用文档https://www.feijing88.com/foo...,需要注册下packagecom.huaying.demo.football;importjavax.xml.bind.JAXBContext;importjavax.xml.bind.Unmarshaller;importjavax.xml.bind.annotation.XmlElement;导入javax.xml.bind.annotation.XmlRootElement;导入java.io.ByteArrayInputStream;导入java.nio.charset.StandardCharsets;导入java.nio.file.Files;导入java.nio.file.Paths;importjava.util.List;/***@API:14.百家欧赔接口*@Website:https://www.feijing88.com*/publicclassFootballOdds100{publicstaticvoidmain(String[]args){try{Stringcontent=getContent();JAXBContextjaxbContext=JAXBContext.newInstance(MatchList.class);解组器unmarshaller=jaxbContext.createUnmarshaller();MatchListmatchList=(MatchList)unmarshaller.unmarshal(newByteArrayInputStream(content.getBytes()));matchList.getMatchList().forEach(item->System.out.println(item));}赶上(可抛t){t.printStackTrace();}}/***获取API返回的内容**注意:我这里为了测试方便,使用了本地文件,需要替换为真实接口返回的内容*/privatestaticStringgetContent(){尝试{StringBuilder构建器=newStringBuilder();Listlines=Files.readAllLines(Paths.get("./src/main/resources/FootballBet100.xml"),StandardCharsets.UTF_8);lines.forEach(line->builder.append(line));返回builder.toString();}catch(Throwablet){t.printStackTrace();返回””;}}@XmlRootElement(name="c")publicstaticclassMatchList{privateListmatchList;@XmlElement(name="h")publicListgetMatchList(){returnmatchList;}publicvoidsetMatchList(ListmatchList){this.matchList=matchList;}}公共静态类匹配{@XmlElement(name="id")privateStringmatchId;@XmlElement(name="time")privateStringmatchTime;@XmlElement(name="league")privateStringleagueName;@XmlElement(name="home")privateStringhomeTeamName;@XmlElement(name="away")privateStringawayTeamName;@XmlElement(name="odds")privateListoddsList;@OverridepublicStringtoString(){return"Match{"+"matchId='"+matchId+'\''+",matchTime='"+matchTime+'\''+",leagueName='"+leagueName+'\''+",homeTeamName='"+homeTeamName+'\''+",awayTeamName='"+awayTeamName+'\''+",oddsList="+oddsList+'}';}publicStringgetMatchId(){返回matchId;}公共字符串getMatchTime()}publicStringgetLeagueName(){返回联赛名称;}publicStringgetHomeTeamName(){returnhomeTeamName;}publicStringgetAwayTeamName(){returnawayTeamName;}publicListgetOddsList(){returnoddsList;staticclassOdds{@XmlElement(name="o")privateStringitem;@OverridepublicStringtoString(){return"Odds{"+"item='"+item+'\''+'}';}publicStringgetItem(){返回项目;}}}请输入代码API返回数据如下:Match{matchId='1755160',matchTime='2019/7/2217:30:00',leagueName='INTCF,clubFriendship,clubfriendship',homeTeamName='Caldas,Caldas,Caldas',awayTeamName='Al-Nasr(KSA),Al-Nasr,Al-Nasr',oddsList=[Odds{item='null'}]}Match{matchId='1755377',matchTime='2019/7/2217:45:00',leagueName='CFL,CarlUnited,CarlUnited',homeTeamName='WBPoliceSC,WBPoliceSC,WBPoliceSC',awayTeamName='CFC,CFC,CFC',oddsList=[Odds{item='281,Bet365,1.8,3,4.5,,,,2019/7/2215:28:00,bet365(英国)'}]}比赛{matchId='1700121',matchTime='2019/7/2218:00:00',leagueName='KORWD1,KoreanWomen'sLeague,KoreanWomen'sLeague',homeTeamName='BoeunSangmu(w),BoeunSangmuWomen'sFootball,BoeunSangmuWomen'sFootball',awayTeamName='GyeongjuFCW,GyeongjuFCWomen'sFootball,GyeongjuFCWomen'sFootball',oddsList=[Odds{item='1047,1xBet,4.56,4.1,1.63,4.58,4.28,1.6,2019/7/2214:44:00,1xBet'}]}比赛{matchId='1700123',matchTime='2019/7/2218:00:00',leagueName='KORWD1,KoreanWomen'sLeague,KoreanWomen'sLeague',homeTeamName='HyundaiSteelRedAngels(w),HyundaiSteelWomen'sFootball,HyundaiSteelWomen'sFootball',awayTeamName='KSPOFC(w),华川KSPO女足,华川KSPO女足',oddsList=[Odds{item='1231,LeonBets,1.51,4.45,5.15,1.41,4.8,6.25,2019/7/2217:36:00,莱昂投注'}]}