怎样调用php的足球联赛接口,基于php的足球联赛查询接口调用代码实例

编程入门 行业动态 更新时间:2024-10-07 02:27:04

怎样调用php的<a href=https://www.elefans.com/category/jswz/34/1739740.html style=足球联赛接口,基于php的足球联赛查询接口调用代码实例"/>

怎样调用php的足球联赛接口,基于php的足球联赛查询接口调用代码实例

基于php的足球联赛查询接口调用代码实例

// +----------------------------------------------------------------------

//----------------------------------

// 足球联赛调用示例代码 - 聚合数据

// 在线接口文档:

//----------------------------------

header('Content-type:text/html;charset=utf-8');

//配置您申请的appkey

$appkey = "*********************";

//************1.足球联赛赛事查询************

$url = "";

$params = array(

"key" => $appkey,//应用APPKEY(应用详细页查询)

"dtype" => "",//返回数据的格式,xml或json,默认json

"league" => "",//联赛名称

);

$paramstring = http_build_query($params);

$content = juhecurl($url,$paramstring);

$result = json_decode($content,true);

if($result){

if($result['error_code']=='0'){

print_r($result);

}else{

echo $result['error_code'].":".$result['reason'];

}

}else{

echo "请求失败";

}

//**************************************************

//************2.球队赛事查询************

$url = "";

$params = array(

"key" => $appkey,//应用APPKEY(应用详细页查询)

"dtype" => "",//返回数据的格式,xml或json,默认json

"team" => "",//球队名称

);

$paramstring = http_build_query($params);

$content = juhecurl($url,$paramstring);

$result = json_decode($content,true);

if($result){

if($result['error_code']=='0'){

print_r($result);

}else{

echo $result['error_code'].":".$result['reason'];

}

}else{

echo "请求失败";

}

//**************************************************

//************3.球队对战赛赛程查询************

$url = "";

$params = array(

"key" => $appkey,//应用APPKEY(应用详细页查询)

"dtype" => "",//返回数据的格式,xml或json,默认json

"hteam" => "",//主队球队名称

"vteam" => "",//客队球队名称

);

$paramstring = http_build_query($params);

$content = juhecurl($url,$paramstring);

$result = json_decode($content,true);

if($result){

if($result['error_code']=='0'){

print_r($result);

}else{

echo $result['error_code'].":".$result['reason'];

}

}else{

echo "请求失败";

}

//**************************************************

/**

* 请求接口返回内容

* @param string $url [请求的URL地址]

* @param string $params [请求的参数]

* @param int $ipost [是否采用POST形式]

* @return string

*/

function juhecurl($url,$params=false,$ispost=0){

$httpInfo = array();

$ch = curl_init();

curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );

curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );

curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );

curl_setopt( $ch, CURLOPT_TIMEOUT , 60);

curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

if( $ispost )

{

curl_setopt( $ch , CURLOPT_POST , true );

curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );

curl_setopt( $ch , CURLOPT_URL , $url );

}

else

{

if($params){

curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );

}else{

curl_setopt( $ch , CURLOPT_URL , $url);

}

}

$response = curl_exec( $ch );

if ($response === FALSE) {

//echo "cURL Error: " . curl_error($ch);

return false;

}

$httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );

$httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );

curl_close( $ch );

return $response;

}

更多推荐

怎样调用php的足球联赛接口,基于php的足球联赛查询接口调用代码实例

本文发布于:2024-03-23 15:24:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1739738.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:足球联赛   接口   实例   代码   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!