Frage

Ich verwende in App -Einkäufen in meiner Bewerbung. Ich sende eine Anfrage an den Server, um die Transaktionsbeleg für das gekaufte Produkt mit der folgenden Methode zu überprüfen:

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

Danach heißt die folgende GotReceipTesponse -Methode:

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

The value I get in response is for example : u008bbu0095u008fu00b1u008eu00c20D{u00be"rMu0082bcu00d2u009fu00a8u00e8u00e8u00a3=u00c7u00cau00adDu00ec u009c u00bdfb ( u00ffn u00ae u00a1b u00b7 u00dd u00ce> u00cd u00ec <6, xcq " u00d6> u0092 u00ecyb u00cy u00cb) u00ecyb) u00ecyb) u00ecyb) u00e8 u00e0 u00daq u00c1z u00f7 u00c2 u00ff u009bfh- u00a4 u00cc u00f4 u00a6 u00f u00a.

u00e6a u00a2 u00edz u00bb u00e85 u00a2 u00e4 u0087 u00b2 u0096 u00d7 u00 u00 u00 u00. u00 u00 u00 u00c5 u00c5 u00c5 u00c5 u00c5 u00c5 u00c5 u00 u00 u00. u00ACF u00c6 u008f u00d5 u00ef u00b0 u00fd u0090 u00ae u0091r u008f u00Fe u00ed u00e3 &}.

Und in JsonResp ist der Wert null. Ich wollte also nur wissen, wie ich diese Unicode -Zeichenfolge codieren kann. Damit ich verstehen kann, was die Antwort ist, die ich bekomme, und auch der Grund für den Nullwert in JSONRESP.

War es hilfreich?

Lösung

Verwenden [req responseData] Um die Rohdaten zu erhalten und die Daten manuell mithilfe der Daten zu codieren:

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

Wenn Sie weitere Validierungsinformationen benötigen, müssen Sie einen JSON -Parser verwenden und die Ergebnisse analysieren.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top