Beispiel #1
0
 /**
  * 用户通过手机号来注册
  */
 public function registerAction()
 {
     $view = new ViewModel();
     $request = $this->getRequest();
     $user = $this->authentication()->getIdentity();
     if ($user) {
         return $this->redirect()->toUrl('/test_qoros');
     } else {
         //get user info
         if (parent::isWeixin() && !$request->isPost()) {
             $code = $this->getParam('code', false);
             if (!$code) {
                 $redirectUrl = $this->wechat->getOauthRedirect('http://' . $_SERVER['SERVER_NAME'] . '/test_qoros/user/completeInfo');
                 return $this->redirect()->toUrl($redirectUrl);
             }
             $tokenData = $this->wechat->getOauthData();
             $user = $this->userModel->getByOpenId($tokenData['openid']);
             if ($user) {
                 $result = $this->login($user->mobile, null, false);
                 if ($result->getCode() == Result::SUCCESS && $user->username != $user->openid) {
                     return $this->redirect()->toUrl('/test_qoros');
                 }
             }
             $view->setVariables(array('openid' => $tokenData['openid']));
         }
     }
     if ($request->isPost()) {
         $mobile = $this->getParam('mobile');
         $openid = $this->getParam('openid', false);
         $exsit = $this->userModel->getUserByMobile($mobile);
         if ($exsit) {
             //to login
             $this->login($mobile, false, false);
             $user = $this->authentication()->getIdentity();
             if (isset($openid) && $openid) {
                 $userInfo = $this->wechat->getUserInfo($openid);
                 if (isset($userInfo['headimgurl'])) {
                     $user->avatar = $userInfo['headimgurl'];
                 }
                 $user->open_id = $openid;
                 $this->userModel->updateUserInfo($user);
             }
             return new UnifyJsonModel();
         } else {
             return new ErrorJsonModel(1001, '手机号码不存在');
         }
     }
     return $view;
 }
 function __construct()
 {
     parent::__construct();
 }