Commit 66975480973537ce4d59edd9e3a350cf399b6ee3

Authored by guoruipeng
1 parent 1d8d6635

no message

CNLiveBusinessTools.podspec
... ... @@ -32,7 +32,7 @@ Pod::Spec.new do |s|
32 32  
33 33 s.source_files = 'CNLiveBusinessTools/Classes/**/*'
34 34  
35   - # s.resource_bundles = {
  35 + # s.resource_bun/Users/open/CNLiveBaseKit/CNLiveBaseKit.podspecdles = {
36 36 # 'CNLiveBusinessTools' => ['CNLiveBusinessTools/Assets/*.png']
37 37 # }
38 38  
... ... @@ -40,5 +40,5 @@ Pod::Spec.new do |s|
40 40 s.frameworks = 'UIKit', 'MapKit','Photos'
41 41 s.dependency 'CNLiveEnvironmentConfiguration'
42 42 s.dependency 'CNLiveUserManagement'
43   -
  43 + s.dependency 'CNLiveBaseKit'
44 44 end
... ...
CNLiveBusinessTools/Classes/CNLiveBusinessTools.h
... ... @@ -54,6 +54,13 @@ typedef NS_ENUM(NSInteger, CNFileType) {
54 54 + (NSString *)getSpid;
55 55 + (NSString *)getSidIdfv;
56 56 #pragma mark --
  57 +#pragma mark --
  58 ++ (NSString *)signvalue:(NSDictionary *)parameter;
  59 ++ (NSString *)sha1:(NSString *)string;
  60 +
  61 +//sha1签名
  62 ++ (NSMutableDictionary *_Nullable)encryptionSignWithParameter:(NSMutableDictionary *_Nullable)parameter encryptionKey:(NSString *_Nullable)encryptionKey;
  63 +#pragma mark --
57 64 @end
58 65  
59 66 NS_ASSUME_NONNULL_END
... ...
CNLiveBusinessTools/Classes/CNLiveBusinessTools.m
... ... @@ -9,7 +9,8 @@
9 9 #import <Photos/Photos.h>
10 10 #import <CNLiveEnvironmentConfiguration/CNLiveEnvironmentConfiguration.h>
11 11 #import <CNLiveUserManagement/CNUserInfoManager.h>
12   -
  12 +#import "CommonCrypto/CommonDigest.h"
  13 +#import <CNLiveBaseKit/CNLiveBaseKit-umbrella.h>
13 14 @implementation CNLiveBusinessTools
14 15  
15 16 + (NSString *)cnStatWithType:(CNStatType)statType type:(NSString *)type userId:(NSString *)userId programId:(NSString *)programId title:(NSString *)title {
... ... @@ -288,4 +289,135 @@
288 289 }
289 290 return uid;
290 291 }
  292 +
  293 ++ (NSMutableDictionary *)encryptionSignWithParameter:(NSMutableDictionary *)parameter encryptionKey:(NSString *)encryptionKey
  294 +{
  295 + NSMutableDictionary *muDic = [NSMutableDictionary dictionaryWithDictionary:parameter];
  296 + NSArray *allKeys = [muDic allKeys];
  297 + BOOL isContainAppId = NO;
  298 + BOOL isContainPlat = NO;
  299 + BOOL isPlatform_id = NO;
  300 + BOOL isTimestamp = NO;
  301 + BOOL isVer = NO;
  302 + BOOL isUUID = NO;
  303 + BOOL isSign = NO;
  304 + BOOL isLoginId = NO;
  305 + for (NSString *key in allKeys) {
  306 + if ([key isEqualToString:@"appId"]){
  307 + isContainAppId = YES;
  308 + }else if ([key isEqualToString:@"plat"]) {
  309 + isContainPlat = YES;
  310 + }else if ([key isEqualToString:@"platform_id"]) {
  311 + isPlatform_id = YES;
  312 + }else if ([key isEqualToString:@"timestamp"]) {
  313 + isTimestamp = YES;
  314 + }else if ([key isEqualToString:@"ver"]) {
  315 + isVer = YES;
  316 + }else if ([key isEqualToString:@"uuid"]) {
  317 + isUUID = YES;
  318 + }else if ([key isEqualToString:@"sign"]){
  319 + isSign = YES;
  320 + }else if ([key isEqualToString:@"loginSid"]) {
  321 + isLoginId = YES;
  322 + }
  323 + if (isContainAppId && isContainPlat && isPlatform_id && isTimestamp && isVer && isUUID && isLoginId) {
  324 + break;
  325 + }
  326 + }
  327 + if (!isContainAppId) {
  328 + [muDic setObject:AppId forKey:@"appId"];
  329 + }
  330 + if (!isContainPlat) {
  331 + [muDic setObject:@"i" forKey:@"plat"];
  332 + }
  333 + if (!isPlatform_id) {
  334 + [muDic setObject:[self getBundleID] forKey:@"platform_id"];
  335 + }
  336 + if (!isTimestamp) {
  337 + [muDic setObject:[NSString stringWithFormat:@"%zd",[self getNowTimestamp]] forKey:@"timestamp"];
  338 + }
  339 + if (!isVer) {
  340 + [muDic setObject:AppVersion forKey:@"ver"];
  341 + }
  342 + if (!isUUID) {
  343 + [muDic setObject:[CNLiveBusinessTools uuid] forKey:@"uuid"];
  344 + }
  345 + if (!isLoginId) {
  346 + [muDic setObject:CNUserShareModel.uid.length == 0 ? @"" : CNUserShareModel.uid forKey:@"loginSid"];
  347 + }
  348 +
  349 + NSMutableDictionary *startPara = [NSMutableDictionary dictionaryWithDictionary:muDic];
  350 + if (!isSign) {
  351 + NSString *string = [NSString stringWithFormat:@"%@&key=%@",[self signvalue:muDic],encryptionKey];
  352 + NSString *signString = [[self sha1:string] uppercaseString];
  353 + [startPara setObject:signString forKey:@"sign"];
  354 + }
  355 + return startPara;
  356 +}
  357 +
  358 ++ (NSInteger)getNowTimestamp{
  359 + NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  360 + [formatter setDateStyle:NSDateFormatterMediumStyle];
  361 + [formatter setTimeStyle:NSDateFormatterShortStyle];
  362 + [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
  363 + //设置时区,这个对于时间的处理有时很重要
  364 + NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
  365 + [formatter setTimeZone:timeZone];
  366 + NSDate *datenow = [NSDate date];//现在时间
  367 + // NSLog(@"设备当前的时间:%@",[formatter stringFromDate:datenow]);
  368 + //时间转时间戳的方法:
  369 + NSInteger timeSp = [[NSNumber numberWithDouble:[datenow timeIntervalSince1970]] integerValue];
  370 + // NSLog(@"设备当前的10位时间戳:%ld",(long)timeSp); //时间戳的值
  371 + return timeSp;
  372 +}
  373 +
  374 ++ (NSString *)signvalue:(NSDictionary*)parameter
  375 +{
  376 + //对所有传入参数按照字段名的 ASCII 码从小到大排序
  377 + NSArray *keyArr=[parameter allKeys];
  378 + NSArray *arr = [keyArr sortedArrayUsingSelector:@selector(compare:)];
  379 +
  380 + NSMutableString *string1 = [[NSMutableString alloc]init];
  381 + for (int i=0; i<arr.count; i++) {
  382 +
  383 + NSString *parameterString = parameter[[arr objectAtIndex:i]];
  384 + if (parameterString.length > 0) {
  385 + [string1 appendString:[NSString stringWithFormat:@"%@=%@&",[arr objectAtIndex:i],parameter[[arr objectAtIndex:i]]]];
  386 + }
  387 + }
  388 +
  389 + if (string1.length > 0) {
  390 + [string1 deleteCharactersInRange:NSMakeRange(string1.length-1, 1)];
  391 + }
  392 +
  393 + return string1;
  394 +}
  395 +
  396 ++ (NSString*)sha1:(NSString *)string
  397 +{
  398 + NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
  399 +
  400 + uint8_t digest[CC_SHA1_DIGEST_LENGTH];
  401 +
  402 + CC_SHA1(data.bytes, (int)data.length, digest);
  403 +
  404 + NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
  405 +
  406 + for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
  407 + [output appendFormat:@"%02x", digest[i]];
  408 +
  409 + while ([[output substringToIndex:1] isEqualToString:@"0"]) {
  410 + output = [[NSMutableString alloc] initWithString:[output substringFromIndex:1]];
  411 + }
  412 +
  413 + return output;
  414 +}
  415 +
  416 +//获取BundleID
  417 ++ (NSString*)getBundleID
  418 +{
  419 + return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
  420 +
  421 +}
  422 +
291 423 @end
... ...
Example/CNLiveBusinessTools.xcodeproj/project.pbxproj
... ... @@ -350,6 +350,7 @@
350 350 );
351 351 inputPaths = (
352 352 "${PODS_ROOT}/Target Support Files/Pods-CNLiveBusinessTools_Example/Pods-CNLiveBusinessTools_Example-frameworks.sh",
  353 + "${BUILT_PRODUCTS_DIR}/CNLiveBaseKit/CNLiveBaseKit.framework",
353 354 "${BUILT_PRODUCTS_DIR}/CNLiveBusinessTools/CNLiveBusinessTools.framework",
354 355 "${BUILT_PRODUCTS_DIR}/CNLiveUserManagement/CNLiveUserManagement.framework",
355 356 "${BUILT_PRODUCTS_DIR}/MJExtension/MJExtension.framework",
... ... @@ -358,6 +359,7 @@
358 359 outputFileListPaths = (
359 360 );
360 361 outputPaths = (
  362 + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveBaseKit.framework",
361 363 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveBusinessTools.framework",
362 364 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveUserManagement.framework",
363 365 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MJExtension.framework",
... ...