Commit 52d0b15b8b85bc7ff7b65c1adf82d42922e98a49
1 parent
16dc30b6
新建验证主播请求类
Showing
2 changed files
with
93 additions
and
0 deletions
LiveVideoCloud/Classes/Sections/LiveSections/LVCVerifyLiveAuthService.h
0 → 100644
| 1 | +// | |
| 2 | +// LVCVerifyLiveAuthService.h | |
| 3 | +// LiveVideoCloud | |
| 4 | +// | |
| 5 | +// Created by cnliveJunBo on 17/5/15. | |
| 6 | +// Copyright © 2017年 cnlive. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "HttpService.h" | |
| 10 | + | |
| 11 | +@interface LVCVerifyLiveAuthService : HttpService | |
| 12 | + | |
| 13 | ++ (NSURLSessionDataTask *)verifyLiveAuthWithHandler:(completionHandler)handler; | |
| 14 | + | |
| 15 | +@end | ... | ... |
LiveVideoCloud/Classes/Sections/LiveSections/LVCVerifyLiveAuthService.m
0 → 100644
| 1 | +// | |
| 2 | +// LVCVerifyLiveAuthService.m | |
| 3 | +// LiveVideoCloud | |
| 4 | +// | |
| 5 | +// Created by cnliveJunBo on 17/5/15. | |
| 6 | +// Copyright © 2017年 cnlive. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "LVCVerifyLiveAuthService.h" | |
| 10 | +#import "CommonCrypto/CommonDigest.h" | |
| 11 | + | |
| 12 | +@implementation LVCVerifyLiveAuthService | |
| 13 | + | |
| 14 | ++ (NSURLSessionDataTask *)verifyLiveAuthWithHandler:(completionHandler)handler { | |
| 15 | + | |
| 16 | + NSInteger time = [[NSDate date] timeIntervalSince1970]; | |
| 17 | + NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 18 | + | |
| 19 | + NSMutableDictionary *parameter = [@{@"appId":UserAppId, | |
| 20 | + @"channelId":[UserInformationModel manager].uid?[UserInformationModel manager].uid:@"", | |
| 21 | + @"timestamp":timeString, | |
| 22 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier} mutableCopy]; | |
| 23 | + | |
| 24 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [self sortParameters:parameter], UserAppKey]; | |
| 25 | + NSString *signString = [[self sha1:string] uppercaseString]; | |
| 26 | + [parameter setObject:signString forKey:@"sign"]; | |
| 27 | + | |
| 28 | + NSMutableDictionary *params = parameter.mutableCopy; | |
| 29 | + completionHandler compleionHandler = ^(id data,NSError *error) { | |
| 30 | + handler(data,error); | |
| 31 | + }; | |
| 32 | + return [[HttpService service] sendRequestWithHttpMethod:E_HTTP_REQUEST_METHOD_GET URLPath:[ZXServerUrl verifyLiveAuthURL] parameters:params completionHandler:compleionHandler]; | |
| 33 | +} | |
| 34 | + | |
| 35 | +//sha1加密 | |
| 36 | ++ (NSString*)sha1:(NSString *)string | |
| 37 | +{ | |
| 38 | + NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; | |
| 39 | + | |
| 40 | + uint8_t digest[CC_SHA1_DIGEST_LENGTH]; | |
| 41 | + | |
| 42 | + CC_SHA1(data.bytes, data.length, digest); | |
| 43 | + | |
| 44 | + NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2]; | |
| 45 | + | |
| 46 | + for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) | |
| 47 | + [output appendFormat:@"%02x", digest[i]]; | |
| 48 | + | |
| 49 | + while ([[output substringToIndex:1] isEqualToString:@"0"]) { | |
| 50 | + output = [[NSMutableString alloc] initWithString:[output substringFromIndex:1]]; | |
| 51 | + } | |
| 52 | + | |
| 53 | + return output; | |
| 54 | +} | |
| 55 | +//参数排序 | |
| 56 | ++ (NSString *)sortParameters:(NSDictionary*)parameters | |
| 57 | +{ | |
| 58 | + //对所有传入参数按照字段名的 ASCII 码从小到大排序 | |
| 59 | + NSArray *keyArr=[parameters allKeys]; | |
| 60 | + NSArray *arr = [keyArr sortedArrayUsingSelector:@selector(compare:)]; | |
| 61 | + | |
| 62 | + NSMutableString *string1 = [[NSMutableString alloc]init]; | |
| 63 | + for (int i=0; i<arr.count; i++) { | |
| 64 | + | |
| 65 | + NSString *parametersString = parameters[[arr objectAtIndex:i]]; | |
| 66 | + if (parametersString.length > 0) { | |
| 67 | + [string1 appendString:[NSString stringWithFormat:@"%@=%@&",[arr objectAtIndex:i],parameters[[arr objectAtIndex:i]]]]; | |
| 68 | + } | |
| 69 | + } | |
| 70 | + | |
| 71 | + if (string1.length > 0) { | |
| 72 | + [string1 deleteCharactersInRange:NSMakeRange(string1.length-1, 1)]; | |
| 73 | + } | |
| 74 | + | |
| 75 | + return string1; | |
| 76 | +} | |
| 77 | + | |
| 78 | +@end | ... | ... |