《基于php的万年历接口调用代码实例》由会员分享,可在线阅读,更多相关《基于php的万年历接口调用代码实例(4页珍藏版)》请在金锄头文库上搜索。
1、基于 php 的万年历接口调用代码实例代码描述:基于 php 的万年历接口调用代码实例代码平台:聚合数据/ +- -/- / 万年历调用示例代码 聚合数据 / 在线接口文档:http:/ appkey$appkey = “*“;/*1.获取当天的详细信息*$url = “http:/ $params = array(“key“ = $appkey,/您申请的 appKey“date“ = “,/指定日期,格式为 YYYY-MM-DD,如月份和日期小于 10,则取个位,如:2012-1-1 );$paramstring = http_build_query($params); $content
2、= juhecurl($url,$paramstring); $result = json_decode($content,true); if($result)if($resulterror_code=0)print_r($result);elseecho $resulterror_code.“:“.$resultreason; elseecho “请求失败“; /*/*2.获取当月近期假期*$url = “http:/ $params = array(“key“ = $appkey,/您申请的 appKey“year-month“ = “,/指定月份,格式为 YYYY-MM,如月份和日期小于
3、 10,则取个位,如:2012-1 ); $paramstring = http_build_query($params); $content = juhecurl($url,$paramstring); $result = json_decode($content,true); if($result)if($resulterror_code=0)print_r($result);elseecho $resulterror_code.“:“.$resultreason; elseecho “请求失败“; /*/*3.获取当年的假期列表*$url = “http:/ $params = arra
4、y(“key“ = $appkey,/您申请的 appKey“year“ = “,/指定年份,格式为 YYYY,如:2015); $paramstring = http_build_query($params); $content = juhecurl($url,$paramstring); $result = json_decode($content,true); if($result)if($resulterror_code=0)print_r($result);elseecho $resulterror_code.“:“.$resultreason; elseecho “请求失败“; /
5、*/* 请求接口返回内容* 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_USERA
6、GENT , 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 , $pa
7、rams );curl_setopt( $ch , CURLOPT_URL , $url );elseif($params)curl_setopt( $ch , CURLOPT_URL , $url.?.$params );elsecurl_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;