Userauth.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Cache;
  6. use TencentCloud\Common\Credential;
  7. use TencentCloud\Common\Profile\ClientProfile;
  8. use TencentCloud\Common\Profile\HttpProfile;
  9. use TencentCloud\Common\Exception\TencentCloudSDKException;
  10. //use TencentCloud\Faceid\V20180301\FaceidClient;
  11. //use TencentCloud\Faceid\V20180301\Models\IdCardVerificationRequest;
  12. use TencentCloud\Iai\V20200303\IaiClient;
  13. use TencentCloud\Iai\V20200303\Models\CompareFaceRequest;
  14. use fast\Random;
  15. /**
  16. * 实名认证,真人认证相关
  17. */
  18. class Userauth extends Api
  19. {
  20. protected $noNeedLogin = [];
  21. protected $noNeedRight = '*';
  22. //实名认证信息
  23. public function idcard_info(){
  24. $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->order('id desc')->find();
  25. $this->success('success',$check);
  26. }
  27. //申请实名认证
  28. public function apply_idcard_confirm(){
  29. $truename = input('truename','');
  30. $idcard = input('idcard' ,'');
  31. if(empty($truename) || empty($idcard)){
  32. $this->error('实名认证信息必填');
  33. }
  34. if($this->auth->idcard_status == 1){
  35. $this->error('您已经完成实名认证');
  36. }
  37. if($this->auth->idcard_status == 0){
  38. $this->error('您已经提交实名认证,请等待审核');
  39. }
  40. Db::startTrans();
  41. $check = Db::name('user_idconfirm')->where('user_id',$this->auth->id)->lock(true)->find();
  42. if(!empty($check)){
  43. if($check['status'] == 0){
  44. Db::rollback();
  45. $this->error('您已经提交实名认证,请等待审核');
  46. }
  47. if($check['status'] == 1){
  48. Db::rollback();
  49. $this->error('您已经完成实名认证');
  50. }
  51. }
  52. $count = Db::name('user_idconfirm')->where(['idcard' => $idcard, 'user_id' => ['neq', $this->auth->id]])->count('id');
  53. if ($count) {
  54. $this->error('该身份证号已被他人使用');
  55. }
  56. //限制每日请求次数
  57. $time = time();
  58. $today_end = strtotime(date('Y-m-d 23:59:59', $time));
  59. $cache_time = $today_end - $time; //缓存时间
  60. $time_count = Cache::get('fourauth' . $this->auth->id);
  61. if (!$time_count) {
  62. Cache::set('fourauth' . $this->auth->id, 1, $cache_time);
  63. } else {
  64. Cache::set('fourauth' . $this->auth->id, $time_count + 1, $cache_time);
  65. if ($time_count > 5) {
  66. $this->error('今日实名次数已到上限,明天再来吧');
  67. }
  68. }
  69. if($this->auth->gender == 0){
  70. //阿里云身份证二要素认证
  71. $auth_restult = $this->userauth_aliyun_two($idcard, $truename);
  72. if($auth_restult == false){
  73. $this->error('身份证信息与姓名不符');
  74. }
  75. }
  76. $data = [
  77. 'user_id' => $this->auth->id,
  78. 'truename' => $truename,
  79. 'idcard' => $idcard,
  80. 'status' => 1, //不需要人工刚审核了,直接过审
  81. 'createtime' => time(),
  82. 'updatetime' => time(),
  83. ];
  84. if($this->auth->gender == 1){
  85. $data['status'] = 0;//男性待审
  86. }
  87. //更新
  88. $update_rs = Db::name('user')->where('id',$this->auth->id)->update(['idcard_status'=>$data['status']]);
  89. if(!empty($check)){
  90. $rs = Db::name('user_idconfirm')->where('id',$check['id'])->update($data);
  91. }else{
  92. $rs = Db::name('user_idconfirm')->insertGetId($data);
  93. }
  94. if($this->auth->gender == 0){
  95. //task任务
  96. //实名认证
  97. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,5);
  98. if($task_rs === false){
  99. Db::rollback();
  100. $this->error('完成任务失败');
  101. }
  102. //系统消息
  103. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'实名认证','实名认证已经审核通过');
  104. }
  105. if(!$rs || !$update_rs){
  106. Db::rollback();
  107. $this->error('提交失败');
  108. }
  109. Db::commit();
  110. if($this->auth->gender == 0){
  111. $this->success('认证通过');
  112. }else{
  113. $this->success('提交成功,请等待审核');
  114. }
  115. }
  116. //产品链接:https://market.aliyun.com/products/57000002/cmapi026109.html#sku=yuncode20109000025
  117. //阿里云-数脉api
  118. //姓名+身份证号
  119. private function userauth_aliyun_two($cardNo = '',$realname = ''){
  120. if(!$cardNo || !$realname){
  121. return false;
  122. }
  123. $config = config('aliyun_auth_shumai_two');
  124. $host = "https://eid.shumaidata.com";
  125. $path = "/eid/check";
  126. $method = "POST";
  127. $appcode = $config['app_code'];
  128. $headers = array();
  129. array_push($headers, "Authorization:APPCODE " . $appcode);
  130. $querys = "idcard=".$cardNo."&name=".urlencode($realname);
  131. $bodys = '';
  132. $url = $host . $path . "?" . $querys;
  133. $curl = curl_init();
  134. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  135. curl_setopt($curl, CURLOPT_URL, $url);
  136. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  137. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  138. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  139. //设定返回信息中是否包含响应信息头,启用时会将头文件的信息作为数据流输出,true 表示输出信息头, false表示不输出信息头
  140. //如果需要将字符串转成json,请将 CURLOPT_HEADER 设置成 false
  141. curl_setopt($curl, CURLOPT_HEADER, false);
  142. if (1 == strpos("$".$host, "https://"))
  143. {
  144. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  145. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  146. }
  147. $returnRes = curl_exec($curl);
  148. //var_dump($returnRes);
  149. curl_close($curl);
  150. $result = json_decode($returnRes,true);
  151. //dump($result);
  152. if(is_array($result) && isset($result['code']) && $result['code'] == 0){
  153. if(isset($result['result']) && isset($result['result']['res'])){
  154. if($result['result']['res'] == 1){
  155. //实名过了
  156. return true;
  157. }
  158. }
  159. }
  160. return false;
  161. }
  162. //产品链接:https://market.aliyun.com/products/57000002/cmapi026100.html?spm=5176.730005.result.8.1dbc123e8ArY19&innerSource=search#sku=yuncode2010000006
  163. //阿里云-数脉api
  164. //姓名+手机号+身份证号
  165. private function userauth_aliyun_three($cardNo = '',$realname = '',$mobile = ''){
  166. if(!$cardNo || !$realname || !$mobile){
  167. return false;
  168. }
  169. $config = config('aliyun_auth_shumai');
  170. $host = "https://mobile3elements.shumaidata.com";
  171. $path = "/mobile/verify_real_name";
  172. $method = "POST";
  173. $appcode = $config['app_code'];
  174. $headers = array();
  175. array_push($headers, "Authorization:APPCODE " . $appcode);
  176. //根据API的要求,定义相对应的Content-Type
  177. array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");
  178. $querys = "";
  179. $bodys = "idcard=".$cardNo."&mobile=".$mobile."&name=".urlencode($realname);
  180. $url = $host . $path;
  181. $curl = curl_init();
  182. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
  183. curl_setopt($curl, CURLOPT_URL, $url);
  184. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  185. curl_setopt($curl, CURLOPT_FAILONERROR, false);
  186. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  187. //设定返回信息中是否包含响应信息头,启用时会将头文件的信息作为数据流输出,true 表示输出信息头, false表示不输出信息头
  188. //如果需要将字符串转成json,请将 CURLOPT_HEADER 设置成 false
  189. curl_setopt($curl, CURLOPT_HEADER, false);
  190. if (1 == strpos("$".$host, "https://"))
  191. {
  192. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  193. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  194. }
  195. curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);
  196. $returnRes = curl_exec($curl);
  197. curl_close($curl);
  198. $result = json_decode($returnRes,true);
  199. if(is_array($result) && isset($result['code']) && $result['code'] == 0){
  200. if(isset($result['result']) && isset($result['result']['res'])){
  201. if($result['result']['res'] == 1){
  202. //实名过了
  203. return true;
  204. }
  205. }
  206. }
  207. return false;
  208. }
  209. ///////////////////////////////////////////真人认证,来自知音////////////
  210. //申请真人认证
  211. public function realauth() {
  212. if ($this->auth->real_status == 1) {
  213. $this->error('您已经真人认证过了~');
  214. }
  215. if ($this->auth->avatar == config('avatar_boy') || $this->auth->avatar == config('avatar_girl')) {
  216. $this->error('请先上传真人头像~');
  217. }
  218. $check = Db::name('user_audit')->where('user_id',$this->auth->id)->where('type','avatar')->where('status',0)->find();
  219. if(!empty($check)){
  220. $this->error('您的头像还在审核中,审核完成在认证吧');
  221. }
  222. //一天最多认证3次
  223. $apiLimitTime = strtotime(date('Y-m-d 23:59:59')) - time();
  224. $rs = $this->apiLimit(3,$apiLimitTime*1000);
  225. if(!$rs){
  226. $this->error('一天最多认证三次');
  227. }
  228. //获取token
  229. $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
  230. $token_result = file_get_contents($token_url);
  231. if (!$token_result) {
  232. $this->error('您的网络开小差啦1~');
  233. }
  234. $token_result = json_decode($token_result, true);
  235. if ($token_result['code'] != 0) {
  236. $this->error('您的网络开小差啦2~');
  237. }
  238. $token = $token_result['access_token'];
  239. //获取签名鉴权参数ticket
  240. $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
  241. $ticket_result = file_get_contents($ticket_url);
  242. if (!$ticket_result) {
  243. $this->error('您的网络开小差啦3~');
  244. }
  245. $ticket_result = json_decode($ticket_result, true);
  246. if ($ticket_result['code'] != 0) {
  247. $this->error('您的网络开小差啦4~');
  248. }
  249. $ticket = $ticket_result['tickets'][0]['value'];
  250. //获取签名
  251. $sign_data = [
  252. 'wbappid' => config('tencent_yun')['secret_id'],
  253. 'userId' => (string)$this->auth->id,
  254. 'version' => '1.0.0',
  255. 'ticket' => $ticket,
  256. 'nonce' => Random::alnum(32)
  257. ];//p($sign_data);
  258. asort($sign_data); //p($sign_data);//排序
  259. $sign_string = join('', $sign_data);//p($sign_string);
  260. $sign = sha1($sign_string);//p($sign);
  261. //上传身份信息
  262. $orderNo = createUniqueNo('A',$this->auth->id); //商户请求的唯一标识
  263. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/server/getAdvFaceId?orderNo=' . $orderNo;
  264. $avatar = one_domain_image($this->auth->avatar);
  265. $avatar = str_replace('https', 'http', $avatar);
  266. $img = file_get_contents($avatar);
  267. $img = str_replace('data:image/jpg;base64', '', $img);
  268. $img = str_replace('\n', '', $img);
  269. $sourcePhotoStr = base64_encode($img);
  270. $data = [
  271. 'webankAppId' => config('tencent_yun')['secret_id'],
  272. 'orderNo' => $orderNo,
  273. 'userId' => (string)$this->auth->id,
  274. 'sourcePhotoStr' => $sourcePhotoStr,
  275. 'sourcePhotoType' => 2,
  276. 'version' => '1.0.0',
  277. 'sign' => $sign,
  278. 'nonce' => $sign_data['nonce']
  279. ];
  280. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  281. if (!$rs) {
  282. $this->error('您的网络开小差啦5~');
  283. }
  284. $rs = json_decode($rs, true);
  285. if (!$rs || $rs['code'] != 0) {
  286. $this->error('您的网络开小差啦6~');
  287. }
  288. $user_auth = [
  289. 'user_id' => $this->auth->id,
  290. 'certify_id' => $rs['result']['faceId'],
  291. 'out_trade_no' => $data['orderNo'],
  292. 'status' => 0,
  293. 'createtime' => time(),
  294. 'updatetime' => time()
  295. ];
  296. //开启事务
  297. Db::startTrans();
  298. //查询是否认证过
  299. $info = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  300. if ($info) {
  301. $auth_rs = Db::name('user_auth')->where(['id' => $info['id']])->setField($user_auth);
  302. } else {
  303. $auth_rs = Db::name('user_auth')->insertGetId($user_auth);
  304. }
  305. if (!$auth_rs) {
  306. Db::rollback();
  307. $this->error('您的网络开小差啦7~');
  308. }
  309. //修改用户表认证状态
  310. $user_rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', 0);
  311. if ($user_rs === false) {
  312. Db::rollback();
  313. $this->error('您的网络开小差啦8~');
  314. }
  315. Db::commit();
  316. $return_data = [
  317. 'face_id' => $user_auth['certify_id'],
  318. 'order_no' => $user_auth['out_trade_no'],
  319. 'user_id' => (string)$this->auth->id,
  320. 'nonce' => $sign_data['nonce'],
  321. 'sign' => $sign
  322. ];
  323. $this->success('success', $return_data);
  324. }
  325. //查询真人认证结果
  326. public function getrealauthresult() {
  327. $user_auth = Db::name('user_auth')->where(['user_id' => $this->auth->id])->find();
  328. if (!$user_auth) {
  329. $this->success('尚未认证');
  330. }
  331. if ($user_auth['status'] == 1) {
  332. $this->success('真人认证通过');
  333. }
  334. if (!$user_auth['certify_id']) {
  335. $this->success('请先进行真人认证');
  336. }
  337. //获取token
  338. $token_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/access_token?app_id='.config('tencent_yun')['secret_id'].'&secret='.config('tencent_yun')['secret_key'].'&grant_type=client_credential&version=1.0.0';
  339. $token_result = file_get_contents($token_url);
  340. if (!$token_result) {
  341. $this->error('您的网络开小差啦1~');
  342. }
  343. $token_result = json_decode($token_result, true);
  344. if ($token_result['code'] != 0) {
  345. $this->error('您的网络开小差啦2~');
  346. }
  347. $token = $token_result['access_token'];
  348. //获取签名鉴权参数ticket
  349. $ticket_url = 'https://miniprogram-kyc.tencentcloudapi.com/api/oauth2/api_ticket?app_id='.config('tencent_yun')['secret_id'].'&access_token='.$token.'&type=SIGN&version=1.0.0';
  350. $ticket_result = file_get_contents($ticket_url);
  351. if (!$ticket_result) {
  352. $this->error('您的网络开小差啦3~');
  353. }
  354. $ticket_result = json_decode($ticket_result, true);
  355. if ($ticket_result['code'] != 0) {
  356. $this->error('您的网络开小差啦4~');
  357. }
  358. $ticket = $ticket_result['tickets'][0]['value'];
  359. //获取签名
  360. $sign_data = [
  361. 'wbappid' => config('tencent_yun')['secret_id'],
  362. 'orderNo' => $user_auth['out_trade_no'],
  363. 'version' => '1.0.0',
  364. 'ticket' => $ticket,
  365. 'nonce' => Random::alnum(32)
  366. ];//p($sign_data);
  367. asort($sign_data); //p($sign_data);//排序
  368. $sign_string = join('', $sign_data);//p($sign_string);
  369. $sign = sha1($sign_string);//p($sign);
  370. //人脸核身结果查询
  371. $url = 'https://miniprogram-kyc.tencentcloudapi.com/api/v2/base/queryfacerecord?orderNo=' . $user_auth['out_trade_no'];
  372. $data = [
  373. 'appId' => config('tencent_yun')['secret_id'],
  374. 'version' => '1.0.0',
  375. 'nonce' => $sign_data['nonce'],
  376. 'orderNo' => $user_auth['out_trade_no'],
  377. 'sign' => $sign
  378. ];
  379. $rs = curl_post($url,json_encode($data, 320), ['Content-Type: application/json']);
  380. if (!$rs) {
  381. $this->error('您的网络开小差啦5~');
  382. }
  383. $rs = json_decode($rs, true);
  384. if (!$rs || $rs['code'] != 0) {
  385. $this->error($rs['msg']);
  386. }
  387. if ($rs['result']['liveRate'] >= 90 && $rs['result']['similarity'] >= 90) {
  388. $edit_data['status'] = 1;
  389. $msg = '真人认证成功';
  390. } else {
  391. $edit_data['status'] = 2;
  392. $edit_data['certify_id'] = '';
  393. $edit_data['out_trade_no'] = '';
  394. $msg = '真人认证失败';
  395. }
  396. $edit_data['updatetime'] = time();
  397. //开启事务
  398. Db::startTrans();
  399. //修改认证信息
  400. $result = Db::name('user_auth')->where(['user_id' => $this->auth->id, 'status' => $user_auth['status']])->setField($edit_data);
  401. if (!$result) {
  402. Db::rollback();
  403. $this->error('查询认证结果失败2');
  404. }
  405. //修改用户信息
  406. $rs = Db::name('user')->where(['id' => $this->auth->id])->setField('real_status', $edit_data['status']);
  407. if (!$rs) {
  408. Db::rollback();
  409. $this->error('查询认证结果失败3');
  410. }
  411. if ($edit_data['status'] == 1) { //通过
  412. //tag任务赠送金币
  413. //真人认证奖励
  414. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,6);
  415. if($task_rs === false){
  416. Db::rollback();
  417. $this->error('完成任务赠送奖励失败');
  418. }
  419. //系统消息
  420. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证已经审核通过');
  421. } else {
  422. //系统消息
  423. $msg_id = \app\common\model\Message::addMessage($this->auth->id,'真人认证','真人认证审核不通过');
  424. }
  425. Db::commit();
  426. $this->success($msg);
  427. }
  428. ///////////////////////////////////////////////////////////////////////
  429. //真人认证后修改头像
  430. public function editrealavatar() {
  431. if ($this->auth->real_status != 1) {
  432. $this->error('尚未通过真人认证');
  433. }
  434. $avatar = input('avatar', '', 'trim'); //头像地址
  435. if ($avatar === '') {
  436. $this->error('参数缺失');
  437. }
  438. $avatar = one_domain_image($avatar);
  439. $now_avatar = one_domain_image($this->auth->avatar);
  440. if ($avatar == $now_avatar) {
  441. $this->error('头像未改变');
  442. }
  443. //腾讯云人脸识别
  444. $auit_result = $this->face_tencent($now_avatar, $avatar); //1通过 0拒绝
  445. if ($auit_result != 1) {
  446. $this->success('提示', ['code' => 2]);
  447. }
  448. $data['avatar'] = $avatar;
  449. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  450. if (!$user_result) {
  451. $this->error('修改失败');
  452. }
  453. $this->success('修改成功');
  454. }
  455. //真人认证后修改头像并取消真人认证
  456. public function editrealavatarcancelauit() {
  457. if ($this->auth->real_status != 1) {
  458. $this->error('尚未通过真人认证');
  459. }
  460. $avatar = input('avatar', '', 'trim'); //头像地址
  461. if ($avatar === '') {
  462. $this->error('参数缺失');
  463. }
  464. $avatar = one_domain_image($avatar);
  465. $now_avatar = one_domain_image($this->auth->avatar);
  466. if ($avatar == $now_avatar) {
  467. $this->error('头像未改变');
  468. }
  469. $data['avatar'] = $avatar;
  470. $data['real_status'] = -1;
  471. //开启事务
  472. Db::startTrans();
  473. $user_result = Db::name('user')->where(['id' => $this->auth->id])->setField($data);
  474. if (!$user_result) {
  475. Db::rollback();
  476. $this->error('修改失败');
  477. }
  478. $user_auth_result = Db::name('user_auth')->where(['user_id' => $this->auth->id])->delete();
  479. if (!$user_auth_result) {
  480. Db::rollback();
  481. $this->error('修改失败');
  482. }
  483. Db::commit();
  484. $this->success('修改成功');
  485. }
  486. //腾讯云人脸识别
  487. public function face_tencent($urla = '', $urlb = '') {
  488. // require_once 'vendor/autoload.php';
  489. try {
  490. // 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
  491. // 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
  492. $config = config('tencent_realauth');
  493. $cred = new Credential($config['SecretId'], $config['SecretKey']);
  494. // 实例化一个http选项,可选的,没有特殊需求可以跳过
  495. $httpProfile = new HttpProfile();
  496. $httpProfile->setEndpoint("iai.tencentcloudapi.com");
  497. // 实例化一个client选项,可选的,没有特殊需求可以跳过
  498. $clientProfile = new ClientProfile();
  499. $clientProfile->setHttpProfile($httpProfile);
  500. // 实例化要请求产品的client对象,clientProfile是可选的
  501. $client = new IaiClient($cred, "ap-beijing", $clientProfile);
  502. // 实例化一个请求对象,每个接口都会对应一个request对象
  503. $req = new CompareFaceRequest();
  504. $params = array(
  505. "UrlA" => $urla,
  506. "UrlB" => $urlb,
  507. "FaceModelVersion" => "3.0"
  508. );
  509. $req->fromJsonString(json_encode($params));
  510. // 返回的resp是一个CompareFaceResponse的实例,与请求对象对应
  511. $resp = $client->CompareFace($req);
  512. // 输出json格式的字符串回包
  513. // print_r($resp->toJsonString());
  514. $result = json_decode($resp->toJsonString(), true);
  515. //3.0版本误识率千分之一对应分数为40分,误识率万分之一对应分数为50分,误识率十万分之一对应分数为60分。 一般超过50分则可认定为同一人。
  516. if (isset($result['Score']) && $result['Score'] >= 60) {
  517. return 1; //通过
  518. } else {
  519. return 0;
  520. }
  521. }
  522. catch(TencentCloudSDKException $e) {
  523. // echo $e;
  524. return 0;
  525. }
  526. }
  527. }