コード例 #1
0
 /**
  * 根据用户id关联用户表和第三方登录表
  *
  * @param string $open_id 用户身份唯一标识
  * @param string $type 第三方绑定类型 Weixin QQ Weibo
  * @return array|bool
  */
 public function getThirdParty($open_id, $type)
 {
     return self::find()->from(self::tableName() . ' t1')->innerJoin(UserThirdPartyLogin::tableName() . 't2', 't1.id=t2.user_id')->where(['t1.open_id' => $open_id, 't2.type' => $type])->one();
 }
コード例 #2
0
ファイル: UserService.php プロジェクト: songhongyu/datecenter
 public function getUserBindInfo($username, $type, $openId)
 {
     $third = new UserThirdPartyLogin();
     $channel = UserThirdPartyLogin::BIND_API_CHANNEL;
     if (!$username) {
         return responseArray(1101, 'username_pwd_params_missing', '用户标识丢失');
     }
     if (!$type) {
         return responseArray(1201, 'third_type_not_found', '第三方类型不能为空');
     }
     if (!$openId) {
         return responseArray(1202, 'third_openId_not_found', '第三方账号关联open_id丢失');
     }
     $user = UserBaseInfo::find()->where(['mobile' => $username])->orWhere(['email' => $username])->one();
     $userOpenId['open_id'] = $user['open_id'];
     if ($user == null) {
         return responseArray(1102, 'user_not_exists', '用户不存在');
     }
     $info = $third->checkBindByUAT($user['id'], $channel, $type, true);
     $beenBind = $third->checkBeenBindUAT($user['id'], $channel, $type, true);
     if ($info && is_array($info) || $beenBind) {
         if ($beenBind['open_id'] == $openId) {
             return responseArray(0, 'success', '用户已绑定并与现操作绑定号一致', $beenBind['open_id']);
         }
         $beenBind['profile_info'] = json_decode($beenBind['profile_info']);
         $oldBind = [];
         if (isset($beenBind['profile_info'])) {
             foreach ($beenBind['profile_info'] as $key => $value) {
                 $oldBind[$key] = $value;
             }
         }
         $oldBind['open_id'] = $beenBind['open_id'];
         return responseArray(1401, 'has_been_bind', '用户已绑定但与现操作绑定号不一致', $oldBind);
     }
     if (!is_array($info)) {
         return responseArray(1301, 'user_not_bind', '用户未绑定', $user->attributes);
     }
 }
コード例 #3
0
 /**
  * 第三方解绑
  */
 public function actionUnbind()
 {
     try {
         $request = Yii::$app->getRequest();
         $thirdParty = new UserThirdPartyLogin();
         $params = $request->post();
         $openid = isset($params['open_id']) ? $params['open_id'] : '';
         $type = isset($params['type']) ? $params['type'] : '';
         if (!$openid) {
             return responseArray(1101, 'openid_params_missing', '缺失用户身份唯一标识openid参数');
         }
         $user = UserBaseInfo::find()->where(['open_id' => $openid])->one();
         if (!$user) {
             return responseArray(2103, 'user_not_exists', '用户不存在');
         }
         if (!$type) {
             return responseArray(1102, 'type_params_missing', '缺失第三方解绑类型参数');
         }
         $userThirdparty = $thirdParty->getByUserId($user->id, UserThirdPartyLogin::BIND_API_CHANNEL, $type);
         if (!$userThirdparty) {
             return responseArray(2104, 'user_notbind_thirdparty', '用户未绑定第三方登录');
         }
         if ($userThirdparty->status == UserThirdPartyLogin::STATUS_LOGIN_UNBIND) {
             return responseArray(2101, 'thirdparty_already_unbind', '第三方登录已解绑');
         }
         $userThirdparty->status = UserThirdPartyLogin::STATUS_LOGIN_UNBIND;
         if ($userThirdparty->save()) {
             return responseArray(0, 'success', '解绑成功');
         } else {
             return responseArray(2102, 'unbind_failure', '解绑失败');
         }
     } catch (Exception $ex) {
         return responseArray(1, 'network_anomaly', '网络异常,请稍后重试');
     }
 }
コード例 #4
0
 public function actionSafety()
 {
     $userBaseInfo = new UserBaseInfo();
     $address = new Address();
     $userTB = new UserThirdPartyLogin();
     $this->layout = 'uc';
     if (!$userBaseInfo->islogin()) {
         return $this->redirect(array('user/login'));
     } else {
         // 获取用户密码信息
         // $cookie = Yii::$app->getRequest()->cookies;
         // $cookieId = $cookie[UserBaseInfo::COOKIE_KEY_ID]->value;
         $session = Yii::$app->session[UserBaseInfo::SESSION_KEY_USER];
         $userId = isset($session['id']) && $session['id'] ? $session['id'] : 0;
         $inforMation = $userBaseInfo->getUserById($userId);
         $addr = $address->getAddress($userId);
         $thirds = $userTB->getBindByUser($userId, UserThirdPartyLogin::BIND_WEB_CHANNEL) ? $userTB->getBindByUser($userId, UserThirdPartyLogin::BIND_WEB_CHANNEL) : [];
         foreach ($thirds as $key => $value) {
             $thirds[$key]['type'] = strtoupper($thirds[$key]['type']);
         }
         $level = 0;
         $item = 5;
         if ($thirds) {
             $level += count($thirds) * 10;
             $item -= count($thirds);
         }
         if ($inforMation['mobile']) {
             $level += 40;
             $item -= 1;
         }
         if ($inforMation['email']) {
             $level += 30;
             $item -= 1;
         }
         $inforMation['level'] = $level;
         $inforMation['item'] = $item;
         $inforMation['addrNum'] = count($addr);
         $inforMation['thirds'] = arrayColumn($thirds, 'type');
         return $this->render('safety', $inforMation);
     }
 }