0
我正在使用应用内购买在我的应用程序...现在我想验证收据,并验证收据签名我使用AppDelegate下面的代码(按顺序要知道,如果用户启动应用程序时)Xcode验证收据签名错误
实际的代码来自WWDC 2013已经购买了它 - 会话308 ;-)
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receiptData = [NSData dataWithContentsOfURL:receiptURL];
NSData *certificateData = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"AppleIncRootCertificate" withExtension:@"cer"]];
/* The PKCS #7 container (the receipt) and The Apple root certificate. */
BIO *b_receipt = BIO_new_mem_buf((void *) [receiptData bytes], (int)[receiptData length]);
BIO *b_x509 = BIO_new_mem_buf((void *)[certificateData bytes], (int)[certificateData length]);
// Convert receipt data to PKCS #7 Representation
PKCS7 *p7 = d2i_PKCS7_bio(b_receipt, NULL);
/* Create the root certificate */
X509_STORE *store = X509_STORE_new();
X509 *appleRootCA = d2i_X509_bio(b_x509, NULL);
X509_STORE_add_cert(store, appleRootCA);
/* Verify the signature. If the verification is correct, b_receiptPayload will contain the PKCS #7 payload and result will be 1. */
BIO *b_receiptPayload = BIO_new(BIO_s_mem());
int result = PKCS7_verify(p7, NULL, store, NULL, b_receiptPayload, 0);
if (result == 1)
{
NSLog(@"Receipt Signature is valid");
} else {
unsigned long error = ERR_get_error();
const char* error_str = ERR_error_string(error, NULL);
NSLog(@"OpenSSL Error: %s",error_str);
}
,但我总是得到以下OpenSSL的错误:错误:2006F079 :lib(32):func(111):reason(121)
我已经googl它但没有任何结果......任何建议?
验证收据签名的另一种方法是?
预先感谢您的合作...
我使用这个库 - https://github.com/robotmedia/RMStore。这里是如何使用收据验证的信息https://github.com/robotmedia/RMStore/wiki/Receipt-verification – Traveler
谢谢,我会检查它... – jankoesp