日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

php 菜谱 源码,基于php的菜谱大全api调用代码实例

發(fā)布時間:2025/4/5 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 菜谱 源码,基于php的菜谱大全api调用代码实例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

代碼描述:基于php的菜譜大全api調(diào)用代碼實例

接口地址:http://www.juhe.cn/docs/api/id/46

PHP代碼

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

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

// 菜譜大全調(diào)用示例代碼 - 聚合數(shù)據(jù)

// 在線接口文檔:http://www.juhe.cn/docs/46

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

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

//配置您申請的appkey

$appkey = "*********************";

//************1.菜譜大全************

$url = "http://apis.juhe.cn/cook/query.php";

$params = array(

"menu" => "",//需要查詢的菜譜名

"key" => $appkey,//應用APPKEY(應用詳細頁查詢)

"dtype" => "",//返回數(shù)據(jù)的格式,xml或json,默認json

"pn" => "",//數(shù)據(jù)返回起始下標

"rn" => "",//數(shù)據(jù)返回條數(shù),最大30

"albums" => "",//albums字段類型,1字符串,默認數(shù)組

);

$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 = "http://apis.juhe.cn/cook/category";

$params = array(

"parentid" => "",//分類ID,默認全部

"key" => $appkey,//應用APPKEY(應用詳細頁查詢)

"dtype" => "",//返回數(shù)據(jù)的格式,xml或json,默認json

);

$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 = "http://apis.juhe.cn/cook/index";

$params = array(

"cid" => "",//標簽ID

"key" => $appkey,//應用APPKEY(應用詳細頁查詢)

"dtype" => "",//返回數(shù)據(jù)的格式,xml或json,默認json

"pn" => "",//數(shù)據(jù)返回起始下標,默認0

"rn" => "",//數(shù)據(jù)返回條數(shù),最大30,默認10

"format" => "",//steps字段屏蔽,默認顯示,format=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 "請求失敗";

}

//**************************************************

//************4.按菜譜ID查看詳細************

$url = "http://apis.juhe.cn/cook/queryid";

$params = array(

"id" => "",//菜譜的ID

"key" => $appkey,//應用APPKEY(應用詳細頁查詢)

"dtype" => "",//返回數(shù)據(jù)的格式,xml或json,默認json

);

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

}

本文原創(chuàng)發(fā)布php中文網(wǎng),轉(zhuǎn)載請注明出處,感謝您的尊重!

總結(jié)

以上是生活随笔為你收集整理的php 菜谱 源码,基于php的菜谱大全api调用代码实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。