账户管理

更新时间:2022-02-17 07:01:31下载pdf

使用邮箱注册账号

在填写完注册邮箱后,请先通过以下方法查询验证码。

fun sendVerifyCode(
        userName: String?,
        region: String?,
        countryCode: String?,
        type: Int,
        listener: Business.ResultListener<String?>?,
    )

邮箱中收到验证码后,再调用以下方法进行注册。

fun register(
        userName: String?,
        region: String?,
        countryCode: String?,
        code: String?,
        passwd: String?,
        callback: IRegisterCallback,
    )

不同大区账号数据不互通,目前大区分为中国区、美洲区、欧洲区。其中 region 可为空(“”),countryCode 请参考 Demo 中的 Global.getCountryList() 方法。

参数说明

参数 说明
userName 用户名
region 可为空
countryCode 国家码
type 可为空

示例代码

TuyaSmartResidenceSdk.account().sendVerifyCode(userName =
        username, Global.region, Global.countryCode, Global.type, object: Business.ResultListener<String?> {
            override fun onFailure(p0: BusinessResponse?, p1: String?, p2: String?) {
                L.d(TAG, "BusinessResponse = $p0, result = $p1, msg = $p2")
            }

            override fun onSuccess(p0: BusinessResponse?, p1: String?, p2: String?) {
                L.d(TAG, "BusinessResponse = $p0, result = $p1, msg = $p2")
            }

        })

TuyaSmartResidenceSdk.account().register(username,  Global
            .region,
        Global.countryCode, authCode, password, object: IRegisterCallback {
            override fun onSuccess(user: User?) {
                context.startActivity(Intent(context, MainActivity::class.java))
            }

            override fun onError(code: String?, error: String?) {
                L.d(TAG, "register Error: code = $code, error = $error")
            }
        }
    )

登录账号

fun loginByEmail(
        countryCode: String?,
        email: String?,
        passwd: String?,
        listener: Business.ResultListener<User?>?,
    )

User 常用字段说明

字段名称 类型 说明
uid String 用户 ID
username String 用户名
mobile String 手机号
email String 邮箱地址
headPic String 头像地址
timezoneId String 时区 ID
nickName String 用户昵称

参数说明

参数 说明
email 邮箱地址
passwd 密码
countryCode 国家码

示例代码

TuyaSmartResidenceSdk.account().loginByEmail(Global.countryCode,
        username, password, object : Business.ResultListener<User?> {
            override fun onFailure(p0: BusinessResponse?, p1: User?, p2: String?) {
                L.d(TAG, "username = $username , password = $password")
                L.d(TAG, "ErrorMsg = ${p0?.errorMsg}, ErrorCode = ${p0?.errorCode}, apiName = $p2")
            }

            override fun onSuccess(p0: BusinessResponse?, p1: User?, p2: String?) {
                context.startActivity(Intent(context, MainActivity::class.java))
            }

        })

三方账号联合登录

涂鸦 智慧居住 App SDK 支持通过第三方账号进行登录,但需要提供第三方账号所属的邮箱地址和授权码,并与相应的第三方账号进行绑定。完成账号绑定后,可以调用智慧居住接口登录。

fun loginWithUid(countryCode: String, uid: String, authCode: String, callback: ILoginCallback)

参数说明

参数 说明
countryCode 国家或地区的编码
uid 邮箱地址
authCode 由调用方生成的授权码

用户 ID(uid)和授权码(authCode)可以根据您自定义的规则生成,智慧居住 SDK 不会限制生成规则,只限制用户 ID 的唯一性,以及用户 ID 和授权码必须一一对应。

查询个人信息

如未在登录成功时,保存登录用户的个人信息,那么可以使用以下方法进行查询。

fun getUserInfo(): User?

设置用户时区

用户需要设置时区以便授权的有效时间的时区单位,使用以下方法获得当前时区。

fun requestTimeZone(
    listener: Business.ResultListener<ArrayList<TimezoneeBean?>?>?
    )

使用以下方法设置时区。

fun updateTimeZone(
    timezoneid: String?,
    listener: Business.ResultListener<Boolean?>?
    )

TimezoneeBean 字段说明

字段名称 类型 说明
display String? 时区展示名称
timezoneId String? 时区 ID

修改密码

用户使用登录邮箱接收验证码可进行密码修改。

fun resetPasswordByEmail(
        countryCode: String?,
        email: String?,
        emailCode: String?,
        newPassword: String?,
        listener: Business.ResultListener<Boolean?>?,
    )

参数说明

参数名称 类型 说明
countryCode String? 国家码
email String? 邮箱地址
emailCode String? 验证码
newPassword String? 新密码
listener Business.ResultListener 结果回调

退出登录

当用户需要登出时调用以下方法即可登出,用户登出时,请返回登录页面,并清空所有缓存,否则会出现新登录的用户使用上一个登录用户数据的情况

fun logout(callBack: ILogoutCallback?)