{ "reason": "successed", "result": { "id": "1657", "yangli": "2014-09-11", "yinli": "甲午(马)年八月十八", "wuxing": "井泉水 建执位", "chongsha": "冲兔(己卯)煞东", "baiji": "乙不栽植千株不长 酉不宴客醉坐颠狂", "jishen": "官日 六仪 益後 月德合 除神 玉堂 鸣犬", "yi": "祭祀 出行 扫舍 馀事勿取", "xiongshen": "月建 小时 土府 月刑 厌对 招摇 五离", "ji": "诸事不宜" }, "error_code": 0 }
<?php /** * Created by PhpStorm. * User: FZS * Time: 2019/3/15 17:50 */ //---------------------------------- // 聚合 老黄历 调用类 //---------------------------------- class freeApi{ private $apiKey = false; //聚合appkey private $apiUrl = 'http://v.juhe.cn/laohuangli/d'; public function __construct($apikey){ $this->apiKey = $apikey; } /** * 将JSON内容转为数据,并返回 * @param string $content [内容] * @return array */ public function returnArray($content){ return json_decode($content,true); } /** * 获取 老黄历 结果 * @return array */ public function getResult(){ $params = [ "key" => $this->apiKey,//应用APPKEY(应用详细页查询) "date" => "",//日期,格式2014-09-09 ]; $params = http_build_query($params); return $this->returnArray($this->freeApiCurl($this->apiUrl,$params,1)); } /** * 请求接口返回内容 * @param string $url [请求的URL地址] * @param string $params [请求的参数] * @param int $ipost [是否采用POST形式] * @return string */ public function freeApiCurl($url,$params=false,$ispost=0){ $ch = curl_init(); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_USERAGENT , 'chuanshuoapi' ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 ); curl_setopt( $ch, CURLOPT_TIMEOUT , 60); curl_setopt( $ch, CURLOPT_RETURNTRANSFER , 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) { return false; } curl_close( $ch ); return $response; } }