1
This commit is contained in:
@@ -24,6 +24,12 @@ typedef void (^KBStreamFetcherFinishHandler)(NSError *_Nullable error);
|
|||||||
// 必填:请求地址
|
// 必填:请求地址
|
||||||
@property (nonatomic, strong) NSURL *url;
|
@property (nonatomic, strong) NSURL *url;
|
||||||
|
|
||||||
|
/// HTTP Method,默认为 GET
|
||||||
|
@property (nonatomic, copy, nullable) NSString *httpMethod;
|
||||||
|
|
||||||
|
/// 自定义请求体(例如 POST 的 JSON body)
|
||||||
|
@property (nonatomic, strong, nullable) NSData *httpBody;
|
||||||
|
|
||||||
// 可选 Header
|
// 可选 Header
|
||||||
@property (nonatomic, copy, nullable) NSDictionary<NSString *, NSString *> *extraHeaders;
|
@property (nonatomic, copy, nullable) NSDictionary<NSString *, NSString *> *extraHeaders;
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ static NSUInteger kb_validUTF8PrefixLen(NSData *data) {
|
|||||||
|
|
||||||
- (instancetype)init {
|
- (instancetype)init {
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
|
_httpMethod = @"GET";
|
||||||
_acceptEventStream = NO;
|
_acceptEventStream = NO;
|
||||||
_disableCompression = YES;
|
_disableCompression = YES;
|
||||||
_treatSlashTAsTab = YES;
|
_treatSlashTAsTab = YES;
|
||||||
@@ -83,7 +84,11 @@ static NSUInteger kb_validUTF8PrefixLen(NSData *data) {
|
|||||||
self.session = [NSURLSession sessionWithConfiguration:cfg delegate:self delegateQueue:[NSOperationQueue mainQueue]];
|
self.session = [NSURLSession sessionWithConfiguration:cfg delegate:self delegateQueue:[NSOperationQueue mainQueue]];
|
||||||
|
|
||||||
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:self.url];
|
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:self.url];
|
||||||
req.HTTPMethod = @"GET";
|
NSString *method = self.httpMethod.length > 0 ? self.httpMethod : @"GET";
|
||||||
|
req.HTTPMethod = method;
|
||||||
|
if (self.httpBody.length > 0) {
|
||||||
|
req.HTTPBody = self.httpBody;
|
||||||
|
}
|
||||||
if (self.disableCompression) { [req setValue:@"identity" forHTTPHeaderField:@"Accept-Encoding"]; }
|
if (self.disableCompression) { [req setValue:@"identity" forHTTPHeaderField:@"Accept-Encoding"]; }
|
||||||
if (self.acceptEventStream) { [req setValue:@"text/event-stream" forHTTPHeaderField:@"Accept"]; }
|
if (self.acceptEventStream) { [req setValue:@"text/event-stream" forHTTPHeaderField:@"Accept"]; }
|
||||||
[req setValue:@"no-cache" forHTTPHeaderField:@"Cache-Control"];
|
[req setValue:@"no-cache" forHTTPHeaderField:@"Cache-Control"];
|
||||||
@@ -290,10 +295,10 @@ static NSUInteger kb_validUTF8PrefixLen(NSData *data) {
|
|||||||
if (rawText.length == 0) return;
|
if (rawText.length == 0) return;
|
||||||
// 调试:在任何处理之前打印后端“原始文本分片”,便于对照排查
|
// 调试:在任何处理之前打印后端“原始文本分片”,便于对照排查
|
||||||
if (self.loggingEnabled) {
|
if (self.loggingEnabled) {
|
||||||
NSLog(@"[KBStream] RAW chunk#%ld len=%lu text=\"%@\"",
|
// NSLog(@"[KBStream] RAW chunk#%ld len=%lu text=\"%@\"",
|
||||||
(long)(self.emittedChunkCount + 1),
|
// (long)(self.emittedChunkCount + 1),
|
||||||
(unsigned long)rawText.length,
|
// (unsigned long)rawText.length,
|
||||||
KBPrintableSnippet(rawText, 160));
|
// KBPrintableSnippet(rawText, 160));
|
||||||
}
|
}
|
||||||
NSString *text = rawText;
|
NSString *text = rawText;
|
||||||
// 0) 规范化换行与段起始:去掉位于片段开头的 \r/\n;将 "\n\t"、"\r\n\t"、"\r\t" 归一为 "\t"
|
// 0) 规范化换行与段起始:去掉位于片段开头的 \r/\n;将 "\n\t"、"\r\n\t"、"\r\t" 归一为 "\t"
|
||||||
|
|||||||
@@ -268,7 +268,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - Network Streaming (GET)
|
#pragma mark - Network Streaming (POST)
|
||||||
|
|
||||||
// 后端测试地址(内网)。若被 ATS 拦截,请在扩展 target 的 Info.plist 中允许 HTTP 或添加例外域。
|
// 后端测试地址(内网)。若被 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";
|
||||||
@@ -278,23 +278,42 @@
|
|||||||
if (![[KBFullAccessManager shared] hasFullAccess]) { return; }
|
if (![[KBFullAccessManager shared] hasFullAccess]) { return; }
|
||||||
|
|
||||||
NSString *apiUrl = [NSString stringWithFormat:@"%@%@", KB_BASE_URL, API_AI_TALK];
|
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];
|
NSURL *url = [NSURL URLWithString:apiUrl];
|
||||||
if (!url) { return; }
|
if (!url) { return; }
|
||||||
|
|
||||||
|
// 组装 POST Body
|
||||||
|
NSInteger characterId = 0;
|
||||||
|
if (self.loadingTagIndex != nil) {
|
||||||
|
NSInteger idx = self.loadingTagIndex.integerValue;
|
||||||
|
if (idx >= 0 && idx < self.modelArray.count) {
|
||||||
|
KBTagItemModel *model = self.modelArray[idx];
|
||||||
|
characterId = model.characterId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NSString *message = seedTitle.length > 0 ? seedTitle : @"";
|
||||||
|
NSInteger resolvedCharacterId = (characterId > 0) ? characterId : 75;
|
||||||
|
NSDictionary *payload = @{
|
||||||
|
@"characterId": @(resolvedCharacterId),
|
||||||
|
@"message": message.length > 0 ? message : @"aliqua non cupidatat"
|
||||||
|
};
|
||||||
|
NSError *bodyError = nil;
|
||||||
|
NSData *bodyData = [NSJSONSerialization dataWithJSONObject:payload options:0 error:&bodyError];
|
||||||
|
if (bodyError || bodyData.length == 0) {
|
||||||
|
NSLog(@"[KBFunction] build body failed: %@", bodyError);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.streamHasOutput = NO; // 重置首段处理标记
|
self.streamHasOutput = NO; // 重置首段处理标记
|
||||||
__weak typeof(self) weakSelf = self;
|
__weak typeof(self) weakSelf = self;
|
||||||
KBStreamFetcher *fetcher = [KBStreamFetcher fetcherWithURL:url];
|
KBStreamFetcher *fetcher = [KBStreamFetcher fetcherWithURL:url];
|
||||||
|
fetcher.httpMethod = @"POST";
|
||||||
|
fetcher.httpBody = bodyData;
|
||||||
|
NSMutableDictionary *headers = [@{ @"Content-Type": @"application/json" } mutableCopy];
|
||||||
|
NSString *token = KBAuthManager.shared.current.accessToken ?: @"";
|
||||||
|
if (token.length > 0) {
|
||||||
|
headers[@"auth-token"] = token;
|
||||||
|
}
|
||||||
|
fetcher.extraHeaders = headers;
|
||||||
// 由本类统一做 /t->\t 与首段去 \t,fetcher 只负责增量与协议解析
|
// 由本类统一做 /t->\t 与首段去 \t,fetcher 只负责增量与协议解析
|
||||||
fetcher.disableCompression = YES;
|
fetcher.disableCompression = YES;
|
||||||
fetcher.acceptEventStream = NO; // 响应头若是 SSE 仍会自动解析
|
fetcher.acceptEventStream = NO; // 响应头若是 SSE 仍会自动解析
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
#define API_VALIDATE_RECEIPT @"/api/apple/validate-receipt" // 排行榜标签列表
|
#define API_VALIDATE_RECEIPT @"/api/apple/validate-receipt" // 排行榜标签列表
|
||||||
|
|
||||||
/// AI
|
/// AI
|
||||||
#define API_AI_TALK @"/demo/talk" // 排行榜标签列表
|
#define API_AI_TALK @"/chat/talk" // 排行榜标签列表
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -169,9 +169,7 @@
|
|||||||
04FC95DD2EB202A3007BD342 /* KBGuideVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95DC2EB202A3007BD342 /* KBGuideVC.m */; };
|
04FC95DD2EB202A3007BD342 /* KBGuideVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95DC2EB202A3007BD342 /* KBGuideVC.m */; };
|
||||||
04FC95E52EB220B5007BD342 /* UIColor+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95E42EB220B5007BD342 /* UIColor+Extension.m */; };
|
04FC95E52EB220B5007BD342 /* UIColor+Extension.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95E42EB220B5007BD342 /* UIColor+Extension.m */; };
|
||||||
04FC95E92EB23B67007BD342 /* KBNetworkManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95E72EB23B67007BD342 /* KBNetworkManager.m */; };
|
04FC95E92EB23B67007BD342 /* KBNetworkManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95E72EB23B67007BD342 /* KBNetworkManager.m */; };
|
||||||
04FC95F12EB339A7007BD342 /* LoginViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95F02EB339A7007BD342 /* LoginViewController.m */; };
|
|
||||||
04FC95F42EB339C1007BD342 /* AppleSignInManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95F32EB339C1007BD342 /* AppleSignInManager.m */; };
|
04FC95F42EB339C1007BD342 /* AppleSignInManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC95F32EB339C1007BD342 /* AppleSignInManager.m */; };
|
||||||
04FC96142EB34E00007BD342 /* KBLoginSheetViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC96122EB34E00007BD342 /* KBLoginSheetViewController.m */; };
|
|
||||||
04FC97002EB30A00007BD342 /* KBGuideTopCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC96FF2EB30A00007BD342 /* KBGuideTopCell.m */; };
|
04FC97002EB30A00007BD342 /* KBGuideTopCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC96FF2EB30A00007BD342 /* KBGuideTopCell.m */; };
|
||||||
04FC97032EB30A00007BD342 /* KBGuideKFCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC97022EB30A00007BD342 /* KBGuideKFCell.m */; };
|
04FC97032EB30A00007BD342 /* KBGuideKFCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC97022EB30A00007BD342 /* KBGuideKFCell.m */; };
|
||||||
04FC97062EB30A00007BD342 /* KBGuideUserCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC97052EB30A00007BD342 /* KBGuideUserCell.m */; };
|
04FC97062EB30A00007BD342 /* KBGuideUserCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 04FC97052EB30A00007BD342 /* KBGuideUserCell.m */; };
|
||||||
@@ -509,13 +507,9 @@
|
|||||||
04FC95E42EB220B5007BD342 /* UIColor+Extension.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIColor+Extension.m"; sourceTree = "<group>"; };
|
04FC95E42EB220B5007BD342 /* UIColor+Extension.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIColor+Extension.m"; sourceTree = "<group>"; };
|
||||||
04FC95E62EB23B67007BD342 /* KBNetworkManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBNetworkManager.h; sourceTree = "<group>"; };
|
04FC95E62EB23B67007BD342 /* KBNetworkManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBNetworkManager.h; sourceTree = "<group>"; };
|
||||||
04FC95E72EB23B67007BD342 /* KBNetworkManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBNetworkManager.m; sourceTree = "<group>"; };
|
04FC95E72EB23B67007BD342 /* KBNetworkManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBNetworkManager.m; sourceTree = "<group>"; };
|
||||||
04FC95EF2EB339A7007BD342 /* LoginViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoginViewController.h; sourceTree = "<group>"; };
|
|
||||||
04FC95F02EB339A7007BD342 /* LoginViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LoginViewController.m; sourceTree = "<group>"; };
|
|
||||||
04FC95F22EB339C1007BD342 /* AppleSignInManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppleSignInManager.h; sourceTree = "<group>"; };
|
04FC95F22EB339C1007BD342 /* AppleSignInManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppleSignInManager.h; sourceTree = "<group>"; };
|
||||||
04FC95F32EB339C1007BD342 /* AppleSignInManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppleSignInManager.m; sourceTree = "<group>"; };
|
04FC95F32EB339C1007BD342 /* AppleSignInManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppleSignInManager.m; sourceTree = "<group>"; };
|
||||||
04FC95F52EB33B52007BD342 /* keyBoard.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = keyBoard.entitlements; sourceTree = "<group>"; };
|
04FC95F52EB33B52007BD342 /* keyBoard.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = keyBoard.entitlements; sourceTree = "<group>"; };
|
||||||
04FC96112EB34E00007BD342 /* KBLoginSheetViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBLoginSheetViewController.h; sourceTree = "<group>"; };
|
|
||||||
04FC96122EB34E00007BD342 /* KBLoginSheetViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBLoginSheetViewController.m; sourceTree = "<group>"; };
|
|
||||||
04FC96FE2EB30A00007BD342 /* KBGuideTopCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBGuideTopCell.h; sourceTree = "<group>"; };
|
04FC96FE2EB30A00007BD342 /* KBGuideTopCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBGuideTopCell.h; sourceTree = "<group>"; };
|
||||||
04FC96FF2EB30A00007BD342 /* KBGuideTopCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBGuideTopCell.m; sourceTree = "<group>"; };
|
04FC96FF2EB30A00007BD342 /* KBGuideTopCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KBGuideTopCell.m; sourceTree = "<group>"; };
|
||||||
04FC97012EB30A00007BD342 /* KBGuideKFCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBGuideKFCell.h; sourceTree = "<group>"; };
|
04FC97012EB30A00007BD342 /* KBGuideKFCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KBGuideKFCell.h; sourceTree = "<group>"; };
|
||||||
@@ -1372,10 +1366,6 @@
|
|||||||
04FC95EC2EB33611007BD342 /* VC */ = {
|
04FC95EC2EB33611007BD342 /* VC */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
04FC95EF2EB339A7007BD342 /* LoginViewController.h */,
|
|
||||||
04FC95F02EB339A7007BD342 /* LoginViewController.m */,
|
|
||||||
04FC96112EB34E00007BD342 /* KBLoginSheetViewController.h */,
|
|
||||||
04FC96122EB34E00007BD342 /* KBLoginSheetViewController.m */,
|
|
||||||
047920612EDEEFC7004E8522 /* KBLoginVC.h */,
|
047920612EDEEFC7004E8522 /* KBLoginVC.h */,
|
||||||
047920622EDEEFC7004E8522 /* KBLoginVC.m */,
|
047920622EDEEFC7004E8522 /* KBLoginVC.m */,
|
||||||
0498BD662EE01180006CC1D5 /* KBEmailRegistVC.h */,
|
0498BD662EE01180006CC1D5 /* KBEmailRegistVC.h */,
|
||||||
@@ -1765,9 +1755,7 @@
|
|||||||
04C6EABE2EAF86530089C901 /* AppDelegate.m in Sources */,
|
04C6EABE2EAF86530089C901 /* AppDelegate.m in Sources */,
|
||||||
04791FFF2ED830FA004E8522 /* KBKeyboardMaskView.m in Sources */,
|
04791FFF2ED830FA004E8522 /* KBKeyboardMaskView.m in Sources */,
|
||||||
0498BD652EE0116D006CC1D5 /* KBEmailLoginVC.m in Sources */,
|
0498BD652EE0116D006CC1D5 /* KBEmailLoginVC.m in Sources */,
|
||||||
04FC95F12EB339A7007BD342 /* LoginViewController.m in Sources */,
|
|
||||||
048908E92EBF843000FABA60 /* KBSkinDetailHeaderCell.m in Sources */,
|
048908E92EBF843000FABA60 /* KBSkinDetailHeaderCell.m in Sources */,
|
||||||
04FC96142EB34E00007BD342 /* KBLoginSheetViewController.m in Sources */,
|
|
||||||
04A9FE1B2EB892460020DB6D /* KBLocalizationManager.m in Sources */,
|
04A9FE1B2EB892460020DB6D /* KBLocalizationManager.m in Sources */,
|
||||||
048908BC2EBE1FCB00FABA60 /* BaseViewController.m in Sources */,
|
048908BC2EBE1FCB00FABA60 /* BaseViewController.m in Sources */,
|
||||||
0498BD902EE6A3BD006CC1D5 /* KBMyMainModel.m in Sources */,
|
0498BD902EE6A3BD006CC1D5 /* KBMyMainModel.m in Sources */,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#import "PayVM.h"
|
#import "PayVM.h"
|
||||||
#import "KBAuthManager.h"
|
#import "KBAuthManager.h"
|
||||||
#import "KBHUD.h"
|
#import "KBHUD.h"
|
||||||
#import "KBLoginSheetViewController.h"
|
//#import "KBLoginSheetViewController.h"
|
||||||
#import "KBBizCode.h"
|
#import "KBBizCode.h"
|
||||||
@interface IAPVerifyTransactionObj ()
|
@interface IAPVerifyTransactionObj ()
|
||||||
@property (nonatomic, strong) PayVM *payVM;
|
@property (nonatomic, strong) PayVM *payVM;
|
||||||
|
|||||||
Reference in New Issue
Block a user