How to implement real-name authentication for three-network mobile phones in PHP

青灯夜游
Release: 2023-03-17 08:20:01
Original
1507 people have browsed it

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.

How to implement real-name authentication for three-network mobile phones in PHP

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

Passed https://www.juhe.cn/docs/api/id/208?s=cpphpcn Self-service application to open the interface and obtain the API request KEY

Request parameters

##NameRequiredDescription##key##realnameisNameidcardisID card numbermobileYesMobile phone numbertypeNo1: Return to the mobile phone operator, If no other values ​​are entered, it will not be returned. NoNoPHP sample codeIf you need to request an encryption interface, please refer to
$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;
}
Copy after login
Return result example
is In Personal Center->My Data, view above the interface name
##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)
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
}
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template