2013-08-21 25 views
0

我有一个自动更新的应用程序内购买。当用户第一次注册时,应用程序会以NSDATA的形式收到收据。我把它编码成一个字符串:在应用程序购买Autorenew收据格式问题

[NSString stringWithUTF8String:[receiptData bytes]]]; 

然后我把它作为一个blob发布到我的服务器。

然后,当用户登录到应用程序,我从服务器获取收据,将其更改为NSData的:

[receipt dataUsingEncoding:NSUTF8StringEncoding] 

然后我在其上运行的方法,以验证该收据是有效的。从我的阅读中,我收集到的答复将是一个新的收据,或者某种状态代码,表明其有效或不合理。

NSString *jsonObjectString = [self encodeBase64:(uint8_t *)receipt.bytes 
             length:receipt.length]; 



NSString *itunescombo = @"xxxxxxxxxxxxxxxxxxxxxx"; 
// Create the POST request payload. 
NSString *payload = [NSString stringWithFormat:@"{\"receipt-data\" : \"%@\", \"password\" : \"%@\"}", 
        jsonObjectString, itunescombo]; 

NSData *payloadData = [payload dataUsingEncoding:NSUTF8StringEncoding]; 


NSString *serverURL = ITMS_SANDBOX_VERIFY_RECEIPT_URL; 

// Create the POST request to the server. 
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverURL]]; 
[request setHTTPMethod:@"POST"]; 
[request setHTTPBody:payloadData]; 

NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 



[conn start]; 

然后作为回应,我不断收到之一:

{"status":21002, "exception":"java.lang.IllegalArgumentException"} 

或只是

{"status":21002} 

是否有人可以告诉我在哪里,我错了?该错误意味着收据的格式不正确,但我不确定在所有格式操作之间发生了什么。

谢谢! [R

回答

0

一旦更改代码以

NSString *jsonObjectString = [self encodeBase64:(uint8_t *)transaction.transactionReceipt.bytes 
             length:transaction.transactionReceipt.length];