基于php的万年历接口调用代码实例

基于php的万年历接口调用代码实例

代码描述:基于php的万年历接口调用代码实例 代码平台:聚合数据

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

// | JuhePHP [ NO ZUO NO DIE ]

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

// | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.

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

// | Author: Juhedata

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

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

// 万年历调用示例代码 - 聚合数据

// 在线接口文档:http://www.juhe.cn/docs/177 //----------------------------------

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

//配置您申请的appkey

$appkey = \;

//************1.获取当天的详细信息************ $url = \; $params = array(

\ => $appkey,//您申请的appKey

\ => \,//指定日期,格式为YYYY-MM-DD,如月份和日期小于10,则取个位,如:2012-1-1 );

$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(

\ => $appkey,//您申请的appKey

\ => \,//指定月份,格式为YYYY-MM,如月份和日期小于10,则取个位,如:2012-1 );

$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(

\ => $appkey,//您申请的appKey

\ => \,//指定年份,格式为YYYY,如:2015 );

$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 ); }

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4