質問

アプリケーションでアプリ購入で使用しています。次の方法を使用して、購入した製品のトランザクション領収書を確認するために、サーバーにリクエストを送信しています。

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

この後、次のgoteiptresponseメソッドが呼び出されます。

- (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 u00ecad u009c u00bdfb( u00ffn u00ae u00a1b u00b7 u00dd u00ce> u00cd u00ec <6、xcq " u00d6> u0092; u00ecy u00e u009af u0095 u00e8 u00e0 u00daq u00c1z u00f7 u00c2 u00ff u009bfh- u00a4 u00cc u00f4 u00f7- u00c4 | uayax uamea uamea uame

u00e6a u00a2 u00edz u00bb u00e85 u00a2 u00e4 u0087 u00b2 u0096 u00d7 u00ad u00d0 u00ad u uea uea uea u009 u009 uea uea u00acf u00c6 u008f u00d5 u00ef u00b0 u00fd u0090 u00ae u0091r u008f u00fe u00ed u00e3&}。

JSonRespでは、値はnullです。だから、このUnicode文字列をエンコードするにはどうすればよいかを知りたかっただけです。私が得ている応答とJSonRespのヌル値の理由を理解できるように。

役に立ちましたか?

解決

使用する [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パーサーを使用して結果を解析する必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top