基于php的万年历接口调用代码实例 代码描述:基于php的万年历接口调用代码实例 代码平台:聚合数据 <?php //---------------------------------- // 万年历调用示例代码 , 聚合数据 // 在线接口文档: //---------------------------------- header('Content-type:text/html;charset=utf-8' ); //配置您申请的appkey $appkey = "*********************"; //************1.获取当天的详细信息************ $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.获取当月近期假期************ $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.获取当年的假期列表************ $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 "请求失败"; } //************************************************** /** * 请求接口返回内容 * @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 , '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 ; }
信息发布:广州名易软件有限公司 http://www.myidp.net
|