Userauth.php 23 KB

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