SocialController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace addons\AvoidTax\api\controllers;
  3. use addons\AvoidTax\common\service\SocialService;
  4. use api\controllers\OnAuthController;
  5. use common\models\user\User;
  6. use phpDocumentor\Reflection\Types\This;
  7. class SocialController extends OnAuthController
  8. {
  9. public $modelClass = '';
  10. /**
  11. * 检查是否授权
  12. */
  13. public function actionCheckAuth(){
  14. $mobile = $this->request->post('mobile');
  15. $name = $this->request->post('name');
  16. if ( empty($mobile) || empty($name) ) return $this->error("缺少姓名或手机号码");
  17. if ( !preg_match("/^1[3456789]{1}\d{9}$/", $mobile) ) return $this->error("请输入正确的支付宝手机号码");
  18. $user_id = User::find()->where(['mall_id'=>$this->mall_id,'mobile'=>$mobile])->select('id')->scalar();
  19. if ( $user_id != $this->user_id ){
  20. return $this->error( "该手机号码已绑定用户ID:{$user_id},请检查重新提交" );
  21. }
  22. // 是否授权
  23. $service = new SocialService(['mall_id'=>$this->mall_id]);
  24. if(!$service->checkAuth(intval($this->user_id))) return $this->success('已授权',['is_auth'=>true]);
  25. // 生成授权url
  26. $auth_url= $service->goToAuth($this->user_id,$name,$mobile);
  27. return $auth_url == false ?
  28. $this->error( $service->error ) :
  29. $this->success('请前往实名认证',['is_auth'=>false,'auth_url'=>$auth_url]);
  30. }
  31. }