#### 1. 前言 --- [前往阿里云云市场购买接口](https://market.aliyun.com/products/57000002/cmapi026100.html?spm=5176.730005.result.1.2eb03524mYsTPg#sku=yuncode2010000004) 姓名、身份证号码二要素实名认证接口约 0.3元/次 姓名、身份证号码、手机号码二要素实名认证接口约 0.35元/次 #### 2. 代码示例 --- 将下面代码中的 appcode 改为自己的即可使用,appcode 从阿里云控制台的云市场获取 ```php /** * 身份实名认证接口(三要素) * * @param $name 姓名 * @param $idcard 身份证号 * @param $mobile 手机号码 * @return true|false 认证成功|认证失败 */ function auth($name, $idcard, $mobile) { $host = "https://mobile3elements.shumaidata.com"; $path = "/mobile/verify_real_name"; $method = "POST"; $appcode = "xxxxxxxxxxxxxxxxxxxx"; $headers = array(); array_push($headers, "Authorization:APPCODE " . $appcode); //根据API的要求,定义相对应的Content-Type array_push($headers, "Content-Type" . ":" . "application/x-www-form-urlencoded; charset=UTF-8"); $querys = ""; $bodys = "idcard={$idcard}&mobile={$mobile}&name=" . urlencode($name); $url = $host . $path; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //设定返回信息中是否包含响应信息头 // 启用时会将头文件的信息作为数据流输出,true 表示输出信息头, false表示不输出信息头 //如果需要将字符串转成json,请将 CURLOPT_HEADER 设置成 false curl_setopt($curl, CURLOPT_HEADER, false); if (1 == strpos("$" . $host, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys); $result = curl_exec($curl); ####### 接口返回值记录到日志文件 ####### // .... ####### 接口返回值记录到日志文件 / ####### if (isset($result['code']) && $result['code'] == 0 && $result['result']['res'] == 1) { return true; // 三要素信息一致 } else { return false; } } ``` #### 3. 返回值示例 --- 姓名、身份证号、手机号三要素信息完全一致时的返回值 ```json { "code":"0", "message":"成功", "result":{ "name":"李易峰", "mobile":"1736705xxxx", "idcard":"41092819990917xxxx", "res":"1", "description":"一致", "sex":"男", "birthday":"19990917", "address":"河南省濮阳市濮阳县" } } ``` 当 appcode 没有填写或是错误的值时返回空字符串 ``` "" ```