| | |
| | | #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_AddDevice @"/home-wisdom/platform/childAddDevice" |
| | | #define API_POST_EZ_GetChildToken @"/home-wisdom/platform/childToken" |
| | | #define API_POST_EZ_ChildDelDevice @"/home-wisdom/platform/childDelDevice" |
| | | #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"//标记报警消息已读 |
| | | |
| | | #define API_POST_EZ_GetCoverSwitchStaus @"/home-wisdom/platform/yingshi/getCoverSwitchStatus"//获取萤石镜头遮蔽开关状态 |
| | | #define API_POST_EZ_GetCoverSwitch @"/home-wisdom/platform/yingshi/coverSwitch"//设置萤石镜头遮蔽开关 |
| | | #define AOI_POST_EZ_UpdateAnswerStatus @"/home-wisdom/platform/yingshi/lock/updateAnswerStatus" // 更改门铃通话状态(接听和未接) |
| | | #define API_POST_EZ_GetAiSupportList @"/home-wisdom/platform/yingshi/getAiSupportList"//获取摄像头智能算法列表和状态 |
| | | #define API_POST_EZ_SetAiSupport @"/home-wisdom/platform/yingshi/setAiSupport"//设置摄像头智能算法 |
| | | |
| | | #pragma mark APP_KEY |
| | | #define APP_KEY @"HDL-HOME-APP-TEST" |
| | | #define SECRET_KEY @"WeJ8TY88vbakCcnvH8G1tDUqzLWY8yss" |
| | | #define APP_KEY @"QWERREWQ" |
| | | #define SECRET_KEY @"CPBUCTRLCPBUABCD" |
| | | |
| | | |
| | | #define TIME_OUT 15.0f |
| | | #define TIME_OUT 30.0f |
| | | |
| | | @implementation EZHttpUtil |
| | | |
| | |
| | | * @param block 回调block |
| | | */ |
| | | - (void)getChildToken:(void (^)(NSString *accessToken))block{ |
| | | |
| | | |
| | | //2.设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [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_GetChildToken parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (block) { |
| | | NSString * token = @""; |
| | | if(responseData.success){ |
| | | token = responseData.data[@"accessToken"]; |
| | | // token = responseData.data[@"accessToken"]; |
| | | token = [NSString stringWithFormat:@"%@",responseData.data]; |
| | | } |
| | | block(token); |
| | | } |
| | |
| | | |
| | | // 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 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_AddDevice parameters:parameters completion:^(ResponseData *responseData) { |
| | | 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:)]) { |
| | | // HDLEZLog(@"添加设备设备成功回调:%@",parameters[@"deviceSerial"]); |
| | | [[EZSDK sharedInstance].delegate addDeviceSuccessed:parameters[@"deviceSerial"]]; |
| | | // |
| | | // //设置设备去掉验证码 |
| | | // [EZOPENSDK setDeviceEncryptStatus:deviceSerial |
| | | // verifyCode:verifyCode |
| | | // encrypt:NO |
| | | // completion:^(NSError *error) { |
| | | // if (error) |
| | | // { |
| | | // |
| | | // } |
| | | // else |
| | | // { |
| | | // } |
| | | // |
| | | // }]; |
| | | } |
| | | } |
| | | |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:deviceSerial forKey:@"deviceSerial"]; |
| | | [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_ChildDelDevice parameters:parameters completion:^(ResponseData *responseData) { |
| | |
| | | // return task; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据设备序列号获取告警信息列表 |
| | | */ |
| | | - (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); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | /** |
| | | * @since 获取镜头隐私遮蔽状态 |
| | | * @param deviceSerial 设备序列号 |
| | | * @param completion 回调block,error为空时表示成功 |
| | | */ |
| | | - (void)getCoverSwitchStatus:(NSString *)deviceSerial |
| | | completion:(void (^)(ResponseData *responseData))completion { |
| | | //设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:deviceSerial forKey:@"deviceSerial"]; |
| | | [parameters setValue:@(1) forKey:@"platform"]; |
| | | [parameters setValue:[NSString stringWithFormat:@"%@",[GlobalKit shareKit].hdlAppKey] forKey:@"appKey"]; |
| | | [parameters setValue:@([[GlobalKit shareKit].hdlHomeId integerValue]) forKey:@"homeId"]; |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | |
| | | NSLog(@"获取设备消息参数:%@",parameters); |
| | | |
| | | [self requestHttpsPost:API_POST_EZ_GetCoverSwitchStaus parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | /** |
| | | * @since 更新接听状态 |
| | | * @param msgId 消息id |
| | | * @param answerStatus 接听状态(answer 已接听、no_answer 未接听) |
| | | * @param completion 回调block,error为空时表示成功 |
| | | */ |
| | | - (void)updateAnswerStatusWithMsgId:(NSString *)msgId |
| | | answerStatus:(NSString *)answerStatus |
| | | completion:(void (^)(ResponseData *responseData))completion { |
| | | //设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:msgId forKey:@"msgId"]; |
| | | [parameters setValue:answerStatus forKey:@"answerStatus"]; |
| | | |
| | | parameters = [self GetSignRequestDictionary:parameters]; |
| | | |
| | | [self requestHttpsPost:AOI_POST_EZ_UpdateAnswerStatus parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | /** |
| | | * @since 设置镜头隐私遮蔽状态 |
| | | * @param deviceSerial 设备序列号 |
| | | * @param enable 隐私遮蔽状态 |
| | | * @param completion 回调block,error为空时表示成功 |
| | | */ |
| | | - (void)coverSwitchStatus:(NSString *)deviceSerial |
| | | enable:(NSInteger)enable |
| | | completion:(void (^)(ResponseData *responseData))completion { |
| | | //设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:deviceSerial forKey:@"deviceSerial"]; |
| | | [parameters setValue:@(enable) forKey:@"enable"]; |
| | | [parameters setValue:@(1) forKey:@"platform"]; |
| | | [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_GetCoverSwitch parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | /** |
| | | * @since 获取摄像头智能算法列表和状态 |
| | | * @param deviceSerial 设备序列号 |
| | | * @param completion 回调block,error为空时表示成功 |
| | | */ |
| | | - (void)getAiSupportDetectionList:(NSString *)deviceSerial |
| | | completion:(void (^)(ResponseData *responseData))completion { |
| | | //设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:deviceSerial forKey:@"deviceSerial"]; |
| | | // [parameters setValue:@(1) forKey:@"platform"]; |
| | | // [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_GetAiSupportList parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | /** |
| | | * @since 设置摄像头智能算法 |
| | | * @param deviceSerial 设备序列号 |
| | | * @param code 智能算法编码 |
| | | * @param completion 回调block,error为空时表示成功 |
| | | */ |
| | | - (void)setAiSupportDetection:(NSString *)deviceSerial |
| | | code:(NSString *)code |
| | | completion:(void (^)(ResponseData *responseData))completion { |
| | | //设置请求参数 |
| | | NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
| | | [parameters setValue:deviceSerial forKey:@"deviceSerial"]; |
| | | [parameters setValue:code forKey:@"code"]; |
| | | // [parameters setValue:@(1) forKey:@"platform"]; |
| | | // [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_SetAiSupport parameters:parameters completion:^(ResponseData *responseData) { |
| | | if (completion) { |
| | | completion (responseData); |
| | | } |
| | | }]; |
| | | } |
| | | |
| | | |
| | | /// 刷新token |
| | |
| | | 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); |
| | | } |
| | | }]; |
| | | } |
| | |
| | | URL = TestRequestHttpsHost; |
| | | } |
| | | URL = [NSString stringWithFormat:@"%@%@", URL, apiPath]; |
| | | NSLog(@"############接口请求url:%@", URL); |
| | | |
| | | // NSURLSessionDataTask * task=nil; |
| | | AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; |
| | |
| | | [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; |
| | | [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; |
| | | [request setValue:GlobalKit.shareKit.hdlAccessToken forHTTPHeaderField:@"Authorization"]; |
| | | //语言类型 |
| | | [manager.requestSerializer setValue:[self getCurrentLanguage] forHTTPHeaderField:@"language"]; |
| | | |
| | | //4.dataTaskWithRequest |
| | | [[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { |
| | | if (completion) { |
| | |
| | | |
| | | 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]; |
| | | } |
| | |
| | | UInt64 recordTime = [[NSDate date] timeIntervalSince1970]*1000; |
| | | [params setValue:APP_KEY forKey:@"appKey"]; |
| | | [params setValue:[NSString stringWithFormat:@"%llu",recordTime] forKey:@"timestamp"]; |
| | | NSLog(@"##########APPKEY:%@, SECRET_KEY:%@", APP_KEY, SECRET_KEY); |
| | | //1.对KEY升序 |
| | | NSArray *keyArray = [params allKeys]; |
| | | NSArray *sortKeyArray = [keyArray sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) { |
| | |
| | | NSString *newString = @""; |
| | | for(NSString *key in sortKeyArray){ |
| | | if(params[key] != NULL){ |
| | | NSString *valueStr = params[key]; |
| | | //Key对应的value强转为NSString |
| | | NSString *valueStr = [NSString stringWithFormat:@"%@",[params objectForKey:key]]; |
| | | //检测当前参数是否需要参与校验 |
| | | if([self IfValueNeedSign:valueStr]){ |
| | | newString = [newString stringByAppendingString:[NSString stringWithFormat:@"%@=%@&", key,valueStr]]; |
| | |
| | | if (( [self stringIsNullOrEmpty:valueStr])//判空字符 |
| | | || ([[valueStr substringToIndex:1] isEqual:@"{"])//判断是否为对象 |
| | | || ([[valueStr substringToIndex:1] isEqual:@"["])//判断是否为数组 |
| | | || ([[valueStr substringToIndex:1] isEqual:@"("])//判断是否为数组 |
| | | ) { |
| | | |
| | | // HDLSDKLog(@"不校验: %@",valueStr); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | /*获取当前系统语言 |
| | | */ |
| | | -(NSString *)getCurrentLanguage{ |
| | | NSArray *languages = [NSLocale preferredLanguages]; |
| | | NSString *currentLocaleLanguageCode=@"en"; |
| | | if (languages.count>0) { |
| | | currentLocaleLanguageCode = languages.firstObject; |
| | | if ([currentLocaleLanguageCode hasPrefix:@"zh"]) {//中文 |
| | | currentLocaleLanguageCode = @"cn"; |
| | | }else {//其它语言 |
| | | currentLocaleLanguageCode = @"en"; |
| | | } |
| | | } |
| | | return currentLocaleLanguageCode; |
| | | } |
| | | |
| | | |
| | | |
| | | @end |
| | | |
| | | |
| | | #pragma mark - 修改记录 |
| | | //2021-07-07 |
| | | //V1.1.3 |
| | | //1.替换为新接口,根据homeId注册萤石子账号方案。 |