我在我的应用程序中使用App购买。 我正在向服务器发送请求,以使用以下方法验证所购买产品的交易收据:
-(void)sendingRequestForReceipt: (SKPaymentTransaction *)transaction{
networkQueue = [ASINetworkQueue queue];
[networkQueue retain];
NSString *serverUrl = @"https://sandbox.itunes.apple.com/";
NSString *receiptStr= [Base64Encoding base64EncodingForData:(transaction.transactionReceipt) WithLineLength:0];
NSString *str = [NSString stringWithFormat:@"%@verifyReceipt", serverUrl];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
NSDictionary* data = [NSDictionary dictionaryWithObjectsAndKeys:receiptStr,@"receipt-data", nil];
[request appendPostData: [[data JSONRepresentation] dataUsingEncoding:NSUTF8StringEncoding]];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request setDidFinishSelector: @selector(gotReceiptResponse:)];
[networkQueue addOperation: request];
[networkQueue go];
}
在此之后调用以下gotReceiptResponse方法:
- (void)gotReceiptResponse:(ASIHTTPRequest *)req{
NSString *response=[req responseString];
NSDictionary *jsonResp = [response JSONValue];
NSString *receiptValue = [jsonResp valueForKey:@"status"];
int receiptCheck=[receiptValue intValue];
if( receiptCheck ==0){
//mark item as purchased
//show alert that item was purchased and will be downloaded
UIAlertView *alert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase:"
message:@"The instrumental was purchased successfully and will now be downloaded. "
"Please do not close the app till download is complete"
delegate :self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[alert show];
[alert release];
}
}
我响应得到的值是例如:\ u008bb \ u0095 \ u008f \ u00b1 \ u008e \ u00c20D {\ u00be“RM \ u0082bc \ u00d2 \ u009f \ u00a8 \ u00e8 \ u00e8 \ u00a3 = \ u00c7 \ u00ca \ u00adD \ u00ec \ u009c \ u00bdFB(\ u00ffN \ u00ae转移\ u00a1B \ U00B7 \ u00dd \ u00ce> \ u00cd \ u00ec&10 6,XCQ“\ u00d6> \ u0092; \ u00ecY \ u00cb \ u009aF)\ u00a5 \ u00eb \ u00c3 \ u0091m \ u00e6 \ u00e8 \ u00e0 \ u00daQ \ u00c1z \ u00f7 \ u00c2 \ u00ff \ u009bFH- \ u00a4 \ u00cc \ u00f4 \ u00f7- \ u00c4 | \ u00aax \ u00de \ u00a6 \ u00e0 \ u00fbd \ u00e8 \ u0085 \ u00ef \ u008fJ \ u00adb
\ u00e6 \ u00a2 \ u00e2 \ u00e2 \ u00e4 \ u002 \ u002 \ u006 \ u006 \ u006 \ u006 \ u00ad \ u00ad \ u00ad \ u00ad \ u00ad \ u00d \ u00ad \ u00d \ u00d \ u00c \ u00c \ u00c \ u00c \ u00c \ u00 \ u00ba&安培; \ u00acf \ u00c6 \ u008f \ u00d5 \ u00ef \ u00b0 \ u00fd \ u0090 \ u00ae转移\ u0091R \ u008f \ u00fe \ u00ed \ u00e3&安培;} 8 / T $ \ u00a0 \ u00b4t \ u00e4 \ u00f3M \ u00f9` ?
并且在jsonResp中,该值为null。 所以我只想知道如何编码这个unicode字符串。这样我就可以理解我得到的响应是什么,以及jsonResp中空值的原因。
答案 0 :(得分:0)
使用[req responseData]
通过使用以下方式手动对原始数据进行编码:
NSString *resultString = [[NSString alloc] initWithData:[req responseData] encoding:NSUTF8StringEncoding];
//This is a simple validation. It's only checking if there is a '"status":0' string in the resultString.
if([resultString rangeOfString:@"\"status\":0"].location != NSNotFound)
resultStatus = 0;
[resultString release];
return (resultStatus == 0);
如果您需要进一步的验证信息,您必须使用JSON解析器并解析resultString。