1
This commit is contained in:
@@ -24,6 +24,9 @@
|
||||
#import "KBVipPay.h"
|
||||
#import "KBUserSessionManager.h"
|
||||
#import "KBLoginVC.h"
|
||||
#import "KBConfig.h"
|
||||
|
||||
static NSTimeInterval const kKBSubscriptionPrefillTTL = 10 * 60.0;
|
||||
|
||||
// 注意:用于判断系统已启用本输入法扩展的 bundle id 需与扩展 target 的
|
||||
// PRODUCT_BUNDLE_IDENTIFIER 完全一致。
|
||||
@@ -199,8 +202,36 @@
|
||||
if ([action isEqualToString:@"autopay"]) {
|
||||
autoPay = YES;
|
||||
}
|
||||
|
||||
BOOL wantsPrefill = NO;
|
||||
NSString *prefillFlag = params[@"prefill"];
|
||||
if ([prefillFlag respondsToSelector:@selector(boolValue)] && prefillFlag.boolValue) {
|
||||
wantsPrefill = YES;
|
||||
}
|
||||
NSString *src = params[@"src"];
|
||||
if ([src isKindOfClass:NSString.class] && [src.lowercaseString isEqualToString:@"keyboard"]) {
|
||||
wantsPrefill = YES;
|
||||
}
|
||||
NSDictionary *prefillPayload = wantsPrefill ? [self kb_consumeSubscriptionPrefillPayloadIfValid] : nil;
|
||||
if ([prefillPayload isKindOfClass:NSDictionary.class]) {
|
||||
NSString *payloadProductId = prefillPayload[@"productId"];
|
||||
if (productId.length == 0 && [payloadProductId isKindOfClass:NSString.class]) {
|
||||
productId = payloadProductId;
|
||||
}
|
||||
}
|
||||
|
||||
KBVipPay *vc = [[KBVipPay alloc] init];
|
||||
[vc configureWithProductId:productId autoPurchase:autoPay];
|
||||
if ([prefillPayload isKindOfClass:NSDictionary.class]) {
|
||||
NSArray *productsJSON = prefillPayload[@"products"];
|
||||
NSNumber *selectedIndexNumber = prefillPayload[@"selectedIndex"];
|
||||
NSInteger selectedIndex = [selectedIndexNumber respondsToSelector:@selector(integerValue)] ? selectedIndexNumber.integerValue : NSNotFound;
|
||||
[vc configureWithProductId:productId
|
||||
autoPurchase:autoPay
|
||||
prefillProductsJSON:productsJSON
|
||||
selectedIndex:selectedIndex];
|
||||
} else {
|
||||
[vc configureWithProductId:productId autoPurchase:autoPay];
|
||||
}
|
||||
[KB_CURRENT_NAV pushViewController:vc animated:true];
|
||||
return YES;
|
||||
}
|
||||
@@ -209,6 +240,23 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (nullable NSDictionary *)kb_consumeSubscriptionPrefillPayloadIfValid {
|
||||
NSUserDefaults *ud = [[NSUserDefaults alloc] initWithSuiteName:AppGroup];
|
||||
if (!ud) { return nil; }
|
||||
id obj = [ud objectForKey:AppGroup_SubscriptionPrefillPayload];
|
||||
[ud removeObjectForKey:AppGroup_SubscriptionPrefillPayload];
|
||||
[ud synchronize];
|
||||
if (![obj isKindOfClass:NSDictionary.class]) { return nil; }
|
||||
NSDictionary *payload = (NSDictionary *)obj;
|
||||
NSNumber *ts = payload[@"ts"];
|
||||
if (![ts respondsToSelector:@selector(doubleValue)]) { return nil; }
|
||||
NSTimeInterval age = [NSDate date].timeIntervalSince1970 - ts.doubleValue;
|
||||
if (age < 0 || age > kKBSubscriptionPrefillTTL) { return nil; }
|
||||
id products = payload[@"products"];
|
||||
if (![products isKindOfClass:NSArray.class] || ((NSArray *)products).count == 0) { return nil; }
|
||||
return payload;
|
||||
}
|
||||
|
||||
- (NSDictionary<NSString *, NSString *> *)kb_queryParametersFromURL:(NSURL *)url {
|
||||
if (!url) { return @{}; }
|
||||
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
|
||||
|
||||
Reference in New Issue
Block a user