Commit 24027121377079c12a9e91ad3bf7a97d30cbda82

Authored by 张旭
1 parent b4936d37

0.1.15

CNLiveBusinessTools.h 0 → 100644
  1 +//
  2 +// CNLiveBusinessTools.h
  3 +// CNLiveBusinessTools
  4 +//
  5 +// Created by 张旭 on 2020/4/14.
  6 +//
  7 +
  8 +#import <Foundation/Foundation.h>
  9 +
  10 +NS_ASSUME_NONNULL_BEGIN
  11 +typedef NS_ENUM(NSInteger, CNStatType) {
  12 + CNStatTypeContentCount = 0, //内容次数统计
  13 + CNStatTypeContentDuration, //内容时长统计
  14 + CNStatTypeShareCount //分享次数统计
  15 +};
  16 +#pragma mark 文件类型
  17 +typedef NS_ENUM(NSInteger, CNFileType) {
  18 + CNFileTypeReadAndLook = 0,//识别和预览
  19 + CNFileTypeOnlyRead, //只能识别,不能预览
  20 + CNFileTypeUnkown, //未知文件
  21 +};
  22 +@interface CNLiveBusinessTools : NSObject
  23 +#pragma mark -- 统计
  24 +/**
  25 + 统计eventId
  26 +
  27 + @param statType 统计类型
  28 + @param type 内容类型 例如:szzg/sxzg/daren/app
  29 + @param userId 用户Id
  30 + @C端/B端
  31 + @return eventId
  32 + */
  33 ++ (NSString *)cnStatWithType:(CNStatType)statType type:(NSString *)type userId:(NSString *)userId programId:(NSString *)programId title:(NSString *)title;
  34 +// 分享单独使用
  35 ++ (NSString *)cnStatWithType:(CNStatType)statType type:(NSString *)type userId:(NSString *)userId programId:(NSString *)programId title:(NSString *)title shareToType:(NSString *)shareToType;
  36 +
  37 +#pragma mark --
  38 +#pragma mark -- UUID
  39 +// 获取UUID
  40 ++ (NSString *)getUidForStat:(NSDate *)date;
  41 +#pragma mark --
  42 +#pragma mark -- 获取 GIF 处理
  43 ++ (BOOL)isGif:(id)asset;
  44 ++ (BOOL)isGifWithImageData: (NSData *)data;
  45 +#pragma mark --
  46 +#pragma mark -- 文件
  47 +///文件类型
  48 ++ (NSDictionary *)fileTypeDic;
  49 +//通过文件后缀名判断是否为可读文件
  50 ++ (CNFileType)isReadedFileByType:(NSString *)suffixType;
  51 +#pragma mark --
  52 +#pragma mark -- 拼接需要的参数
  53 ++ (NSString *)uuid;
  54 ++ (NSString *)getSpid;
  55 ++ (NSString *)getSidIdfv;
  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 --
  64 +#pragma mark -- 缓存
  65 +/**
  66 + GIF表情存放位置
  67 + @return 地址
  68 + */
  69 ++ (NSString *)newChatGifFacePath;
  70 +/**
  71 + @param userId 单聊为对方ID,群聊为群聊 ID,图片和视频存放位置
  72 + @return 地址
  73 + */
  74 ++ (NSString *)newChatFilePathByUserId:(NSString *)userId;
  75 +
  76 ++ (nullable NSString *)chatFileWithCachePathByUserId:(NSString *_Nonnull)userId;
  77 +
  78 +//用户ID
  79 ++ (nullable NSString *)chatFilePathByUserId:(NSString *_Nonnull)userId;
  80 +
  81 +/**
  82 + @param userId 单聊为对方ID,群聊为群聊 ID
  83 + @return 返回聊天发送的文件 所保存的文件夹地址
  84 + */
  85 ++ (NSString *)getChatFilesPathByUserId:(NSString *)userId;
  86 +
  87 +/**
  88 + 0
  89 + @param userId 单聊为对方ID,群聊为群聊 ID ,语音文件保存路径
  90 + */
  91 ++ (NSString *)audioChatFilePathByUserId:(NSString *)userId;
  92 +
  93 +/**
  94 + 聊天背景图图片地址
  95 +
  96 + @return file
  97 + */
  98 ++ (NSString *)chatBackgroupImagefilePath;
  99 +#pragma mark --
  100 +@end
  101 +
  102 +NS_ASSUME_NONNULL_END
... ...
CNLiveBusinessTools.m 0 → 100644
  1 +//
  2 +// CNLiveBusinessTools.m
  3 +// CNLiveBusinessTools
  4 +//
  5 +// Created by 张旭 on 2020/4/14.
  6 +//
  7 +
  8 +#import "CNLiveBusinessTools.h"
  9 +#import <Photos/Photos.h>
  10 +#import <CNLiveEnvironment/CNLiveEnvironment.h>
  11 +#import <CNLiveUserManagement/CNUserInfoManager.h>
  12 +#import "CommonCrypto/CommonDigest.h"
  13 +#import <CNLiveBaseKit/CNLiveBaseKit.h>
  14 +@implementation CNLiveBusinessTools
  15 +
  16 ++ (NSString *)cnStatWithType:(CNStatType)statType type:(NSString *)type userId:(NSString *)userId programId:(NSString *)programId title:(NSString *)title {
  17 +
  18 + NSString *statStr = @"";
  19 + switch (statType) {
  20 + case CNStatTypeContentCount:
  21 + statStr = @"count";
  22 + break;
  23 + case CNStatTypeContentDuration:
  24 + statStr = @"duration";
  25 + break;
  26 + case CNStatTypeShareCount:
  27 + statStr = @"share";
  28 + break;
  29 + default:
  30 + break;
  31 + }
  32 + NSString *channelTypeStr = type?type:@"";
  33 + NSString *uIdStr = userId?userId:@"";
  34 + NSString *proIdStr = programId?programId:@"";
  35 + NSString *titleStr = title?title:@"";
  36 +
  37 + NSString *eventStr = [NSString stringWithFormat:@"type__%@-channel__%@-sid__%@-uid__%@-pid__%@-title__%@-data_",statStr,channelTypeStr,uIdStr,[self getUidForStat:[NSDate date]],proIdStr,titleStr];
  38 + NSLog(@"event:%@",eventStr);
  39 + return eventStr;
  40 +}
  41 +
  42 ++ (NSString *)getUidForStat:(NSDate *)date {
  43 +
  44 + NSString *uid = @"";
  45 + NSString *uidKey = @"kCNLiveUserDefaultsUIDKey";
  46 + NSUserDefaults *defauts = [NSUserDefaults standardUserDefaults];
  47 + if ([defauts objectForKey:uidKey]) {
  48 + uid = [[defauts objectForKey:uidKey] copy];
  49 + return uid;
  50 + }
  51 + else {
  52 +
  53 + NSInteger time = [[NSDate date] timeIntervalSince1970];
  54 + NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
  55 + NSString *stamp = timeString;
  56 + stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""];
  57 + NSString *idfv = [[[[UIDevice currentDevice] identifierForVendor] UUIDString] stringByReplacingOccurrencesOfString:@"-" withString:@""];
  58 + uid = [NSString stringWithFormat:@"%@_%@", idfv, stamp];
  59 + [defauts setObject:uid forKey:uidKey];
  60 + [defauts synchronize];
  61 + return uid;
  62 + }
  63 +}
  64 +
  65 ++ (NSString *)uuid{
  66 + NSString *uid = @"";
  67 + NSString *uidKey = @"kCNLiveUserDefaultsUIDKey";
  68 + NSUserDefaults *defauts = [NSUserDefaults standardUserDefaults];
  69 + if ([defauts objectForKey:uidKey]) {
  70 + uid = [[defauts objectForKey:uidKey] copy];
  71 + return uid;
  72 + } else {
  73 + NSInteger time = [[NSDate date] timeIntervalSince1970];
  74 + NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
  75 + NSString *stamp = timeString;
  76 + stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""];
  77 + NSString *idfv = [[[[UIDevice currentDevice] identifierForVendor] UUIDString] stringByReplacingOccurrencesOfString:@"-" withString:@""];
  78 + uid = [NSString stringWithFormat:@"%@_%@", idfv, stamp];
  79 + [defauts setObject:uid forKey:uidKey];
  80 + [defauts synchronize];
  81 + return uid;
  82 + }
  83 +}
  84 +
  85 +
  86 ++ (NSString *)tingyunUUID{
  87 + NSString *uid = @"";
  88 + NSUserDefaults *defauts = [NSUserDefaults standardUserDefaults];
  89 + if ([defauts objectForKey:@"kCNLiveUserDefaultsTingYunUIDKey"]) {
  90 + uid = [[defauts objectForKey:@"kCNLiveUserDefaultsTingYunUIDKey"] copy];
  91 + return uid;
  92 + } else {
  93 + NSString *idfv = [[[[UIDevice currentDevice] identifierForVendor] UUIDString] stringByReplacingOccurrencesOfString:@"-" withString:@""];
  94 + [defauts setObject:idfv forKey:@"kCNLiveUserDefaultsTingYunUIDKey"];
  95 + [defauts synchronize];
  96 + }
  97 + return uid;
  98 +}
  99 +
  100 ++ (NSString *)cnStatWithType:(CNStatType)statType type:(NSString *)type userId:(NSString *)userId programId:(NSString *)programId title:(NSString *)title shareToType:(NSString *)shareToType
  101 +{
  102 + NSString *statStr = @"";
  103 + switch (statType) {
  104 + case CNStatTypeContentCount:
  105 + statStr = @"count";
  106 + break;
  107 + case CNStatTypeContentDuration:
  108 + statStr = @"duration";
  109 + break;
  110 + case CNStatTypeShareCount:
  111 + statStr = @"share";
  112 + break;
  113 + default:
  114 + break;
  115 + }
  116 + NSString *channelTypeStr = type?type:@"";
  117 + NSString *uIdStr = userId?userId:@"";
  118 + NSString *proIdStr = programId?programId:@"";
  119 + NSString *titleStr = title?title:@"";
  120 + NSString *shareToTypeStr = shareToType?shareToType:@"";
  121 +
  122 + NSString *eventStr = [NSString stringWithFormat:@"type__%@-channel__%@-sid__%@-uid__%@-pid__%@-title__%@-to__%@-data_",statStr,channelTypeStr,uIdStr,[self getUidForStat:[NSDate date]],proIdStr,titleStr,shareToTypeStr];
  123 + NSLog(@"event:%@",eventStr);
  124 + return eventStr;
  125 +}
  126 ++ (BOOL)isGif:(id)asset {
  127 +
  128 + if ([asset isKindOfClass:[PHAsset class]]) {
  129 + PHAsset *phAsset = (PHAsset *)asset;
  130 + if (phAsset.mediaType == PHAssetMediaTypeImage) {
  131 + // Gif
  132 + if ([[phAsset valueForKey:@"filename"] hasSuffix:@"GIF"]) {
  133 + return YES;
  134 + }
  135 + }
  136 + }
  137 + return NO;
  138 +}
  139 ++ (BOOL)isGifWithImageData: (NSData *)data {
  140 + if ([[self contentTypeWithImageData:data] isEqualToString:@"gif"]) {
  141 + return YES;
  142 + }
  143 + return NO;
  144 +}
  145 ++ (NSString *)contentTypeWithImageData: (NSData *)data {
  146 +
  147 + uint8_t c;
  148 +
  149 + [data getBytes:&c length:1];
  150 +
  151 + switch (c) {
  152 +
  153 + case 0xFF:
  154 +
  155 + return @"jpeg";
  156 +
  157 + case 0x89:
  158 +
  159 + return @"png";
  160 +
  161 + case 0x47:
  162 +
  163 + return @"gif";
  164 +
  165 + case 0x49:
  166 +
  167 + case 0x4D:
  168 +
  169 + return @"tiff";
  170 +
  171 + case 0x52:
  172 +
  173 + if ([data length] < 12) {
  174 +
  175 + return nil;
  176 +
  177 + }
  178 +
  179 + NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
  180 +
  181 + if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
  182 +
  183 + return @"webp";
  184 +
  185 + }
  186 +
  187 + return nil;
  188 +
  189 + }
  190 +
  191 + return nil;
  192 +}
  193 +
  194 ++ (NSDictionary *)fileTypeDic
  195 +{
  196 + NSDictionary *dic =
  197 + @{
  198 + @".3gp" : @"video/3gpp",
  199 + @".apk" : @"application/vnd.android.package-archive",
  200 + @".asf" : @"video/x-ms-asf",
  201 + @".avi" : @"video/x-msvideo",
  202 + @".bin" : @"application/octet-stream",
  203 + @".bmp" : @"image/bmp",
  204 + @".c" : @"text/plain",
  205 + @".class" : @"application/octet-stream",
  206 + @".conf" : @"text/plain",
  207 + @".cpp" : @"text/plain",
  208 + @".doc" : @"application/msword",
  209 + @".docx" : @"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
  210 + @".xls" : @"application/vnd.ms-excel",
  211 + @".xlsx" : @"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
  212 + @".exe" : @"application/octet-stream",
  213 + @".gif" : @"image/gif",
  214 + @".gtar" : @"application/x-gtar",
  215 + @".gz" : @"application/x-gzip",
  216 + @".h" : @"text/plain",
  217 + @".htm" : @"text/html",
  218 + @".html" : @"text/html",
  219 + @".jar" : @"application/java-archive",
  220 + @".java" : @"text/plain",
  221 + @".jpeg" : @"image/jpeg",
  222 + @".jpg" : @"image/jpeg",
  223 + @".js" : @"application/x-javascript",
  224 + @".log" : @"text/plain",
  225 + @".m3u" : @"audio/x-mpegurl",
  226 + @".m4a" : @"audio/mp4a-latm",
  227 + @".m4b" : @"audio/mp4a-latm",
  228 + @".m4p" : @"audio/mp4a-latm",
  229 + @".m4u" : @"video/vnd.mpegurl",
  230 + @".m4v" : @"video/x-m4v",
  231 + @".mov" : @"video/quicktime",
  232 + @".mp2" : @"audio/x-mpeg",
  233 + @".mp3" : @"audio/x-mpeg",
  234 + @".mp4" : @"video/mp4",
  235 + @".mpc" : @"application/vnd.mpohun.certificate",
  236 + @".mpe" : @"video/mpeg",
  237 + @".mpeg" : @"video/mpeg",
  238 + @".mpg" : @"video/mpeg",
  239 + @".mpg4" : @"video/mp4",
  240 + @".mpga" : @"audio/mpeg",
  241 + @".msg" : @"application/vnd.ms-outlook",
  242 + @".ogg" : @"audio/ogg",
  243 + @".pdf" : @"application/pdf",
  244 + @".png" : @"image/png",
  245 + @".pps" : @"application/vnd.ms-powerpoint",
  246 + @".ppt" : @"application/vnd.ms-powerpoint",
  247 + @".pptx" : @"application/vnd.openxmlformats-officedocument.presentationml.presentation",
  248 + @".prop" : @"text/plain",
  249 + @".rc" : @"text/plain",
  250 + @".rmvb" : @"audio/x-pn-realaudio",
  251 + @".rtf" : @"application/rtf",
  252 + @".sh" : @"text/plain",
  253 + @".tar" : @"application/x-tar",
  254 + @".tgz" : @"application/x-compressed",
  255 + @".txt" : @"text/plain",
  256 + @".wav" : @"audio/x-wav",
  257 + @".wma" : @"audio/x-ms-wma",
  258 + @".wmv" : @"audio/x-ms-wmv",
  259 + @".wps" : @"application/vnd.ms-works",
  260 + @".xml" : @"text/plain",
  261 + @".z" : @"application/x-compress",
  262 + @".h" : @"text/h-text",
  263 + @".m" : @"text/m-text",
  264 + @".json": @"text/json-text",
  265 + @".key" : @"application/vnd.ms-powerpoint",
  266 + @".numbers" : @"application/vnd.ms-excel",
  267 + @".pages" : @"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
  268 + };
  269 +
  270 + return dic;
  271 +}
  272 ++ (CNFileType)isReadedFileByType:(NSString *)suffixType
  273 +{
  274 + suffixType = [NSString stringWithFormat:@"%@",[suffixType lowercaseString]];
  275 + if ([[CNLiveBusinessTools fileTypeDic] objectForKey:[NSString stringWithFormat:@".%@",suffixType]]) {
  276 + return CNFileTypeReadAndLook;
  277 + }
  278 + else if ([[CNLiveBusinessTools onlyReadFileType] objectForKey:[NSString stringWithFormat:@".%@",suffixType]])
  279 + {
  280 + return CNFileTypeOnlyRead;
  281 + }
  282 + else
  283 + return CNFileTypeUnkown;
  284 +}
  285 +// 文件知道其类型,但是无法预览
  286 ++ (NSDictionary *)onlyReadFileType
  287 +{
  288 + NSDictionary *dic = @{
  289 + @".zip" : @"application/x-zip-compressed",
  290 +
  291 + };
  292 + return dic;
  293 +}
  294 +
  295 ++ (NSString *)getSpid
  296 +{
  297 + NSString *spId = @"";
  298 + NSArray *array = [AppId componentsSeparatedByString:@"_"];
  299 + spId = [array firstObject];
  300 + return spId;
  301 +}
  302 ++ (NSString *)getSidIdfv
  303 +{
  304 + NSString *idfv = [self tingyunUUID];
  305 + NSString *uid = @"";
  306 + if ([CNUserShareManager isLogin]) {
  307 + uid = CNUserShareModel.uid;
  308 + }
  309 + NSString *sidIdfv = [NSString stringWithFormat:@"%@%@",uid,idfv];
  310 + // NSLog(@"sidIdfv:%@",sidIdfv);
  311 + return sidIdfv;
  312 +}
  313 +
  314 +
  315 +
  316 ++ (NSMutableDictionary *)encryptionSignWithParameter:(NSMutableDictionary *)parameter encryptionKey:(NSString *)encryptionKey
  317 +{
  318 + NSMutableDictionary *muDic = [NSMutableDictionary dictionaryWithDictionary:parameter];
  319 + NSArray *allKeys = [muDic allKeys];
  320 + BOOL isContainAppId = NO;
  321 + BOOL isContainPlat = NO;
  322 + BOOL isPlatform_id = NO;
  323 + BOOL isTimestamp = NO;
  324 + BOOL isVer = NO;
  325 + BOOL isUUID = NO;
  326 + BOOL isSign = NO;
  327 + BOOL isLoginId = NO;
  328 + for (NSString *key in allKeys) {
  329 + if ([key isEqualToString:@"appId"]){
  330 + isContainAppId = YES;
  331 + }else if ([key isEqualToString:@"plat"]) {
  332 + isContainPlat = YES;
  333 + }else if ([key isEqualToString:@"platform_id"]) {
  334 + isPlatform_id = YES;
  335 + }else if ([key isEqualToString:@"timestamp"]) {
  336 + isTimestamp = YES;
  337 + }else if ([key isEqualToString:@"ver"]) {
  338 + isVer = YES;
  339 + }else if ([key isEqualToString:@"uuid"]) {
  340 + isUUID = YES;
  341 + }else if ([key isEqualToString:@"sign"]){
  342 + isSign = YES;
  343 + }else if ([key isEqualToString:@"loginSid"]) {
  344 + isLoginId = YES;
  345 + }
  346 + if (isContainAppId && isContainPlat && isPlatform_id && isTimestamp && isVer && isUUID && isLoginId) {
  347 + break;
  348 + }
  349 + }
  350 + if (!isContainAppId) {
  351 + [muDic setObject:AppId forKey:@"appId"];
  352 + }
  353 + if (!isContainPlat) {
  354 + [muDic setObject:@"i" forKey:@"plat"];
  355 + }
  356 + if (!isPlatform_id) {
  357 + [muDic setObject:[self getBundleID] forKey:@"platform_id"];
  358 + }
  359 + if (!isTimestamp) {
  360 + [muDic setObject:[NSString stringWithFormat:@"%zd",[self getNowTimestamp]] forKey:@"timestamp"];
  361 + }
  362 + if (!isVer) {
  363 + [muDic setObject:AppVersion forKey:@"ver"];
  364 + }
  365 + if (!isUUID) {
  366 + [muDic setObject:[CNLiveBusinessTools uuid] forKey:@"uuid"];
  367 + }
  368 + if (!isLoginId) {
  369 + [muDic setObject:CNUserShareModel.uid.length == 0 ? @"" : CNUserShareModel.uid forKey:@"loginSid"];
  370 + }
  371 +
  372 + NSMutableDictionary *startPara = [NSMutableDictionary dictionaryWithDictionary:muDic];
  373 + if (!isSign) {
  374 + NSString *string = [NSString stringWithFormat:@"%@&key=%@",[self signvalue:muDic],encryptionKey];
  375 + NSString *signString = [[self sha1:string] uppercaseString];
  376 + [startPara setObject:signString forKey:@"sign"];
  377 + }
  378 + return startPara;
  379 +}
  380 +
  381 ++ (NSInteger)getNowTimestamp{
  382 + NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  383 + [formatter setDateStyle:NSDateFormatterMediumStyle];
  384 + [formatter setTimeStyle:NSDateFormatterShortStyle];
  385 + [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
  386 + //设置时区,这个对于时间的处理有时很重要
  387 + NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
  388 + [formatter setTimeZone:timeZone];
  389 + NSDate *datenow = [NSDate date];//现在时间
  390 + // NSLog(@"设备当前的时间:%@",[formatter stringFromDate:datenow]);
  391 + //时间转时间戳的方法:
  392 + NSInteger timeSp = [[NSNumber numberWithDouble:[datenow timeIntervalSince1970]] integerValue];
  393 + // NSLog(@"设备当前的10位时间戳:%ld",(long)timeSp); //时间戳的值
  394 + return timeSp;
  395 +}
  396 +
  397 ++ (NSString *)signvalue:(NSDictionary*)parameter
  398 +{
  399 + //对所有传入参数按照字段名的 ASCII 码从小到大排序
  400 + NSArray *keyArr=[parameter allKeys];
  401 + NSArray *arr = [keyArr sortedArrayUsingSelector:@selector(compare:)];
  402 +
  403 + NSMutableString *string1 = [[NSMutableString alloc]init];
  404 + for (int i=0; i<arr.count; i++) {
  405 +
  406 + NSString *parameterString = parameter[[arr objectAtIndex:i]];
  407 + if (parameterString.length > 0) {
  408 + [string1 appendString:[NSString stringWithFormat:@"%@=%@&",[arr objectAtIndex:i],parameter[[arr objectAtIndex:i]]]];
  409 + }
  410 + }
  411 +
  412 + if (string1.length > 0) {
  413 + [string1 deleteCharactersInRange:NSMakeRange(string1.length-1, 1)];
  414 + }
  415 +
  416 + return string1;
  417 +}
  418 +
  419 ++ (NSString*)sha1:(NSString *)string
  420 +{
  421 + NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
  422 +
  423 + uint8_t digest[CC_SHA1_DIGEST_LENGTH];
  424 +
  425 + CC_SHA1(data.bytes, (int)data.length, digest);
  426 +
  427 + NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
  428 +
  429 + for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
  430 + [output appendFormat:@"%02x", digest[i]];
  431 +
  432 + while ([[output substringToIndex:1] isEqualToString:@"0"]) {
  433 + output = [[NSMutableString alloc] initWithString:[output substringFromIndex:1]];
  434 + }
  435 +
  436 + return output;
  437 +}
  438 +
  439 +//获取BundleID
  440 ++ (NSString*)getBundleID
  441 +{
  442 + return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
  443 +
  444 +}
  445 +
  446 +
  447 +/**
  448 + GIF表情存放位置
  449 + @return 地址
  450 + */
  451 ++ (NSString *)newChatGifFacePath{
  452 +
  453 + // NSHomeDirectory():应用程序目录, 在Documents文件夹下创建
  454 + NSString *tempName = [NSString stringWithFormat:@"Documents/%@/GifFace/Cache", CNUserShareModel.uid];
  455 +
  456 + NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:tempName];
  457 +
  458 + NSFileManager *fileManager = [NSFileManager defaultManager];
  459 +
  460 + BOOL isDir = NO;
  461 +
  462 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  463 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  464 +
  465 + if ( !(isDir == YES && existed == YES) ) {
  466 +
  467 + // 在 tmp 目录下创建一个 temp 目录
  468 + [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  469 + }
  470 +
  471 + return filePath;
  472 +
  473 +}
  474 +/**
  475 + @param userId 单聊为对方ID,群聊为群聊 ID,图片和视频存放位置
  476 + @return 地址
  477 + */
  478 ++ (NSString *)newChatFilePathByUserId:(NSString *)userId{
  479 +
  480 + // NSHomeDirectory():应用程序目录, 在Documents文件夹下创建
  481 + NSString *tempName = [NSString stringWithFormat:@"Documents/%@/%@/imageorvideo", CNUserShareModel.uid, userId];
  482 +
  483 + NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:tempName];
  484 +
  485 + NSFileManager *fileManager = [NSFileManager defaultManager];
  486 +
  487 + BOOL isDir = NO;
  488 +
  489 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  490 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  491 +
  492 + if ( !(isDir == YES && existed == YES) ) {
  493 +
  494 + // 在 tmp 目录下创建一个 temp 目录
  495 + [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  496 + }
  497 +
  498 + return filePath;
  499 +
  500 +}
  501 +
  502 ++ (nullable NSString *)chatFileWithCachePathByUserId:(NSString *_Nonnull)userId{
  503 + // NSHomeDirectory():应用程序目录, @"tmp/temp":在tmp文件夹下创建temp 文件夹
  504 + // NSString *tempName = [NSString stringWithFormat:@"cache/%@/%@", CNUserShareModel.uid, userId];
  505 +
  506 + NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0]; //stringByAppendingPathComponent:tempName];
  507 +
  508 + NSFileManager *fileManager = [NSFileManager defaultManager];
  509 +
  510 + BOOL isDir = NO;
  511 +
  512 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  513 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  514 +
  515 + if ( !(isDir == YES && existed == YES) ) {
  516 +
  517 + // 在 tmp 目录下创建一个 temp 目录
  518 + [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  519 + }
  520 +
  521 + return filePath;
  522 +}
  523 +
  524 +//用户ID
  525 ++ (nullable NSString *)chatFilePathByUserId:(NSString *_Nonnull)userId{
  526 +
  527 + // NSHomeDirectory():应用程序目录, @"tmp/temp":在tmp文件夹下创建temp 文件夹
  528 + NSString *tempName = [NSString stringWithFormat:@"%@/",userId];
  529 +
  530 + NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:tempName];
  531 +
  532 + NSFileManager *fileManager = [NSFileManager defaultManager];
  533 +
  534 + BOOL isDir = NO;
  535 +
  536 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  537 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  538 +
  539 + if ( !(isDir == YES && existed == YES) ) {
  540 +
  541 + // 在 temp 目录下创建一临时文件
  542 + [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  543 + }
  544 +
  545 + return filePath;
  546 +
  547 +}
  548 +
  549 +/**
  550 + @param userId 单聊为对方ID,群聊为群聊 ID
  551 + @return 返回聊天发送的文件 所保存的文件夹地址
  552 + */
  553 ++ (NSString *)getChatFilesPathByUserId:(NSString *)userId{
  554 + NSString *tempName = [NSString stringWithFormat:@"Documents/%@/%@/file", CNUserShareModel.uid, userId];
  555 +
  556 + NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:tempName];
  557 +
  558 + NSFileManager *fileManager = [NSFileManager defaultManager];
  559 +
  560 + BOOL isDir = NO;
  561 +
  562 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  563 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  564 +
  565 + if ( !(isDir == YES && existed == YES) ) {
  566 +
  567 + // 在 Documents 目录下创建
  568 +
  569 + if ([fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil]) {
  570 + NSLog(@"创建聊天文件路径成功");
  571 + }
  572 + else
  573 + {
  574 + NSLog(@"聊天文件路径已经创建过");
  575 + }
  576 + }
  577 + return filePath;
  578 +}
  579 +
  580 +/**
  581 + 0
  582 + @param userId 单聊为对方ID,群聊为群聊 ID ,语音文件保存路径
  583 + */
  584 ++ (NSString *)audioChatFilePathByUserId:(NSString *)userId{
  585 + NSString *tempName = [NSString stringWithFormat:@"Documents/%@/%@/audio", CNUserShareModel.uid, userId];
  586 +
  587 + NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:tempName];
  588 +
  589 + NSFileManager *fileManager = [NSFileManager defaultManager];
  590 +
  591 + BOOL isDir = NO;
  592 +
  593 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  594 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  595 +
  596 + if ( !(isDir == YES && existed == YES) ) {
  597 +
  598 + // 在 Documents 目录下创建
  599 +
  600 + if ([fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil]) {
  601 + NSLog(@"创建语音文件成功");
  602 + }
  603 + else
  604 + {
  605 + NSLog(@"语音文件已经存在");
  606 + }
  607 + }
  608 + return filePath;
  609 +}
  610 +
  611 +/**
  612 + 聊天背景图图片地址
  613 +
  614 + @return file
  615 + */
  616 ++ (NSString *)chatBackgroupImagefilePath{
  617 +
  618 + // NSHomeDirectory():应用程序目录, 在Documents文件夹下创建
  619 + NSString *tempName = [NSString stringWithFormat:@"Documents/%@/chatBackgroupImage", CNUserShareModel.uid];
  620 +
  621 + NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:tempName];
  622 +
  623 + NSFileManager *fileManager = [NSFileManager defaultManager];
  624 +
  625 + BOOL isDir = NO;
  626 +
  627 + // fileExistsAtPath 判断一个文件或目录是否有效,isDirectory判断是否一个目录
  628 + BOOL existed = [fileManager fileExistsAtPath:filePath isDirectory:&isDir];
  629 +
  630 + if ( !(isDir == YES && existed == YES) ) {
  631 +
  632 + // 在 tmp 目录下创建一个 temp 目录
  633 + [fileManager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  634 + }
  635 +
  636 + return filePath;
  637 +
  638 +}
  639 +@end
... ...
CNLiveBusinessTools.podspec
... ... @@ -8,7 +8,7 @@
8 8  
9 9 Pod::Spec.new do |s|
10 10 s.name = 'CNLiveBusinessTools'
11   - s.version = '0.1.14'
  11 + s.version = '0.1.15'
12 12 s.summary = '业务工具集合组件.'
13 13  
14 14 # This description is used to generate tags and improve search results.
... ...
CNLiveBusinessTools/Classes/CNLiveBusinessTools.h renamed to CNLiveBusinessToolsHeader.h
  1 +//
  2 +// CNLiveBusinessToolsHeader.h
  3 +// CNLiveBusinessTools
  4 +//
  5 +// Created by 张旭 on 2020/4/14.
  6 +//
  7 +
1 8 // 业务模块工具
2 9  
3 10 #import "HttpService.h"
4   -#import "CNLiveNetBusinessTools.h"
  11 +#import "CNLiveBusinessTools.h"
5 12 #import "CNLiveQQEmotionManager.h"
6 13 #import "CNLiveEmotionHelper.h"
7 14 #import "QMUIEmotion+CNLiveEmotion.h"
8   -
... ...