Как интерпретировать ответ сервера на запрос подтверждения покупки в приложении? - PullRequest
1 голос
/ 26 июля 2011

Я использую в приложении покупки в моем приложении. Я отправляю запрос на сервер для подтверждения получения транзакции для приобретенного продукта следующим способом:

-(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 \ u008f \ u008e \ u00c20D {\ u00be "rM \ u0082bc \ u00d2 \ u009f \ u00a8 \ u00e8 \ u00e8 = \ u00a3 = \ u00c7 u00adD \ u00ec \ u009c \ u00bdFB (\ u00ffN \ u00ae \ u00a1B \ u00b7 \ u00dd \ u00ce> \ u00cd \ u00ec <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

u00a2 \ u00ed2 \ u00e85 \ u00e2 \ u0087 \ u00b2 \ u00d7 \ u00ad0 \ u00d4 \ u00c5 \ u0099 \ u0000 \ u00009 \ u00baf \ u00c6 \ u008f \ u00f5 \ u00fd \ u00ae \ u00aeR \ u008f \ u00fe / u00ef \ u00ef \ u00ef \ u00ef \ u00ef \ u00ef \ u00ef \ u00ef \ u00ef \ u00ef \ u00e3 & u00e0 & u00a4 \ u003? 1009 *

и в jsonResp значение равно нулю. Так что просто хотел знать, как я могу закодировать эту строку Unicode. Чтобы я мог понять, какой ответ я получаю, а также причину нулевого значения в jsonResp.

1 Ответ

0 голосов
/ 26 июля 2011

Используйте [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.

...