Commit 64bd97de8713d9961b7fcc5a353c6fb4fa552652
1 parent
855cbe63
增加网加加统计APP使用时长 ,渠道from统计
Showing
10 changed files
with
125 additions
and
12 deletions
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUserManager.h
| ... | ... | @@ -15,6 +15,7 @@ |
| 15 | 15 | @property (nonatomic, strong) NSString *appKey; |
| 16 | 16 | @property (nonatomic, strong) NSString *appSecret; |
| 17 | 17 | @property (nonatomic ,assign) BOOL isTestEnvironment; |
| 18 | +@property (nonatomic, copy) NSString *userId; | |
| 18 | 19 | |
| 19 | 20 | + (CNLiveUserManager *)manager; |
| 20 | 21 | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUserManager.m
| ... | ... | @@ -10,7 +10,6 @@ |
| 10 | 10 | #import "CNLiveUserSystemTools.h" |
| 11 | 11 | #import "Common.h" |
| 12 | 12 | |
| 13 | -#define testStatUrl @"http://testappsta.cnlive.com/app.js" | |
| 14 | 13 | #define formalStatUrl @"http://app.sta.cnlive.com/app.js" |
| 15 | 14 | |
| 16 | 15 | @interface CNLiveUserManager () |
| ... | ... | @@ -48,11 +47,11 @@ |
| 48 | 47 | |
| 49 | 48 | NSString *stamp = realTime; |
| 50 | 49 | stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; |
| 51 | - NSString *baseUrl = self.isTestEnvironment ? formalStatUrl : testStatUrl; | |
| 52 | - NSString *vvUrl = [NSString stringWithFormat:@"%@?sver=%@&uid=%@&tm=%@&from=&spid=&appid=%@&version=1005_%@&eventid=1300&uri=&sid=&plat=i_%@&objid=",baseUrl,kSVer,[CNLiveUserSystemTools uidForStat:realTime],stamp,self.appId,SDKVersion, StatAppVersion]; | |
| 50 | + NSString *baseUrl = formalStatUrl; | |
| 51 | + NSString *vvUrl = [NSString stringWithFormat:@"%@?sver=%@&uid=%@&tm=%@&from=iphone&spid=&appid=%@&version=1005_%@&eventid=1300&uri=&sid=&plat=i_%@&objid=",baseUrl,kSVer,[CNLiveUserSystemTools uidForStat:realTime],stamp,self.appId,SDKVersion, StatAppVersion]; | |
| 53 | 52 | |
| 54 | 53 | [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil]; |
| 55 | - | |
| 54 | + | |
| 56 | 55 | }]; |
| 57 | 56 | } |
| 58 | 57 | |
| ... | ... | @@ -65,9 +64,39 @@ |
| 65 | 64 | |
| 66 | 65 | NSString *endDate = [NSString stringWithFormat:@"%.3f",[netDate timeIntervalSinceDate:_startDate]]; |
| 67 | 66 | endDate = [endDate stringByReplacingOccurrencesOfString:@"." withString:@""]; |
| 68 | - NSString *baseUrl = self.isTestEnvironment ? formalStatUrl : testStatUrl; | |
| 69 | - NSString *vvUrl = [NSString stringWithFormat:@"%@?sver=%@&uid=%@&tm=%@&from=&spid=&appid=%@&version=1005_%@&eventid=1311&uri=%@&sid=&plat=i_%@&objid=",baseUrl,kSVer,[CNLiveUserSystemTools uidForStat:realTime],stamp,self.appId,SDKVersion,endDate,StatAppVersion]; | |
| 67 | + NSString *baseUrl = formalStatUrl; | |
| 68 | + NSString *vvUrl = [NSString stringWithFormat:@"%@?sver=%@&uid=%@&tm=%@&from=iphone&spid=&appid=%@&version=1005_%@&eventid=1311&uri=%@&sid=&plat=i_%@&objid=",baseUrl,kSVer,[CNLiveUserSystemTools uidForStat:realTime],stamp,self.appId,SDKVersion,endDate,StatAppVersion]; | |
| 69 | + | |
| 70 | + [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil]; | |
| 71 | + }]; | |
| 72 | +} | |
| 73 | + | |
| 74 | +- (void)wjjStartUserStat | |
| 75 | +{ | |
| 76 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 77 | + | |
| 78 | + _startDate = netDate; | |
| 79 | + | |
| 80 | + NSString *stamp = realTime; | |
| 81 | + stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; | |
| 82 | + NSString *baseUrl = formalStatUrl; | |
| 83 | + NSString *vvUrl = [NSString stringWithFormat:@"%@?sver=%@&uid=%@&tm=%@&from=iphone&spid=&appid=%@&version=1005_%@&eventid=1320&uri=&sid=%@&plat=i_%@&objid=",baseUrl,kSVer,[CNLiveUserSystemTools uidForStat:realTime],stamp,self.appId,SDKVersion, [CNLiveUserManager manager].userId,StatAppVersion]; | |
| 84 | + [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil]; | |
| 85 | + | |
| 86 | + }]; | |
| 87 | +} | |
| 88 | + | |
| 89 | +- (void)wjjEndUserStat | |
| 90 | +{ | |
| 91 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 70 | 92 | |
| 93 | + NSString *stamp = realTime; | |
| 94 | + stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; | |
| 95 | + | |
| 96 | + NSString *endDate = [NSString stringWithFormat:@"%.3f",[netDate timeIntervalSinceDate:_startDate]]; | |
| 97 | + endDate = [endDate stringByReplacingOccurrencesOfString:@"." withString:@""]; | |
| 98 | + NSString *baseUrl = formalStatUrl; | |
| 99 | + NSString *vvUrl = [NSString stringWithFormat:@"%@?sver=%@&uid=%@&tm=%@&from=iphone&spid=&appid=%@&version=1005_%@&eventid=1321&uri=%@&sid=%@&plat=i_%@&objid=",baseUrl,kSVer,[CNLiveUserSystemTools uidForStat:realTime],stamp,self.appId,SDKVersion,endDate,[CNLiveUserManager manager].userId,StatAppVersion]; | |
| 71 | 100 | [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil]; |
| 72 | 101 | }]; |
| 73 | 102 | } |
| ... | ... | @@ -75,10 +104,20 @@ |
| 75 | 104 | - (void)applicationBecomeActive |
| 76 | 105 | { |
| 77 | 106 | [self startUserStat]; |
| 107 | + | |
| 108 | + if ([CNLiveUserManager manager].userId) | |
| 109 | + { | |
| 110 | + [self wjjStartUserStat]; | |
| 111 | + } | |
| 78 | 112 | } |
| 79 | 113 | |
| 80 | 114 | - (void)applicationEnterBackground |
| 81 | 115 | { |
| 82 | 116 | [self endUserStat]; |
| 117 | + | |
| 118 | + if ([CNLiveUserManager manager].userId) | |
| 119 | + { | |
| 120 | + [self wjjEndUserStat]; | |
| 121 | + } | |
| 83 | 122 | } |
| 84 | 123 | @end | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUserSystemCenter.h
| ... | ... | @@ -24,6 +24,13 @@ |
| 24 | 24 | + (void)setAppId:(NSString *)appId appKey:(NSString *)appKey appSecret:(NSString *)appSecret isTestEnvironment:(BOOL)isTestEnvironment; |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | + 用户ID | |
| 28 | + | |
| 29 | + @param userId 用户ID | |
| 30 | + */ | |
| 31 | ++ (void)setUserId:(NSString *)userId; | |
| 32 | + | |
| 33 | +/** | |
| 27 | 34 | @abstract 初始化 |
| 28 | 35 | @param appId 注册成功获得应用ID |
| 29 | 36 | @param appKey 注册成功获得应用key |
| ... | ... | @@ -96,7 +103,7 @@ |
| 96 | 103 | |
| 97 | 104 | |
| 98 | 105 | /** |
| 99 | - @abstract 发送验证码 | |
| 106 | + @abstract 发送验证码(旧) | |
| 100 | 107 | @param mobile 手机号 |
| 101 | 108 | @param type 发送验证码类型(详见VerificationCodeType) |
| 102 | 109 | @param success 成功回调 |
| ... | ... | @@ -104,6 +111,16 @@ |
| 104 | 111 | */ |
| 105 | 112 | + (void)verificationCodeType:(VerificationCodeType)type mobile:(NSString *)mobile success:(void (^)(id result))success failure:(void (^)(NSDictionary *errorDic))failure; |
| 106 | 113 | |
| 114 | +/** | |
| 115 | + @abstract 发送验证码(新) | |
| 116 | + @param type 发送验证码类型(详见VerificationCodeType) | |
| 117 | + @param mobile 手机号 | |
| 118 | + @param countryCode 手机号国家码 | |
| 119 | + @param success 成功回调 | |
| 120 | + @param failure 失败回调 | |
| 121 | + */ | |
| 122 | ++ (void)verificationCodeType:(VerificationCodeType)type mobile:(NSString *)mobile countryCode:(NSString *)countryCode success:(void (^)(id result))success failure:(void (^)(NSDictionary *errorDic))failure; | |
| 123 | + | |
| 107 | 124 | |
| 108 | 125 | /** |
| 109 | 126 | @abstract 更新用户附加信息 | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUserSystemCenter.m
| ... | ... | @@ -50,6 +50,11 @@ |
| 50 | 50 | [[CNLiveUserManager manager] addObserver]; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | ++ (void)setUserId:(NSString *)userId | |
| 54 | +{ | |
| 55 | + [CNLiveUserManager manager].userId = userId; | |
| 56 | +} | |
| 57 | + | |
| 53 | 58 | /** |
| 54 | 59 | * 注册 |
| 55 | 60 | */ |
| ... | ... | @@ -103,7 +108,7 @@ |
| 103 | 108 | } |
| 104 | 109 | |
| 105 | 110 | /** |
| 106 | - * 发送验证码 | |
| 111 | + * 发送验证码(旧) | |
| 107 | 112 | */ |
| 108 | 113 | + (void)verificationCodeType:(VerificationCodeType)type mobile:(NSString *)mobile success:(void (^)(id))success failure :(void (^)(NSDictionary *))failure |
| 109 | 114 | { |
| ... | ... | @@ -113,6 +118,16 @@ |
| 113 | 118 | } |
| 114 | 119 | |
| 115 | 120 | /** |
| 121 | + * 发送验证码 (新) | |
| 122 | + */ | |
| 123 | ++ (void)verificationCodeType:(VerificationCodeType)type mobile:(NSString *)mobile countryCode:(NSString *)countryCode success:(void (^)(id result))success failure:(void (^)(NSDictionary *errorDic))failure | |
| 124 | +{ | |
| 125 | + CNLiveVerificationCode *verification = [[CNLiveVerificationCode alloc] init]; | |
| 126 | + | |
| 127 | + [verification getVerificationCodeWithAppId:[CNLiveUserManager manager].appId appKey:[CNLiveUserManager manager].appKey type:type mobile:mobile countryCode:countryCode success:success failure:failure]; | |
| 128 | +} | |
| 129 | + | |
| 130 | +/** | |
| 116 | 131 | * 更新用户附加信息 |
| 117 | 132 | */ |
| 118 | 133 | +(void)updateOtherInfoWithUid:(NSString *)uid extInfo:(NSString *)extInfo success:(void (^)(id))success failure:(void (^)(NSDictionary *))failure | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUserSystemTools.m
| ... | ... | @@ -115,7 +115,7 @@ |
| 115 | 115 | NSString *stamp = realTime; |
| 116 | 116 | stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; |
| 117 | 117 | NSString *baseUrl = self.isTestEnvironment ? formalStatUrl : testStatUrl; |
| 118 | - NSString *vvUrl = [NSString stringWithFormat:@"%@?sver=%@&uid=%@&tm=%@&from=&spid=&appid=%@&version=1005_%@&eventid=1000&uri=%@&sid=%@&plat=i_%@&objid=_",baseUrl,kSVer, [self uidForStat:realTime], stamp, [CNLiveUserManager manager].appId, SDKVersion, errorString,[self getSid],StatAppVersion]; | |
| 118 | + NSString *vvUrl = [NSString stringWithFormat:@"%@?sver=%@&uid=%@&tm=%@&from=iphone&spid=&appid=%@&version=1005_%@&eventid=1000&uri=%@&sid=%@&plat=i_%@&objid=_",baseUrl,kSVer, [self uidForStat:realTime], stamp, [CNLiveUserManager manager].appId, SDKVersion, errorString,[self getSid],StatAppVersion]; | |
| 119 | 119 | [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil]; |
| 120 | 120 | }]; |
| 121 | 121 | } | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveVerificationCode.h
| ... | ... | @@ -10,7 +10,10 @@ |
| 10 | 10 | #import "CNLiveUserSystemTypeDef.h" |
| 11 | 11 | |
| 12 | 12 | @interface CNLiveVerificationCode : NSObject |
| 13 | - | |
| 13 | +//获取验证码(旧) | |
| 14 | 14 | - (void)getVerificationCodeWithAppId:(NSString *)appId appKey:(NSString *)appKey type:(VerificationCodeType)type mobile:(NSString *)mobile success:(void (^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure; |
| 15 | 15 | |
| 16 | +//获取验证码(新) | |
| 17 | +- (void)getVerificationCodeWithAppId:(NSString *)appId appKey:(NSString *)appKey type:(VerificationCodeType)type mobile:(NSString *)mobile countryCode:(NSString *)countryCode success:(void (^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure; | |
| 18 | + | |
| 16 | 19 | @end | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveVerificationCode.m
| ... | ... | @@ -46,6 +46,27 @@ static NSString *passwordFormalURL = @"https://api.cnlive.com/open/api2/user/se |
| 46 | 46 | }]; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | +- (void)getVerificationCodeWithAppId:(NSString *)appId appKey:(NSString *)appKey type:(VerificationCodeType)type mobile:(NSString *)mobile countryCode:(NSString *)countryCode success:(void (^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure | |
| 50 | +{ | |
| 51 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 52 | + NSString *timeString = realTime; | |
| 53 | + | |
| 54 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 55 | + @"mobile":[CNLiveUserSystemTools verify:mobile], | |
| 56 | + @"countryCode":countryCode, @"clientPlat":@"i", | |
| 57 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 58 | + @"timestamp": timeString}; | |
| 59 | + | |
| 60 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 61 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 62 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 63 | + | |
| 64 | + [parameter setObject:signString forKey:@"sign"]; | |
| 65 | + | |
| 66 | + [self requestWithURL:[self getURL:type] parameter:parameter success:success failure:failure]; | |
| 67 | + }]; | |
| 68 | +} | |
| 69 | + | |
| 49 | 70 | #pragma mark - request |
| 50 | 71 | |
| 51 | 72 | - (void)requestWithURL:(NSString *)URL parameter:(NSDictionary *)param success:(void(^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure | ... | ... |
CNLiveUserSystemSDK.xcodeproj/project.pbxproj
| ... | ... | @@ -259,7 +259,7 @@ |
| 259 | 259 | ); |
| 260 | 260 | runOnlyForDeploymentPostprocessing = 0; |
| 261 | 261 | shellPath = /bin/sh; |
| 262 | - shellScript = "if [ \"${ACTION}\" = \"build\" ]\nthen\nINSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME}.framework\n\nDEVICE_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework\n\nSIMULATOR_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework\n\nif [ -d \"${INSTALL_DIR}\" ]\nthen\nrm -rf \"${INSTALL_DIR}\"\nfi\n\nmkdir -p \"${INSTALL_DIR}\"\n\ncp -R \"${DEVICE_DIR}/\" \"${INSTALL_DIR}/\"\n#ditto \"${DEVICE_DIR}/Headers\" \"${INSTALL_DIR}/Headers\"\n\nlipo -create \"${DEVICE_DIR}/${PROJECT_NAME}\" \"${SIMULATOR_DIR}/${PROJECT_NAME}\" -output \"${INSTALL_DIR}/${PROJECT_NAME}\"\n\n#open \"${DEVICE_DIR}\"\n#open \"${SRCROOT}/Products\"\nfi"; | |
| 262 | + shellScript = "if [ \"${ACTION}\" = \"build\" ]\nthen\nINSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME}.framework\n\nDEVICE_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework\n\nSIMULATOR_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework\n\nif [ -d \"${INSTALL_DIR}\" ]\nthen\nrm -rf \"${INSTALL_DIR}\"\nfi\n\nmkdir -p \"${INSTALL_DIR}\"\n\ncp -R \"${DEVICE_DIR}/\" \"${INSTALL_DIR}/\"\n#ditto \"${DEVICE_DIR}/Headers\" \"${INSTALL_DIR}/Headers\"\n\nlipo -create \"${DEVICE_DIR}/${PROJECT_NAME}\" \"${SIMULATOR_DIR}/${PROJECT_NAME}\" -output \"${INSTALL_DIR}/${PROJECT_NAME}\"\n\n#open \"${DEVICE_DIR}\"\n#open \"${SRCROOT}/Products\"\nfi\n"; | |
| 263 | 263 | }; |
| 264 | 264 | /* End PBXShellScriptBuildPhase section */ |
| 265 | 265 | ... | ... |
Products/CNLiveUserSystemSDK.framework/CNLiveUserSystemSDK
No preview for this file type
Products/CNLiveUserSystemSDK.framework/Headers/CNLiveUserSystemCenter.h
| ... | ... | @@ -24,6 +24,13 @@ |
| 24 | 24 | + (void)setAppId:(NSString *)appId appKey:(NSString *)appKey appSecret:(NSString *)appSecret isTestEnvironment:(BOOL)isTestEnvironment; |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | + 用户ID | |
| 28 | + | |
| 29 | + @param userId 用户ID | |
| 30 | + */ | |
| 31 | ++ (void)setUserId:(NSString *)userId; | |
| 32 | + | |
| 33 | +/** | |
| 27 | 34 | @abstract 初始化 |
| 28 | 35 | @param appId 注册成功获得应用ID |
| 29 | 36 | @param appKey 注册成功获得应用key |
| ... | ... | @@ -96,7 +103,7 @@ |
| 96 | 103 | |
| 97 | 104 | |
| 98 | 105 | /** |
| 99 | - @abstract 发送验证码 | |
| 106 | + @abstract 发送验证码(旧) | |
| 100 | 107 | @param mobile 手机号 |
| 101 | 108 | @param type 发送验证码类型(详见VerificationCodeType) |
| 102 | 109 | @param success 成功回调 |
| ... | ... | @@ -104,6 +111,16 @@ |
| 104 | 111 | */ |
| 105 | 112 | + (void)verificationCodeType:(VerificationCodeType)type mobile:(NSString *)mobile success:(void (^)(id result))success failure:(void (^)(NSDictionary *errorDic))failure; |
| 106 | 113 | |
| 114 | +/** | |
| 115 | + @abstract 发送验证码(新) | |
| 116 | + @param type 发送验证码类型(详见VerificationCodeType) | |
| 117 | + @param mobile 手机号 | |
| 118 | + @param countryCode 手机号国家码 | |
| 119 | + @param success 成功回调 | |
| 120 | + @param failure 失败回调 | |
| 121 | + */ | |
| 122 | ++ (void)verificationCodeType:(VerificationCodeType)type mobile:(NSString *)mobile countryCode:(NSString *)countryCode success:(void (^)(id result))success failure:(void (^)(NSDictionary *errorDic))failure; | |
| 123 | + | |
| 107 | 124 | |
| 108 | 125 | /** |
| 109 | 126 | @abstract 更新用户附加信息 | ... | ... |