AuthController.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. namespace app\appapi\controller;
  15. use cmf\controller\HomeBaseController;
  16. use think\Db;
  17. use cmf\lib\Upload;
  18. class AuthController extends HomebaseController {
  19. public function index(){
  20. $data = $this->request->param();
  21. $uid=isset($data['uid']) ? $data['uid']: '';
  22. $token=isset($data['token']) ? $data['token']: '';
  23. $reset=isset($data['reset']) ? $data['reset']: '0';
  24. $uid=(int)checkNull($uid);
  25. $token=checkNull($token);
  26. $reset=checkNull($reset);
  27. $checkToken=checkToken($uid,$token);
  28. if($checkToken==700){
  29. $reason='您的登陆状态失效,请重新登陆!';
  30. $this->assign('reason', $reason);
  31. return $this->fetch(':error');
  32. }
  33. $user=[
  34. 'id'=>$uid,
  35. ];
  36. session('user',$user);
  37. $this->assign("uid",$uid);
  38. $this->assign("token",$token);
  39. if($reset!=1){
  40. $auth=Db::name("user_auth")->where(["uid"=>$uid])->find();
  41. if($auth){
  42. if($auth['status']==0){
  43. return $this->fetch('success');
  44. exit;
  45. }else if($auth['status']==1){
  46. $auth['front_view']=get_upload_path($auth['front_view']);
  47. $auth['back_view']=get_upload_path($auth['back_view']);
  48. $auth['handset_view']=get_upload_path($auth['handset_view']);
  49. $this->assign("auth",$auth);
  50. return $this->fetch('authstep2');
  51. }else if($auth['status']==2){
  52. $this->assign("reason",nl2br($auth['reason']));
  53. return $this->fetch('error');
  54. }
  55. }
  56. }
  57. return $this->fetch();
  58. }
  59. /* 图片上传 */
  60. public function upload(){
  61. $file=isset($_FILES['file'])?$_FILES['file']:'';
  62. if($file){
  63. $name=$file['name'];
  64. $pathinfo = pathinfo($name);
  65. if(!isset($pathinfo['extension'])){
  66. $_FILES['file']['name']=$name.'.jpg';
  67. }
  68. }
  69. $uploader = new Upload();
  70. $uploader->setFileType('image');
  71. $result = $uploader->upload();
  72. if ($result === false) {
  73. echo json_encode(array("ret"=>0,'file'=>'','msg'=>$uploader->getError()));
  74. exit;
  75. }
  76. echo json_encode(array("ret"=>200,'data'=>array("url"=>$result['url']),'msg'=>''));
  77. exit;
  78. }
  79. /* 认证页面2020-12-26已调整为APP原生界面 */
  80. public function authstep(){
  81. $data = $this->request->param();
  82. $uid=isset($data['uid']) ? $data['uid']: '';
  83. $token=isset($data['token']) ? $data['token']: '';
  84. $uid=(int)checkNull($uid);
  85. $token=checkNull($token);
  86. //获取后台插件配置的七牛信息
  87. $qiniu_plugin=Db::name("plugin")->where("name='Qiniu'")->find();
  88. if(!$qiniu_plugin){
  89. $reason='请联系管理员确认配置信息';
  90. $this->assign('reason', $reason);
  91. return $this->fetch(':error');
  92. }
  93. $qiniu_config=json_decode($qiniu_plugin['config'],true);
  94. if(!$qiniu_config){
  95. $reason='请联系管理员确认配置信息';
  96. $this->assign('reason', $reason);
  97. return $this->fetch(':error');
  98. }
  99. $protocol=$qiniu_config['protocol']; //协议名称
  100. $domain=$qiniu_config['domain']; //七牛加速域名
  101. $zone=$qiniu_config['zone']; //存储区域代号
  102. if(!$protocol || !$domain || !$zone){
  103. $reason='请联系管理员确认配置信息';
  104. $this->assign('reason', $reason);
  105. return $this->fetch(':error');
  106. }
  107. $upload_url='';
  108. switch ($zone) {
  109. case 'z0': //华东
  110. $upload_url='up.qiniup.com';
  111. break;
  112. case 'z1': //华北
  113. $upload_url='up-z1.qiniup.com';
  114. break;
  115. case 'z2': //华南
  116. $upload_url='up-z2.qiniup.com';
  117. break;
  118. case 'na0': //北美
  119. $upload_url='up-na0.qiniup.com';
  120. break;
  121. case 'as0': //东南亚
  122. $upload_url='up-as0.qiniup.com';
  123. break;
  124. default:
  125. $upload_url='up.qiniup.com';
  126. break;
  127. }
  128. $checkToken=checkToken($uid,$token);
  129. if($checkToken==700){
  130. $reason='您的登陆状态失效,请重新登陆!';
  131. $this->assign('reason', $reason);
  132. return $this->fetch(':error');
  133. }
  134. $this->assign("uid",$uid);
  135. $this->assign("token",$token);
  136. $this->assign("protocol",$protocol);
  137. $this->assign("domain",$domain);
  138. $this->assign("upload_url",$upload_url);
  139. return $this->fetch();
  140. }
  141. /* 认证保存 */
  142. public function authsave(){
  143. $data = $this->request->param();
  144. $uid=isset($data['uid']) ? $data['uid']: '';
  145. $token=isset($data['token']) ? $data['token']: '';
  146. $uid=(int)checkNull($uid);
  147. $token=checkNull($token);
  148. if( !$uid || !$token || checkToken($uid,$token)==700 ){
  149. echo json_encode(array("ret"=>0,'data'=>array(),'msg'=>'您的登陆状态失效,请重新登陆!'));
  150. exit;
  151. }
  152. $real_name=isset($data['real_name']) ? $data['real_name']: '';
  153. $mobile=isset($data['mobile']) ? $data['mobile']: '';
  154. $cer_no=isset($data['cer_no']) ? $data['cer_no']: '';
  155. $front_view=isset($data['front_view']) ? $data['front_view']: '';
  156. $back_view=isset($data['back_view']) ? $data['back_view']: '';
  157. $handset_view=isset($data['handset_view']) ? $data['handset_view']: '';
  158. if($real_name==''){
  159. echo json_encode(array("ret"=>0,'data'=>array(),'msg'=>'请填写您的真实姓名'));
  160. exit;
  161. }
  162. if($mobile==''){
  163. echo json_encode(array("ret"=>0,'data'=>array(),'msg'=>'请填写您的手机号'));
  164. exit;
  165. }
  166. if($cer_no==''){
  167. echo json_encode(array("ret"=>0,'data'=>array(),'msg'=>'请填写您的身份证号'));
  168. exit;
  169. }
  170. if($front_view==''){
  171. echo json_encode(array("ret"=>0,'data'=>array(),'msg'=>'请上传证件相关照片'));
  172. exit;
  173. }
  174. if($back_view==''){
  175. echo json_encode(array("ret"=>0,'data'=>array(),'msg'=>'请上传证件相关照片'));
  176. exit;
  177. }
  178. if($handset_view==''){
  179. echo json_encode(array("ret"=>0,'data'=>array(),'msg'=>'请上传证件相关照片'));
  180. exit;
  181. }
  182. $data2=[
  183. 'uid'=>$uid,
  184. 'real_name'=>$real_name,
  185. 'mobile'=>$mobile,
  186. 'cer_no'=>$cer_no,
  187. 'front_view'=>$front_view,
  188. 'back_view'=>$back_view,
  189. 'handset_view'=>$handset_view,
  190. 'status'=>0,
  191. 'addtime'=>time(),
  192. ];
  193. $result=Db::name("user_auth")->where(["uid"=>$data['uid']])->update($data2);
  194. if(!$result){
  195. $result=Db::name("user_auth")->insert($data2);
  196. }
  197. if($result!==false){
  198. echo json_encode(array("ret"=>200,'data'=>array(),'msg'=>''));
  199. }else{
  200. echo json_encode(array("ret"=>0,'data'=>array(),'msg'=>'提交失败,请重新提交'));
  201. }
  202. exit;
  203. }
  204. /* 成功 */
  205. public function succ(){
  206. return $this->fetch('success');
  207. }
  208. //获取上传驱动的token
  209. public function getuploadtoken(){
  210. $uploader = new Upload();
  211. $result = $uploader->getuploadtoken();
  212. if ($result === false) {
  213. echo json_encode(array("ret"=>0,'file'=>'','msg'=>'获取失败'));
  214. exit;
  215. }
  216. echo json_encode(
  217. array(
  218. "ret"=>200,
  219. "token"=>$result['token'],
  220. 'domain'=>$result['domain'],
  221. 'msg'=>''
  222. )
  223. );
  224. exit;
  225. }
  226. }