[TOC] #### 1. 前言 --- [阿里云云市場購買身份證圖片識別接口](https://market.aliyun.com/products/57124001/cmapi010401.html#sku=yuncode440100000 "123") [阿里云云市場購買身份證信息真實性查詢接口](https://market.aliyun.com/products/57002003/cmapi00035152.html?spm=5176.730005.result.1.c5ea3524BhxUTy&innerSource=search_%E5%AE%9E%E5%90%8D%E8%AE%A4%E8%AF%81%E6%8E%A5%E5%8F%A3#sku=yuncode29152000014 "前往云市場購買") 本文介紹的實名認(rèn)證接口可以配合阿里云的身份證圖片識別接口配合使用 先使用身份證圖片識別接口將姓名和身份證號識別出來,然后在使用本文的實名認(rèn)證接口判斷身份證信息的真實性 #### 2. 代碼示例 --- 將下面代碼中的 appcode 改為自己的即可使用,appcode 從阿里云控制臺的云市場獲取 ```php /** * 身份證實名認(rèn)證接口 * * @param $name 姓名 * @param $idcard 身份證號 * @return true|false 認(rèn)證成功|認(rèn)證失敗 */ function auth($name, $idcard) { $host = "http://checkone.market.alicloudapi.com"; $path = "/chinadatapay/1882"; $method = "POST"; // 阿里云的云市場 appcode $appcode = "xxxxxxxxxxxxxxxxxxxxxxx"; $headers = array(); array_push($headers, "Authorization:APPCODE " . $appcode); //根據(jù)API的要求,定義相對應(yīng)的Content-Type array_push($headers, "Content-Type" . ":" . "application/x-www-form-urlencoded; charset=UTF-8"); $querys = ""; $bodys = "idcard={$idcard}&name={$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); // curl_setopt($curl, CURLOPT_HEADER, true); 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); // 認(rèn)證成功返回值示例: // {"code":"10000","message":"成功","data":{"result":"1"},"seqNo":"9231181I220411080826830"} $result = curl_exec($curl); ####### 寫入日志 ####### // 在這里可以將接口返回值寫入到日志文件 ####### 寫入日志 / ####### if (isset($result['code']) && $result['code'] == 10000 && $result['result'] == 1) { return true; // 認(rèn)證成功 } else { return false; // 認(rèn)證失敗 } } ``` #### 3. 返回值示例 --- 當(dāng)姓名和身份證號正確時(code = 10000,data.result = 1,,滿足這兩個條件說明認(rèn)證成功) ``` {"code":"10000","message":"成功","data":{"result":"1"},"seqNo":"9231181I220411080826830"} ``` 當(dāng) appcode 沒有填寫或是錯誤的值時返回空字符串 ``` "" ``` 當(dāng)身份證號錯誤時 ``` {"code":"10000","message":"成功","data":{"result":"2"},"seqNo":"7K47GY0U220411081125638"} ```