|
基于php的萬年歷接口調(diào)用代碼實例 代碼描述:基于php的萬年歷接口調(diào)用代碼實例 代碼平臺:聚合數(shù)據(jù) <?php //---------------------------------- // 萬年歷調(diào)用示例代碼 , 聚合數(shù)據(jù) // 在線接口文檔: //---------------------------------- header('Content-type:text/html;charset=utf-8' ); //配置您申請的appkey $appkey = "*********************"; //************1.獲取當(dāng)天的詳細(xì)信息************ $url = ";ar/day" ; $params = array( "key" => $appkey,//您申請的appKey "date" => "",//指定日期,格式為YYYY-MM-DD,如月份和日期小于10,則取個位,如:2012-1-1 ); $paramstring = http_build_query($params );$conten = juhecutrl($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.獲取當(dāng)月近期假期************ $url = ;ar/month" ;$params = array( "key" => $appkey,//您申請的appKey "year-month" => "",//指定月份,格式為YYYY-MM,如月份和日期小于10,則取 個位,如:2012-1 ); $paramstring = http_build_query($params );$conten = juhecutrl($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.獲取當(dāng)年的假期列表************ $url = ";ar/year" ;$params = array( "key" => $appkey,//您申請的appKey "year" => "",//指定年份,格式為YYYY,如:2015 ); $paramstring = http_build_query($params );$conten = juhecutrl($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 "請求失敗"; } //************************************************** /** * 請求接口返回內(nèi)容 * @param string $url [請求的URL地址 ] * @param string $params [請求的參數(shù)] * @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 , 'JuheDa ); ta' 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( $httpIn , curl_gfoetinfo( $ch) ); curl_close( $ch ); return $response ; }
信息發(fā)布:廣州名易軟件有限公司 http://www.jetlc.com
|