更新时间:2024-06-26 01:45:01下载pdf
SDK 最低支持 iOS 系统版本 10.0。
在 Podfile
文件中添加以下内容,之后在项目根目录下执行 pod update
命令进行集成。
platform :ios, '10.0'
target 'Your_Project_Name' do
pod "ThingSmartUserToBKit"
end
名词 | 解释 |
---|---|
商户 | 商户实体信息,主要关联一些商户信息,包括商户名和营业执照等 |
主账号 | SaaS 体系主账号,等同于开发者账号 |
子账号 | SaaS 体系子账号,会关联一个主账号 |
通过 [ThingSmartUser sharedInstance]
,获取对应 ThingSmartUser
操作类。用户相关的属性在 ThingSmartUser.h
下获取。
账号分为主账号和子账号,均可使用该密码登录功能。如果为预登录(当返回多个商户信息时),需要选择商户,并将选择的商户 Code 填入登录入参,重新进行密码登录。
接口说明
账号密码登录。
- (void)loginMerchantByPassword:(NSString *_Nonnull)password
countryCode:(NSString *_Nonnull)countryCode
username:(NSString *_Nonnull)username
merchantCode:(NSString *_Nullable)merchantCode
multiMerchantHanlder:(void(^_Nullable)(NSArray<ThingSmartMerchantModel *> * _Nonnull merchantInfos))multiMerchantHanlder
success:(ThingSuccessHandler _Nullable)success
failure:(ThingFailureError _Nullable)failure
参数说明
字段 | 是否必填 | 描述 |
---|---|---|
username | 必填 | 账号 | 邮箱 |
password | 必填 | 密码 |
countryCode | 必填 | 国家区号,例如 86 |
merchantCode | 非必填 | 商户 Code。单商户时不需要填,多商户时需要填 |
multiMerchantHanlder | 非必填 | 当商户数量大于 1 时,会回调,无法直接登录成功,需要选择商户后重新登录 当商户数量为 1 时,直接登录成功 |
示例代码
Objective-C:
//单商户
[[ThingSmartUser sharedInstance]loginMerchantByPassword:@"your_password" countryCode:@"your_countryCode" username:@"your_username" merchantCode:nil multiMerchantHanlder:nil success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login error");
}];
//多商户
[[ThingSmartUser sharedInstance]loginMerchantByPassword:@"your_password" countryCode:@"your_countryCode" username:@"your_username" merchantCode:nil multiMerchantHanlder:^(NSArray<ThingSmartMerchantModel *> * _Nonnull merchantInfos) {
NSLog(@"get merchantCode and login again");
[[ThingSmartUser sharedInstance]loginMerchantByPassword:@"your_password" countryCode:@"your_countryCode" username:@"your_username" merchantCode:@"your_merchantCode" multiMerchantHanlder:nil success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login error");
}];
} success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login error");
}];
Swift:
//单商户
ThingSmartUser.sharedInstance()?.loginMerchant(byPassword: "your_password", countryCode: "your_countryCode", username: "your_username", merchantCode: nil, multiMerchantHanlder: nil, success: {
print("login success")
}, failure: { (error) in
if let e = error {
print("login failure: \(e)")
}
})
//多商户
ThingSmartUser.sharedInstance()?.loginMerchant(byPassword: "your_password", countryCode: "your_countryCode", username: "your_username", merchantCode: nil, multiMerchantHanlder: { (result) in
ThingSmartUser.sharedInstance()?.loginMerchant(byPassword: "your_password", countryCode: "your_countryCode", username: "your_username", merchantCode: "merchant_code", multiMerchantHanlder: nil, success: {
print("login success")
}, failure: { (error) in
if let e = error {
print("login failure: \(e)")
}
})
}, success: {
print("login success")
}, failure: { (error) in
if let e = error {
print("login failure: \(e)")
}
})
验证码登录功能分为两步,先获取登录验证码,然后将验证码填入验证码登录入参。如果是预登录(有多商户)操作,则需要传入对应的商户 Code 来重新获取验证码,并将对应的验证码和商户 Code 传入进行登录。
接口说明
获取登录验证码。
- (void)sendMerchantVerifyCodeWithCountryCode:(NSString *_Nonnull)countryCode
username:(NSString *_Nonnull)username
codeType:(ThingMerchantCodeType)codeType
merchantCode:(NSString *_Nullable)merchantCode
success:(ThingSuccessHandler _Nullable)success
failure:(ThingFailureError _Nullable)failure
参数说明
参数 | 说明 |
---|---|
countryCode | 国家区号,例如 86 |
username | 手机号码 | 邮箱 |
codeType | 获取验证码类型,登录类型传 ThingMerchantCodeLogin |
示例代码
Objective-C:
[[ThingSmartUser sharedInstance]sendMerchantVerifyCodeWithCountryCode:@"your_country_code" username:@"your_username" codeType:ThingMerchantCodeLogin merchantCode:nil success:^{
NSLog(@"send verify code success");
} failure:^(NSError *error) {
NSLog(@"send verify code failure: %@", error);
}];
Swift:
ThingSmartUser.sharedInstance()?.sendMerchantVerifyCode(withCountryCode: "your_country_code", username: "your_username", codeType: ThingMerchantCodeType.login, merchantCode: nil, success: {
print("send verify code success")
}, failure: { (error) in
if let error = error {
print("send verify code failure: \(error)")
}
})
接口说明
验证码登录。
- (void)loginMerchantByVerificationCode:(NSString *_Nonnull)code
countryCode:(NSString *_Nonnull)countryCode
username:(NSString *_Nonnull)username
merchantCode:(NSString *_Nullable)merchantCode
multiMerchantHanlder:(void(^_Nullable)(NSArray<ThingSmartMerchantModel *> * _Nonnull merchantInfos))multiMerchantHanlder
success:(ThingSuccessHandler _Nullable)success
failure:(ThingFailureError _Nullable)failure
字段 | 描述 |
---|---|
username | 账号,手机号码 | 邮箱 |
code | 验证码 |
countryCode | 国家区号,例如 86 |
merchantCode | 商户 Code。单商户时不需要填,多商户时需要填 |
multiMerchantHanlder | 当商户数量大于 1 时,会回调,无法直接登录成功,需要选择商户后重新登录 当商户数量为 1 时,直接登录成功 |
示例代码
Objective-C:
//单商户
[[ThingSmartUser sharedInstance]loginMerchantByVerificationCode:@"verification_code" countryCode:@"your_countryCode" username:@"your_username" merchantCode:nil multiMerchantHanlder:nil success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login error");
}];
//多商户
[[ThingSmartUser sharedInstance]loginMerchantByVerificationCode:@"verification_code" countryCode:@"your_countryCode" username:@"your_username" merchantCode:nil multiMerchantHanlder:^(NSArray<ThingSmartMerchantModel *> * _Nonnull merchantInfos) {
NSLog(@"get merchantCode and login again");
[[ThingSmartUser sharedInstance]loginMerchantByVerificationCode:@"verification_code" countryCode:@"your_countryCode" username:@"your_username" merchantCode:@"merchant_code" multiMerchantHanlder:nil success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login error");
}];
} success:^{
NSLog(@"login success");
} failure:^(NSError *error) {
NSLog(@"login error");
}];
Swift:
//单商户
ThingSmartUser.sharedInstance()?.loginMerchant(byVerificationCode: "verification_code", countryCode: "your_countryCode", username: "your_username", merchantCode: nil, multiMerchantHanlder: nil, success: {
print("login success")
}, failure: { (error) in
if let e = error {
print("login failure: \(e)")
}
})
//多商户
ThingSmartUser.sharedInstance()?.loginMerchant(byVerificationCode: "verification_code", countryCode: "your_countryCode", username: "your_username", merchantCode: nil, multiMerchantHanlder: { (result) in
ThingSmartUser.sharedInstance()?.loginMerchant(byVerificationCode: "verification_code", countryCode: "your_countryCode", username: "your_username", merchantCode: "merchant_code", multiMerchantHanlder: nil, success: {
print("login success")
}, failure: { (error) in
if let e = error {
print("login failure: \(e)")
}
})
}, success: {
print("login success")
}, failure: { (error) in
if let e = error {
print("login failure: \(e)")
}
})
授权流程
三方系统服务端授权账户到涂鸦开发者平台,由三方系统决定授权账户的范围,可以是三方系统的用户或员工账号,也可以是内部任何业务形态对应一个账号授权到涂鸦开发者平台。例如,企业、门店和项目等。
已经授权的账户,三方系统服务端通过账户加国家码,向涂鸦开发者平台申请一个 Ticket。
使用场景
lighting.console.tuyacn.com?ticket=xxx
。例如,访问涂鸦的系统网站,或扫码访问设备控制 H5 页面。接口说明
三方系统授权登录。
- (void)loginMerchantByTicket:(nonnull NSString*)ticket
multiMerchantHanlder:(void(^_Nullable)(NSArray<ThingSmartMerchantModel *> * _Nonnull merchantInfos))multiMerchantHanlder
success:(nullable ThingSuccessHandler)success
failure:(nullable ThingFailureError)failure;
参数说明
参数 | 说明 |
---|---|
ticket | 通过授权流程获取 Ticket |
示例代码
Objective-C:
- (void)loginByTicket:(NSString *)ticket {
[[ThingSmartUser sharedInstance] loginMerchantByTicket: ticket
multiMerchantHanlder:^(NSArray<ThingSmartMerchantModel *> * _Nullable merchantInfos) {
NSLog(@"get merchant list");
} success:^{
NSLog(@"login by ticket success");
} failure:^(NSError *error) {
NSLog(@"login by ticket failure: %@",error);
}];
}
Swift:
func loginByTicket(ticket: String) {
ThingSmartUser.sharedInstance()?.loginMerchant(byTicket: ticket, multiMerchantHanlder: nil, success:{
print("login by ticket success")
}, failure:{ (error) in
if let e = error {
print("login by ticket failure:\(e)")
}
})
}
用户登录前修改密码,分为三个步骤:
接口说明
获取验证码。
- (void)sendMerchantVerifyCodeWithCountryCode:(NSString *_Nonnull)countryCode
username:(NSString *_Nonnull)username
codeType:(ThingMerchantCodeType)codeType
merchantCode:(NSString *_Nullable)merchantCode
success:(ThingSuccessHandler _Nullable)success
failure:(ThingFailureError _Nullable)failure
参数说明
参数 | 说明 |
---|---|
countryCode | 国家区号,例如 86 |
username | 手机号码 | 邮箱 |
codeType | 获取验证码类型,类型传 ThingMerchantCodeModifyOrFindPasswordOrQuery |
示例代码
Objective-C:
[[ThingSmartUser sharedInstance]sendMerchantVerifyCodeWithCountryCode:@"your_country_code" username:@"your_username" codeType:ThingMerchantCodeModifyOrFindPasswordOrQuery merchantCode:nil success:^{
NSLog(@"sendVerifyCode success");
} failure:^(NSError *error) {
NSLog(@"sendVerifyCode failure: %@", error);
}];
Swift:
ThingSmartUser.sharedInstance()?.sendMerchantVerifyCode(withCountryCode: "your_country_code", username: "your_username", codeType: ThingMerchantCodeType.modifyOrFindPasswordOrQuery, merchantCode: nil, success: {
print("sendVerifyCode success")
}, failure: { (error) in
if let error = error {
print("sendVerifyCode failure: \(error)")
}
})
接口说明
查找商户列表。
- (void)queryMerchantInfosByVerificationCode:(NSString *_Nonnull)code
username:(NSString *_Nonnull)username
countryCode:(NSString *_Nonnull)countryCode
success:(void(^_Nullable)(NSArray<ThingSmartMerchantModel *> * _Nullable merchantInfos))success
failure:(ThingFailureError _Nullable)failure
参数说明
参数 | 说明 |
---|---|
countryCode | 国家区号,例如 86 |
username | 手机号码 | 邮箱 |
code | 验证码 |
示例代码
Objective-C:
[[ThingSmartUser sharedInstance]queryMerchantInfosByVerificationCode:@"verification_code" username:@"your_username" countryCode:@"country_code" success:^(NSArray<ThingSmartMerchantModel *> * _Nullable merchantInfos) {
NSLog(@"get merchant list");
} failure:^(NSError *error) {
NSLog(@"error");
}];
Swift:
ThingSmartUser.sharedInstance()?.queryMerchantInfos(byVerificationCode: "verification_code", username: "your_username", countryCode: "country_code", success: { (result) in
print("get merchant list")
}, failure: { (error) in
if let error = error {
print("failure: \(error)")
}
})
接口说明
找回密码。
- (void)getBackMerchantPasswordByVerificationCode:(NSString *_Nonnull)code
username:(NSString *_Nonnull)username
countryCode:(NSString *_Nonnull)countryCode
newPassword:(NSString *_Nonnull)newPassword
merchantCode:(NSString *_Nonnull)merchantCode
success:(ThingSuccessHandler _Nullable)success
failure:(ThingFailureError _Nullable)failure
字段 | 描述 |
---|---|
username | 账号,手机号码 | 邮箱 |
newPassword | 新密码 |
code | 验证码 |
countryCode | 国家区号,例如 86 |
merchantCode | 商户 code |
示例代码
Objective-C:
[[ThingSmartUser sharedInstance]getBackMerchantPasswordByVerificationCode:@"verification_code" username:@"your_username" countryCode:@"country_code" newPassword:@"new_password" merchantCode:@"merchant_code" success:^{
NSLog(@"get back password success");
} failure:^(NSError *error) {
NSLog(@"get back password failure");
}];
Swift:
ThingSmartUser.sharedInstance()?.getBackMerchantPassword(byVerificationCode: "verification_code", username: "username", countryCode: "country_code", newPassword: "new_password", merchantCode: "merchant_code", success: {
print("get password success")
}, failure: { (error) in
if let error = error {
print("get password failure: \(error)")
}
})
用户登录后修改密码,可以直接通过传递旧密码和新密码来修改密码。
接口说明
修改密码。
- (void)resetMerchantPasswordWithUsername:(NSString *_Nonnull)username
countryCode:(NSString *_Nonnull)countryCode
oldPassword:(NSString *_Nonnull)oldPassword
newPassword:(NSString *_Nonnull)newPassword
success:(ThingSuccessHandler _Nullable)success
failure:(ThingFailureError _Nullable)failure
字段 | 描述 |
---|---|
oldPassword | 旧密码 |
newPassword | 新密码 |
username | 账号,手机号码 |
countryCode | 国家区号,例如 86 |
示例代码
Objective-C:
[[ThingSmartUser sharedInstance]resetMerchantPasswordWithUsername:@"your_user_name" countryCode:@"country_code" oldPassword:@"old_password" newPassword:@"new_password" success:^{
NSLog(@"reset password success");
} failure:^(NSError *error) {
NSLog(@"reset password failure");
}];
Swift:
ThingSmartUser.sharedInstance()?.resetMerchantPassword(withUsername: "your_user_name", countryCode: "country_code", oldPassword: "old_password", newPassword: "new_password", success: {
print("reset password success")
}, failure: { (error) in
print("reset password failure")
})
接口说明
账号登出。
- (void)loginOutMerchantWithSuccess:(ThingSuccessHandler _Nullable)success
failure:(ThingFailureError _Nullable)failure
接口说明
账号注销。
- (void)cancelMerchantAccount:(nullable ThingSuccessHandler)success
failure:(nullable ThingFailureError)failure
获取并同步最新的用户信息到本地。
接口说明
- (void)getMerchantUserInfoWithSuccess:(ThingSuccessHandler _Nullable)success
failure:(ThingFailureError _Nullable)failure
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈