Home>Article>Backend Development> How to implement real-name authentication for three-network mobile phones in PHP
Implementation method: 1. Apply to open the three-network mobile phone real-name authentication API interface and obtain the API request KEY; 2. Use "$params=compact('key','realname','idcard','mobile ','showid')" combined request parameters; 3. Make a request through "function juhecurl($url,$params=false,$ispost=0){...}", process the data and return the result.
The operating environment of this tutorial: windows7 system, PHP8.1 version, DELL G3 computer
Based on PHP Example of calling the real-name mobile phone real-name authentication API interface
Apply for the three-network mobile phone real-name authentication API interface
Passedhttps://www.juhe.cn/docs/api/id/208?s=cpphpcn
Self-service application to open the interface and obtain the API request KEY
Request parameters
$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; }
Required | Description | |
---|---|---|
is | In Personal Center->My Data, view above the interface name | ##realname |
Name | idcard | |
ID card number | mobile | |
Mobile phone number | type | |
1: Return to the mobile phone operator, If no other values are entered, it will not be returned. | ##province | |
1: Return to the location of the mobile phone number, province, city. If you do not enter it, it will not return | detail | |
Whether to display the matching detail code, pass 1 to display, the default is not to display (in the simplified version, when 1 is entered, 24 is returned) | ||
If you need to request an encryption interface, please refer to | https://www.sdk for the encryption method .cn/details/d591E8oY9X9r67veZz |
{ "reason": "查询成功", "result": { "realname": "***", "mobile": "***********", "idcard": "******************", "res": 2, "resmsg": "三要素身份验证不一致", "type": "移动", "orderid":"J201712251904163782Ay", "province":"广东省", "city" : "惠州市", "rescode":"24" }, "error_code": 0 }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to implement real-name authentication for three-network mobile phones in PHP. For more information, please follow other related articles on the PHP Chinese website!