站長資訊網
        最全最豐富的資訊網站

        php怎么查詢笑話大全

        php查詢笑話大全的方法:1、開通笑話大全接口服務,獲取接口的調用憑證請求key;2、調用接口API發出請求,獲取查詢結果(json格式);3、使用json_decode()將查詢內容解析成數組;4、打印解析后的內容,例“var_dump(結果數組);”。

        php怎么查詢笑話大全

        php入門到就業線上直播課:進入學習
        Apipost = Postman + Swagger + Mock + Jmeter 超好用的API調試工具:點擊使用

        本教程操作環境:windows7系統、PHP8.1版、DELL G3電腦

        基于PHP的笑話大全接口調用示例

        前期準備

        • 申請接口

          通過 https://www.juhe.cn/docs/api/id/95?s=cpphpcn 自助申請開通接口

        • 獲取接口的調用憑證請求key

          可以在個人中心 ➡️ 數據中心 ➡️ 我的API 模塊看到此接口的調用憑證請求key

        請仔細閱讀官網的接口文檔,這是聚合數據與開發者的約定,它將有助于您對接口業務的理解,從而順利地開展開發工作

        1.隨機獲取笑話接口

        請求參數

        名稱 必填 類型 說明
        key string 在個人中心->我的數據,接口名稱上方查看

        代碼示例

        //請求的接口URL $apiUrl = 'http://v.juhe.cn/joke/randJoke.php';  //請求參數 $params = [     'key' => '聚合數據上申請的接口調用key', ]; //參數數組轉換成字符串 $paramsString = http_build_query($params);  //發起接口網絡請求 $response = null; try {     $response = juheHttpRequest($apiUrl, $paramsString, 1); } catch (Exception $e) {     var_dump($e);     //此處根據自己的需求進行具體的異常處理 } if (!$response) {     echo '請求異常' . PHP_EOL; } //接收接口返回內容 $result = json_decode($response, true); if (!$result) {     echo '請求異常' . PHP_EOL; } $errorCode = $result['error_code']; if ($errorCode == 0) {     $data = $result['result']; } else {     echo "請求異常:{$errorCode}_{$result['reason']}" . PHP_EOL; } //打印接口返回結果 var_dump($result);  /**  * 發起網絡請求函數  * @param String $url 請求的URL  * @param bool $params  請求的參數內容  * @param int $isPost   是否POST請求  * @return bool|string  返回內容  */ function juheHttpRequest($url, $params = false, $isPost = 0) {     $httpInfo = [];     $ch = curl_init();      curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);     curl_setopt($ch, CURLOPT_USERAGENT,  'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36');     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);     curl_setopt($ch, CURLOPT_TIMEOUT, 12);     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);         }     }     $reponse = curl_exec($ch);     if ($reponse === 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 $reponse; }
        登錄后復制

        返回結果示例

        array(3) {   ["reason"]=>   string(7) "success"   ["result"]=>   array(10) {     [0]=>     array(3) {       ["content"]=>       string(395) "【落馬官員的基本特征】 嘴上學雷鋒,心里學和珅; 贊揚焦裕祿,看齊雷政富; 都像孔繁森,全是王寶森; 八榮是講話通稿,八恥是行為準則; 以黨性作保證,以異性為獵物; 脫了褲子嫖妓,穿上褲子掃黃; 以國為家,國產變私產,愛民若子,民脂刮不止; 白天文明不精神,晚上精神不文明。"       ["hashId"]=>       string(32) "DE693E907034ADD4ABCF591B8181C13A"       ["unixtime"]=>       int(1425001334)     }     [1]=>     array(3) {       ["content"]=>       string(235) "‍‍昨晚和老婆吵架了。 老婆:“氣死我了,我要罵人了!” 然后,她對著我家汪汪一個勁的罵啊! 我:“我在這呢!你怎么罵汪汪啊?” 老婆回話了:“你!你還是人嗎!”"       ["hashId"]=>       string(32) "88C00FC1B66D1EDA7912E54A2D6E0F89"       ["unixtime"]=>       int(1425001344)     }     [2]=>     array(3) {       ["content"]=>       string(363) "  一次,我在公園玩悠悠球,一個小朋友跑過來問我:“哥哥,你玩的是什么呀?讓我看看好嗎?“我笑瞇瞇的答應,把悠悠球給了他,這時那小朋友的媽媽來了,小朋友舉著我的悠悠球對他媽媽說:“媽媽,你看,這是哥哥送我的。”他媽媽說:“那還不快謝謝哥哥!”"       ["hashId"]=>       string(32) "9779B468CDE58940AABB7E826CB677D0"       ["unixtime"]=>       int(1425001379)     }     [3]=>     array(3) {       ["content"]=>       string(243) "家里鬧耗子了,問同事:你家里有貓不,借我養兩天,嚇嚇老鼠。同事賤笑地對我說:不行,是母貓。艸,當哥沒看過段子嗎?回了句:哦,那你留著,自己用。留同事在風中凌亂……"       ["hashId"]=>       string(32) "98b9e3b27c3ac6c44d61ffa84e8a3a11"       ["unixtime"]=>       int(1425001431)     }     [4]=>     array(3) {       ["content"]=>       string(837) "無論遇到什么事情;不要輕易說分手;不要輕易放棄感情;更別拿什么緣淺當借口;有時候感情差的就是一個轉身而已;下一站未必會更好;感情再深;你不去呵護;慢慢就淡了;許多熟悉的事;你不去回味;漸漸就忘了;微笑;因一個人而起;痛苦;因一個人而生;一次冷落;會悶悶不樂;一句想你;會倍感幸福;所以;當愛在時;就要好好去珍惜;好緣分可遇不可求;有緣的人才能聚首;真感情可守不可丟;有愛的心永不說分手;別把真心愛過;變成曾經擁有;別把一次過錯;變成一生錯過;原諒并不難;只要感情深;永遠并不遠,只要彼此真。在一起不是說說而已,而是用心珍惜;真情意不是一時興起;而是一世相依!"       ["hashId"]=>       string(32) "FC065A2FDFB0E7B1A661C08403C22153"       ["unixtime"]=>       int(1425001924)     }     [5]=>     array(3) {       ["content"]=>       string(186) "媽媽給小明煮了兩個雞蛋,但是小明居然只吃了一個。媽媽心說孩子長大了知道心疼媽了。就問小明為啥留一個呢?小明說因為今天是剩蛋節"       ["hashId"]=>       string(32) "5DA85D97DA9E99F1C0C433768C50B890"       ["unixtime"]=>       int(1425001932)     }     [6]=>     array(3) {       ["content"]=>       string(361) "說個我兄弟的,12年大年三十的晚上,這貨沒事干給10086客服拜年,結果口才好把人家小姑娘感動哭了,非要給他留電話,這是GC么?當然不是,GC是這小丫頭被查到給用戶留電話被開除了,更GC的是這兩人還在一起了,現在開了個服裝店,很苦也很幸福,今年就要結婚了……"       ["hashId"]=>       string(32) "1DDE835A3CCA61D149C0D0B8AA708885"       ["unixtime"]=>       int(1425001932)     }     [7]=>     array(3) {       ["content"]=>       string(173) "‍‍‍‍“你愛我哪一點?”婦人問她的丈夫,“是我的天生麗質呢,還是我動人的身軀?” “我最愛你的這些幽默感。”‍‍‍‍"       ["hashId"]=>       string(32) "8F0BA8288787959CF6C818FC091128AB"       ["unixtime"]=>       int(1425001941)     }     [8]=>     array(3) {       ["content"]=>       string(123) "問:“是不是復姓的人名字比較上檔次?” 答:“歐陽翠花?”“宇文鐵柱?”“司馬來福?”"       ["hashId"]=>       string(32) "0CEC9589B4F2C445FC913A79910F9B36"       ["unixtime"]=>       int(1425002526)     }     [9]=>     array(3) {       ["content"]=>       string(114) "朋友問我高原上蚊子多不,我回他說,不多,他問為啥,我說,你沒聽說那邊缺癢呀?"       ["hashId"]=>       string(32) "91834BA3A265DD91527C1B7EB4188052"       ["unixtime"]=>       int(1425002536)     }   }   ["error_code"]=>   int(0) }
        登錄后復制

        2.按更新時間查詢笑話

        請求參數

        名稱 必填 類型 說明
        key string 在個人中心->我的數據,接口名稱上方查看
        page int 當前頁數,默認1,最大20
        pagesize int 每次返回條數,默認1,最大20
        time string 時間戳(10位),如:1418816972

        代碼示例

        <?php  //請求的接口URL $apiUrl = 'http://v.juhe.cn/joke/content/list.php';  //請求參數 $params = [     'key' => '聚合數據上申請的接口調用key',     'sort' => 'desc',     'time' => '1603439247',     'pagesize' => 3 ]; //參數數組轉換成字符串 $paramsString = http_build_query($params);  //發起接口網絡請求 $response = null; try {     $response = juheHttpRequest($apiUrl, $paramsString, 1); } catch (Exception $e) {     var_dump($e);     //此處根據自己的需求進行具體的異常處理 } if (!$response) {     echo '請求異常' . PHP_EOL; } //接收接口返回內容 $result = json_decode($response, true); if (!$result) {     echo '請求異常' . PHP_EOL; } $errorCode = $result['error_code']; if ($errorCode == 0) {     $data = $result['result']; } else {     echo "請求異常:{$errorCode}_{$result['reason']}" . PHP_EOL; } //打印接口返回結果 var_dump($result);  /**  * 發起網絡請求函數  * @param String $url 請求的URL  * @param bool $params  請求的參數內容  * @param int $isPost   是否POST請求  * @return bool|string  返回內容  */ function juheHttpRequest($url, $params = false, $isPost = 0) {     $httpInfo = [];     $ch = curl_init();      curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);     curl_setopt($ch, CURLOPT_USERAGENT,  'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36');     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);     curl_setopt($ch, CURLOPT_TIMEOUT, 12);     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);         }     }     $reponse = curl_exec($ch);     if ($reponse === 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 $reponse; }
        登錄后復制

        返回結果示例

        array(3) {   ["reason"]=>   string(7) "Success"   ["result"]=>   array(1) {     ["data"]=>     array(3) {       [0]=>       array(4) {         ["content"]=>         string(294) "某先生是地方上的要人。一天,他像往常一樣在書房里例覽當日報紙,突然對妻子大聲喊道:喂,安娜,你看到今天早報上的流言蜚語了嗎?真可笑!他們說,你收拾行裝出走了。你聽見了嗎?安娜、你在哪兒?安娜?啊!"         ["hashId"]=>         string(32) "90B182FC7F74865B40B1E5807CFEBF41"         ["unixtime"]=>         int(1418745227)         ["updatetime"]=>         string(19) "2014-12-16 23:53:47"       }       [1]=>       array(4) {         ["content"]=>         string(192) "有一天我看著報紙,小聲嘟囔著一篇文章的題目鳥兒也有外語,丈夫聽了對了一句:鳥兒當然也有‘外遇’。原來丈夫聽錯了,我笑得前仰后合。"         ["hashId"]=>         string(32) "206F5C52FD2ED94772CBC66C8AC61F2A"         ["unixtime"]=>         int(1418745227)         ["updatetime"]=>         string(19) "2014-12-16 23:53:47"       }       [2]=>       array(4) {         ["content"]=>         string(363) "新提拔的經理覺得從員工中得到的尊重不夠,于是一天戴上一枚自制的徽章,上面寫著:“我是頭兒!”然后在辦公室神氣地來回巡視。中午吃完飯后,經理回到辦公室,看見桌上留著一張字條,上面寫著:“你的妻子打來電話,說讓你記著下班后把徽章帶回去,她要用。”"         ["hashId"]=>         string(32) "B36BF69DC3B622BD8A4F5A7740C31806"         ["unixtime"]=>         int(1418745227)         ["updatetime"]=>         string(19) "2014-12-16 23:53:47"       }     }   }   ["error_code"]=>   int(0) }
        登錄后復制

        3.最新笑話

        請求參數

        名稱 必填 類型 說明
        key string 在個人中心->我的數據,接口名稱上方查看
        pagesize int 每次返回條數,默認1,最大20
        page int 當前頁數,默認1,最大20

        代碼示例

        <?php  //請求的接口URL $apiUrl = 'http://v.juhe.cn/joke/content/text.php';  //請求參數 $params = [     'key' => 聚合數據上申請的接口調用key,     'page' => 1,     'pagesize' => 3 ]; //參數數組轉換成字符串 $paramsString = http_build_query($params);  //發起接口網絡請求 $response = null; try {     $response = juheHttpRequest($apiUrl, $paramsString, 1); } catch (Exception $e) {     var_dump($e);     //此處根據自己的需求進行具體的異常處理 } if (!$response) {     echo '請求異常' . PHP_EOL; } //接收接口返回內容 $result = json_decode($response, true); if (!$result) {     echo '請求異常' . PHP_EOL; } $errorCode = $result['error_code']; if ($errorCode == 0) {     $data = $result['result']; } else {     echo "請求異常:{$errorCode}_{$result['reason']}" . PHP_EOL; } //打印接口返回結果 var_dump($result);  /**  * 發起網絡請求函數  * @param String $url 請求的URL  * @param bool $params  請求的參數內容  * @param int $isPost   是否POST請求  * @return bool|string  返回內容  */ function juheHttpRequest($url, $params = false, $isPost = 0) {     $httpInfo = [];     $ch = curl_init();      curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);     curl_setopt($ch, CURLOPT_USERAGENT,  'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36');     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);     curl_setopt($ch, CURLOPT_TIMEOUT, 12);     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);         }     }     $reponse = curl_exec($ch);     if ($reponse === 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 $reponse; }
        登錄后復制

        返回結果示例

        array(3) {   ["reason"]=>   string(7) "Success"   ["result"]=>   array(1) {     ["data"]=>     array(3) {       [0]=>       array(4) {         ["content"]=>         string(335) "&nbsp; &nbsp; 小區門口修車師傅生意特好。人實在,只要不換零件,常常不收錢或只收個塊把錢辛苦錢。最近發現他心黑了,價錢明顯上調,就連充個氣也收1塊錢。旁邊書報亭大媽是知情人,: 唉,多擔待一下吧!他家上個月二胎,一窩生了四個帶把的。。。。"         ["hashId"]=>         string(32) "2e010657b420dcee335c870bf9a18301"         ["unixtime"]=>         int(1559789702)         ["updatetime"]=>         string(19) "2019-06-06 10:55:02"       }       [1]=>       array(4) {         ["content"]=>         string(246) "前天和同事去逛超市,說好久沒買肉吃了,于是去看豬肉,結果看到的最便宜的豬肉都要十八塊多,同事當場驚呼:“豬怎么了,這是!”賣肉的師傅笑著說:“豬沒事,就是漲價了。”"         ["hashId"]=>         string(32) "d261d1f0d76bdc665d80f104cf7a7d65"         ["unixtime"]=>         int(1556845202)         ["updatetime"]=>         string(19) "2019-05-03 09:00:02"       }       [2]=>       array(4) {         ["content"]=>         string(518) "去小賣部買煙,10塊錢一盒的,給老板100,老板喜咪咪的看著我說:“我沒零錢找你,就讓我閨女陪你一晚抵賬得了。”我一激動:“你老別介啊,我攢個私房錢出來偷偷買煙,真的很不容易啊!”老板:“怎么,你不愿意?要不然我去把我閨女叫出來!”我:“別!別!這錢你不用找了,千萬別讓您閨女知道我藏私房錢啊!”老板:“好女婿,只要你經常來買東西,我保證不說!哈哈哈”"         ["hashId"]=>         string(32) "7d6e3f6cda682c18c3bc122a767b8756"         ["unixtime"]=>         int(1556845202)         ["updatetime"]=>         string(19) "2019-05-03 09:00:02"       }     }   }   ["error_code"]=>   int(0) }
        登錄后復制

        推薦學習:《PHP視頻教程》

        贊(0)
        分享到: 更多 (0)
        網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號
        主站蜘蛛池模板: 四虎影视884a精品国产四虎| 精品久久久久久国产三级| 91精品婷婷国产综合久久| 亚洲国产精品丝袜在线观看| 91精品国产福利在线观看麻豆| 亚洲精品久久久www| 91精品在线国产| 国产精品9999久久久久| 精品人妻少妇嫩草AV无码专区| 国产亚洲精品观看91在线| 免费国产在线精品一区| 国产福利91精品一区二区三区 | 在线精品国产一区二区三区| 99国内精品久久久久久久| 成人精品在线视频| 精品一区二区三区自拍图片区| 亚洲精品在线视频| 精品欧美激情在线看| 国产精品高清2021在线 | 99精品欧美一区二区三区| 国产精品亚洲专区在线观看| 久久亚洲私人国产精品| 亚洲国产精品尤物YW在线观看| 另类国产精品一区二区| 亚洲精品在线观看视频| 国产福利91精品一区二区| 国产精品99久久精品| 午夜精品一区二区三区在线观看| 久久激情亚洲精品无码?V| 狠狠精品久久久无码中文字幕 | 国产区精品福利在线观看精品| jiucao在线观看精品| 2022国内精品免费福利视频 | 九九久久精品国产| 国产精品人人做人人爽人人添| 中文字幕精品一区二区三区视频| 久久久久久久亚洲精品| 男人的天堂精品国产一区| 免费人妻精品一区二区三区| 综合在线视频精品专区| 人妻VA精品VA欧美VA|