Auth.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-02-17
  10. // +—————————————————————————————————————————————————————————————————————
  11. /*
  12. * 实名认证
  13. */
  14. class Api_Auth extends PhalApi_Api {
  15. public function getRules() {
  16. return array(
  17. 'getAuth'=>array(
  18. 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
  19. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
  20. ),
  21. 'setAuth'=>array(
  22. 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
  23. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
  24. 'real_name' => array('name' => 'real_name', 'type' => 'string', 'require' => true, 'desc' => '真实姓名'),
  25. 'mobile' => array('name' => 'mobile', 'type' => 'string', 'require' => true, 'desc' => '手机号'),
  26. 'cer_no' => array('name' => 'cer_no', 'type' => 'string', 'require' => true, 'desc' => '身份证号'),
  27. 'front_view' => array('name' => 'front_view', 'type' => 'string', 'require' => true, 'desc' => '证件正面'),
  28. 'back_view' => array('name' => 'back_view', 'type' => 'string', 'require' => true, 'desc' => '证件反面'),
  29. 'handset_view' => array('name' => 'handset_view', 'type' => 'string', 'require' => true, 'desc' => '手持证件照'),
  30. ),
  31. );
  32. }
  33. /**
  34. * 获取用户认证信息
  35. * @desc 用于获取用户认证信息
  36. * @return int code 操作码,0表示成功
  37. * @return array info
  38. * @return string msg 提示信息
  39. */
  40. public function getAuth() {
  41. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  42. $uid=checkNull($this->uid);
  43. $token=checkNull($this->token);
  44. $isBlackUser=isBlackUser($uid);
  45. if($isBlackUser=='0'){
  46. $rs['code'] = 700;
  47. $rs['msg'] = '该账号已被禁用';
  48. return $rs;
  49. }
  50. $checkToken=checkToken($uid,$token);
  51. if($checkToken==700){
  52. $rs['code'] = $checkToken;
  53. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  54. return $rs;
  55. }else if($checkToken==10020){
  56. $rs['code'] = 700;
  57. $rs['msg'] = '该账号已被禁用';
  58. return $rs;
  59. }
  60. $domain = new Domain_Auth();
  61. $info = $domain->getAuth($uid);
  62. $rs['info'][0]=$info;
  63. return $rs;
  64. }
  65. /**
  66. * 用户提交认证信息
  67. * @desc 用于用户提交认证信息
  68. * @return int code 操作码,0表示成功
  69. * @return array info
  70. * @return string msg 提示信息
  71. */
  72. public function setAuth() {
  73. $rs = array('code' => 0, 'msg' => '提交成功,官方飞速审核中', 'info' => array());
  74. $uid=checkNull($this->uid);
  75. $token=checkNull($this->token);
  76. $real_name=checkNull($this->real_name);
  77. $mobile=checkNull($this->mobile);
  78. $cer_no=checkNull($this->cer_no);
  79. $front_view=checkNull($this->front_view);
  80. $back_view=checkNull($this->back_view);
  81. $handset_view=checkNull($this->handset_view);
  82. $checkToken=checkToken($uid,$token);
  83. if($checkToken==700){
  84. $rs['code'] = $checkToken;
  85. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  86. return $rs;
  87. }else if($checkToken==10020){
  88. $rs['code'] = 700;
  89. $rs['msg'] = '该账号已被禁用';
  90. return $rs;
  91. }
  92. if($real_name==''){
  93. $rs['code'] = 1001;
  94. $rs['msg'] = '请填写真实姓名';
  95. return $rs;
  96. }
  97. if(mb_strlen($real_name)>10){
  98. $rs['code'] = 1001;
  99. $rs['msg'] = '姓名长度在10个字符以内';
  100. return $rs;
  101. }
  102. if($cer_no==''){
  103. $rs['code'] = 1001;
  104. $rs['msg'] = '请输入身份证号码';
  105. return $rs;
  106. }
  107. if(!isCreditNo($cer_no)){
  108. $rs['code']=1001;
  109. $rs['msg']="身份证号不合法";
  110. return $rs;
  111. }
  112. //$ismobile=checkMobile($mobile);
  113. if($mobile==''){
  114. $rs['code'] = 1001;
  115. $rs['msg'] = '请输入正确手机号码';
  116. return $rs;
  117. }
  118. if($front_view==''){
  119. $rs['code'] = 1001;
  120. $rs['msg'] = '请上传证件正面';
  121. return $rs;
  122. }
  123. if($back_view==''){
  124. $rs['code'] = 1001;
  125. $rs['msg'] = '请上传证件反面';
  126. return $rs;
  127. }
  128. if($handset_view==''){
  129. $rs['code'] = 1001;
  130. $rs['msg'] = '请上传手持证件正面照';
  131. return $rs;
  132. }
  133. $data=[
  134. 'uid'=>$uid,
  135. 'real_name'=>$real_name,
  136. 'mobile'=>$mobile,
  137. 'cer_no'=>$cer_no,
  138. 'front_view'=>$front_view,
  139. 'back_view'=>$back_view,
  140. 'handset_view'=>$handset_view,
  141. 'addtime'=>time(),
  142. 'reason'=>'',
  143. 'status'=>'0',
  144. ];
  145. $domain = new Domain_Auth();
  146. $info = $domain->setAuth($data);
  147. if(!$info){
  148. $rs['code'] = 1001;
  149. $rs['msg'] = '提交失败,请稍后重试!';
  150. return $rs;
  151. }
  152. unset($data['reason']);
  153. unset($data['addtime']);
  154. //处理图片路径
  155. $data['front_view']=get_upload_path($data['front_view']);
  156. $data['back_view']=get_upload_path($data['back_view']);
  157. $data['handset_view']=get_upload_path($data['handset_view']);
  158. $rs['info'][0]=$data;
  159. return $rs;
  160. }
  161. }