更新时间:2019-11-20
描述
在使用CloudEC解决方案下的各类业务之前,需要向服务器完成登录。不再使用业务时需注销,确保业务接口使用的安全性。
登录成功后,SDK自动按保活周期定时刷新鉴权凭证信息。
前提条件
已完成初始化。
业务流程
//Java code TsdkLoginParam tsdkLoginParam = new TsdkLoginParam(); tsdkLoginParam.setUserId(1); tsdkLoginParam.setAuthType(TsdkAuthType.TSDK_E_AUTH_NORMAL); tsdkLoginParam.setUserName(loginParam.getUserName()); tsdkLoginParam.setPassword(loginParam.getPassword()); tsdkLoginParam.setServerAddr(loginParam.getServerUrl()); tsdkLoginParam.setServerPort(loginParam.getServerPort()); tsdkLoginParam.setServerVersion(""); tsdkLoginParam.setServerType(TSDK_E_SERVER_TYPE_PORTAL); tsdkLoginParam.setUserTicket(""); ret = TsdkManager.getInstance().getLoginManager().login(tsdkLoginParam); |
//Java code public void onEvtAuthSuccess(int userId, TsdkImLoginParam imLoginParam) { LogUtil.e(TAG, "authorize success."); // 启动IM的登录 if (TsdkManager.getInstance().getAppInfo().getSupportIm() == 1 && null != imLoginParam) { ImAccountInfo imAccountInfo = new ImAccountInfo(); imAccountInfo.setAccount(imLoginParam.getAccount()); imAccountInfo.setToken(imLoginParam.getToken()); String[] MaaUri = imLoginParam.getMaaServerUri().split(":"); imAccountInfo.setMaaServer(MaaUri[0]); imAccountInfo.setMaaServerPort(Integer.valueOf(MaaUri[1])); imAccountInfo.setPassword(imLoginParam.getPassword()); imAccountInfo.setPushServer(imLoginParam.getPushServerUri()); sendHandlerMessage(LoginEvent.LOGIN_E_EVT_AUTH_SUCCESS.getIndex(), imAccountInfo); } } |
如果登录成功,会上报帐号短号号码,UI应保存此号码,以方便后续操作。
//Java code public void onEvtVoipAccountStatus(int userId, TsdkVoipAccountInfo voipAccountInfo ) { LogUtil.e(TAG, "voip account status: " ); this.sipNumber = voipAccountInfo.getNumber(); if (!voipAccountInfo.getTerminal().equals("")) { this.terminal = voipAccountInfo.getTerminal(); } } |
有时候会出现鉴权成功,但是voip登录失败的情况。可修改初始化时的参数productName来解决。
//Java code public void onEvtLoginSuccess(int userId) { LogUtil.i(TAG, "voip login success"); this.loginEventNotifyUI.onLoginEventNotify(LoginConstant.LoginUIEvent.LOGIN_SUCCESS, userId, "voip login success"); } |
注意事项
无。
描述
不再使用业务时需注销,确保业务接口使用的安全性。
前提条件
登录成功。
业务流程
//Java code public void logout() { int ret = TsdkManager.getInstance().getLoginManager().logout(); if (ret != 0) { LogUtil.e(TAG, "login is failed, return " + ret); } ImMgr.getInstance().imLogout(); } |
注意事项
无。
描述
不再使用业务时需注销,确保业务接口使用的安全性。
前提条件
登录成功。
业务流程
用户帐号在其他位置登录时,服务器会通知应用程序注销本地帐号。
注意事项
无。
应用程序监测到断网重连,应根据预先配置的策略确定是否自动发起登录流程,若预配置,则发起登录流程,与普通的“登录”流程相同。
描述
用户可以通过该接口修改自己的帐号的密码。
前提条件
登录成功。
业务流程
//Java code public int modifyPwd(String newPwd, String oldPwd) { TsdkModifyPasswordParam modifyPasswordParam = new TsdkModifyPasswordParam(newPwd, oldPwd); int ret = TsdkManager.getInstance().getLoginManager().modifyPassword(modifyPasswordParam); if (ret != 0) { LogUtil.e(TAG, "modifyPwd is failed, return " + ret); } return ret; } |
代码示例:
//Java code @Override public void onEvtModifyPasswordResult(int userId, final TsdkCommonResult result) { Log.i(TAG, "onEvtModifyPasswordResult notify."); LoginMgr.getInstance().handModifyPasswordResult(result); }