php查詢星座運勢的方法:1、開通星座運勢API接口;2、創(chuàng)建PHP示例文件;3、請求接口URL;4、配置申請的appkey;5、發(fā)起接口網(wǎng)絡(luò)請求;6、通過“function juhecurl($url,$params=false,$ispost=0){…}”方式請求接口返回內(nèi)容,再根據(jù)業(yè)務(wù)實際邏輯調(diào)整修改即可。
php入門到就業(yè)線上直播課:進(jìn)入學(xué)習(xí)
Apipost = Postman + Swagger + Mock + Jmeter 超好用的API調(diào)試工具:點擊使用
本教程操作環(huán)境:windows7系統(tǒng)、PHP8.1版、Dell G3電腦。
php怎么查詢星座運勢?
1、開通星座運勢API接口:
通過https://www.juhe.cn/docs/api/id/58?s=cpphpcn
注冊及開通
接口說明:(十二星座的今日運勢)
-
12星座運勢解析
-
解析內(nèi)容全面,有今日運勢解析,明日運勢解析及本周運勢解析
-
解析內(nèi)容新穎,個人運勢解析,貴人運勢分析,需提防事宜等。
2、基于php的星座運勢接口調(diào)用示例
代碼示例:
// 星座運勢調(diào)用示例代碼 header('Content-type:text/html;charset=utf-8'); //配置您申請的appkey $appkey = "*********************"; //************1.運勢查詢************ $url = "http://web.juhe.cn:8080/constellation/getAll"; $params = array( "key" => $appkey,//應(yīng)用APPKEY(應(yīng)用詳細(xì)頁查詢) "consName" => "",//星座名稱,如:白羊座 "type" => "",//運勢類型:today,tomorrow,week,nextweek,month,year ); $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 "請求失敗"; } //************************************************** /** * 請求接口返回內(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 , '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 ); } 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( $httpInfo , curl_getinfo( $ch ) ); curl_close( $ch ); return $response; }
登錄后復(fù)制
推薦學(xué)習(xí):《PHP視頻教程》