Userauth.php 23 KB

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