暗号化インターフェイスをリクエストする必要がある場合は、 | https:// を参照してください。暗号化方式の www.sdk .cn/details/d591E8oY9X9r67veZz | $apiurl="http://v.juhe.cn/telecom/query";//请求地址
$key = "";//32位的KEY
$realname = "";//真实姓名
$idcard="";//身份证号码
$mobile="";//手机号码
$showid=1;//传入返回单号
$params=compact('key','realname','idcard','mobile','showid');//组合请求参数
$content=juhecurl($apiurl,$params);//获取接口返回内容json字符串
$result = json_decode($content,true);//解析成数组
if($result){
if($result['error_code']=='0'){
echo $result['result']['res'].':'.$result['result']['resmsg'];
#print_r($result);
}else{
echo $result['error_code'].":".$result['reason'];
}
}else{
echo "请求失败";
}
//网络请求方法
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_CONNECTTIMEOUT , 3);
curl_setopt( $ch, CURLOPT_TIMEOUT , 8);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
if ($params) {
if (is_array($params)) {
$paramsString = http_build_query($params);
} else {
$paramsString = $params;
}
} else {
$paramsString = "";
}
if( $ispost )
{
curl_setopt( $ch , CURLOPT_POST , true );
curl_setopt( $ch , CURLOPT_POSTFIELDS , $paramsString);
curl_setopt( $ch , CURLOPT_URL , $url );
}
else
{
if($paramsString ){
curl_setopt( $ch , CURLOPT_URL , $url.'?'.$paramsString);
}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;
}
戻り結果の例 | {
"reason": "查询成功",
"result": {
"realname": "***",
"mobile": "***********",
"idcard": "******************",
"res": 2,
"resmsg": "三要素身份验证不一致",
"type": "移动",
"orderid":"J201712251904163782Ay",
"province":"广东省",
"city" : "惠州市",
"rescode":"24"
},
"error_code": 0
}
推奨学習: 「