我過去幾天試圖測試我的第一個應用內購買iPhone應用程序。不幸的是,我找不到與iTunes服務器交談的方式來驗證transactionReceipt。使用transactionReceipt生成JSON對象
因爲這是我第一次嘗試這種技術,我選擇使用服務器支持直接從iPhone驗證收據。但在嘗試發送帶有使用JSON API從Google代碼創建的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];
}
也許我忘在請求的報頭的東西,但我認爲這個問題是在我用它來創建JSON對象的方法。
這裏的JSON對象看起來像之前我把它添加到HTTPBody:
string to send: {"receipt-data":"{\n\t\"signature\" = \"AUYMbhY
...........
D0gIjEuMCI7Cn0=\";\n\t\"pod\" = \"100\";\n\t\"signing-status\" = \"0\";\n}"}
我已經得到了響應:
完全反應{ 例外=「java.lang中。 IllegalArgumentException:在嘗試讀取未加引號的字符串時,屬性列表解析失敗。未找到允許的字符。行號:1,列:0。 status = 21002; }
非常感謝您的指導。
沒有在文檔中說'transactionReceipt'可以解釋爲一個UTF-8編碼的字符串 – user102008 2013-04-30 22:22:38