php如何調(diào)用駕照題庫(kù)

本篇內(nèi)容主要講解“php如何調(diào)用駕照題庫(kù)”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“php如何調(diào)用駕照題庫(kù)”吧!

創(chuàng)新互聯(lián)是創(chuàng)新、創(chuàng)意、研發(fā)型一體的綜合型網(wǎng)站建設(shè)公司,自成立以來(lái)公司不斷探索創(chuàng)新,始終堅(jiān)持為客戶提供滿意周到的服務(wù),在本地打下了良好的口碑,在過(guò)去的十多年時(shí)間我們累計(jì)服務(wù)了上千家以及全國(guó)政企客戶,如成都廣告設(shè)計(jì)等企業(yè)單位,完善的項(xiàng)目管理流程,嚴(yán)格把控項(xiàng)目進(jìn)度與質(zhì)量監(jiān)控加上過(guò)硬的技術(shù)實(shí)力獲得客戶的一致表?yè)P(yáng)。

php調(diào)用駕照題庫(kù)的方法:1、申請(qǐng)駕照題庫(kù)API接口;2、配置申請(qǐng)的appkey;3、分析接口數(shù)據(jù)并選擇考試科目類型及駕照類型;4、通過(guò)“function juhecurl($url,$params=false,$ispost=0){...}”方式請(qǐng)求接口返回內(nèi)容即可。

php怎么調(diào)用駕照題庫(kù)?

基于php的駕照題庫(kù)接口調(diào)用代碼實(shí)例

駕照題庫(kù)API接口申請(qǐng):https://www.juhe.cn/docs/api/id/183?s=cpphpcn

接口說(shuō)明:

  • 公安部駕照考試題庫(kù);

  • 考題種類齊全,分類明確;

  • 考題可按順序或者隨機(jī)兩種方試獲取

根據(jù)輸入?yún)?shù)返回相關(guān)題目。

PHP示例:

// +----------------------------------------------------------------------
//----------------------------------
// 駕照題庫(kù)調(diào)用示例代碼 - 聚合數(shù)據(jù)
// 在線接口文檔:https://www.juhe.cn/docs/api/id/183?s=cpphpcn
//----------------------------------
header('Content-type:text/html;charset=utf-8');
//配置您申請(qǐng)的appkey
$appkey = "*********************";
//************1.題庫(kù)接口************
$url = "http://api2.juheapi.com/jztk/query";
$params = array(
"key" => $appkey,//您申請(qǐng)的appKey
"subject" => "",//選擇考試科目類型,1:科目1;4:科目4
"model" => "",//駕照類型,可選擇參數(shù)為:c1,c2,a1,a2,b1,b2;當(dāng)subject=4時(shí)可省略
"testType" => "",//測(cè)試類型,rand:隨機(jī)測(cè)試(隨機(jī)100個(gè)題目),order:順序測(cè)試(所選科目全部題目)
);
$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 "請(qǐng)求失敗";
}
//**************************************************
//************2.answer字段對(duì)應(yīng)答案************
$url = "http://api2.juheapi.com/jztk/answers";
$params = array(
"key" => $appkey,//您申請(qǐng)的appk
);
$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 "請(qǐng)求失敗";
}
//**************************************************
/**
* 請(qǐng)求接口返回內(nèi)容
* @param string $url [請(qǐng)求的URL地址]
* @param string $params [請(qǐng)求的參數(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;
}

到此,相信大家對(duì)“php如何調(diào)用駕照題庫(kù)”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

名稱欄目:php如何調(diào)用駕照題庫(kù)
網(wǎng)站URL:http://bm7419.com/article26/gejpjg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁(yè)設(shè)計(jì)公司、搜索引擎優(yōu)化、服務(wù)器托管Google、網(wǎng)站導(dǎo)航網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)