我正在在 OSX 应用上进行应用内购买验证并遇到一些问题~
我的请求代码是这样的:
NSData* data = [NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]];
NSString* base64Str = [data base64EncodedString];
NSDictionary* dict = [NSDictionary dictionaryWithObject:base64Str forKey:@"receipt-data"];
SBJSON *jsonParser = [[[SBJSON alloc] init] autorelease];
NSString* jsonStr = [jsonParser stringWithObject:dict error:nil];
postUrl = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];
_verifyRequest = [[NSMutableURLRequest alloc] init];
[_verifyRequest setTimeoutInterval:_sTimeoutInterval];
[_verifyRequest setURL:postUrl];
[_verifyRequest setHTTPBody:[jsonStr dataUsingEncoding:NSUTF8StringEncoding]];
[_verifyRequest setHTTPMethod:ASCommon_HttpMethodPost];
_verifyConnection = [[NSURLConnection alloc] initWithRequest:_verifyRequest delegate:self];
[_verifyConnection start];
我得到这样的结果
{
exception = "java.lang.IllegalArgumentException";
status = 21002;
}
而且我记录的 jsonStr 变量似乎没有问题:
{"receipt-data":"..........................................................."}
Apple doc here说“检索收据数据。......在 OS X 上,这是应用程序包内收据文件的全部内容。使用 base64 编码对收据数据进行编码。”
我是否误解收据数据是文件的全部内容?还是我的代码有问题?