Home > Article > Backend Development > How to implement real-name authentication in php
php Steps to implement real-name authentication: 1. Open the identity verification interface service and obtain the API request KEY; 2. Call the interface API to make a request and combine the given data (name, ID number) and official Compare the data and return the comparison result (json format); 3. Parse the returned result into an array, obtain the specified array element and determine whether it is 1. If so, the real-name authentication is successful, otherwise it is unsuccessful.
The operating environment of this tutorial: Windows 7 system, PHP version 8.1, DELL G3 computer
Identity based on PHP Confirmation name authentication example
1. Application interface
passhttps://www.juhe.cn/docs/api/ id/103?s=cpphpcn
Self-service application to open the interface and obtain the API request KEY.
Identity verification and name authentication service:
Official real-name verification of the two elements of the ID card, input the name and ID number, and verify whether the two elements are consistent. Directly connected to official authoritative channels, accurate real-time verification, millisecond-level response, zero caching, and 99.99% accuracy.
2. Use sample code PHP
//如需请求加密接口,加密方式请参考https://www.sdk.cn/details/d591E8oY9X9r67veZz $apiurl="http://op.juhe.cn/idcard/query";//请求地址 $key = "";//32位的KEY $realname = "";//真实姓名 $idcard="";//身份证号码 $params=compact('key','realname','idcard');//组合请求参数 $content=juhecurl($apiurl,$params);//获取接口返回内容json字符串 $result = json_decode($content,true);//解析成数组 if($result){ if($result['error_code']=='0'){ if($result['result']['res'] == '1'){ echo "身份证号码和真实姓名一致"; }else{ echo "身份证号码和真实姓名不一致"; } #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; }
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to implement real-name authentication in php. For more information, please follow other related articles on the PHP Chinese website!