Car*_*los 8 json itunesconnect objective-c storekit iphone-sdk-3.0
过去几天我一直试图测试我的第一个应用程序中的purchse iphone应用程序.不幸的是我无法找到与iTunes服务器通信以验证transactionReceipt的方法.
因为这是我第一次尝试使用这项技术,所以我选择直接从iPhone验证收据,而不是使用服务器支持.但是在尝试使用来自谷歌代码的JSON api创建的JSON onbject发送POST请求之后,itunes总是返回一个奇怪的响应(而不是我等待的"status = 0"字符串).
这是我用来验证收据的代码:
- (void)recordTransaction:(SKPaymentTransaction *)transaction {
NSString *receiptStr = [[NSString alloc] initWithData:transaction.transactionReceipt encoding:NSUTF8StringEncoding];
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"algo mas",@"receipt-data",nil];
NSString *jsonString = [jsonDictionary JSONRepresentation];
NSLog(@"string to send: %@",jsonString);
NSLog(@"JSON Created");
urlData = [[NSMutableData data] retain];
//NSURL *sandboxStoreURL = [[NSURL alloc] initWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"will create connection");
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
Run Code Online (Sandbox Code Playgroud)
也许我忘记了请求标题中的内容,但我认为问题出在我用来创建JSON对象的方法中.
在将JSON对象添加到HTTPBody之前,它是如何看起来的:
string to send: {"receipt-data":"{\n\t\"signature\" = \"AUYMbhY
...........
D0gIjEuMCI7Cn0=\";\n\t\"pod\" = \"100\";\n\t\"signing-status\" = \"0\";\n}"}
Run Code Online (Sandbox Code Playgroud)
我收到的回复:
完成响应{exception ="java.lang.IllegalArgumentException:尝试读取未加引号的字符串时,属性列表解析失败.未找到允许的字符.在行号:1,列:0."; status = 21002; }
非常感谢您的指导.
Ole*_*eev 20
经过2天的挣扎,我刚刚解决了这个问题.在插入json对象之前,必须使用Base64对收据进行编码.就像那样(Ruby):
dataForVerification = {"receipt-data" => Base64.encode64(receipt)}.to_json
Run Code Online (Sandbox Code Playgroud)
官方文档中没有提到Base64(至少对于SDK 3.0),仅在几个博客上提及.
例如,这里的人在将它传递给PHP服务器之前在Base64中对收据进行编码,但不会在PHP中对其进行解码,从而将Base64编码的字符串发送到iTunes.
| 归档时间: |
|
| 查看次数: |
16354 次 |
| 最近记录: |