Pregunta

Estoy usando en compras de aplicaciones en mi aplicación. Estoy enviando una solicitud al servidor para verificar el recibo de transacción para el producto comprado utilizando el siguiente método:

-(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];
}

Después de esto, se llama el siguiente método 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];
}
}

El valor que recibo en respuesta es, por ejemplo: 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 <6, xcq " u00d6> u0092; u00e8 u00e0 u00daq u00c1z u00f7 u00c2 u00ff u009bfh- u00a4 u00cc u00f4 u00f7- u00c4 | u00aax u00de u00a6 u00e0 u00fbd u00E8 u0085

u00e6a u00a2 u00edz u00bb u00e85 u00a2 u00e4 u0087 u00b2 u0096 u00d7 u00ad u00d0 u00ad u00d4 u00c5 u0099 u00dd u00e9 | u00c9 u00f8ogh ba ba u0099 u00dd u00e9 | u00c9 u00f8ogh ba ba ba u0099 u00dd u00e9 | u00c9 u00f8ogh ba ba ba u0099 u00dd u00e9 | u00c9 u00f8ogh ba ba ba U0099 U00ACF U00C6 U008F U00D5 U00EF U00B0 U00FD U0090 U00E U0091R U008F U00FE U00ED U00E3 &}. 8/T $ U00A0 U00B4T U00E4 U00F3M U00F9``??

y en jsonResp el valor es nulo. Así que solo quería saber cómo puedo codificar esta cadena Unicode. Para que pueda entender cuál es la respuesta que estoy recibiendo y también la razón del valor nulo en JSONRESP.

¿Fue útil?

Solución

Usar [req responseData] Para obtener los datos sin procesar, codifica los datos manualmente utilizando:

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);

Si necesita más información de validación, debe utilizar un analizador JSON y analizar la extracción de resultados.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top