文档

账号及用户SDK

更新时间:
一键部署

账号及用户SDK提供了账号能力,包括注册、登录、登出、获取账号、会话管理、人机校验等功能,还提供了UI集成显示、UI定制等能力。本文介绍内置账号和三方自有账号功能内容。

初始化

初始化前需确保已正确集成安全图片。具体操作,请参见SDK初始化集成安全图片

内置账号

内置账号为物联网智能视频服务提供的账号能力,您在客户端集成后即可使用。包括以下内容:

  • 基础功能:包括注册、登录、退出登录、忘记密码、注销账号等。发送短信的业务存在使用限制,具体说明,请参见使用限制的短信限制

    • 注册。

      调用登录页面后,在登录页面内会出现注册和忘记密码的功能,无需额外开发。

    • 登录。

      目前平台已经支持两种登录方式:账号登录、邮箱登录。登录页面调起后,两种登录方式都可以使用。

      LoginBusiness.login(new ILoginCallback() {
          @Override
          public void onLoginSuccess() {
              Log.i(TAG,"登录成功");                    
         }
          @Override
          public void onLoginFailed(int code, String error) {
              Log.i(TAG,"登录失败");                    
          }
      });

      您也可以自行开发短信登录方式,需自行开发UI界面。

      /**
       * 获取验证码
       * @param mobile 手机号码
       * @param mobileLocationCode 手机号国家区号 
       * @param callback 
       */
      LoginBusiness.sendPhoneSmsCodeForLogin(mobile, mobileLocationCode, new SendSMSCallback() {
          @Override
          public void onSuccess() {
              Log.d(TAG,"sendPhoneSmsCodeForLogin onSuccess");
          }
      
          @Override
          public void onFailure(int code, String msg) {
              Log.d(TAG,"sendPhoneSmsCodeForLogin onFailure   code:"+code+"  msg:"+msg);
          }
      });
      
      /**
       * 通过验证码登录接口
       * @param context 上下文可以是Activity
       * @param mobile 手机号码
       * @param mobileLocationCode 手机号国家区号 
       * @param smsCode 手机验证码
       * @param callback 
       */
      LoginBusiness.loginWithSMSCode(context, mobile, mobileLocationCode, smsCode, new ILoginCallback() {
          @Override
          public void onLoginSuccess() {
             Log.d(TAG,"onLoginSuccess");
          }
      
          @Override
          public void onLoginFailed(int errorCode, String errorMsg) {
              Log.d(TAG,"onLoginFailed     code:"+errorCode+"    errorMsg:"+errorMsg);
          }
      });
    • 退出登录。

      LoginBusiness.logout(new ILogoutCallback() {
          @Override
          public void onLogoutSuccess() {
              Log.i(TAG,"登出成功");                    
          }
      
          @Override
          public void onLogoutFailed(int code, String error) {
              Log.i(TAG,"登出失败");                    
          }
      });
    • 忘记密码。

      在调起登录页面后,在登录页面内会出现注册和忘记密码的功能,无需额外开发。

    • 注销账号。

      注销账号的同时会把用户绑定的设备都解除绑定关系,请参见客户端API参考>账号服务文档。

  • 修改个人信息。

    Map<String, Object> map = new LinkedHashMap<>();
    map.put("displayName", newName);
    OpenAccountUIService oas = OpenAccountSDK.getService(OpenAccountUIService.class);
    oas.updateProfile(getApplicationContext(), map, new LoginCallback() {
        @Override
        public void onSuccess(OpenAccountSession openAccountSession) {
        }
    
        @Override
        public void onFailure(int i, String s) {
        }
    });
  • 修改头像。

    Map<String, Object> map = new LinkedHashMap<>();
    map.put("avatarUrl", avatarUrl);
    OpenAccountUIService oas = OpenAccountSDK.getService(OpenAccountUIService.class);
    oas.updateProfile(getApplicationContext(), map, new LoginCallback() {
        @Override
        public void onSuccess(OpenAccountSession openAccountSession) {
        }
    
        @Override
        public void onFailure(int i, String s) {
        }
    });
  • 刷新会话。

    LoginBusiness.refreshSession(true, new IRefreshSessionCallback() {
        @Override
        public void onRefreshSuccess() {
            Log.i(TAG,"刷新Session成功");
        }
    
        @Override
        public void onRefreshFailed() {
            Log.i(TAG,"刷新Session失败");
        }
    });
  • 获取会话ID。

    LoginBusiness.getSessionId();
  • 获取用户信息。

    LoginBusiness.getUserInfo();

三方自有账号

在对接三方自有账号之前,须先确认默认的账号页面(内置账号体系)可以正常注册和登录,并完成SDK的初始化。

选择自有账号通过OAuth 2.0协议接入,配置流程,请参见用户账号开发指南

三方自有账号在自有服务器上登录成功之后,获取Authorization Code(请参见用户账号开发指南),然后调用以下方法完成认证。

说明

在调用登录或者登出接口时,直接调用LoginBusiness.loginLoginBusiness.logout两个方法即可。

LoginBusiness.authCodeLogin(authCode, new ILoginCallback() {
    @Override
    public void onLoginSuccess() {

    }

    @Override
    public void onLoginFailed(int i, String s) {
        Log.d(TAG, "code: " + i + ", str: " + s);
    }
});