使用App Store验证收据 [英] Verifying a Receipt with the App Store
本文介绍了使用App Store验证收据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从事务的transactionReceipt属性中检索收据数据,并使用base64编码对其进行编码。
Retrieve the receipt data from the transaction’s transactionReceipt property and encode it using base64 encoding.
如何使用base64编码?请提供相应的代码。
How can I encode NSData using base64 encoding? Please give the code for that.
编辑
我做到了。但现在响应是
EDIT
I did it. but now the response is
{exception = "java.lang.NullPointerException"; status = 21002;}
我的收件人验证方法是这个
my recipt verification method is this
-(BOOL)verifyReceipt:(SKPaymentTransaction *)transaction
{
NSString *recieptString = [transaction.transactionReceipt base64EncodingWithLineLength:0];
NSLog(@"%@",recieptString);
ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://buy.itunes.apple.com/verifyReceipt"]]];
[request setPostValue:recieptString forKey:@"receipt-data"];
[request setPostValue:@"95140bdac98d47a2b15e8e5555f55d41" forKey:@"password"];
[request start];
NSDictionary* subsInfo = [[request responseString] JSONValue];
NSLog(@"%@",subsInfo);
return subscriptionEnabled;
}
其中
NSString *recieptString = [transaction.transactionReceipt base64EncodingWithLineLength:0];
返回base64编码的字符串。
我也试过了?
returns me base64 encoded string.
I also tried
NSString *recieptString = [transaction.transactionReceipt base64EncodingWithLineLength:[transaction.transactionReceipt length]];
但响应相同。
你们中的任何人都可以告诉我可能出错的地方。
谢谢 -
but response is same.
can any one of you let me know where I could be wrong.
Thanks-
推荐答案
+ (NSString*)base64forData:(NSData*)theData {
const uint8_t* input = (const uint8_t*)[theData bytes];
NSInteger length = [theData length];
static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4];
uint8_t* output = (uint8_t*)data.mutableBytes;
NSInteger i;
for (i=0; i < length; i += 3) {
NSInteger value = 0;
NSInteger j;
for (j = i; j < (i + 3); j++) {
value <<= 8;
if (j < length) {
value |= (0xFF & input[j]);
}
}
NSInteger theIndex = (i / 3) * 4;
output[theIndex + 0] = table[(value >> 18) & 0x3F];
output[theIndex + 1] = table[(value >> 12) & 0x3F];
output[theIndex + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '=';
output[theIndex + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '=';
}
return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
}
这篇关于使用App Store验证收据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文