AuthController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * 会员中心模块
  4. * @author wesmiler
  5. */
  6. namespace app\weixin\controller;
  7. use app\weixin\model\Member;
  8. use app\weixin\model\UserLog;
  9. use app\weixin\model\UserProfile;
  10. use app\weixin\model\Wechat;
  11. use app\weixin\service\PRedis;
  12. use app\weixin\validate\MemberValidate;
  13. use think\Db;
  14. use think\Request;
  15. class AuthController extends BaseController
  16. {
  17. public function __construct()
  18. {
  19. parent::__construct();
  20. $needRegProfile = session('needRegProfile');
  21. if($needRegProfile == true){
  22. Wechat::redirectUrl(url('/weixin/index/entry', '', '', true));
  23. exit;
  24. }
  25. }
  26. /**
  27. * 认证
  28. * @return mixed
  29. */
  30. public function index()
  31. {
  32. return $this->fetch();
  33. }
  34. /**
  35. * VIP认证
  36. * @return mixed
  37. */
  38. public function vip()
  39. {
  40. return $this->fetch();
  41. }
  42. /**
  43. * 人工牵线
  44. * @return mixed
  45. */
  46. public function hand()
  47. {
  48. return $this->fetch();
  49. }
  50. /**
  51. * 身份证认证
  52. * @return mixed
  53. */
  54. public function idcard()
  55. {
  56. return $this->fetch();
  57. }
  58. /**
  59. * 认证结果
  60. * @return mixed|string
  61. */
  62. public function authResult(){
  63. $params = input();
  64. $data = input('response','');
  65. $data = $data? json_decode($data, true) : [];
  66. $code = isset($data['resultCode'])? $data['resultCode'] : '';
  67. $idcard = isset($data['certNo'])? $data['certNo'] : '';
  68. $realname = isset($data['certName'])? $data['certName'] : '';
  69. $bizNo = isset($data['bizId'])? $data['bizId'] : '';
  70. $passed = isset($data['passed'])? $data['passed'] : '';
  71. $type = isset($data['type'])? $data['type'] : 0;
  72. $typeName = $type==1?'静默活体':($type==2? '读数活体':'混合活体');
  73. // 签名验证
  74. $len = mb_strlen($bizNo, 'utf-8');
  75. $userId = mb_substr($bizNo, 11, $len,'utf-8');
  76. PRedis::set("caches:zimAuth:{$userId}:notify", $data, 7200);
  77. if($idcard && $realname && $code == 'CZFE_SUCCESS' && $passed == 'T' && $userId){
  78. // 更新信息
  79. Member::updateAuth($userId, $realname, $idcard);
  80. $this->assign('bizNo',$bizNo);
  81. $this->assign('code','success');
  82. $this->assign('result',"<em>身份{$typeName}验证成功</em>,请等待审核");
  83. }else{
  84. $this->assign('bizNo', '');
  85. $this->assign('code','error');
  86. $this->assign('result',"<em>身份{$typeName}验证失败</em>,请返回重试");
  87. }
  88. $params['user_id'] = $userId;
  89. PRedis::set("caches:faceAuth:result:{$bizNo}", $params, 3600);
  90. return $this->fetch();
  91. }
  92. /**
  93. * 认证结果
  94. * @return mixed|string
  95. */
  96. public function authFace(){
  97. $params = input();
  98. $data = input('data','');
  99. $data = $data? json_decode($data, true) : [];
  100. $code = isset($data['code'])? $data['code'] : '';
  101. $idcard = isset($data['id'])? $data['id'] : '';
  102. $realname = isset($data['name'])? $data['name'] : '';
  103. $bizNo = isset($data['bizNo'])? $data['bizNo'] : '';
  104. // 签名验证
  105. $len = mb_strlen($bizNo, 'utf-8');
  106. $userId = mb_substr($bizNo, 11, $len,'utf-8');
  107. if($idcard && $realname && $code == 'PASS' && $userId){
  108. // 更新信息
  109. Member::updateAuth($userId, $realname, $idcard);
  110. $this->assign('bizNo',$bizNo);
  111. $this->assign('code','success');
  112. $this->assign('result','<em>身份验证成功</em>,请等待审核');
  113. }else{
  114. $this->assign('bizNo', '');
  115. $this->assign('code','error');
  116. $this->assign('result','<em>身份验证失败</em>,请返回重试');
  117. }
  118. $params['user_id'] = $userId;
  119. PRedis::set("caches:faceAuth:result:{$bizNo}", $params, 3600);
  120. return $this->fetch();
  121. }
  122. /**
  123. * 学历认证
  124. * @return mixed
  125. */
  126. public function education()
  127. {
  128. return $this->fetch();
  129. }
  130. /**
  131. * 职位认证
  132. * @return mixed
  133. */
  134. public function position()
  135. {
  136. return $this->fetch();
  137. }
  138. }