CNLiveFeedback.m
2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// CNLiveFeedback.m
// CNLiveUserSystemDemo
//
// Created by iOS on 16/9/13.
// Copyright © 2016年 zhulin. All rights reserved.
//
#import "CNLiveFeedback.h"
#import "CNLiveNetworkManager.h"
#import "CNLiveUserSystemTools.h"
#import "NSDictionary+Safety.h"
//反馈
static NSString *feedbackURL = @"https://api.cnlive.com/open/api2/user/userReport";
@implementation CNLiveFeedback
- (void)feedbackWithAppId:(NSString *)appId appKey:(NSString *)appKey contentId:(NSString *)contentId message:(NSString *)message success:(void (^)(id result))success failure:(void (^)(NSError *))failure
{
NSDate *date = [NSDate date];
NSInteger time = [date timeIntervalSince1970];
NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId],
@"id":[CNLiveUserSystemTools verify:contentId],
@"msg":[CNLiveUserSystemTools verify:message],
@"clientPlat":@"i",
@"platform_id":[NSBundle mainBundle].bundleIdentifier,
@"timestamp": timeString};
NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params];
NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]];
NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString];
[parameter setObject:signString forKey:@"sign"];
[self requestWithParameter:parameter success:success failure:failure];
}
#pragma mark - request
- (void)requestWithParameter:(NSDictionary *)param success:(void(^)(id result))success failure :(void (^)(NSError * error))failure
{
[[CNLiveNetworkManager manager] requestPostURL:feedbackURL parameters:param success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) {
responseObject = [responseObject validatedDictionary];
success(responseObject);
} failure:^(NSURLResponse * _Nullable response, NSError * _Nullable error) {
failure(error);
}];
}
@end