新聞中心
本篇內(nèi)容介紹了“php如何查詢星座運勢”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比巴彥淖爾網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式巴彥淖爾網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋巴彥淖爾地區(qū)。費用合理售后完善,10余年實體公司更值得信賴。
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怎么查詢星座運勢?
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)用詳細頁查詢)
"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;
}
“php如何查詢星座運勢”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
文章題目:php如何查詢星座運勢
URL網(wǎng)址:http://fisionsoft.com.cn/article/gccgog.html