gpt4 book ai didi

ios - Apple 收据设备哈希验证

转载 作者:行者123 更新时间:2023-11-29 12:51:02 24 4
gpt4 key购买 nike

我正在尝试使用来自名为 RMStore 的流行收据验证库中的代码来验证收据是否针对此特定设备:

NSUUID * uuid = [[UIDevice currentDevice] identifierForVendor];
uuid_t uuidBytes;
[uuid getUUIDBytes:uuidBytes];

NSMutableData * data = [[NSMutableData alloc] init];
[data appendBytes:uuidBytes length:sizeof(uuidBytes)];
[data appendData:_parsedReceipt.opaqueValue];
[data appendData:_parsedReceipt.bundleIdentifierData];

NSMutableData * computedHash = [NSMutableData dataWithLength:SHA_DIGEST_LENGTH];
SHA1(data.bytes, data.length, computedHash.mutableBytes);

return [computedHash isEqualToData:_parsedReceipt.hash];

但是这两个哈希值不相等。代码有问题吗?

编辑

    SKReceiptRefreshRequest * request = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:@{SKReceiptPropertyIsRevoked: @YES}];
[request setDelegate:self];
[request start];

在我重新获取收据一次后,哈希值开始匹配。这是我见过的最奇怪的行为。有谁知道为什么会发生这种情况?

最佳答案

如您获取该代码的答案中所示,Apple 建议在验证失败时刷新收据。这是 RMStore 用来验证收据/交易的方法:

RMAppReceipt *receipt = [RMAppReceipt bundleReceipt];
const BOOL verified = [self verifyTransaction:transaction inReceipt:receipt success:successBlock failure:nil]; // failureBlock is nil intentionally. See below.
if (verified) return;

// Apple recommends to refresh the receipt if validation fails on iOS
[[RMStore defaultStore] refreshReceiptOnSuccess:^{
RMAppReceipt *receipt = [RMAppReceipt bundleReceipt];
[self verifyTransaction:transaction inReceipt:receipt success:successBlock failure:failureBlock];
} failure:^(NSError *error) {
[self failWithBlock:failureBlock error:error];
}];

关于ios - Apple 收据设备哈希验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22417956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com