Ejemplo n.º 1
0
 /**
  * 判断第三方账号是否绑定
  *
  * @param array $params 第三方返回账号唯一标示
  * @return array
  */
 public function checkBind($params)
 {
     $mTplogin = new UserThirdPartyLogin();
     $channel = UserThirdPartyLogin::BIND_API_CHANNEL;
     $openid = $params['open_id'];
     if (empty($openid)) {
         return responseArray(1101, 'id_not_find', '用户open_id丢失');
     }
     $checkResult = $mTplogin->checkBindByOpenid($openid, $channel);
     if ($checkResult === false) {
         return responseArray(1001, 'account_not_been_bind', '账号未绑定');
     } else {
         if ($checkResult > 0 && !is_array($checkResult)) {
             $userInfo = UserBaseInfo::find()->where('id=:id', [':id' => $checkResult])->one();
             if ($userInfo) {
                 if (!$userInfo->username) {
                     $userInfo->username = UserBaseInfo::genUsername($userInfo->id);
                     if (!$userInfo->save()) {
                         return responseArray(1, 'network_anomaly', '网络异常,稍后重试');
                     }
                 }
                 return responseArray(0, 'success', '账号已绑定', $userInfo->attributes);
             } else {
                 return responseArray(1402, 'user_not_exists', '用户不存在');
             }
         } else {
             if (is_array($checkResult)) {
                 return responseArray(1201, 'state_solution', '处于解绑状态');
             } else {
                 if ($checkResult === UserThirdPartyLogin::NOT_BOUND_USERID) {
                     return responseArray(1401, 'not_find_userid', '账户绑定但找不到user_id');
                 }
             }
         }
     }
 }