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