diff --git a/CustomKeyboard/KeyboardViewController.m b/CustomKeyboard/KeyboardViewController.m index 30154a8..6921b52 100644 --- a/CustomKeyboard/KeyboardViewController.m +++ b/CustomKeyboard/KeyboardViewController.m @@ -218,19 +218,9 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, [self showFunctionPanel:NO]; return; } - -// // 1. 构造充值入口的通用链接(UL)和自定义 Scheme: -// // - 当前复用 /login 路径,通过 entry=recharge 区分场景: -// // https://app.tknb.net/ul/login?src=keyboard&entry=recharge -// // - 若宿主拒绝或 UL 配置异常,则回退到 kbkeyboardAppExtension://recharge?src=keyboard -// NSString *ulStr = [NSString stringWithFormat:@"%@?src=keyboard&entry=recharge", KB_UL_RECHARGE]; -// NSURL *ul = [NSURL URLWithString:ulStr]; -// + NSString *schemeStr = [NSString stringWithFormat:@"%@://recharge?src=keyboard", KB_APP_SCHEME]; NSURL *scheme = [NSURL URLWithString:schemeStr]; -// -// if (!ul && !scheme) { return; } -// // 从当前视图作为起点,通过响应链找到 UIApplication 再调起主 App BOOL ok = [KBHostAppLauncher openHostAppURL:scheme fromResponder:self.view]; diff --git a/CustomKeyboard/View/KBFunctionView.m b/CustomKeyboard/View/KBFunctionView.m index a0e69ef..44cc14a 100644 --- a/CustomKeyboard/View/KBFunctionView.m +++ b/CustomKeyboard/View/KBFunctionView.m @@ -238,13 +238,25 @@ #pragma mark - Network Streaming (GET) // 后端测试地址(内网)。若被 ATS 拦截,请在扩展 target 的 Info.plist 中允许 HTTP 或添加例外域。 -static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/talk"; +//static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/talk"; - (void)kb_startNetworkStreamingWithSeed:(NSString *)seedTitle { [self kb_stopNetworkStreaming]; if (![[KBFullAccessManager shared] hasFullAccess]) { return; } - NSURL *url = [NSURL URLWithString:kKBStreamDemoURL]; + NSString *apiUrl = [NSString stringWithFormat:@"%@%@", KB_BASE_URL, API_AI_TALK]; + // 将选中的标签文案作为 seed 透传给后端(通过 query 参数) + if (seedTitle.length > 0) { + NSString *encodedSeed = [seedTitle stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]] ?: @""; + if (encodedSeed.length > 0) { + if ([apiUrl containsString:@"?"]) { + apiUrl = [apiUrl stringByAppendingFormat:@"&userInput=%@", encodedSeed]; + } else { + apiUrl = [apiUrl stringByAppendingFormat:@"?userInput=%@", encodedSeed]; + } + } + } + NSURL *url = [NSURL URLWithString:apiUrl]; if (!url) { return; } self.streamHasOutput = NO; // 重置首段处理标记 @@ -332,34 +344,42 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/ // 2) 权限没问题,再判断是否登录:未登录 -> 直接拉起主 App,由主 App 负责完成登录 if (!KBAuthManager.shared.isLoggedIn) { + + UIInputViewController *ivc = KBFindInputViewController(self); - if (!ivc) return; - NSString *encodedTitle = [title stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]] ?: @""; - NSURL *ul = [NSURL URLWithString:[NSString stringWithFormat:@"%@?src=functionView&index=%ld&title=%@", KB_UL_LOGIN, (long)index, encodedTitle]]; - if (!ul) return; - // 发起 UL,不依赖 ok 结果 - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [ivc.extensionContext openURL:ul completionHandler:^(__unused BOOL ok) {}]; - }); - // 双路兜底:500ms 内未收到主 App 确认,则回退到自定义 Scheme(通过宿主 UIApplication 打开) - self.kb_ulHandledFlag = NO; - NSUInteger token = ++self.kb_ulSeq; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - if (token != self.kb_ulSeq) return; // 已有新请求覆盖 - if (self.kb_ulHandledFlag) return; // 主 App 已确认处理 - NSURL *scheme = [NSURL URLWithString:[NSString stringWithFormat:@"%@://login?src=functionView&index=%ld&title=%@", KB_APP_SCHEME, (long)index, encodedTitle]]; - if (!scheme) return; - UIResponder *start = ivc.view ?: (UIResponder *)self; - // 让键盘失去焦点 - [ivc dismissKeyboard]; - BOOL ok = [KBHostAppLauncher openHostAppURL:scheme fromResponder:start]; - if (!ok) { - [KBHUD showInfo:KBLocalized(@"请切换到主App完成登录")]; - }else{ - - } - }); + + NSString *schemeStr = [NSString stringWithFormat:@"%@://login?src=keyboard", KB_APP_SCHEME]; + NSURL *scheme = [NSURL URLWithString:schemeStr]; + // 从当前视图作为起点,通过响应链找到 UIApplication 再调起主 App + BOOL ok = [KBHostAppLauncher openHostAppURL:scheme fromResponder:ivc.view]; return; +// if (!ivc) return; +// NSString *encodedTitle = [title stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]] ?: @""; +// NSURL *ul = [NSURL URLWithString:[NSString stringWithFormat:@"%@?src=functionView&index=%ld&title=%@", KB_UL_LOGIN, (long)index, encodedTitle]]; +// if (!ul) return; +// // 发起 UL,不依赖 ok 结果 +// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ +// [ivc.extensionContext openURL:ul completionHandler:^(__unused BOOL ok) {}]; +// }); +// // 双路兜底:500ms 内未收到主 App 确认,则回退到自定义 Scheme(通过宿主 UIApplication 打开) +// self.kb_ulHandledFlag = NO; +// NSUInteger token = ++self.kb_ulSeq; +// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ +// if (token != self.kb_ulSeq) return; // 已有新请求覆盖 +// if (self.kb_ulHandledFlag) return; // 主 App 已确认处理 +// NSURL *scheme = [NSURL URLWithString:[NSString stringWithFormat:@"%@://login?src=functionView&index=%ld&title=%@", KB_APP_SCHEME, (long)index, encodedTitle]]; +// if (!scheme) return; +// UIResponder *start = ivc.view ?: (UIResponder *)self; +// // 让键盘失去焦点 +// [ivc dismissKeyboard]; +// BOOL ok = [KBHostAppLauncher openHostAppURL:scheme fromResponder:start]; +// if (!ok) { +// [KBHUD showInfo:KBLocalized(@"请切换到主App完成登录")]; +// }else{ +// +// } +// }); +// return; } // 3) 已登录:开始业务逻辑(展示加载并拉取流式内容) diff --git a/Shared/KBAPI.h b/Shared/KBAPI.h index 380ceaf..668e0eb 100644 --- a/Shared/KBAPI.h +++ b/Shared/KBAPI.h @@ -43,6 +43,8 @@ /// pay #define API_VALIDATE_RECEIPT @"/api/apple/validate-receipt" // 排行榜标签列表 +/// AI +#define API_AI_TALK @"/demo/talk" // 排行榜标签列表