Commit 7a2219e75599fd826e801792bc13ae3f0a9c3b8e
1 parent
da8be6c1
增加测试环境代码但没用到,所有时间都从网络获取
Showing
16 changed files
with
695 additions
and
361 deletions
CNLiveUserSystemDemo.xcodeproj/xcuserdata/cnlive.xcuserdatad/xcschemes/CNLiveUserSystemDemo.xcscheme
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<Scheme | |
| 3 | + LastUpgradeVersion = "0830" | |
| 4 | + version = "1.3"> | |
| 5 | + <BuildAction | |
| 6 | + parallelizeBuildables = "YES" | |
| 7 | + buildImplicitDependencies = "YES"> | |
| 8 | + <BuildActionEntries> | |
| 9 | + <BuildActionEntry | |
| 10 | + buildForTesting = "YES" | |
| 11 | + buildForRunning = "YES" | |
| 12 | + buildForProfiling = "YES" | |
| 13 | + buildForArchiving = "YES" | |
| 14 | + buildForAnalyzing = "YES"> | |
| 15 | + <BuildableReference | |
| 16 | + BuildableIdentifier = "primary" | |
| 17 | + BlueprintIdentifier = "812642C01D86A7A800B402CA" | |
| 18 | + BuildableName = "CNLiveUserSystemDemo.app" | |
| 19 | + BlueprintName = "CNLiveUserSystemDemo" | |
| 20 | + ReferencedContainer = "container:CNLiveUserSystemDemo.xcodeproj"> | |
| 21 | + </BuildableReference> | |
| 22 | + </BuildActionEntry> | |
| 23 | + </BuildActionEntries> | |
| 24 | + </BuildAction> | |
| 25 | + <TestAction | |
| 26 | + buildConfiguration = "Debug" | |
| 27 | + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | |
| 28 | + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | |
| 29 | + shouldUseLaunchSchemeArgsEnv = "YES"> | |
| 30 | + <Testables> | |
| 31 | + <TestableReference | |
| 32 | + skipped = "NO"> | |
| 33 | + <BuildableReference | |
| 34 | + BuildableIdentifier = "primary" | |
| 35 | + BlueprintIdentifier = "812642D91D86A7A800B402CA" | |
| 36 | + BuildableName = "CNLiveUserSystemDemoTests.xctest" | |
| 37 | + BlueprintName = "CNLiveUserSystemDemoTests" | |
| 38 | + ReferencedContainer = "container:CNLiveUserSystemDemo.xcodeproj"> | |
| 39 | + </BuildableReference> | |
| 40 | + </TestableReference> | |
| 41 | + <TestableReference | |
| 42 | + skipped = "NO"> | |
| 43 | + <BuildableReference | |
| 44 | + BuildableIdentifier = "primary" | |
| 45 | + BlueprintIdentifier = "812642E41D86A7A800B402CA" | |
| 46 | + BuildableName = "CNLiveUserSystemDemoUITests.xctest" | |
| 47 | + BlueprintName = "CNLiveUserSystemDemoUITests" | |
| 48 | + ReferencedContainer = "container:CNLiveUserSystemDemo.xcodeproj"> | |
| 49 | + </BuildableReference> | |
| 50 | + </TestableReference> | |
| 51 | + </Testables> | |
| 52 | + <MacroExpansion> | |
| 53 | + <BuildableReference | |
| 54 | + BuildableIdentifier = "primary" | |
| 55 | + BlueprintIdentifier = "812642C01D86A7A800B402CA" | |
| 56 | + BuildableName = "CNLiveUserSystemDemo.app" | |
| 57 | + BlueprintName = "CNLiveUserSystemDemo" | |
| 58 | + ReferencedContainer = "container:CNLiveUserSystemDemo.xcodeproj"> | |
| 59 | + </BuildableReference> | |
| 60 | + </MacroExpansion> | |
| 61 | + <AdditionalOptions> | |
| 62 | + </AdditionalOptions> | |
| 63 | + </TestAction> | |
| 64 | + <LaunchAction | |
| 65 | + buildConfiguration = "Debug" | |
| 66 | + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | |
| 67 | + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | |
| 68 | + launchStyle = "0" | |
| 69 | + useCustomWorkingDirectory = "NO" | |
| 70 | + ignoresPersistentStateOnLaunch = "NO" | |
| 71 | + debugDocumentVersioning = "YES" | |
| 72 | + debugServiceExtension = "internal" | |
| 73 | + allowLocationSimulation = "YES"> | |
| 74 | + <BuildableProductRunnable | |
| 75 | + runnableDebuggingMode = "0"> | |
| 76 | + <BuildableReference | |
| 77 | + BuildableIdentifier = "primary" | |
| 78 | + BlueprintIdentifier = "812642C01D86A7A800B402CA" | |
| 79 | + BuildableName = "CNLiveUserSystemDemo.app" | |
| 80 | + BlueprintName = "CNLiveUserSystemDemo" | |
| 81 | + ReferencedContainer = "container:CNLiveUserSystemDemo.xcodeproj"> | |
| 82 | + </BuildableReference> | |
| 83 | + </BuildableProductRunnable> | |
| 84 | + <AdditionalOptions> | |
| 85 | + </AdditionalOptions> | |
| 86 | + </LaunchAction> | |
| 87 | + <ProfileAction | |
| 88 | + buildConfiguration = "Release" | |
| 89 | + shouldUseLaunchSchemeArgsEnv = "YES" | |
| 90 | + savedToolIdentifier = "" | |
| 91 | + useCustomWorkingDirectory = "NO" | |
| 92 | + debugDocumentVersioning = "YES"> | |
| 93 | + <BuildableProductRunnable | |
| 94 | + runnableDebuggingMode = "0"> | |
| 95 | + <BuildableReference | |
| 96 | + BuildableIdentifier = "primary" | |
| 97 | + BlueprintIdentifier = "812642C01D86A7A800B402CA" | |
| 98 | + BuildableName = "CNLiveUserSystemDemo.app" | |
| 99 | + BlueprintName = "CNLiveUserSystemDemo" | |
| 100 | + ReferencedContainer = "container:CNLiveUserSystemDemo.xcodeproj"> | |
| 101 | + </BuildableReference> | |
| 102 | + </BuildableProductRunnable> | |
| 103 | + </ProfileAction> | |
| 104 | + <AnalyzeAction | |
| 105 | + buildConfiguration = "Debug"> | |
| 106 | + </AnalyzeAction> | |
| 107 | + <ArchiveAction | |
| 108 | + buildConfiguration = "Release" | |
| 109 | + revealArchiveInOrganizer = "YES"> | |
| 110 | + </ArchiveAction> | |
| 111 | +</Scheme> | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveCheckVerificationCode.m
| ... | ... | @@ -12,10 +12,12 @@ |
| 12 | 12 | #import "NSDictionary+Safety.h" |
| 13 | 13 | |
| 14 | 14 | //注册前校验手机验证码 |
| 15 | -static NSString *registerCheckVerificationCodeURL = @"https://api.cnlive.com/open/api2/user/checkVerifyCodeForUnRegistered"; | |
| 15 | +static NSString *registerCheckVerificationCodeTestURL = @"http://test.open.cnlive.com/openapi/api2/user/checkVerifyCodeForUnRegistered"; | |
| 16 | +static NSString *registerCheckVerificationCodeFormalURL = @"https://api.cnlive.com/open/api2/user/checkVerifyCodeForUnRegistered"; | |
| 16 | 17 | |
| 17 | 18 | //快捷登录前前校验手机验证码 |
| 18 | -static NSString *shortcutLoginCheckVerificationCodeURL = @"https://api.cnlive.com/open/api2/user/checkVerifyCode"; | |
| 19 | +static NSString *shortcutLoginCheckVerificationCodeTestURL = @"http://test.open.cnlive.com/openapi/api2/user/checkVerifyCode"; | |
| 20 | +static NSString *shortcutLoginCheckVerificationCodeFormalURL = @"https://api.cnlive.com/open/api2/user/checkVerifyCode"; | |
| 19 | 21 | |
| 20 | 22 | @implementation CNLiveCheckVerificationCode |
| 21 | 23 | |
| ... | ... | @@ -94,10 +96,19 @@ static NSString *shortcutLoginCheckVerificationCodeURL = @"https://api.cnlive.c |
| 94 | 96 | NSString *url; |
| 95 | 97 | switch (type) { |
| 96 | 98 | case CheckVerificationCodeTypeShortcutLogin: |
| 97 | - url = shortcutLoginCheckVerificationCodeURL; | |
| 99 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 100 | + url = shortcutLoginCheckVerificationCodeTestURL; | |
| 101 | + }else{ | |
| 102 | + url = shortcutLoginCheckVerificationCodeFormalURL; | |
| 103 | + } | |
| 104 | + | |
| 98 | 105 | break; |
| 99 | 106 | case CheckVerificationCodeTypeRegister: |
| 100 | - url = registerCheckVerificationCodeURL; | |
| 107 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 108 | + url = registerCheckVerificationCodeTestURL; | |
| 109 | + } else { | |
| 110 | + url = registerCheckVerificationCodeFormalURL; | |
| 111 | + } | |
| 101 | 112 | break; |
| 102 | 113 | |
| 103 | 114 | default: | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveEmailModifyPassword.m
| ... | ... | @@ -12,8 +12,8 @@ |
| 12 | 12 | #import "NSDictionary+Safety.h" |
| 13 | 13 | |
| 14 | 14 | //通过邮箱修改密码 |
| 15 | -static NSString *emailModifyPwdURL = @"https://api.cnlive.com/open/api2/user/updatePwdByEmail"; | |
| 16 | - | |
| 15 | +static NSString *emailModifyPwdTestURL = @"http://test.open.cnlive.com/openapi/api2/user/updatePwdByEmail"; | |
| 16 | +static NSString *emailModifyPwdFormalURL = @"https://api.cnlive.com/open/api2/user/updatePwdByEmail"; | |
| 17 | 17 | |
| 18 | 18 | @implementation CNLiveEmailModifyPassword |
| 19 | 19 | |
| ... | ... | @@ -31,7 +31,13 @@ static NSString *emailModifyPwdURL = @"https://api.cnlive.com/open/api2/user/up |
| 31 | 31 | NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; |
| 32 | 32 | |
| 33 | 33 | [parameter setObject:signString forKey:@"sign"]; |
| 34 | - [self requestWithURL:emailModifyPwdURL parameter:parameter success:success failure:failure]; | |
| 34 | + NSString *url; | |
| 35 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 36 | + url = emailModifyPwdTestURL; | |
| 37 | + } else { | |
| 38 | + url = emailModifyPwdFormalURL; | |
| 39 | + } | |
| 40 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 35 | 41 | } |
| 36 | 42 | |
| 37 | 43 | #pragma mark - request | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveFeedback.m
| ... | ... | @@ -12,38 +12,44 @@ |
| 12 | 12 | #import "NSDictionary+Safety.h" |
| 13 | 13 | |
| 14 | 14 | //反馈 |
| 15 | -static NSString *feedbackURL = @"https://api.cnlive.com/open/api2/user/userReport"; | |
| 15 | +static NSString *feedbackTestURL = @"http://test.open.cnlive.com/openapi/api2/user/userReport"; | |
| 16 | +static NSString *feedbackFormalURL = @"https://api.cnlive.com/open/api2/user/userReport"; | |
| 16 | 17 | |
| 17 | 18 | @implementation CNLiveFeedback |
| 18 | 19 | |
| 19 | 20 | - (void)feedbackWithAppId:(NSString *)appId appKey:(NSString *)appKey contentId:(NSString *)contentId message:(NSString *)message success:(void (^)(id))success failure:(void (^)(NSDictionary *))failure |
| 20 | 21 | { |
| 21 | - | |
| 22 | - NSDate *date = [NSDate date]; | |
| 23 | - NSInteger time = [date timeIntervalSince1970]; | |
| 24 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 25 | - | |
| 26 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 27 | - @"id":[CNLiveUserSystemTools verify:contentId], | |
| 28 | - @"msg":[CNLiveUserSystemTools verify:message], | |
| 29 | - @"clientPlat":@"i", | |
| 30 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 31 | - @"timestamp": timeString}; | |
| 32 | - | |
| 33 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 34 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 35 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 36 | - | |
| 37 | - [parameter setObject:signString forKey:@"sign"]; | |
| 38 | - [self requestWithParameter:parameter success:success failure:failure]; | |
| 22 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 39 | 23 | |
| 24 | + NSString *timeString = realTime; | |
| 25 | + | |
| 26 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 27 | + @"id":[CNLiveUserSystemTools verify:contentId], | |
| 28 | + @"msg":[CNLiveUserSystemTools verify:message], | |
| 29 | + @"clientPlat":@"i", | |
| 30 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 31 | + @"timestamp": timeString}; | |
| 32 | + | |
| 33 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 34 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 35 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 36 | + | |
| 37 | + [parameter setObject:signString forKey:@"sign"]; | |
| 38 | + [self requestWithParameter:parameter success:success failure:failure]; | |
| 39 | + }]; | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | #pragma mark - request |
| 43 | 43 | |
| 44 | 44 | - (void)requestWithParameter:(NSDictionary *)param success:(void(^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure |
| 45 | 45 | { |
| 46 | - [[CNLiveUserNetworkManager manager] requestPostURL:feedbackURL parameters:param success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) { | |
| 46 | + NSString *url; | |
| 47 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 48 | + url = feedbackTestURL; | |
| 49 | + } else { | |
| 50 | + url = feedbackFormalURL; | |
| 51 | + } | |
| 52 | + [[CNLiveUserNetworkManager manager] requestPostURL:url parameters:param success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) { | |
| 47 | 53 | |
| 48 | 54 | responseObject = [responseObject validatedDictionary]; |
| 49 | 55 | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveLogin.m
| ... | ... | @@ -12,49 +12,59 @@ |
| 12 | 12 | #import "NSDictionary+Safety.h" |
| 13 | 13 | |
| 14 | 14 | //快捷登录 |
| 15 | -static NSString *shortcutLoginURL = @"https://api.cnlive.com/open/api2/user/loginInQuickly"; | |
| 15 | +static NSString *shortcutLoginTestURL = @"http://test.open.cnlive.com/openapi/api2/user/loginInQuickly"; | |
| 16 | +static NSString *shortcutLoginFormalURL = @"https://api.cnlive.com/open/api2/user/loginInQuickly"; | |
| 16 | 17 | |
| 17 | 18 | //登录 |
| 18 | -static NSString *loginURL = @"https://api.cnlive.com/open/api2/user/loginIn"; | |
| 19 | +static NSString *loginTestURL = @"http://test.open.cnlive.com/openapi/api2/user/loginIn"; | |
| 20 | +static NSString *loginFormalURL = @"https://api.cnlive.com/open/api2/user/loginIn"; | |
| 19 | 21 | |
| 20 | 22 | //第三方登录 |
| 21 | -static NSString *thirdLoginURL = @"https://api.cnlive.com/open/api2/user/loginIn3rd"; | |
| 23 | +static NSString *thirdLoginTestURL = @"http://test.open.cnlive.com/openapi/api2/user/loginIn3rd"; | |
| 24 | +static NSString *thirdLoginFormalURL = @"https://api.cnlive.com/open/api2/user/loginIn3rd"; | |
| 25 | + | |
| 22 | 26 | |
| 23 | 27 | //验证第三方账号是否注册,若注册则登录返回用户信息,若未注册则errorCode |
| 24 | -static NSString *thirdCheckLoginURL = @"https://api.cnlive.com/open/api2/user/loginIn3rdHasMobile4server"; | |
| 28 | +static NSString *thirdCheckLoginTestURL = @"http://test.open.cnlive.com/openapi/api2/user/loginIn3rdHasMobile4server"; | |
| 29 | +static NSString *thirdCheckLoginFormalURL = @"https://api.cnlive.com/open/api2/user/loginIn3rdHasMobile4server"; | |
| 25 | 30 | |
| 26 | 31 | //第三方注册强制绑定手机号: 手机号+密码+验证码+三方账号 |
| 27 | -static NSString *thirdBindMobileLoginURL = @"https://api.cnlive.com/open/api2/user/loginIn3rdAndBindMobile4server"; | |
| 28 | - | |
| 32 | +static NSString *thirdBindMobileLoginTestURL = @"http://test.open.cnlive.com/openapi/api2/user/loginIn3rdAndBindMobile4server"; | |
| 33 | +static NSString *thirdBindMobileLoginFormalURL = @"https://api.cnlive.com/open/api2/user/loginIn3rdAndBindMobile4server"; | |
| 29 | 34 | |
| 30 | 35 | @implementation CNLiveLogin |
| 31 | 36 | |
| 32 | 37 | - (void)thirdPartyLoginWithAppId:(NSString *)appId appKey:(NSString *)appKey thirdPartyPlatType:(NSString *)plat thirdPartyId:(NSString *)thirdPartyId nickName:(NSString *)nickName gender:(NSString *)gender location:(NSString *)location faceUrl:(NSString *)faceUrl frmId:(NSString *)frmId success:(void (^)(id result))success failure:(void (^)(NSDictionary *))failure |
| 33 | 38 | { |
| 34 | - NSDate *date = [NSDate date]; | |
| 35 | - NSInteger time = [date timeIntervalSince1970]; | |
| 36 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 37 | - | |
| 38 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 39 | - @"thirdPartyPlat":[CNLiveUserSystemTools verify:plat], | |
| 40 | - @"thirdPartyId":[CNLiveUserSystemTools verify:thirdPartyId], | |
| 41 | - @"nickName":[CNLiveUserSystemTools verify:nickName], | |
| 42 | - @"gender":[CNLiveUserSystemTools verify:gender], | |
| 43 | - @"location":[CNLiveUserSystemTools verify:location], | |
| 44 | - @"faceUrl":[CNLiveUserSystemTools verify:faceUrl], | |
| 45 | - @"uuid":[CNLiveUserSystemTools uidForStat:[NSDate date]], | |
| 46 | - @"frmId":[CNLiveUserSystemTools verify:frmId], | |
| 47 | - @"clientPlat":@"i", | |
| 48 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 49 | - @"timestamp": timeString}; | |
| 50 | - | |
| 51 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 52 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 53 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 54 | - | |
| 55 | - [parameter setObject:signString forKey:@"sign"]; | |
| 56 | - [self requestWithURL:thirdLoginURL parameter:parameter success:success failure:failure]; | |
| 57 | - | |
| 39 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 40 | + NSString *timeString = realTime; | |
| 41 | + | |
| 42 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 43 | + @"thirdPartyPlat":[CNLiveUserSystemTools verify:plat], | |
| 44 | + @"thirdPartyId":[CNLiveUserSystemTools verify:thirdPartyId], | |
| 45 | + @"nickName":[CNLiveUserSystemTools verify:nickName], | |
| 46 | + @"gender":[CNLiveUserSystemTools verify:gender], | |
| 47 | + @"location":[CNLiveUserSystemTools verify:location], | |
| 48 | + @"faceUrl":[CNLiveUserSystemTools verify:faceUrl], | |
| 49 | + @"uuid":[CNLiveUserSystemTools uidForStat:realTime], | |
| 50 | + @"frmId":[CNLiveUserSystemTools verify:frmId], | |
| 51 | + @"clientPlat":@"i", | |
| 52 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 53 | + @"timestamp": timeString}; | |
| 54 | + | |
| 55 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 56 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 57 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 58 | + | |
| 59 | + [parameter setObject:signString forKey:@"sign"]; | |
| 60 | + NSString *url; | |
| 61 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 62 | + url = thirdLoginTestURL; | |
| 63 | + } else { | |
| 64 | + url = thirdLoginFormalURL; | |
| 65 | + } | |
| 66 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 67 | + }]; | |
| 58 | 68 | } |
| 59 | 69 | |
| 60 | 70 | /** |
| ... | ... | @@ -62,26 +72,32 @@ static NSString *thirdBindMobileLoginURL = @"https://api.cnlive.com/open/api2/u |
| 62 | 72 | */ |
| 63 | 73 | - (void)shortcutLoginWithAppId:(NSString *)appId appKey:(NSString *)appKey userName:(NSString *)userName verificationCode:(NSString *)verificationCode frmId:(NSString *)frmId success:(void (^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure |
| 64 | 74 | { |
| 65 | - NSDate *date = [NSDate date]; | |
| 66 | - NSInteger time = [date timeIntervalSince1970]; | |
| 67 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 68 | - | |
| 69 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 70 | - @"userName":[CNLiveUserSystemTools verify:userName], | |
| 71 | - @"verificationCode":[CNLiveUserSystemTools verify:verificationCode], | |
| 72 | - @"uuid":[CNLiveUserSystemTools uidForStat:[NSDate date]], | |
| 73 | - @"frmId":[CNLiveUserSystemTools verify:frmId], | |
| 74 | - @"clientPlat":@"i", | |
| 75 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 76 | - @"timestamp": timeString}; | |
| 77 | - | |
| 78 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 79 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 80 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 81 | - | |
| 82 | - [parameter setObject:signString forKey:@"sign"]; | |
| 83 | - [self requestWithURL:shortcutLoginURL parameter:parameter success:success failure:failure]; | |
| 84 | - | |
| 75 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 76 | + | |
| 77 | + NSString *timeString = realTime; | |
| 78 | + | |
| 79 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 80 | + @"userName":[CNLiveUserSystemTools verify:userName], | |
| 81 | + @"verificationCode":[CNLiveUserSystemTools verify:verificationCode], | |
| 82 | + @"uuid":[CNLiveUserSystemTools uidForStat:realTime], | |
| 83 | + @"frmId":[CNLiveUserSystemTools verify:frmId], | |
| 84 | + @"clientPlat":@"i", | |
| 85 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 86 | + @"timestamp": timeString}; | |
| 87 | + | |
| 88 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 89 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 90 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 91 | + | |
| 92 | + [parameter setObject:signString forKey:@"sign"]; | |
| 93 | + NSString *url; | |
| 94 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 95 | + url = shortcutLoginTestURL; | |
| 96 | + } else { | |
| 97 | + url = shortcutLoginFormalURL; | |
| 98 | + } | |
| 99 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 100 | + }]; | |
| 85 | 101 | } |
| 86 | 102 | |
| 87 | 103 | /** |
| ... | ... | @@ -89,25 +105,31 @@ static NSString *thirdBindMobileLoginURL = @"https://api.cnlive.com/open/api2/u |
| 89 | 105 | */ |
| 90 | 106 | - (void)loginWithAppId:(NSString *)appId appKey:(NSString *)appKey userName:(NSString *)userName password:(NSString *)password frmId:(NSString *)frmId success:(void (^)(id result))success failure:(void (^)(NSDictionary *))failure |
| 91 | 107 | { |
| 92 | - NSDate *date = [NSDate date]; | |
| 93 | - NSInteger time = [date timeIntervalSince1970]; | |
| 94 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 95 | - | |
| 96 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 97 | - @"userName":[CNLiveUserSystemTools verify:userName], | |
| 98 | - @"pwd":[CNLiveUserSystemTools verify:password], | |
| 99 | - @"uuid":[CNLiveUserSystemTools uidForStat:[NSDate date]], | |
| 100 | - @"frmId":[CNLiveUserSystemTools verify:frmId], | |
| 101 | - @"clientPlat":@"i", | |
| 102 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 103 | - @"timestamp": timeString}; | |
| 104 | - | |
| 105 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 106 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 107 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 108 | - | |
| 109 | - [parameter setObject:signString forKey:@"sign"]; | |
| 110 | - [self requestWithURL:loginURL parameter:parameter success:success failure:failure]; | |
| 108 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 109 | + NSString *timeString = realTime; | |
| 110 | + | |
| 111 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 112 | + @"userName":[CNLiveUserSystemTools verify:userName], | |
| 113 | + @"pwd":[CNLiveUserSystemTools verify:password], | |
| 114 | + @"uuid":[CNLiveUserSystemTools uidForStat:realTime], | |
| 115 | + @"frmId":[CNLiveUserSystemTools verify:frmId], | |
| 116 | + @"clientPlat":@"i", | |
| 117 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 118 | + @"timestamp": timeString}; | |
| 119 | + | |
| 120 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 121 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 122 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 123 | + | |
| 124 | + [parameter setObject:signString forKey:@"sign"]; | |
| 125 | + NSString *url; | |
| 126 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 127 | + url = loginTestURL; | |
| 128 | + } else { | |
| 129 | + url = loginFormalURL; | |
| 130 | + } | |
| 131 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 132 | + }]; | |
| 111 | 133 | } |
| 112 | 134 | |
| 113 | 135 | /** |
| ... | ... | @@ -115,20 +137,28 @@ static NSString *thirdBindMobileLoginURL = @"https://api.cnlive.com/open/api2/u |
| 115 | 137 | */ |
| 116 | 138 | - (void)thirdPartyCheckLoginWithAppId:(NSString *)appId appKey:(NSString *)appKey thirdPartyPlatType:(NSString *)plat thirdPartyId:(NSString *)thirdPartyId frmId:(NSString *)frmId success:(void (^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure |
| 117 | 139 | { |
| 118 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 119 | - @"thirdPartyPlat":[CNLiveUserSystemTools verify:plat], | |
| 120 | - @"thirdPartyId":[CNLiveUserSystemTools verify:thirdPartyId], | |
| 121 | - @"uuid":[CNLiveUserSystemTools uidForStat:[NSDate date]], | |
| 122 | - @"frmId":[CNLiveUserSystemTools verify:frmId], | |
| 123 | - @"clientPlat":@"i" | |
| 124 | - }; | |
| 125 | - | |
| 126 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 127 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 128 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 129 | - | |
| 130 | - [parameter setObject:signString forKey:@"sign"]; | |
| 131 | - [self requestWithURL:thirdCheckLoginURL parameter:parameter success:success failure:failure]; | |
| 140 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 141 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 142 | + @"thirdPartyPlat":[CNLiveUserSystemTools verify:plat], | |
| 143 | + @"thirdPartyId":[CNLiveUserSystemTools verify:thirdPartyId], | |
| 144 | + @"uuid":[CNLiveUserSystemTools uidForStat:realTime], | |
| 145 | + @"frmId":[CNLiveUserSystemTools verify:frmId], | |
| 146 | + @"clientPlat":@"i" | |
| 147 | + }; | |
| 148 | + | |
| 149 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 150 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 151 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 152 | + | |
| 153 | + [parameter setObject:signString forKey:@"sign"]; | |
| 154 | + NSString *url; | |
| 155 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 156 | + url = thirdCheckLoginTestURL; | |
| 157 | + } else { | |
| 158 | + url = thirdCheckLoginFormalURL; | |
| 159 | + } | |
| 160 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 161 | + }]; | |
| 132 | 162 | } |
| 133 | 163 | |
| 134 | 164 | /** |
| ... | ... | @@ -136,27 +166,35 @@ static NSString *thirdBindMobileLoginURL = @"https://api.cnlive.com/open/api2/u |
| 136 | 166 | */ |
| 137 | 167 | - (void)thirdPartyBindMobileLoginWithAppId:(NSString *)appId appKey:(NSString *)appKey thirdPartyPlatType:(NSString *)plat thirdPartyId:(NSString *)thirdPartyId nickName:(NSString *)nickName gender:(NSString *)gender location:(NSString *)location faceUrl:(NSString *)faceUrl mobile:(NSString *)mobile verificationCode:(NSString *)verificationCode pawd:(NSString *)pawd frmId:(NSString *)frmId success:(void (^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure |
| 138 | 168 | { |
| 139 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 140 | - @"thirdPartyPlat":[CNLiveUserSystemTools verify:plat], | |
| 141 | - @"thirdPartyId":[CNLiveUserSystemTools verify:thirdPartyId], | |
| 142 | - @"nickName":[CNLiveUserSystemTools verify:nickName], | |
| 143 | - @"gender":[CNLiveUserSystemTools verify:gender], | |
| 144 | - @"location":[CNLiveUserSystemTools verify:location], | |
| 145 | - @"faceUrl":[CNLiveUserSystemTools verify:faceUrl], | |
| 146 | - @"uuid":[CNLiveUserSystemTools uidForStat:[NSDate date]], | |
| 147 | -// @"frmId":[CNLiveUserSystemTools verify:frmId], | |
| 148 | - @"mobile":[CNLiveUserSystemTools verify:mobile], | |
| 149 | - @"verificationCode":[CNLiveUserSystemTools verify:verificationCode], | |
| 150 | - @"pawd":[CNLiveUserSystemTools verify:pawd], | |
| 151 | - @"clientPlat":@"i" | |
| 152 | - }; | |
| 153 | - | |
| 154 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 155 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 156 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 157 | - | |
| 158 | - [parameter setObject:signString forKey:@"sign"]; | |
| 159 | - [self requestWithURL:thirdBindMobileLoginURL parameter:parameter success:success failure:failure]; | |
| 169 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 170 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 171 | + @"thirdPartyPlat":[CNLiveUserSystemTools verify:plat], | |
| 172 | + @"thirdPartyId":[CNLiveUserSystemTools verify:thirdPartyId], | |
| 173 | + @"nickName":[CNLiveUserSystemTools verify:nickName], | |
| 174 | + @"gender":[CNLiveUserSystemTools verify:gender], | |
| 175 | + @"location":[CNLiveUserSystemTools verify:location], | |
| 176 | + @"faceUrl":[CNLiveUserSystemTools verify:faceUrl], | |
| 177 | + @"uuid":[CNLiveUserSystemTools uidForStat:realTime], | |
| 178 | + // @"frmId":[CNLiveUserSystemTools verify:frmId], | |
| 179 | + @"mobile":[CNLiveUserSystemTools verify:mobile], | |
| 180 | + @"verificationCode":[CNLiveUserSystemTools verify:verificationCode], | |
| 181 | + @"pawd":[CNLiveUserSystemTools verify:pawd], | |
| 182 | + @"clientPlat":@"i" | |
| 183 | + }; | |
| 184 | + | |
| 185 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 186 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 187 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 188 | + | |
| 189 | + [parameter setObject:signString forKey:@"sign"]; | |
| 190 | + NSString *url; | |
| 191 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 192 | + url = thirdBindMobileLoginTestURL; | |
| 193 | + } else { | |
| 194 | + url = thirdBindMobileLoginFormalURL; | |
| 195 | + } | |
| 196 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 197 | + }]; | |
| 160 | 198 | } |
| 161 | 199 | |
| 162 | 200 | #pragma mark - request |
| ... | ... | @@ -190,7 +228,6 @@ static NSString *thirdBindMobileLoginURL = @"https://api.cnlive.com/open/api2/u |
| 190 | 228 | } failure:^(NSURLResponse * _Nullable response, NSError * _Nullable error) { |
| 191 | 229 | |
| 192 | 230 | NSDictionary *errorDic = @{@"errorCode": [NSString stringWithFormat:@"%ld", error.code], @"errorMessage": error.localizedDescription}; |
| 193 | - | |
| 194 | 231 | if (failure) { |
| 195 | 232 | failure(errorDic); |
| 196 | 233 | } | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveRegister.m
| ... | ... | @@ -12,42 +12,47 @@ |
| 12 | 12 | #import "NSDictionary+Safety.h" |
| 13 | 13 | |
| 14 | 14 | //注册 |
| 15 | -static NSString *registerURL = @"https://api.cnlive.com/open/api2/user/register"; | |
| 15 | +static NSString *registerTestURL = @"http://test.open.cnlive.com/openapi/api2/user/register"; | |
| 16 | +static NSString *registerFormalURL = @"https://api.cnlive.com/open/api2/user/register"; | |
| 16 | 17 | |
| 17 | 18 | @implementation CNLiveRegister |
| 18 | 19 | |
| 19 | 20 | - (void)registerWithAppId:(NSString *)appId appKey:(NSString *)appKey userName:(NSString *)userName password:(NSString *)password verificationCode:(NSString *)verificationCode invitationCode:(NSString *)invitationCode frmId:(NSString *)frmId success:(void (^)(id result))success failure:(void (^)(NSDictionary *))failure |
| 20 | 21 | { |
| 21 | - | |
| 22 | - NSDate *date = [NSDate date]; | |
| 23 | - NSInteger time = [date timeIntervalSince1970]; | |
| 24 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 25 | - | |
| 26 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 27 | - @"userName":[CNLiveUserSystemTools verify:userName], | |
| 28 | - @"pwd":[CNLiveUserSystemTools verify:password], | |
| 29 | - @"verificationCode":[CNLiveUserSystemTools verify:verificationCode], | |
| 30 | - @"invitationCode":[CNLiveUserSystemTools verify:invitationCode], | |
| 31 | - @"uuid":[CNLiveUserSystemTools uidForStat:[NSDate date]], | |
| 32 | - @"frmId":[CNLiveUserSystemTools verify:frmId], | |
| 33 | - @"clientPlat":@"i", | |
| 34 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 35 | - @"timestamp": timeString}; | |
| 36 | - | |
| 37 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 38 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 39 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 40 | - | |
| 41 | - [parameter setObject:signString forKey:@"sign"]; | |
| 42 | - [self requestWithParameter:parameter success:success failure:failure]; | |
| 22 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 23 | + NSString *timeString = realTime; | |
| 24 | + | |
| 25 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 26 | + @"userName":[CNLiveUserSystemTools verify:userName], | |
| 27 | + @"pwd":[CNLiveUserSystemTools verify:password], | |
| 28 | + @"verificationCode":[CNLiveUserSystemTools verify:verificationCode], | |
| 29 | + @"invitationCode":[CNLiveUserSystemTools verify:invitationCode], | |
| 30 | + @"uuid":[CNLiveUserSystemTools uidForStat:realTime], | |
| 31 | + @"frmId":[CNLiveUserSystemTools verify:frmId], | |
| 32 | + @"clientPlat":@"i", | |
| 33 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 34 | + @"timestamp": timeString}; | |
| 35 | + | |
| 36 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 37 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 38 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 39 | + | |
| 40 | + [parameter setObject:signString forKey:@"sign"]; | |
| 41 | + [self requestWithParameter:parameter success:success failure:failure]; | |
| 42 | + }]; | |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | #pragma mark - request |
| 46 | 46 | |
| 47 | 47 | - (void)requestWithParameter:(NSDictionary *)param success:(void(^)(id result))success failure :(void (^)(NSDictionary *errorDic))failure |
| 48 | 48 | { |
| 49 | - | |
| 50 | - [[CNLiveUserNetworkManager manager] requestPostURL:registerURL parameters:param success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) { | |
| 49 | + NSString *url; | |
| 50 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 51 | + url = registerTestURL; | |
| 52 | + } else { | |
| 53 | + url = registerFormalURL; | |
| 54 | + } | |
| 55 | + [[CNLiveUserNetworkManager manager] requestPostURL:url parameters:param success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) { | |
| 51 | 56 | |
| 52 | 57 | responseObject = [responseObject validatedDictionary]; |
| 53 | 58 | |
| ... | ... | @@ -74,7 +79,7 @@ static NSString *registerURL = @"https://api.cnlive.com/open/api2/user/register |
| 74 | 79 | |
| 75 | 80 | } failure:^(NSURLResponse * _Nullable response, NSError * _Nullable error) { |
| 76 | 81 | |
| 77 | - NSDictionary *errorDic = @{@"errorCode": [NSString stringWithFormat:@"%ld", error.code], @"errorMessage": error.localizedDescription}; | |
| 82 | + NSDictionary *errorDic = @{@"errorCode": [NSString stringWithFormat:@"%ld", (long)error.code], @"errorMessage": error.localizedDescription}; | |
| 78 | 83 | |
| 79 | 84 | if (failure) { |
| 80 | 85 | failure(errorDic); | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUploadIcon.m
| ... | ... | @@ -12,10 +12,12 @@ |
| 12 | 12 | #import "NSDictionary+Safety.h" |
| 13 | 13 | |
| 14 | 14 | //获取access_token |
| 15 | -static NSString *accessTokenURL = @"https://api.cnlive.com/open/api2/token"; | |
| 15 | +static NSString *accessTokenTestURL = @"http://test.open.cnlive.com/openapi/api2/token"; | |
| 16 | +static NSString *accessTokenFormalURL = @"https://api.cnlive.com/open/api2/token"; | |
| 16 | 17 | |
| 17 | 18 | //上传头像 |
| 18 | -static NSString *uploadIconURL = @"https://api.cnlive.com/open/api2/user/updateUserFaceById"; | |
| 19 | +static NSString *uploadIconTestURL = @"http://test.open.cnlive.com/openapi/api2/user/updateUserFaceById"; | |
| 20 | +static NSString *uploadIconFormalURL = @"https://api.cnlive.com/open/api2/user/updateUserFaceById"; | |
| 19 | 21 | |
| 20 | 22 | @implementation CNLiveUploadIcon |
| 21 | 23 | |
| ... | ... | @@ -31,7 +33,13 @@ static NSString *uploadIconURL = @"https://api.cnlive.com/open/api2/user/update |
| 31 | 33 | NSDictionary *paramters = @{@"appId":[CNLiveUserSystemTools verify:appId], |
| 32 | 34 | @"secret":[CNLiveUserSystemTools verify:secret]}; |
| 33 | 35 | |
| 34 | - [[CNLiveUserNetworkManager manager] requestPostURL:accessTokenURL parameters:paramters success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) { | |
| 36 | + NSString *url; | |
| 37 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 38 | + url = accessTokenTestURL; | |
| 39 | + } else { | |
| 40 | + url = accessTokenFormalURL; | |
| 41 | + } | |
| 42 | + [[CNLiveUserNetworkManager manager] requestPostURL:url parameters:paramters success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) { | |
| 35 | 43 | |
| 36 | 44 | responseObject = [responseObject validatedDictionary]; |
| 37 | 45 | |
| ... | ... | @@ -73,7 +81,13 @@ static NSString *uploadIconURL = @"https://api.cnlive.com/open/api2/user/update |
| 73 | 81 | @"token":[CNLiveUserSystemTools verify:token], |
| 74 | 82 | @"access_token":[CNLiveUserSystemTools verify:accessToken]}; |
| 75 | 83 | |
| 76 | - [[CNLiveUserNetworkManager manager] uploadImageWithURL:uploadIconURL parameters:paramters imageData:data success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) { | |
| 84 | + NSString *url; | |
| 85 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 86 | + url = uploadIconTestURL; | |
| 87 | + } else { | |
| 88 | + url = uploadIconFormalURL; | |
| 89 | + } | |
| 90 | + [[CNLiveUserNetworkManager manager] uploadImageWithURL:url parameters:paramters imageData:data success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) { | |
| 77 | 91 | |
| 78 | 92 | responseObject = [responseObject validatedDictionary]; |
| 79 | 93 | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUserInfo.m
| ... | ... | @@ -12,28 +12,36 @@ |
| 12 | 12 | #import "NSDictionary+Safety.h" |
| 13 | 13 | |
| 14 | 14 | //更新手机号 |
| 15 | -static NSString *updateMobileURL = @"https://api.cnlive.com/open/api2/user/updateMobileById"; | |
| 15 | +static NSString *updateMobileTestURL = @"http://test.open.cnlive.com/openapi/api2/user/updateMobileById"; | |
| 16 | +static NSString *updateMobileFormalURL = @"https://api.cnlive.com/open/api2/user/updateMobileById"; | |
| 16 | 17 | |
| 17 | 18 | //查询用户信息 |
| 18 | -static NSString *queryUserInfoURL = @"https://api.cnlive.com/open/api2/user/readUserById"; | |
| 19 | +static NSString *queryUserInfoTestURL = @"http://test.open.cnlive.com/openapi/api2/user/readUserById"; | |
| 20 | +static NSString *queryUserInfoFormalURL = @"https://api.cnlive.com/open/api2/user/readUserById"; | |
| 19 | 21 | |
| 20 | 22 | //查询多条用户信息 |
| 21 | -static NSString *queryMoreUserInfoURL = @"https://api.cnlive.com/open/api2/user/readUsersById4server"; | |
| 23 | +static NSString *queryMoreUserInfoTestURL = @"http://test.open.cnlive.com/openapi/api2/user/readUsersById4server"; | |
| 24 | +static NSString *queryMoreUserInfoFormalURL = @"https://api.cnlive.com/open/api2/user/readUsersById4server"; | |
| 22 | 25 | |
| 23 | 26 | //修改用户单项信息 |
| 24 | -static NSString *updateUserByIdURL = @"https://api.cnlive.com/open/api2/user/updateUserById"; | |
| 27 | +static NSString *updateUserByIdTestURL = @"http://test.open.cnlive.com/openapi/api2/user/updateUserById"; | |
| 28 | +static NSString *updateUserByIdFormalURL = @"https://api.cnlive.com/open/api2/user/updateUserById"; | |
| 25 | 29 | |
| 26 | 30 | //更新用户附加信息 |
| 27 | -static NSString *updateOtherInfoURL = @"https://api.cnlive.com/open/api2/user/updateUserExtInfo"; | |
| 31 | +static NSString *updateOtherInfoTestURL = @"http://test.open.cnlive.com/openapi/api2/user/updateUserExtInfo"; | |
| 32 | +static NSString *updateOtherInfoFormalURL = @"https://api.cnlive.com/open/api2/user/updateUserExtInfo"; | |
| 28 | 33 | |
| 29 | 34 | //修改密码 |
| 30 | -static NSString *updatePwdURL = @"https://api.cnlive.com/open/api2/user/updatePwdByMobile"; | |
| 35 | +static NSString *updatePwdTestURL = @"http://test.open.cnlive.com/openapi/api2/user/updatePwdByMobile"; | |
| 36 | +static NSString *updatePwdFormalURL = @"https://api.cnlive.com/open/api2/user/updatePwdByMobile"; | |
| 31 | 37 | |
| 32 | 38 | //绑定第三方账号 |
| 33 | -static NSString *BindingThirdURL = @"https://api.cnlive.com/open/api2/user/bind3rd"; | |
| 39 | +static NSString *BindingThirdTestURL = @"http://test.open.cnlive.com/openapi/api2/user/bind3rd"; | |
| 40 | +static NSString *BindingThirdFormalURL = @"https://api.cnlive.com/open/api2/user/bind3rd"; | |
| 34 | 41 | |
| 35 | 42 | //通过原密码修改密码 |
| 36 | -static NSString *oldPwdUpdatePwdURL = @"https://api.cnlive.com/open/api2/user/updatePwd"; | |
| 43 | +static NSString *oldPwdUpdatePwdTestURL = @"http://test.open.cnlive.com/openapi/api2/user/updatePwd"; | |
| 44 | +static NSString *oldPwdUpdatePwdFormalURL = @"https://api.cnlive.com/open/api2/user/updatePwd"; | |
| 37 | 45 | |
| 38 | 46 | @implementation CNLiveUserInfo |
| 39 | 47 | |
| ... | ... | @@ -42,26 +50,32 @@ static NSString *oldPwdUpdatePwdURL = @"https://api.cnlive.com/open/api2/ |
| 42 | 50 | */ |
| 43 | 51 | - (void)updateMobileWithAppId:(NSString *)appId appKey:(NSString *)appKey uid:(NSString *)uid mobile:(NSString *)mobile verificationCode:(NSString *)verificationCode token:(NSString *)token success:(void (^)(id result))success failure:(void (^)(NSDictionary *))failure |
| 44 | 52 | { |
| 45 | - NSDate *date = [NSDate date]; | |
| 46 | - NSInteger time = [date timeIntervalSince1970]; | |
| 47 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 48 | - | |
| 49 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 50 | - @"uid":[CNLiveUserSystemTools verify:uid], | |
| 51 | - @"mobile":[CNLiveUserSystemTools verify:mobile], | |
| 52 | - @"verificationCode":[CNLiveUserSystemTools verify:verificationCode], | |
| 53 | - @"clientPlat":@"i", | |
| 54 | - @"token":[CNLiveUserSystemTools verify:token], | |
| 55 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 56 | - @"timestamp": timeString}; | |
| 57 | - | |
| 58 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 59 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 60 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 61 | - | |
| 62 | - [parameter setObject:signString forKey:@"sign"]; | |
| 63 | - [self requestWithURL:updateMobileURL parameter:parameter success:success failure:failure]; | |
| 53 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 64 | 54 | |
| 55 | + NSString *timeString = realTime; | |
| 56 | + | |
| 57 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 58 | + @"uid":[CNLiveUserSystemTools verify:uid], | |
| 59 | + @"mobile":[CNLiveUserSystemTools verify:mobile], | |
| 60 | + @"verificationCode":[CNLiveUserSystemTools verify:verificationCode], | |
| 61 | + @"clientPlat":@"i", | |
| 62 | + @"token":[CNLiveUserSystemTools verify:token], | |
| 63 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 64 | + @"timestamp": timeString}; | |
| 65 | + | |
| 66 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 67 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 68 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 69 | + | |
| 70 | + [parameter setObject:signString forKey:@"sign"]; | |
| 71 | + NSString *url; | |
| 72 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 73 | + url = updateMobileTestURL; | |
| 74 | + } else { | |
| 75 | + url = updateMobileFormalURL; | |
| 76 | + } | |
| 77 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 78 | + }]; | |
| 65 | 79 | } |
| 66 | 80 | |
| 67 | 81 | /** |
| ... | ... | @@ -69,25 +83,31 @@ static NSString *oldPwdUpdatePwdURL = @"https://api.cnlive.com/open/api2/ |
| 69 | 83 | */ |
| 70 | 84 | - (void)bindingThirdPartyWithAppId:(NSString *)appId appKey:(NSString *)appKey uid:(NSString *)uid thirdPartyPlatType:(NSString *)plat thirdPartyId:(NSString *)thirdPartyId token:(NSString *)token success:(void (^)(id))success failure:(void (^)(NSDictionary *))failure |
| 71 | 85 | { |
| 72 | - NSDate *date = [NSDate date]; | |
| 73 | - NSInteger time = [date timeIntervalSince1970]; | |
| 74 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 75 | - | |
| 76 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 77 | - @"uid":[CNLiveUserSystemTools verify:uid], | |
| 78 | - @"thirdPartyPlat":[CNLiveUserSystemTools verify:plat], | |
| 79 | - @"thirdPartyId":[CNLiveUserSystemTools verify:thirdPartyId], | |
| 80 | - @"token":[CNLiveUserSystemTools verify:token], | |
| 81 | - @"clientPlat":@"i", | |
| 82 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 83 | - @"timestamp": timeString}; | |
| 84 | - | |
| 85 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 86 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 87 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 88 | - | |
| 89 | - [parameter setObject:signString forKey:@"sign"]; | |
| 90 | - [self requestWithURL:BindingThirdURL parameter:parameter success:success failure:failure]; | |
| 86 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 87 | + NSString *timeString = realTime; | |
| 88 | + | |
| 89 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 90 | + @"uid":[CNLiveUserSystemTools verify:uid], | |
| 91 | + @"thirdPartyPlat":[CNLiveUserSystemTools verify:plat], | |
| 92 | + @"thirdPartyId":[CNLiveUserSystemTools verify:thirdPartyId], | |
| 93 | + @"token":[CNLiveUserSystemTools verify:token], | |
| 94 | + @"clientPlat":@"i", | |
| 95 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 96 | + @"timestamp": timeString}; | |
| 97 | + | |
| 98 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 99 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 100 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 101 | + | |
| 102 | + [parameter setObject:signString forKey:@"sign"]; | |
| 103 | + NSString *url; | |
| 104 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 105 | + url = BindingThirdTestURL; | |
| 106 | + } else { | |
| 107 | + url = BindingThirdFormalURL; | |
| 108 | + } | |
| 109 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 110 | + }]; | |
| 91 | 111 | } |
| 92 | 112 | |
| 93 | 113 | /** |
| ... | ... | @@ -95,25 +115,30 @@ static NSString *oldPwdUpdatePwdURL = @"https://api.cnlive.com/open/api2/ |
| 95 | 115 | */ |
| 96 | 116 | - (void)queryUserInfoWithAppId:(NSString *)appId appKey:(NSString *)appKey uid:(NSString *)uid srcUid:(NSString *)srcUid token:(NSString *)token success:(void (^)(id result))success failure:(void (^)(NSDictionary *))failure |
| 97 | 117 | { |
| 98 | - NSDate *date = [NSDate date]; | |
| 99 | - NSInteger time = [date timeIntervalSince1970]; | |
| 100 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 101 | - | |
| 102 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 103 | - @"uid":[CNLiveUserSystemTools verify:uid], | |
| 104 | - @"srcUid":[CNLiveUserSystemTools verify:srcUid], | |
| 105 | - @"clientPlat":@"i", | |
| 106 | - @"token":[CNLiveUserSystemTools verify:token], | |
| 107 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 108 | - @"timestamp": timeString}; | |
| 118 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 119 | + NSString *timeString = realTime; | |
| 109 | 120 | |
| 110 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 111 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 112 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 113 | - | |
| 114 | - [parameter setObject:signString forKey:@"sign"]; | |
| 115 | - [self requestWithURL:queryUserInfoURL parameter:parameter success:success failure:failure]; | |
| 116 | - | |
| 121 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 122 | + @"uid":[CNLiveUserSystemTools verify:uid], | |
| 123 | + @"srcUid":[CNLiveUserSystemTools verify:srcUid], | |
| 124 | + @"clientPlat":@"i", | |
| 125 | + @"token":[CNLiveUserSystemTools verify:token], | |
| 126 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 127 | + @"timestamp": timeString}; | |
| 128 | + | |
| 129 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 130 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 131 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 132 | + | |
| 133 | + [parameter setObject:signString forKey:@"sign"]; | |
| 134 | + NSString *url; | |
| 135 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 136 | + url = queryUserInfoTestURL; | |
| 137 | + } else { | |
| 138 | + url = queryUserInfoFormalURL; | |
| 139 | + } | |
| 140 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 141 | + }]; | |
| 117 | 142 | } |
| 118 | 143 | |
| 119 | 144 | /** |
| ... | ... | @@ -121,26 +146,32 @@ static NSString *oldPwdUpdatePwdURL = @"https://api.cnlive.com/open/api2/ |
| 121 | 146 | */ |
| 122 | 147 | - (void)queryMoreUserInfoWithAppId:(NSString *)appId appKey:(NSString *)appKey uid:(NSString *)uid srcUids:(NSArray *)srcUids token:(NSString *)token success:(void (^)(id))success failure:(void (^)(NSDictionary *))failure |
| 123 | 148 | { |
| 124 | - NSDate *date = [NSDate date]; | |
| 125 | - NSInteger time = [date timeIntervalSince1970]; | |
| 126 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 127 | - | |
| 128 | - NSString *uids = [srcUids componentsJoinedByString:@","]; | |
| 129 | - | |
| 130 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 131 | - @"uid":[CNLiveUserSystemTools verify:uid], | |
| 132 | - @"srcUids":[CNLiveUserSystemTools verify:uids], | |
| 133 | - @"clientPlat":@"i", | |
| 134 | - @"token":[CNLiveUserSystemTools verify:token], | |
| 135 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 136 | - @"timestamp": timeString}; | |
| 137 | - | |
| 138 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 139 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 140 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 141 | - | |
| 142 | - [parameter setObject:signString forKey:@"sign"]; | |
| 143 | - [self requestWithURL:queryMoreUserInfoURL parameter:parameter success:success failure:failure]; | |
| 149 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 150 | + NSString *timeString = realTime; | |
| 151 | + | |
| 152 | + NSString *uids = [srcUids componentsJoinedByString:@","]; | |
| 153 | + | |
| 154 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 155 | + @"uid":[CNLiveUserSystemTools verify:uid], | |
| 156 | + @"srcUids":[CNLiveUserSystemTools verify:uids], | |
| 157 | + @"clientPlat":@"i", | |
| 158 | + @"token":[CNLiveUserSystemTools verify:token], | |
| 159 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 160 | + @"timestamp": timeString}; | |
| 161 | + | |
| 162 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 163 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 164 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 165 | + | |
| 166 | + [parameter setObject:signString forKey:@"sign"]; | |
| 167 | + NSString *url; | |
| 168 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 169 | + url = queryMoreUserInfoTestURL; | |
| 170 | + } else { | |
| 171 | + url = queryMoreUserInfoFormalURL; | |
| 172 | + } | |
| 173 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 174 | + }]; | |
| 144 | 175 | } |
| 145 | 176 | |
| 146 | 177 | /** |
| ... | ... | @@ -148,27 +179,31 @@ static NSString *oldPwdUpdatePwdURL = @"https://api.cnlive.com/open/api2/ |
| 148 | 179 | */ |
| 149 | 180 | - (void)modifyUserInfoWithAppId:(NSString *)appId appKey:(NSString *)appKey type:(UserInfoType)type uid:(NSString *)uid modifyInfo:(NSString *)info token:(NSString *)token success:(void (^)(id result))success failure :(void (^)(NSDictionary *error))failure |
| 150 | 181 | { |
| 151 | - | |
| 152 | - NSDate *date = [NSDate date]; | |
| 153 | - NSInteger time = [date timeIntervalSince1970]; | |
| 154 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 155 | - | |
| 156 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 157 | - @"uid":[CNLiveUserSystemTools verify:uid], | |
| 158 | - @"type":[self updateType:type], | |
| 159 | - @"value":[CNLiveUserSystemTools verify:info], | |
| 160 | - @"clientPlat":@"i", | |
| 161 | - @"token":[CNLiveUserSystemTools verify:token], | |
| 162 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 163 | - @"timestamp": timeString}; | |
| 164 | - | |
| 165 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 166 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 167 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 168 | - | |
| 169 | - [parameter setObject:signString forKey:@"sign"]; | |
| 170 | - [self requestWithURL:updateUserByIdURL parameter:parameter success:success failure:failure]; | |
| 171 | - | |
| 182 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 183 | + NSString *timeString = realTime; | |
| 184 | + | |
| 185 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 186 | + @"uid":[CNLiveUserSystemTools verify:uid], | |
| 187 | + @"type":[self updateType:type], | |
| 188 | + @"value":[CNLiveUserSystemTools verify:info], | |
| 189 | + @"clientPlat":@"i", | |
| 190 | + @"token":[CNLiveUserSystemTools verify:token], | |
| 191 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 192 | + @"timestamp": timeString}; | |
| 193 | + | |
| 194 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 195 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 196 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 197 | + | |
| 198 | + [parameter setObject:signString forKey:@"sign"]; | |
| 199 | + NSString *url; | |
| 200 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 201 | + url = updateUserByIdTestURL; | |
| 202 | + } else { | |
| 203 | + url = updateUserByIdFormalURL; | |
| 204 | + } | |
| 205 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 206 | + }]; | |
| 172 | 207 | } |
| 173 | 208 | |
| 174 | 209 | /** |
| ... | ... | @@ -176,24 +211,30 @@ static NSString *oldPwdUpdatePwdURL = @"https://api.cnlive.com/open/api2/ |
| 176 | 211 | */ |
| 177 | 212 | - (void)updateOtherInfoWithAppId:(NSString *)appId appKey:(NSString *)appKey uid:(NSString *)uid extInfo:(NSString *)extInfo token:(NSString *)token success:(void (^)(id result))success failure:(void (^)(NSDictionary *))failure |
| 178 | 213 | { |
| 179 | - NSDate *date = [NSDate date]; | |
| 180 | - NSInteger time = [date timeIntervalSince1970]; | |
| 181 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 182 | - | |
| 183 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 184 | - @"token":[CNLiveUserSystemTools verify:token], | |
| 185 | - @"uid":[CNLiveUserSystemTools verify:uid], | |
| 186 | - @"extInfo":[CNLiveUserSystemTools verify:extInfo], | |
| 187 | - @"clientPlat":@"i", | |
| 188 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 189 | - @"timestamp": timeString}; | |
| 190 | - | |
| 191 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 192 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 193 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 194 | - | |
| 195 | - [parameter setObject:signString forKey:@"sign"]; | |
| 196 | - [self requestWithURL:updateOtherInfoURL parameter:parameter success:success failure:failure]; | |
| 214 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 215 | + NSString *timeString = realTime; | |
| 216 | + | |
| 217 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 218 | + @"token":[CNLiveUserSystemTools verify:token], | |
| 219 | + @"uid":[CNLiveUserSystemTools verify:uid], | |
| 220 | + @"extInfo":[CNLiveUserSystemTools verify:extInfo], | |
| 221 | + @"clientPlat":@"i", | |
| 222 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 223 | + @"timestamp": timeString}; | |
| 224 | + | |
| 225 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 226 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 227 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 228 | + | |
| 229 | + [parameter setObject:signString forKey:@"sign"]; | |
| 230 | + NSString *url; | |
| 231 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 232 | + url = updateOtherInfoTestURL; | |
| 233 | + } else { | |
| 234 | + url = updateOtherInfoFormalURL; | |
| 235 | + } | |
| 236 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 237 | + }]; | |
| 197 | 238 | } |
| 198 | 239 | |
| 199 | 240 | /** |
| ... | ... | @@ -201,25 +242,30 @@ static NSString *oldPwdUpdatePwdURL = @"https://api.cnlive.com/open/api2/ |
| 201 | 242 | */ |
| 202 | 243 | - (void)changePasswordWithAppId:(NSString *)appId appKey:(NSString *)appKey mobile:(NSString *)mobile verificationCode:(NSString *)verificationCode newPassword:(NSString *)newPassword success:(void (^)(id result))success failure:(void (^)(NSDictionary *))failure |
| 203 | 244 | { |
| 204 | - NSDate *date = [NSDate date]; | |
| 205 | - NSInteger time = [date timeIntervalSince1970]; | |
| 206 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 207 | - | |
| 208 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 209 | - @"mobile":[CNLiveUserSystemTools verify:mobile], | |
| 210 | - @"verificationCode":[CNLiveUserSystemTools verify:verificationCode], | |
| 211 | - @"newPwd":[CNLiveUserSystemTools verify:newPassword], | |
| 212 | - @"clientPlat":@"i", | |
| 213 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 214 | - @"timestamp": timeString}; | |
| 215 | - | |
| 216 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 217 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 218 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 219 | - | |
| 220 | - [parameter setObject:signString forKey:@"sign"]; | |
| 221 | - [self requestWithURL:updatePwdURL parameter:parameter success:success failure:failure]; | |
| 222 | - | |
| 245 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 246 | + NSString *timeString = realTime; | |
| 247 | + | |
| 248 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 249 | + @"mobile":[CNLiveUserSystemTools verify:mobile], | |
| 250 | + @"verificationCode":[CNLiveUserSystemTools verify:verificationCode], | |
| 251 | + @"newPwd":[CNLiveUserSystemTools verify:newPassword], | |
| 252 | + @"clientPlat":@"i", | |
| 253 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 254 | + @"timestamp": timeString}; | |
| 255 | + | |
| 256 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 257 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 258 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 259 | + | |
| 260 | + [parameter setObject:signString forKey:@"sign"]; | |
| 261 | + NSString *url; | |
| 262 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 263 | + url = updatePwdTestURL; | |
| 264 | + } else { | |
| 265 | + url = updatePwdFormalURL; | |
| 266 | + } | |
| 267 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 268 | + }]; | |
| 223 | 269 | } |
| 224 | 270 | |
| 225 | 271 | /** |
| ... | ... | @@ -241,7 +287,13 @@ static NSString *oldPwdUpdatePwdURL = @"https://api.cnlive.com/open/api2/ |
| 241 | 287 | NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; |
| 242 | 288 | |
| 243 | 289 | [parameter setObject:signString forKey:@"sign"]; |
| 244 | - [self requestWithURL:oldPwdUpdatePwdURL parameter:parameter success:success failure:failure]; | |
| 290 | + NSString *url; | |
| 291 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 292 | + url = oldPwdUpdatePwdTestURL; | |
| 293 | + } else { | |
| 294 | + url = oldPwdUpdatePwdFormalURL; | |
| 295 | + } | |
| 296 | + [self requestWithURL:url parameter:parameter success:success failure:failure]; | |
| 245 | 297 | } |
| 246 | 298 | |
| 247 | 299 | #pragma mark - request | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUserManager.h
| ... | ... | @@ -14,6 +14,7 @@ |
| 14 | 14 | @property (nonatomic, strong) NSString *appId; |
| 15 | 15 | @property (nonatomic, strong) NSString *appKey; |
| 16 | 16 | @property (nonatomic, strong) NSString *appSecret; |
| 17 | +@property (nonatomic ,assign) BOOL isTestEnvironment; | |
| 17 | 18 | |
| 18 | 19 | + (CNLiveUserManager *)manager; |
| 19 | 20 | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUserManager.m
| ... | ... | @@ -39,29 +39,34 @@ |
| 39 | 39 | |
| 40 | 40 | - (void)startUserStat |
| 41 | 41 | { |
| 42 | - NSDate *date = [NSDate date]; | |
| 43 | - _startDate = date; | |
| 44 | - | |
| 45 | - NSString *stamp = [NSString stringWithFormat:@"%.3f", [date timeIntervalSince1970]]; | |
| 46 | - stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; | |
| 42 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 43 | + | |
| 44 | + _startDate = netDate; | |
| 45 | + | |
| 46 | + NSString *stamp = realTime; | |
| 47 | + stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; | |
| 48 | + | |
| 49 | + NSString *vvUrl = [NSString stringWithFormat:@"http://app.sta.cnlive.com/app.js?sver=%@&uid=%@&tm=%@&from=&spid=&appid=%@&version=1005_%@&eventid=1300&uri=&sid=&plat=i_%@&objid=",kSVer,[CNLiveUserSystemTools uidForStat:realTime],stamp,self.appId,SDKVersion, StatAppVersion]; | |
| 50 | + | |
| 51 | + [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil]; | |
| 47 | 52 | |
| 48 | - NSString *vvUrl = [NSString stringWithFormat:@"http://app.sta.cnlive.com/app.js?sver=%@&uid=%@&tm=%@&from=&spid=&appid=%@&version=1005_%@&eventid=1300&uri=&sid=&plat=i_%@&objid=",kSVer,[CNLiveUserSystemTools uidForStat:date],stamp,self.appId,SDKVersion, StatAppVersion]; | |
| 49 | - | |
| 50 | - [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil]; | |
| 53 | + }]; | |
| 51 | 54 | } |
| 52 | 55 | |
| 53 | 56 | - (void)endUserStat |
| 54 | 57 | { |
| 55 | - NSDate *date = [NSDate date]; | |
| 56 | - NSString *stamp = [NSString stringWithFormat:@"%.3f", [date timeIntervalSince1970]]; | |
| 57 | - stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; | |
| 58 | - | |
| 59 | - NSString *endDate = [NSString stringWithFormat:@"%.3f",[date timeIntervalSinceDate:_startDate]]; | |
| 60 | - endDate = [endDate stringByReplacingOccurrencesOfString:@"." withString:@""]; | |
| 61 | - | |
| 62 | - NSString *vvUrl = [NSString stringWithFormat:@"http://app.sta.cnlive.com/app.js?sver=%@&uid=%@&tm=%@&from=&spid=&appid=%@&version=1005_%@&eventid=1311&uri=%@&sid=&plat=i_%@&objid=",kSVer,[CNLiveUserSystemTools uidForStat:date],stamp,self.appId,SDKVersion,endDate,StatAppVersion]; | |
| 63 | - | |
| 64 | - [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil]; | |
| 58 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 59 | + | |
| 60 | + NSString *stamp = realTime; | |
| 61 | + stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; | |
| 62 | + | |
| 63 | + NSString *endDate = [NSString stringWithFormat:@"%.3f",[netDate timeIntervalSinceDate:_startDate]]; | |
| 64 | + endDate = [endDate stringByReplacingOccurrencesOfString:@"." withString:@""]; | |
| 65 | + | |
| 66 | + NSString *vvUrl = [NSString stringWithFormat:@"http://app.sta.cnlive.com/app.js?sver=%@&uid=%@&tm=%@&from=&spid=&appid=%@&version=1005_%@&eventid=1311&uri=%@&sid=&plat=i_%@&objid=",kSVer,[CNLiveUserSystemTools uidForStat:realTime],stamp,self.appId,SDKVersion,endDate,StatAppVersion]; | |
| 67 | + | |
| 68 | + [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil]; | |
| 69 | + }]; | |
| 65 | 70 | } |
| 66 | 71 | |
| 67 | 72 | - (void)applicationBecomeActive | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUserSystemCenter.h
| ... | ... | @@ -19,6 +19,9 @@ |
| 19 | 19 | @param appSecret 注册成功获得应用secret |
| 20 | 20 | @warning 必传参数 |
| 21 | 21 | 必须在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions; 方法中调用 |
| 22 | + *此方法环境默认为正式环境,建议使用如下方法初始化. | |
| 23 | + + (void)setAppId:(NSString *)appId appKey:(NSString *)appKey appSecret:(NSString *)appSecret isTestEnvironment:(BOOL)isTestEnvironment; | |
| 24 | + | |
| 22 | 25 | */ |
| 23 | 26 | + (void)setAppId:(NSString *)appId appKey:(NSString *)appKey appSecret:(NSString *)appSecret; |
| 24 | 27 | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUserSystemCenter.m
| ... | ... | @@ -26,10 +26,30 @@ |
| 26 | 26 | [CNLiveUserManager manager].appId = appId; |
| 27 | 27 | [CNLiveUserManager manager].appKey = appKey; |
| 28 | 28 | [CNLiveUserManager manager].appSecret = appSecret; |
| 29 | + [CNLiveUserManager manager].isTestEnvironment = NO; | |
| 29 | 30 | |
| 30 | 31 | [[CNLiveUserManager manager] addObserver]; |
| 31 | 32 | } |
| 32 | 33 | |
| 34 | +///** | |
| 35 | +// @abstract 初始化 | |
| 36 | +// @param appId 注册成功获得应用ID | |
| 37 | +// @param appKey 注册成功获得应用key | |
| 38 | +// @param appSecret 注册成功获得应用secret | |
| 39 | +// @param isTestEnvironment 测试环境开关,YES为测试环境,NO为正式环境 | |
| 40 | +// @warning 必传参数 | |
| 41 | +// 必须在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions; 方法中调用 | |
| 42 | +// */ | |
| 43 | +//+ (void)setAppId:(NSString *)appId appKey:(NSString *)appKey appSecret:(NSString *)appSecret isTestEnvironment:(BOOL)isTestEnvironment | |
| 44 | +//{ | |
| 45 | +// [CNLiveUserManager manager].appId = appId; | |
| 46 | +// [CNLiveUserManager manager].appKey = appKey; | |
| 47 | +// [CNLiveUserManager manager].appSecret = appSecret; | |
| 48 | +// [CNLiveUserManager manager].isTestEnvironment = isTestEnvironment; | |
| 49 | +// | |
| 50 | +// [[CNLiveUserManager manager] addObserver]; | |
| 51 | +//} | |
| 52 | + | |
| 33 | 53 | /** |
| 34 | 54 | * 注册 |
| 35 | 55 | */ | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUserSystemTools.h
| ... | ... | @@ -13,19 +13,22 @@ |
| 13 | 13 | /** |
| 14 | 14 | * uuid |
| 15 | 15 | */ |
| 16 | -+ (NSString *)uidForStat:(NSDate *)date; | |
| 16 | ++ (nullable NSString *)uidForStat:(NSString * _Nullable)dateStr; | |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * 加密 |
| 20 | 20 | */ |
| 21 | -+ (NSString*)sha1:(NSString *)string; | |
| 22 | -+ (NSString *)signvalue:(NSDictionary*)parameter; | |
| 21 | ++ (NSString*_Nullable)sha1:(NSString *_Nullable)string; | |
| 22 | ++ (NSString *_Nullable)signvalue:(NSDictionary*_Nullable)parameter; | |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * 检验空字符串 |
| 26 | 26 | */ |
| 27 | -+ (NSString *)verify:(NSString *)string; | |
| 27 | ++ (NSString *_Nullable)verify:(NSString *_Nullable)string; | |
| 28 | 28 | |
| 29 | -+ (void)errorStat:(NSString *)errorString; | |
| 29 | ++ (void)errorStat:(NSString *_Nullable)errorString; | |
| 30 | 30 | |
| 31 | ++ (void)getRealTimeString:(void (^_Nullable)(NSString * __nullable realTime,NSDate * _Nullable netDate))realTime; | |
| 32 | + | |
| 33 | ++ (BOOL)isTestEnvironment; | |
| 31 | 34 | @end | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveUserSystemTools.m
| ... | ... | @@ -16,8 +16,7 @@ |
| 16 | 16 | |
| 17 | 17 | #pragma mark - uuid |
| 18 | 18 | |
| 19 | -+ (NSString *)uidForStat:(NSDate *)date | |
| 20 | -{ | |
| 19 | ++ (nullable NSString *)uidForStat:(NSString *)dateStr{ | |
| 21 | 20 | |
| 22 | 21 | NSString *uid = @""; |
| 23 | 22 | |
| ... | ... | @@ -26,9 +25,10 @@ |
| 26 | 25 | if ([defauts objectForKey:@"kCNLiveUserDefaultsUIDKey"]) { |
| 27 | 26 | uid = [[defauts objectForKey:@"kCNLiveUserDefaultsUIDKey"] copy]; |
| 28 | 27 | return uid; |
| 29 | - } else { | |
| 28 | + } | |
| 29 | + else { | |
| 30 | 30 | |
| 31 | - NSString *stamp = [NSString stringWithFormat:@"%.3f", [date timeIntervalSince1970]]; | |
| 31 | + NSString *stamp = dateStr; | |
| 32 | 32 | stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; |
| 33 | 33 | |
| 34 | 34 | NSString *idfv = [[[[UIDevice currentDevice] identifierForVendor] UUIDString] stringByReplacingOccurrencesOfString:@"-" withString:@""]; |
| ... | ... | @@ -49,7 +49,7 @@ |
| 49 | 49 | |
| 50 | 50 | uint8_t digest[CC_SHA1_DIGEST_LENGTH]; |
| 51 | 51 | |
| 52 | - CC_SHA1(data.bytes, data.length, digest); | |
| 52 | + CC_SHA1(data.bytes, (int)data.length, digest); | |
| 53 | 53 | |
| 54 | 54 | NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2]; |
| 55 | 55 | |
| ... | ... | @@ -107,11 +107,13 @@ |
| 107 | 107 | + (void)errorStat:(NSString *)errorString |
| 108 | 108 | { |
| 109 | 109 | errorString = [self urlEncodeUsingEncodingString:errorString]; |
| 110 | - NSDate *date = [NSDate date]; | |
| 111 | - NSString *stamp = [NSString stringWithFormat:@"%.3f", [date timeIntervalSince1970]]; | |
| 112 | - stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; | |
| 113 | - NSString *vvUrl = [NSString stringWithFormat:@"http://app.sta.cnlive.com/app.js?sver=%@&uid=%@&tm=%@&from=&spid=&appid=%@&version=1005_%@&eventid=1000&uri=%@&sid=%@&plat=i_%@&objid=_", kSVer, [self uidForStat:date], stamp, [CNLiveUserManager manager].appId, SDKVersion, errorString,[self getSid],StatAppVersion]; | |
| 114 | - [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil]; | |
| 110 | + | |
| 111 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 112 | + NSString *stamp = realTime; | |
| 113 | + stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; | |
| 114 | + NSString *vvUrl = [NSString stringWithFormat:@"http://app.sta.cnlive.com/app.js?sver=%@&uid=%@&tm=%@&from=&spid=&appid=%@&version=1005_%@&eventid=1000&uri=%@&sid=%@&plat=i_%@&objid=_", kSVer, [self uidForStat:realTime], stamp, [CNLiveUserManager manager].appId, SDKVersion, errorString,[self getSid],StatAppVersion]; | |
| 115 | + [NSURLConnection connectionWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:vvUrl]] delegate:nil]; | |
| 116 | + }]; | |
| 115 | 117 | } |
| 116 | 118 | |
| 117 | 119 | + (NSString *)urlEncodeUsingEncodingString:(NSString *)string { |
| ... | ... | @@ -130,4 +132,41 @@ |
| 130 | 132 | } |
| 131 | 133 | return @""; |
| 132 | 134 | } |
| 135 | + | |
| 136 | ++ (void)getRealTimeString:(void (^_Nullable)(NSString * __nullable realTime,NSDate * _Nullable netDate))realTime | |
| 137 | +{ | |
| 138 | + [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://m.baidu.com"]] queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) { | |
| 139 | + | |
| 140 | + if (!response) { | |
| 141 | + NSInteger time = [[NSDate date] timeIntervalSince1970]; | |
| 142 | + NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 143 | + dispatch_sync(dispatch_get_main_queue(), ^{ | |
| 144 | + realTime(timeString,[NSDate date]); | |
| 145 | + }); | |
| 146 | + return ; | |
| 147 | + } | |
| 148 | + | |
| 149 | + NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; | |
| 150 | + NSString *timestamp = [[httpResponse allHeaderFields] objectForKey:@"Date"]; | |
| 151 | + | |
| 152 | + NSString *timeStr = [timestamp substringWithRange:NSMakeRange(5, 20)]; | |
| 153 | + NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; | |
| 154 | + NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"GMT"]; | |
| 155 | + NSLocale *local = [[NSLocale alloc]initWithLocaleIdentifier:@"en_US_POSIX"]; | |
| 156 | + [formatter setLocale:local];//需要配置区域,不然会造成模拟器正常,真机日期为null的情况 | |
| 157 | + [formatter setTimeZone:timeZone]; | |
| 158 | + [formatter setDateFormat:@"dd MMM yyyy HH:mm:ss"];//设置源时间字符串的格式 | |
| 159 | + NSDate *date = [formatter dateFromString:timeStr];//将源时间字符串转化为NSDate | |
| 160 | + | |
| 161 | + NSString *timeString = [NSString stringWithFormat:@"%.0f", [date timeIntervalSince1970]]; | |
| 162 | + dispatch_sync(dispatch_get_main_queue(), ^{ | |
| 163 | + realTime(timeString,date); | |
| 164 | + }); | |
| 165 | + }]; | |
| 166 | +} | |
| 167 | + | |
| 168 | ++ (BOOL)isTestEnvironment | |
| 169 | +{ | |
| 170 | + return [CNLiveUserManager manager].isTestEnvironment; | |
| 171 | +} | |
| 133 | 172 | @end | ... | ... |
CNLiveUserSystemDemo/CNLiveUserSystemSDK/CNLiveVerificationCode.m
| ... | ... | @@ -12,35 +12,38 @@ |
| 12 | 12 | #import "NSDictionary+Safety.h" |
| 13 | 13 | |
| 14 | 14 | //快捷登录前发手机验证码 |
| 15 | -static NSString *shortcutLoginURL = @"https://api.cnlive.com/open/api2/user/sendVerifyCode"; | |
| 15 | +static NSString *shortcutLoginTestURL = @"http://test.open.cnlive.com/openapi/api2/user/sendVerifyCode"; | |
| 16 | +static NSString *shortcutLoginFormalURL = @"https://api.cnlive.com/open/api2/user/sendVerifyCode"; | |
| 16 | 17 | |
| 17 | 18 | //注册或修改手机号前发手机验证码 |
| 18 | -static NSString *registerOrModifyURL = @"https://api.cnlive.com/open/api2/user/sendVerifyCodeForUnRegistered"; | |
| 19 | +static NSString *registerOrModifyTestURL = @"http://test.open.cnlive.com/openapi/api2/user/sendVerifyCodeForUnRegistered"; | |
| 20 | +static NSString *registerOrModifyFormalURL = @"https://api.cnlive.com/open/api2/user/sendVerifyCodeForUnRegistered"; | |
| 19 | 21 | |
| 20 | 22 | //找回或修改密码前发手机验证码 |
| 21 | -static NSString *passwordURL = @"https://api.cnlive.com/open/api2/user/sendVerifyCodeForRegistered"; | |
| 23 | +static NSString *passwordTestURL = @"http://test.open.cnlive.com/openapi/api2/user/sendVerifyCodeForRegistered"; | |
| 24 | +static NSString *passwordFormalURL = @"https://api.cnlive.com/open/api2/user/sendVerifyCodeForRegistered"; | |
| 22 | 25 | |
| 23 | 26 | @implementation CNLiveVerificationCode |
| 24 | 27 | |
| 25 | 28 | - (void)getVerificationCodeWithAppId:(NSString *)appId appKey:(NSString *)appKey type:(VerificationCodeType)type mobile:(NSString *)mobile success:(void (^)(id result))success failure:(void (^)(NSDictionary *))failure |
| 26 | 29 | { |
| 27 | - NSDate *date = [NSDate date]; | |
| 28 | - NSInteger time = [date timeIntervalSince1970]; | |
| 29 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 30 | - | |
| 31 | - NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 32 | - @"mobile":[CNLiveUserSystemTools verify:mobile], | |
| 33 | - @"clientPlat":@"i", | |
| 34 | - @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 35 | - @"timestamp": timeString}; | |
| 36 | - | |
| 37 | - NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 38 | - NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 39 | - NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 40 | - | |
| 41 | - [parameter setObject:signString forKey:@"sign"]; | |
| 42 | - | |
| 43 | - [self requestWithURL:[self getURL:type] parameter:parameter success:success failure:failure]; | |
| 30 | + [CNLiveUserSystemTools getRealTimeString:^(NSString * _Nullable realTime, NSDate * _Nullable netDate) { | |
| 31 | + NSString *timeString = realTime; | |
| 32 | + | |
| 33 | + NSDictionary *params = @{@"appId":[CNLiveUserSystemTools verify:appId], | |
| 34 | + @"mobile":[CNLiveUserSystemTools verify:mobile], | |
| 35 | + @"clientPlat":@"i", | |
| 36 | + @"platform_id":[NSBundle mainBundle].bundleIdentifier, | |
| 37 | + @"timestamp": timeString}; | |
| 38 | + | |
| 39 | + NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:params]; | |
| 40 | + NSString *string = [NSString stringWithFormat:@"%@&key=%@", [CNLiveUserSystemTools signvalue:parameter], [CNLiveUserSystemTools verify:appKey]]; | |
| 41 | + NSString *signString = [[CNLiveUserSystemTools sha1:string] uppercaseString]; | |
| 42 | + | |
| 43 | + [parameter setObject:signString forKey:@"sign"]; | |
| 44 | + | |
| 45 | + [self requestWithURL:[self getURL:type] parameter:parameter success:success failure:failure]; | |
| 46 | + }]; | |
| 44 | 47 | } |
| 45 | 48 | |
| 46 | 49 | #pragma mark - request |
| ... | ... | @@ -84,13 +87,31 @@ static NSString *passwordURL = @"https://api.cnlive.com/open/api2/user/sendVeri |
| 84 | 87 | NSString *url; |
| 85 | 88 | switch (type) { |
| 86 | 89 | case VerificationCodeTypeShortcutLogin: |
| 87 | - url = shortcutLoginURL; | |
| 90 | + { | |
| 91 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 92 | + url = shortcutLoginTestURL; | |
| 93 | + } else { | |
| 94 | + url = shortcutLoginFormalURL; | |
| 95 | + } | |
| 96 | + } | |
| 88 | 97 | break; |
| 89 | 98 | case VerificationCodeTypeRegister: |
| 90 | - url = registerOrModifyURL; | |
| 99 | + { | |
| 100 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 101 | + url = registerOrModifyTestURL; | |
| 102 | + } else { | |
| 103 | + url = registerOrModifyFormalURL; | |
| 104 | + } | |
| 105 | + } | |
| 91 | 106 | break; |
| 92 | 107 | case VerificationCodeTypeRetrievePassword: |
| 93 | - url = passwordURL; | |
| 108 | + { | |
| 109 | + if ([CNLiveUserSystemTools isTestEnvironment]) { | |
| 110 | + url = passwordTestURL; | |
| 111 | + } else { | |
| 112 | + url = passwordFormalURL; | |
| 113 | + } | |
| 114 | + } | |
| 94 | 115 | break; |
| 95 | 116 | |
| 96 | 117 | default: | ... | ... |
iOS用户SDK.docx
No preview for this file type