Merchant Account Management

Last Updated on : 2022-02-17 06:11:39download

Overview

Noun explanation
Merchant Merchant entity information, mainly related to some merchant information, including merchant name, business license, etc.
Master account SaaS system master account, equivalent to developer account
Sub-account SaaS system sub-account will be associated with the master account

The corresponding ITuyaUser operation class can be obtained through TuyaOSUser.getUserInstance().

Account password login

Accounts are divided into main account and sub-account, both of which can use the password login function

Password login, if it is a pre-login (when returning multiple merchant information), you need to select the merchant, fill in the selected merchant Code into the login parameters, and re-log in with the password

Description

Account password login

void loginWithPassword(TuyaUserLoginWithPwdReqBean request, ITuyaUserLoginCallback<User> callback)

Parameter

Parameters Required or not Description
userName Required Account | Email
password Required Password
countryCode Required Country code such as “86”
merchantCode Optional Merchant Code

Example

/**
 * Account password login
 * @param view
 */
public void loginWithPwd(View view) {
    String username = etUsername.getText().toString();
    String merchantCode = etMerchant.getText().toString();
    String password = etPwd.getText().toString();
    TuyaUserLoginWithPwdReqBean reqBean = new TuyaUserLoginWithPwdReqBean();
    reqBean.setPassword(password);
    reqBean.setUsername(username);
    reqBean.setCountryCode("86");
    reqBean.setMerchantCode(merchantCode);

    TuyaOSUser.getUserInstance().loginWithPassword(reqBean, new ITuyaUserLoginCallback<User>() {
        @Override
        public void onPreLogin(List<TuyaMerchantBean> merchantBeanList) {
            StringBuilder sb = new StringBuilder();
            for (TuyaMerchantBean item: merchantBeanList) {
                sb.append(item.getMerchantCode())
                        .append(item.getMerchantName())
                        .append("\n");
            }
            toast("Need to enter the merchant code");
            L.d(TAG, "get merchantList");
            L.d(TAG, sb.toString());
            if(null != merchantBeanList && !merchantBeanList.isEmpty()){
                String merchantCode = merchantBeanList.get(0).getMerchantCode();
                etMerchant.setText(merchantCode);
                toast("Fill the merchant code");
            }
        }

        @Override
        public void onSuccess(User data) {
            toast("login success");
        }

        @Override
        public void onError(String errorCode, String errorMessage) {
            L.e(TAG, errorMessage);
            toast(errorMessage);
        }
    });
}

Account Verification Code Login

This function is divided into two steps. Obtain the login verification code, and then fill in the verification code to log in to the parameters. If it is a pre-login (multi-merchant) operation, the corresponding merchant code needs to be passed in to obtain the verification code again, and the corresponding The verification code and merchant code are passed in for login

Description

Get login verification code

void getValidateCode(TuyaUserSendCodeReqBean request, IResultCallback callback)

Parameter

Parameters Description
countryCode Country code: such as “86”
username phone number | email
codeType Get verification code type, login type pass 0

Description

Verification code login

void loginWithVerifyCode(TuyaUserLoginWithCodeReqBean request, ITuyaUserLoginCallback<User> callback)
Parameters Description
userName account number, phone number | email
code Verification code
countryCode Country code, such as “86”
merchantCode Merchant code, optional
/**
 * Account verification code login
 * @param view
 */
public void loginWithCode(View view) {
    String username = etUsername.getText().toString();
    String merchantCode = etMerchant.getText().toString();
    String code = etCode.getText().toString();
    TuyaUserLoginWithCodeReqBean reqBean = new TuyaUserLoginWithCodeReqBean();
    reqBean.setCode(code);
    reqBean.setUsername(username);
    reqBean.setCountryCode("86");
    reqBean.setMerchantCode(merchantCode);

    TuyaOSUser.getUserInstance().loginWithVerifyCode(reqBean, new ITuyaUserLoginCallback<User>() {
        @Override
        public void onPreLogin(List<TuyaMerchantBean> merchantBeanList) {
            StringBuilder sb = new StringBuilder();
            for (TuyaMerchantBean item: merchantBeanList) {
                sb.append(item.getMerchantCode())
                        .append(item.getMerchantName())
                        .append("\n");
            }
            toast("Need to enter the merchant code");
            L.d(TAG, "get merchantList");
            L.d(TAG, sb.toString());
            if(null != merchantBeanList && !merchantBeanList.isEmpty()){
                String merchantCode = merchantBeanList.get(0).getMerchantCode();
                etMerchant.setText(merchantCode);
                toast("Fill the merchant code");
            }
        }

        @Override
        public void onSuccess(User data) {
            toast("login success");
        }

        @Override
        public void onError(String errorCode, String errorMessage) {
            L.e(TAG, errorMessage);
            toast(errorMessage);
        }
    });
}

Three-party system authorization login

Authorization Process

  1. The three-party system server authorizes the account to Tuya Cloud. The third-party system determines the scope of the authorized account. It can be a user or employee account of the three-party system, or it can be authorized to Tuya Cloud for an account corresponding to any internal business form. Such as: companies, stores, projects, etc.
  2. For the authorized account, the general account of the three-party system server plus the country code, apply for a ticket to Tuya Cloud.

Merchant Account Management

scenes to be used

  1. Tuya’s system domain name plus this ticket can realize non-logging redirection. Example: lighting.console.tuyacn.com?ticket=xxx. For example: visit Tuya’s system website, or scan the code to visit the device control h5 page.
  2. Tuya Commercial Photo SDK obtains the session interface, passes in the ticket, obtains the session status, and accesses the complete SDK capabilities.

Description

Three-party system authorization login

void loginByTicket(String ticket, ITuyaUserResultCallback<User> listener);

Parameter

Parameters Description
ticket [Get ticket through authorization process](#Authorization process)

Sample Code

TuyaOSUser.getUserInstance().loginByTicket(content, new ITuyaUserResultCallback<User>(){
    @Override
    public void onSuccess(User user) {
        Log.e(TAG,"Login successful")
    }

    @Override
    public void onError(String code, String error) {
    Log.e(TAG,"Login failed:" + error)
    }
});

Sign in and register

The main account is directly registered through the login function, which is divided into two steps. First, obtain the verification code for login and registration, and then perform the login and registration function

Description

get verification code

void getValidateCode(TuyaUserSendCodeReqBean request, IResultCallback callback)

Parameter

Parameters Description
countryCode Country code: such as “86”
username phone number | email
codeType Get verification code type, type pass 3

Description

Login and register

void loginOrRegister(TuyaUserLoginOrRegisterReqBean request, ITuyaUserResultCallback<User> callback);

Parameter

Parameters Description
username account phone number | email
code Verification code
countryCode Country code such as “86”
industryType Industry Type
/**
 * get verification code
 * @param v
 */
public void getCode(View v){
  String username = etUsername.getText().toString();
  String merchantCode = etMerchant.getText().toString();
  TuyaUserSendCodeReqBean reqBean = new TuyaUserSendCodeReqBean();
  reqBean.setCountryCode("86");
  reqBean.setUsername(username);
  reqBean.setCodeType(codeType);
  reqBean.setMerchantCode(merchantCode);

  TuyaOSUser.getUserInstance().getValidateCode(reqBean, new IResultCallback() {
    @Override
    public void onError(String code, String error) {
      L.e(TAG, error);
      toast(error);
    }

    @Override
    public void onSuccess() {
      toast("getCode success");
    }
  });
}

/**
* Login to register
* */
public void loginOrRegister(View view) {
  String username = etUsername.getText().toString();
  String code = etCode.getText().toString();
  String countryCode = "86";
  String industryType = "security_az";

  TuyaUserLoginOrRegisterReqBean reqBean = new TuyaUserLoginOrRegisterReqBean();
  reqBean.setUsername(username);
  reqBean.setCode(code);
  reqBean.setCountry
Code(countryCode);
  reqBean.setIndustryType(industryType);

  TuyaOSUser.getUserInstance().loginOrRegister(reqBean, new ITuyaUserResultCallback<User>() {
    @Override
    public void onSuccess(User data) {
      toast("login or register success");
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
      toast(errorMessage);
    }
  });
}

Retrieve or reset password

Before the user logs in, there are three steps to modify the password. First, obtain the verification code for retrieving the password, pass the verification code into the list of merchants to find, and obtain the method for the corresponding individual merchant to retrieve the password.

Description

get verification code

void getValidateCode(TuyaUserSendCodeReqBean request, IResultCallback callback)

Parameter

Parameters Description
countryCode Country code: such as “86”
username phone number | email
codeType Get verification code type, type pass 2

Description

Find a business listing

void loginWithVerifyCode(TuyaUserLoginWithCodeReqBean request, ITuyaUserLoginCallback<User> callback);

Parameter

Parameters Description
countryCode Country code: such as “86”
username phone number | email
code Verification code

Description

Retrieve password

void findPassword(TuyaUserFindPwdReqBean request, ITuyaUserFindPasswordCallback callback);
Parameters Description
username account phone number | email
newPassword New Password
code Verification code
countryCode Country code such as “86”
merchantCode 商户code
/**
 * 1.0 Get verification code
 * @param v
 */
public void getCode(View v){
  String username = etUsername.getText().toString();
  String merchantCode = etMerchant.getText().toString();
  TuyaUserSendCodeReqBean reqBean = new TuyaUserSendCodeReqBean();
  reqBean.setCountryCode("86");
  reqBean.setUsername(username);
  reqBean.setCodeType(codeType);
  reqBean.setMerchantCode(merchantCode);

  TuyaOSUser.getUserInstance().getValidateCode(reqBean, new IResultCallback() {
    @Override
    public void onError(String code, String error) {
      L.e(TAG, error);
      toast(error);
    }

    @Override
    public void onSuccess() {
      toast("getCode success");
    }
  });
}

/**
 * 2.0 Query merchant list
 * @param view
 */
public void queryMerchants(View view) {
  String username = etUsername.getText().toString();
  String code = etCode.getText().toString();

  TuyaUserQueryMerchantWithCodeReqBean reqBean = new TuyaUserQueryMerchantWithCodeReqBean();
  reqBean.setCode(code);
  reqBean.setCountryCode("86");
  reqBean.setUsername(username);
  TuyaOSUser.getUserInstance().queryMerchantList(reqBean, new ITuyaUserResultCallback<List<TuyaMerchantBean>>() {
    @Override
    public void onSuccess(List<TuyaMerchantBean> data) {
      if(null == data ){
        toast("The merchant list is empty");
        return;
      }
      int size = data.size();
      if(0 <= size){
        String merchantCode = data.get(0).getMerchantCode();
        etMerchant.setText(merchantCode);
        toast("queryMerchants success fill the 0th merchant code");
      }
    }

    @Override
    public void onError(String errorCode, String errorMessage) {
      toast(errorMessage);
    }
  });
}

/**
 * Retrieve password
 * @param view
 */
public void resetPwd(View view) {
  String username = etUsername.getText().toString();
  String merchantCode = etMerchant.getText().toString();
  String code = etCode.getText().toString();
  String password = etPwd.getText().toString();

  TuyaUserFindPwdReqBean reqBean = new TuyaUserFindPwdReqBean();
  reqBean.setUsername(username);
  reqBean.setNewPassword(password);
  reqBean.setCode(code);
  reqBean.setCountryCode("86");
  reqBean.setMerchantCode(merchantCode);

  TuyaOSUser.getUserInstance().findPassword(reqBean, new IResultCallback() {
    @Override
    public void onError(String code, String error) {
      toast(error);
    }

    @Override
    public void onSuccess() {
      toast("findPassword success");
    }
  });
}

Change password

After the user logs in to modify the password, the password can be modified directly by passing the old password and the new password

Description

change Password

void modifyPassword(TuyaUserModifyPwdReqBean request, IResultCallback callback);
Parameters Description
oldPassword Old Password
newPassword New Password

Example

public void modifyPwd(View view) {
  String oldPwd = etPwd.getText().toString();
  String newPwd = etNewPwd.getText().toString();
  TuyaUserModifyPwdReqBean reqBean = new TuyaUserModifyPwdReqBean();
  reqBean.setOldPassword(oldPwd);
  reqBean.setNewPassword(newPwd);

  TuyaOSUser.getUserInstance().modifyPassword(reqBean, new IResultCallback() {
    @Override
    public void onError(String code, String error) {
      toast(error);
      L.e(TAG, error);
    }

    @Override
    public void onSuccess() {
      toast("modify success");
    }
  });
}

Account logout

Description

Account logout

void logout(IResultCallback callback)

Account logout

Description

Account logout

void cancelAccount(IResultCallback callback)

User infomation

Sync user information

When the user information is changed, such as the user’s avatar, nickname, etc., the synchronization user information interface needs to be called to keep the user information in the latest state. If multiple devices log in at the same time, one device has modified user information. Another device also needs to synchronize user information. You can call the synchronization interface when viewing user information to synchronize the latest user information.

Description

Used to synchronize user information

void updateUserInfo(IResultCallback callback);

Parameter

Parameters Description
callback callback

Sample Code

TuyaOSUser.getUserInstance().updateU
serInfo(new IResultCallback() {
  @Override
  public void onError(String code, String error) {

  }

  @Override
  public void onSuccess() {
    User user = TuyaOSUser.getUserInstance().getUser();
  }
});

Modify user avatar

Description

Used to upload user-defined avatars.

void uploadUserAvatar(File file, IResultCallback callback)

Parameter

Parameters Description
file User profile picture file
callback callback

Sample Code

TuyaOSUser.getUserInstance().uploadUserAvatar(file,
    new IResultCallback() {
        @Override
        public void onSuccess() {
        }

        @Override
        public void onError(String code, String error) {

        }
});

Change username

Description

change username

void updateNickName(String name, final IResultCallback callback);

Parameter

Parameters Description
name nickname
callback callback

Sample Code

TuyaOSUser.getUserInstance().updateNickName(nickName,
    new IResultCallback() {
        @Override
        public void onSuccess() {
        }
        @Override
        public void onError(String code, String error) {

        }
});

Update user time zone

Description

Used to update the user’s time zone.

void updateTimeZone(String timezoneId, IResultCallback callback);

Parameter

Parameters Description
timezoneId timezone id
callback callback

Sample Code

TuyaOSUser.getUserInstance().updateTimeZone(
    timezoneId,
    new IResultCallback() {
        @Override
        public void onSuccess() {
        }

        @Override
        public void onError(String code, String error) {

        }
});