#### 1. 前言 --- [前往阿里云云市場(chǎng)購(gòu)買接口](https://market.aliyun.com/products/57000002/cmapi026100.html?spm=5176.730005.result.1.2eb03524mYsTPg#sku=yuncode2010000004) 姓名、身份證號(hào)碼二要素實(shí)名認(rèn)證接口約 0.3元/次 姓名、身份證號(hào)碼、手機(jī)號(hào)碼二要素實(shí)名認(rèn)證接口約 0.35元/次 #### 2. 代碼示例 --- 將下面代碼中的 appcode 改為自己的即可使用,appcode 從阿里云控制臺(tái)的云市場(chǎng)獲取 ```php /** * 身份實(shí)名認(rèn)證接口(三要素) * * @param $name 姓名 * @param $idcard 身份證號(hào) * @param $mobile 手機(jī)號(hào)碼 * @return true|false 認(rèn)證成功|認(rèn)證失敗 */ 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); //根據(jù)API的要求,定義相對(duì)應(yīng)的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); //設(shè)定返回信息中是否包含響應(yīng)信息頭 // 啟用時(shí)會(huì)將頭文件的信息作為數(shù)據(jù)流輸出,true 表示輸出信息頭, false表示不輸出信息頭 //如果需要將字符串轉(zhuǎn)成json,請(qǐng)將 CURLOPT_HEADER 設(shè)置成 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. 返回值示例 --- 姓名、身份證號(hào)、手機(jī)號(hào)三要素信息完全一致時(shí)的返回值 ```json { "code":"0", "message":"成功", "result":{ "name":"李易峰", "mobile":"1736705xxxx", "idcard":"41092819990917xxxx", "res":"1", "description":"一致", "sex":"男", "birthday":"19990917", "address":"河南省濮陽(yáng)市濮陽(yáng)縣" } } ``` 當(dāng) appcode 沒(méi)有填寫(xiě)或是錯(cuò)誤的值時(shí)返回空字符串 ``` "" ```