Example #1
0
 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);
     }
 }