示例#1
0
 private void requestThirdBind(int type) {
   Object object = ThirdPortDelivery.getUserInfo(type);
   if (object == null) {
     return;
   }
   String platform = "";
   String userName = "";
   String nickName = "";
   String avatar = "";
   String gender = "";
   String token = "";
   switch (type) {
     case PlatformManager.PLATFORM_WECHAT:
       {
         WeiChat.WeChatUserInfo userInfo = (WeiChat.WeChatUserInfo) object;
         platform = "weixin";
         userName = userInfo.unionid;
         nickName = userInfo.nickname;
         avatar = userInfo.headimgurl;
         gender = userInfo.sex == 1 ? "1" : "0";
         token = userInfo.token;
         UserProperties.saveWeiXin(userName);
         UserProperties.saveUserOpenId(userInfo.openid);
         break;
       }
     case PlatformManager.PLATFORM_QQ:
       {
         QQConnect.QQUserInfo userInfo = (QQConnect.QQUserInfo) object;
         platform = "qq";
         userName = userInfo.uid;
         nickName = userInfo.nickName;
         avatar = userInfo.avatar;
         gender = userInfo.isBoy() ? "1" : "0";
         token = userInfo.token;
         UserProperties.saveQQ(userName);
         UserProperties.saveUserOpenId(userInfo.uid);
         break;
       }
     case PlatformManager.PLATFORM_WEBLOG:
       {
         WeiBlog.UserInfo userInfo = (WeiBlog.UserInfo) object;
         platform = "weibo";
         userName = userInfo.uid;
         nickName = userInfo.name;
         avatar = userInfo.avatar;
         gender = userInfo.isGirl() ? "0" : "1";
         token = userInfo.token;
         UserProperties.saveWeiBo(userName);
         UserProperties.saveUserOpenId(userInfo.uid);
         break;
       }
   }
   Intent intent = new Intent(UserProperties.INTENT_BIND);
   LocalBroadcastManager.getInstance(BaseApp.getApplication()).sendBroadcast(intent);
   finishAfterDone(0);
 }
示例#2
0
  private void requestThirdLogin(int type) {
    Object object = ThirdPortDelivery.getUserInfo(type);
    if (object == null) {
      return;
    }
    String platform = "";
    String userName = "";
    String nickName = "";
    String avatar = "";
    String gender = "";
    String token = "";
    switch (type) {
      case PlatformManager.PLATFORM_WECHAT:
        {
          WeiChat.WeChatUserInfo userInfo = (WeiChat.WeChatUserInfo) object;
          platform = "weixin";
          userName = userInfo.unionid;
          nickName = userInfo.nickname;
          avatar = userInfo.headimgurl;
          gender = userInfo.sex == 1 ? "1" : "0";
          token = userInfo.token;
          UserProperties.saveWeiXin(userName);
          UserProperties.saveUserOpenId(userInfo.openid);
          break;
        }
      case PlatformManager.PLATFORM_QQ:
        {
          QQConnect.QQUserInfo userInfo = (QQConnect.QQUserInfo) object;
          platform = "qq";
          userName = userInfo.uid;
          nickName = userInfo.nickName;
          avatar = userInfo.avatar;
          gender = userInfo.isBoy() ? "1" : "0";
          token = userInfo.token;
          UserProperties.saveQQ(userName);
          UserProperties.saveUserOpenId(userInfo.uid);
          break;
        }
      case PlatformManager.PLATFORM_WEBLOG:
        {
          WeiBlog.UserInfo userInfo = (WeiBlog.UserInfo) object;
          platform = "weibo";
          userName = userInfo.uid;
          nickName = userInfo.name;
          avatar = userInfo.avatar;
          gender = userInfo.isGirl() ? "0" : "1";
          token = userInfo.token;
          UserProperties.saveWeiBo(userName);
          UserProperties.saveUserOpenId(userInfo.uid);
          break;
        }
    }

    final String platformInfo = platform;
    UserProperties.saveUserCurrentAccountType(platformInfo);

    UserApi.platformLogin(
        platformInfo,
        userName,
        nickName,
        avatar,
        gender,
        token,
        new ApiCallback<User>() {
          @Override
          public void onResult(User result) {
            if (result != null && result.available()) {
              UserProperties.login(result);
              ToastAlarm.show("登录成功");
              if (StringUtils.isEmpty(result.getPhone())) {
                startActivity(new Intent(getContext(), UserBindPhoneActivity.class));
              }
            } else {
              if (result.getStatusState() == -2) { // 未注册
                startActivity(new Intent(getContext(), UserBindPhoneActivity.class));
              }
              if (result != null) {
                ToastAlarm.show(result.getErrorMsg());
              } else {
                ToastAlarm.show("未知原因");
              }
            }
            finishAfterDone(0);
          }
        });
  }