Browse Source

SDK初始化参数

Steven 1 year ago
parent
commit
d75578794a

+ 4 - 0
KulexiuForTeacher/KulexiuForTeacher/AppDelegate.m

@@ -80,6 +80,7 @@
 
 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
     // Override point for customization after application launch.
+    [self configCertConfig];
     [self networkEnableCheck];
     [Bugly startWithAppId:@"c0513c2cf4"];
     [self registerSDK];
@@ -144,6 +145,9 @@
     return YES;
 }
 
+- (void)configCertConfig {
+    [KSNetworkingManager configCertConfig];
+}
 - (void)configRootVC {
     BOOL hasLaunchGuide = UserDefaultBoolForKey(FIRST_LOGIN_KEY);
     if (hasLaunchGuide == NO) {

+ 37 - 8
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSBaseWKWebViewController.m

@@ -1068,19 +1068,48 @@ typedef NS_ENUM(NSInteger, CHOOSETYPE) {
 
 - (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *_Nullable))completionHandler
 {
-    
     dispatch_queue_t queue =  dispatch_queue_create("webViewChallengeQueue", NULL);
     dispatch_async(queue, ^{
-        if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
-            if (challenge.previousFailureCount == 0) {
-                NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
-                completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
-            } else {
-                completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
+        if (SSL_AUTH) {
+
+            NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengePerformDefaultHandling;
+            NSURLCredential *customCredential = nil;
+            
+            if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
+                // 默认信任
+                customCredential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
+                disposition = NSURLSessionAuthChallengeUseCredential;
+            }
+            else if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate]) {
+                // client authentication
+                SecIdentityRef identity = NULL;
+                SecTrustRef trust = NULL;
+                if ([AuthChallengeManager extractIdentity:&identity andTrust:&trust filePath:CERT_PATH]) {
+                    SecCertificateRef certificate = NULL;
+                    SecIdentityCopyCertificate(identity, &certificate);
+                    const void*certs[] = {certificate};
+                    CFArrayRef certArray =CFArrayCreate(kCFAllocatorDefault, certs,1,NULL);
+                    customCredential =[NSURLCredential credentialWithIdentity:identity certificates:(__bridge  NSArray*)certArray persistence:NSURLCredentialPersistencePermanent];
+                    disposition = NSURLSessionAuthChallengeUseCredential;
+                }
+            }
+            
+            if (completionHandler) {
+                completionHandler(disposition, customCredential);
             }
         }
         else {
-            completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
+            if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {
+                if (challenge.previousFailureCount == 0) {
+                    NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
+                    completionHandler(NSURLSessionAuthChallengeUseCredential, credential);
+                } else {
+                    completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
+                }
+            }
+            else {
+                completionHandler(NSURLSessionAuthChallengeCancelAuthenticationChallenge, nil);
+            }
         }
     });
 }

+ 3 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSNetworkingManager.h

@@ -11,6 +11,9 @@
 NS_ASSUME_NONNULL_BEGIN
 
 @interface KSNetworkingManager : NSObject
+// 认证相关
++ (void)configCertConfig;
+
 + (void)addHeader:(NSString *)headValue forKey:(NSString *)headKey;
 
 // 配置请求头

+ 7 - 2
KulexiuForTeacher/KulexiuForTeacher/Common/Base/KSNetworkingManager.m

@@ -14,6 +14,11 @@
 
 @implementation KSNetworkingManager
 
+// 认证相关
++ (void)configCertConfig {
+    [VoNetworking configCertificatePath:CERT_PATH baseHost:hostURL needAuth:SSL_AUTH];
+}
+
 + (void)addHeader:(NSString *)headValue forKey:(NSString *)headKey {
     [[VoNetworking sharedManager] addHttpHeader:headValue forKey:headKey];
 }
@@ -167,10 +172,10 @@
     [LOADING_MANAGER removeHUD];
 
     if (isDisable) {
-        [self showMessage:@"登录过期,请重新登录"];
+        [LOADING_MANAGER MBShowAUTOHidingInWindow:@"登录过期,请重新登录"];
     }
     else {
-        [self showMessage:@"未认证"];
+        [LOADING_MANAGER MBShowAUTOHidingInWindow:@"未认证"];
     }
     [self logoutAction];
 }

+ 2 - 0
KulexiuForTeacher/KulexiuForTeacher/Common/Define/KSDomain.h

@@ -12,6 +12,8 @@
 #define AGENT_NAME (@"COLEXIUAPPI")
 #define AGENT_DOMAIN (@"COLEXIUTEACHER")
 
+#define CERT_PATH ([[NSBundle mainBundle] pathForResource:@"client" ofType:@"p12"])
+
 #define WEBPATH (@"/teacher")
 
 #define FILE_DOMAIN (@"klx/")

+ 31 - 2
KulexiuForTeacher/KulexiuForTeacher/Module/Login/Model/UserInfoManager.m

@@ -14,7 +14,7 @@
 #import "AppDelegate+AppService.h"
 #import <SDWebImage/SDWebImageManager.h>
 
-@interface UserInfoManager ()
+@interface UserInfoManager ()<KSUploadManagerDelegate>
 
 @property (nonatomic, copy) UserInfoCallback callback;
 
@@ -145,6 +145,8 @@
             
             NSString *uid = self.userInfo.userId;
             UserDefaultSet(uid, UIDKey);
+            // 上传配置
+            [self settingUploadConfig];
             
             NSString *imUserID = self.userInfo.imUserId;
             UserDefaultSet(imUserID, IM_USERID);
@@ -211,7 +213,8 @@
             
             NSString *uid = self.userInfo.userId;
             UserDefaultSet(uid, UIDKey);
-            
+            // 上传配置
+            [self settingUploadConfig];
             // IM ID
             NSString *IMUserId = self.userInfo.imUserId;
             UserDefaultSet(IMUserId, IM_USERID);
@@ -400,4 +403,30 @@
         NSLog(@"---");
     }];
 }
+
+- (void)settingUploadConfig {
+    UPLOAD_MANAGER.uploadDelegate = self;
+    [UPLOAD_MANAGER configFileDomain:FILE_DOMAIN userID:UserDefault(UIDKey)];
+}
+
+- (void)notiferUploadSignWithCosFileName:(NSString *)cosFileName cosBucketName:(NSString *)cosBucketName callback:(void (^)(NSString * _Nullable))callback {
+    [KSNetworkingManager getTXCosUploadSignRequest:KS_POST fileName:cosFileName keyName:cosFileName bucketName:cosBucketName success:^(NSDictionary * _Nonnull dic) {
+        if ([dic ks_integerValueForKey:@"code"] == 200) {
+            NSString *signatureString = [[dic ks_dictionaryValueForKey:@"data"] ks_stringValueForKey:@"signature"];
+            if (callback) {
+                callback(signatureString);
+            }
+        }
+        else {
+            if (callback) {
+                callback(nil);
+            }
+        }
+    } faliure:^(NSError * _Nonnull error) {
+        if (callback) {
+            callback(nil);
+        }
+    }];
+}
+
 @end