diff --git a/CustomKeyboard/Network/KBNetworkManager.m b/CustomKeyboard/Network/KBNetworkManager.m index 8b1f65e..0d9103e 100644 --- a/CustomKeyboard/Network/KBNetworkManager.m +++ b/CustomKeyboard/Network/KBNetworkManager.m @@ -30,10 +30,8 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network"; // 默认请求头:Accept 任意类型 + 使用项目多语言管理器设置 Accept-Language NSString *lang = [KBLocalizationManager shared].currentLanguageCode ?: KBLanguageCodeEnglish; // NSString *token = [KBUserSessionManager shared].accessToken ? [KBUserSessionManager shared].accessToken : @""; - NSString *token = KBAuthManager.shared.current.accessToken ? KBAuthManager.shared.current.accessToken : @""; _defaultHeaders = @{ @"Accept": @"*/*", - @"auth-token" : token, @"Accept-Language": lang }; // 设置基础域名,路径可相对该地址拼接 @@ -191,6 +189,12 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network"; - (void)applyHeaders:(NSDictionary *)headers toMutableRequest:(NSMutableURLRequest *)req contentType:(NSString *)contentType { // 合并默认头与局部头,并注入授权头(若可用)。局部覆盖优先。 NSMutableDictionary *all = [self.defaultHeaders mutableCopy] ?: [NSMutableDictionary new]; + NSString *token = [KBAuthManager shared].current.accessToken; + if (token.length > 0) { + all[@"auth-token"] = token; + } else { + [all removeObjectForKey:@"auth-token"]; + } NSDictionary *auth = [[KBAuthManager shared] authorizationHeader]; [auth enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) { all[key] = obj; }]; if (contentType) all[@"Content-Type"] = contentType; diff --git a/keyBoard/Class/Login/VM/KBLoginVM.m b/keyBoard/Class/Login/VM/KBLoginVM.m index 0bbd2ef..dbf3729 100644 --- a/keyBoard/Class/Login/VM/KBLoginVM.m +++ b/keyBoard/Class/Login/VM/KBLoginVM.m @@ -171,7 +171,7 @@ self.myVM = [[KBMyVM alloc] init]; } /// 防止token写入过慢导致请求head没有token - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self.myVM fetchCharacterListByUserWithCompletion:^(NSArray * _Nonnull characterArray, NSError * _Nullable error) { if (error) { KBLOG(@"[Login] Failed to sync keyboard characters after login: %@", error); diff --git a/keyBoard/Class/Network/KBNetworkManager.m b/keyBoard/Class/Network/KBNetworkManager.m index ebc5d66..71f41fc 100644 --- a/keyBoard/Class/Network/KBNetworkManager.m +++ b/keyBoard/Class/Network/KBNetworkManager.m @@ -44,7 +44,6 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network"; _timeout = 10.0; NSString *lang = [KBLocalizationManager shared].currentLanguageCode ?: KBLanguageCodeEnglish; - NSString *token = [KBUserSessionManager shared].accessToken ? [KBUserSessionManager shared].accessToken : @""; // 如果还有 query 参数也塞进来 // signParams[@"lang"] = @"zh"; @@ -54,7 +53,6 @@ NSErrorDomain const KBNetworkErrorDomain = @"com.company.keyboard.network"; _defaultHeaders = @{ @"Accept": @"*/*", @"Accept-Language": lang, - @"auth-token" : token, }; // 设置基础域名,路径可相对该地址拼接 _baseURL = [NSURL URLWithString:KB_BASE_URL]; @@ -357,6 +355,12 @@ autoShowBusinessError:YES - (void)applyHeaders:(NSDictionary *)headers toMutableRequest:(NSMutableURLRequest *)req contentType:(NSString *)contentType { // 合并默认头与局部头,并注入授权头(若可用)。局部覆盖优先。 NSMutableDictionary *all = [self.defaultHeaders mutableCopy] ?: [NSMutableDictionary new]; + NSString *token = [KBAuthManager shared].current.accessToken; + if (token.length > 0) { + all[@"auth-token"] = token; + } else { + [all removeObjectForKey:@"auth-token"]; + } NSDictionary *auth = [[KBAuthManager shared] authorizationHeader]; [auth enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) { all[key] = obj; }]; if (contentType) all[@"Content-Type"] = contentType; diff --git a/keyBoard/Class/Pay/VM/PayVM.m b/keyBoard/Class/Pay/VM/PayVM.m index 4f68c86..ddb8e76 100644 --- a/keyBoard/Class/Pay/VM/PayVM.m +++ b/keyBoard/Class/Pay/VM/PayVM.m @@ -14,8 +14,8 @@ - (void)applePayReqWithParams:(NSDictionary *)params needShow:(BOOL)needShow completion:(KBPayCompletion)completion { - if (needShow) { [KBHUD show]; } - +// if (needShow) { [KBHUD show]; } + [KBHUD showWithStatus:@"Please wait"]; [[KBNetworkManager shared] POST:API_VALIDATE_RECEIPT jsonBody:params headers:nil @@ -39,7 +39,9 @@ return; } - if (completion) completion(KBBizCodeSuccess, @"JWS-ok"); +// if (completion) completion(KBBizCodeSuccess, @"JWS-ok"); + if (completion) completion(KBBizCodeSuccess, nil); + }]; }