| | |
| | | #import <Foundation/Foundation.h> |
| | | #import <CommonCrypto/CommonDigest.h> |
| | | #import "AFNetworking.h" |
| | | #import "YYModel.h" |
| | | |
| | | #define TestRequestHttpsHost @"https://test-gz.hdlcontrol.com" |
| | | #pragma mark API |
| | | #define API_POST_EZ_VerifyLocalLock @"/home-wisdom/platform/yingshi/lock/verifyLocalLock"//萤石门锁本地验证 |
| | | #define API_POST_EZ_AddDevice @"/home-wisdom/platform/yingshi/child/addDevice" |
| | | #define API_POST_EZ_GetChildToken @"/home-wisdom/platform/yingshi/child/token" |
| | | #define API_POST_EZ_ChildDelDevice @"/home-wisdom/platform/yingshi/child/deleteDevice" |
| | | #define API_POST_EZ_RefreshToken @"/smart-footstone/member/oauth/login" |
| | | #define API_POST_EZ_LockAuth @"/home-wisdom/platform/yingshi/lock/auth"//萤石门锁终端授权 |
| | | #define API_POST_EZ_RemoteOpen @"/home-wisdom/platform/yingshi/lock/remote/open/door"//萤石门锁远程开锁 |
| | | #define API_POST_EZ_TempList @"/home-wisdom/platform/yingshi/lock/temp/list"//萤石门临时密码列表 |
| | | #define API_POST_EZ_AddTemp @"/home-wisdom/platform/yingshi/lock/temp/add"//萤石门添加临时密码 |
| | | #define API_POST_EZ_DeleteTemp @"/home-wisdom/platform/yingshi/lock/temp/delete"//萤石门删除临时密码 |
| | | #define API_POST_EZ_DeviceMessage @"/home-wisdom/app/device/message"//萤石设备消息列表 |
| | | |
| | | #define API_POST_EZ_GetAlarmList @"/home-wisdom/platform/yingshi/alarm/records"//获取报警消息 |
| | | #define API_POST_EZ_DeleteAlarmMes @"/home-wisdom/platform/yingshi/alarm/delete"//删除报警消息 |
| | | #define API_POST_EZ_ReadAlarmMes @"/home-wisdom/platform/yingshi/alarm/updateChecked"//标记报警消息已读 |
| | | |
| | | #pragma mark APP_KEY |
| | | #define APP_KEY @"HDL-HOME-APP-TEST" |
| | |
| | | |
| | | // return task; |
| | | } |
| | | |
| | | /** |
| | | * @since 河东添加设备之前本地验证的接口(智能门锁使用,调用接口后输入门锁密码,再进行绑定) |
| | | * @param deviceSerial 设备序列号 |
| | | * @param completion 回调block,error为空时表示调用验证接口成功 |
| | | * |
| | | */ |
| | | - (void)verifyLocalLockByHDL:(NSString *)deviceSerial |
| | | completion:(void (^)(ResponseData *responseData))completion{ |
| | | //2.设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:deviceSerial forKey:@"deviceSerial"]; |
| | | [parameters setValue:[NSString stringWithFormat:@"%@",[GlobalKit shareKit].hdlAppKey] forKey:@"appKey"]; |
| | | [parameters setValue: [NSString stringWithFormat:@"%d",[GlobalKit shareKit].hdlPlatform] forKey:@"platform"]; |
| | | [parameters setValue:[GlobalKit shareKit].hdlHomeId forKey:@"homeId"]; |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | |
| | | [self requestHttpsPost:API_POST_EZ_VerifyLocalLock parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | /** |
| | | * @since 河东添加设备的接口 |
| | | * 根据设备序列号和设备验证码添加设备接口 |
| | |
| | | verifyCode:(NSString *)verifyCode |
| | | completion:(void (^)(ResponseData *responseData))completion{ |
| | | |
| | | //2.设置请求参数 |
| | | //设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:deviceSerial forKey:@"deviceSerial"]; |
| | | [parameters setValue:verifyCode forKey:@"validateCode"]; |
| | |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | |
| | | HDLEZLog(@"添加设备参数:%@",parameters); |
| | | |
| | | |
| | | [self requestHttpsPost:API_POST_EZ_AddDevice parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (responseData.success){//添加成功,触发代理 |
| | | if ([EZSDK sharedInstance].delegate&&[[EZSDK sharedInstance].delegate respondsToSelector:@selector(addDeviceSuccessed)]) { |
| | | [[EZSDK sharedInstance].delegate addDeviceSuccessed]; |
| | | } |
| | | } |
| | | |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据设备序列号获取告警信息列表 |
| | | */ |
| | | - (void)getAlarmList:(NSString *)deviceSerial |
| | | pageNo:(NSInteger)pageNo |
| | | pageSize:(NSInteger)pageSize |
| | | completion:(void (^)(ResponseData *responseData))completion{ |
| | | |
| | | //1.设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:deviceSerial forKey:@"deviceSerial"]; |
| | | [parameters setValue:[GlobalKit shareKit].hdlHomeId forKey:@"homeId"]; |
| | | [parameters setValue:[NSString stringWithFormat:@"%ld",(long)pageSize] forKey:@"pageSize"]; |
| | | [parameters setValue:[NSString stringWithFormat:@"%ld",(long)pageNo] forKey:@"pageNo"]; |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | NSLog(@"HDLpageNo:%ld",(long)pageNo); |
| | | [self requestHttpsPost:API_POST_EZ_GetAlarmList parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | /** |
| | | * 批量删除报警记录 |
| | | */ |
| | | - (void)deleteAlarmMessage:(NSArray *)alarmIds |
| | | completion:(void (^)(ResponseData *responseData))completion{ |
| | | |
| | | //1.设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:[alarmIds yy_modelToJSONObject] forKey:@"alarmIds"]; |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | |
| | | [self requestHttpsPost:API_POST_EZ_DeleteAlarmMes parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 批量标记报警记录已读 |
| | | */ |
| | | - (void)readAlarmMessage:(NSArray *)alarmIds |
| | | completion:(void (^)(ResponseData *responseData))completion{ |
| | | |
| | | //1.设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:@"1" forKey:@"isChecked"]; |
| | | [parameters setValue:[alarmIds yy_modelToJSONObject] forKey:@"alarmIds"]; |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | |
| | | [self requestHttpsPost:API_POST_EZ_ReadAlarmMes parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | /** |
| | | * @since 河东门锁终端授权接口 |
| | | * @param password 门锁密码 |
| | | * @param deviceId 设备id |
| | | * @param completion 回调block,error为空时表示添加成功 |
| | | * |
| | | */ |
| | | - (void)authLockByHDL:(NSString *)password |
| | | deviceId:(NSString *)deviceId |
| | | completion:(void (^)(ResponseData *responseData))completion{ |
| | | //2.设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:deviceId forKey:@"deviceId"]; |
| | | [parameters setValue:[NSString stringWithFormat:@"%@",[GlobalKit shareKit].hdlAppKey] forKey:@"appKey"]; |
| | | [parameters setValue:password forKey:@"password"]; |
| | | [parameters setValue:[GlobalKit shareKit].hdlHomeId forKey:@"homeId"]; |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | |
| | | NSLog(@"终端授权参数:%@",parameters); |
| | | |
| | | [self requestHttpsPost:API_POST_EZ_LockAuth parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @since 河东远程开锁接口 |
| | | * @param streamToken 设备序列号 |
| | | * @param deviceId 设备id |
| | | * @param completion 回调block,error为空时表示添加成功 |
| | | * |
| | | */ |
| | | - (void)remoteOpenByHDL:(NSString *)streamToken |
| | | deviceId:(NSString *)deviceId |
| | | completion:(void (^)(ResponseData *responseData))completion{ |
| | | //2.设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:deviceId forKey:@"deviceId"]; |
| | | [parameters setValue:[NSString stringWithFormat:@"%@",[GlobalKit shareKit].hdlAppKey] forKey:@"appKey"]; |
| | | [parameters setValue:streamToken forKey:@"streamToken"]; |
| | | [parameters setValue:[GlobalKit shareKit].hdlHomeId forKey:@"homeId"]; |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | |
| | | NSLog(@"开门参数:%@",parameters); |
| | | |
| | | [self requestHttpsPost:API_POST_EZ_RemoteOpen parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @since 河东获取临时密码列表接口 |
| | | * @param deviceId 设备id |
| | | * @param completion 回调block,error为空时表示成功 |
| | | * |
| | | */ |
| | | - (void)getTempListByHDL:(NSString *)deviceId |
| | | completion:(void (^)(ResponseData *responseData))completion{ |
| | | //设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:deviceId forKey:@"deviceId"]; |
| | | [parameters setValue:[NSString stringWithFormat:@"%@",[GlobalKit shareKit].hdlAppKey] forKey:@"appKey"]; |
| | | [parameters setValue:[GlobalKit shareKit].hdlHomeId forKey:@"homeId"]; |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | |
| | | NSLog(@"获取临时密码列表参数:%@",parameters); |
| | | |
| | | [self requestHttpsPost:API_POST_EZ_TempList parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | /** |
| | | * @since 河东添加临时密码接口 |
| | | * @param tempInfo 临时密码信息 |
| | | * @param deviceId 设备id |
| | | * @param completion 回调block,error为空时表示成功 |
| | | * |
| | | */ |
| | | - (void)addTempByHDL:(HDLEZTemInfoModel *)tempInfo |
| | | deviceId:(NSString *)deviceId |
| | | completion:(void (^)(ResponseData *responseData))completion{ |
| | | //设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:[tempInfo yy_modelToJSONObject]]; |
| | | [parameters setValue:deviceId forKey:@"deviceId"]; |
| | | [parameters setValue:[NSString stringWithFormat:@"%@",[GlobalKit shareKit].hdlAppKey] forKey:@"appKey"]; |
| | | [parameters setValue:[GlobalKit shareKit].hdlHomeId forKey:@"homeId"]; |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | |
| | | NSLog(@"添加临时密码参数1:%@",parameters); |
| | | |
| | | [self requestHttpsPost:API_POST_EZ_AddTemp parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | /** |
| | | * @since 河东删除临时密码接口 |
| | | * @param extVisitorId 临时密码索引 |
| | | * @param deviceId 设备id |
| | | * @param completion 回调block,error为空时表示成功 |
| | | * |
| | | */ |
| | | - (void)deleteTempByHDL:(NSString *)extVisitorId |
| | | deviceId:(NSString *)deviceId |
| | | completion:(void (^)(ResponseData *responseData))completion{ |
| | | //设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:extVisitorId forKey:@"extVisitorId"]; |
| | | [parameters setValue:deviceId forKey:@"deviceId"]; |
| | | [parameters setValue:[NSString stringWithFormat:@"%@",[GlobalKit shareKit].hdlAppKey] forKey:@"appKey"]; |
| | | [parameters setValue:[GlobalKit shareKit].hdlHomeId forKey:@"homeId"]; |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | |
| | | NSLog(@"删除临时密码参数:%@",parameters); |
| | | |
| | | [self requestHttpsPost:API_POST_EZ_DeleteTemp parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @since 河东获取设备消息 |
| | | * @param deviceId 设备id |
| | | * @param pageSize 页面大小 |
| | | * @param pageNo 当前页 |
| | | * @param completion 回调block,error为空时表示成功 |
| | | * |
| | | */ |
| | | - (void)getDeviceMessageByHDL:(NSString *)deviceId |
| | | pageSize:(NSInteger)pageSize |
| | | pageNo:(NSInteger)pageNo |
| | | completion:(void (^)(ResponseData *responseData))completion{ |
| | | //设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:deviceId forKey:@"deviceId"]; |
| | | [parameters setValue:[NSString stringWithFormat:@"%ld",(long)pageSize] forKey:@"pageSize"]; |
| | | [parameters setValue:[NSString stringWithFormat:@"%ld",(long)pageNo] forKey:@"pageNo"]; |
| | | [parameters setValue:[NSString stringWithFormat:@"%@",[GlobalKit shareKit].hdlAppKey] forKey:@"appKey"]; |
| | | [parameters setValue:[GlobalKit shareKit].hdlHomeId forKey:@"homeId"]; |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | |
| | | NSLog(@"获取设备消息参数:%@",parameters); |
| | | |
| | | [self requestHttpsPost:API_POST_EZ_DeviceMessage parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | /// 刷新token |
| | | /// @param block 结果 |
| | |
| | | if (block) { |
| | | if (responseData) { |
| | | if(responseData.success){ |
| | | [EZSDK setHDlAccessToken: |
| | | [[EZSDK sharedInstance] setHDlAccessToken: |
| | | [NSString stringWithFormat:@"%@%@",responseData.data[@"headerPrefix"], responseData.data[@"accessToken"]] |
| | | refreshToken:responseData.data[@"refreshToken"]]; |
| | | |
| | |
| | | completion(responseData); |
| | | return; |
| | | }]; |
| | | }else{ |
| | | completion(responseData); |
| | | } |
| | | }]; |
| | | }else{ |
| | | completion(responseData); |
| | | } |
| | | |
| | | completion(responseData); |
| | | } |
| | | }]; |
| | | } |
| | |
| | | |
| | | if(responseObject != NULL){ |
| | | //4.解析拿到的响应数据 |
| | | NSLog(@"%@",[[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding]); |
| | | NSLog(@"数据返回%@",[[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding]); |
| | | NSDictionary * outDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil]; |
| | | responseData = [[ResponseData alloc] initWithDictionary:outDic]; |
| | | } |