日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

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

發(fā)布時間:2025/4/5 php 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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,//應(yīng)用APPKEY(應(yīng)用詳細(xì)頁查詢)

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

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

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

"albums" => "",//albums字段類型,1字符串,默認(rèn)數(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.分類標(biāo)簽列表************

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

$params = array(

"parentid" => "",//分類ID,默認(rèn)全部

"key" => $appkey,//應(yīng)用APPKEY(應(yīng)用詳細(xì)頁查詢)

"dtype" => "",//返回數(shù)據(jù)的格式,xml或json,默認(rèn)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.按標(biāo)簽檢索菜譜************

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

$params = array(

"cid" => "",//標(biāo)簽ID

"key" => $appkey,//應(yīng)用APPKEY(應(yīng)用詳細(xì)頁查詢)

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

"pn" => "",//數(shù)據(jù)返回起始下標(biāo),默認(rèn)0

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

"format" => "",//steps字段屏蔽,默認(rèn)顯示,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查看詳細(xì)************

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

$params = array(

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

"key" => $appkey,//應(yīng)用APPKEY(應(yīng)用詳細(xì)頁查詢)

"dtype" => "",//返回數(shù)據(jù)的格式,xml或json,默認(rèn)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)容還不錯,歡迎將生活随笔推薦給好友。