Davin
2024-06-07 4c1abca185a5727da6fb314a0cb4cd44bfe1b3bf
EZSDK/EZSDK/EZ/Global/EZHttpUtil.m
@@ -30,12 +30,18 @@
#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
@@ -58,7 +64,7 @@
 *  @param block 回调block
 */
- (void)getChildToken:(void (^)(NSString *accessToken))block{
    //2.设置请求参数
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setValue: [NSString stringWithFormat:@"%d", [GlobalKit shareKit].hdlPlatform] forKey:@"platform"];
@@ -134,6 +140,21 @@
            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
//                                            {
//                                            }
//
//                }];
            }
        }
        
@@ -406,6 +427,136 @@
    }];
}
/**
 *  @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
/// @param block 结果
- (void)refreshHDLToken:(void (^)(BOOL isSuccess))block{
@@ -486,6 +637,7 @@
        URL = TestRequestHttpsHost;
    }
    URL = [NSString stringWithFormat:@"%@%@", URL, apiPath];
    NSLog(@"############接口请求url:%@", URL);
    
//    NSURLSessionDataTask * task=nil;
    AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
@@ -533,6 +685,7 @@
    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) {