问题描述
2天的不间断搜索,我在IAP的一个重要问题上空白。我们需要我们的服务器验证收据,响应总是21002。
2 days of non stop searching and I'm coming up blank on an important issue with IAP. We need our server to validate the receipt and the response is always 21002.
在客户端我发送
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
NSDictionary* post = @{@"receipt":[receipt base64EncodedStringWithOptions:0]};
[ServerRequest requestWithUrl:url Callback:nil SendToIM:NO PostData:post];//does standard _POST to our php server
'p>下面是一个沙箱收据作为一个base64字符串它击中服务器
Here is a sandbox receipt as a base64 string before it hits the server
MIIU2gYJKoZIhvcNAQcCoIIUyzCCFMcCAQExCzAJBgUrDgMCGgUAMIIEiwYJKoZIhvcNAQcBoIIEfASCBHgxggR0MAoCAQgCAQEEAhYAMAoCARICAQEEAhYAMAoCARMCAQEEAgwAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADALAgELAgEBBAMCAQAwCwIBDgIBAQQDAgFTMAsCAQ8CAQEEAwIBADALAgEQAgEBBAMCAQAwCwIBGQIBAQQDAgEDMAwCAQoCAQEEBBYCNCswDQIBAwIBAQQFDAMwLjYwDQIBDQIBAQQFAgMBEdQwDgIBCQIBAQQGAgRQMjI4MBgCAQQCAQIEEM7oReI9bPs0X/hqFDngWuUwGwIBAAIBAQQTDBFQcm9kdWN0aW9uU2FuZGJveDAcAgEFAgEBBBQ8LF7D7deEfXmQd9NITmWuDFXXkDAeAgEMAgEBBBYWFDIwMTQtMDMtMjFUMTk6NDU6MDhaMCwCAQICAQEEJAwiY29tLmNsaXB3aXJlZ2FtZXMuQ3JpdHRlci1Db25xdWVzdDA4AgEHAgEBBDBrGHw8H08L2bC6tSu08pjZKzOeXY8iNjZxZFrJSPr1QnpwMtHhPd44Lky0BciZY0wwOwIBBgIBAQQz4eLimps057PHKFJAyTiNF4fTO5uWOQQkM1dk2ivH6xnWf3/e8qD+9GzS2HH2qzIzZvonMIIBTAIBEQIBAQSCAUIxgg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
$postData = json_encode(
array('receipt-data' => $receipt));
//标准cURL发布并从Apple Sandbox Server获取
//standard cURL post and get from Apple Sandbox Server
我已经阅读了关于此的所有示例和论坛帖子,似乎无法使其正常运行。
I've read every example and forum post on this and can't seem to get this working.
我最好的猜测是我的收据编码错误,但我尝试了每种格式选项,我总是得到21002(在我的服务器上)。
My best guess was that I was encoding my receipt wrong but I've tried every format option and I always get 21002 back (on my server).
这里有什么我想念的吗?基本上我正在尝试:
1.将NSData收据作为字符串发送到服务器
2.让我的服务器ping Apple服务器
3.处理有效或无效的收据问题
Is there something I'm missing here? Basically I'm trying to:1. Send the NSData receipt as a string to the server2. Have my server ping Apple server3. Process valid or invalid receipt issues
看来我的第1步是错的,但我不确定。我使用base64encode发送收据数据是错误的吗?
It seems my step 1 is wrong but Im not sure. Am I wrong using base64encode to send the receipt data?
我的服务器上是否需要保留格式?
Is there something on my server I need to do to preserve the format?
非常感谢任何和所有建议。
Any and all advice greatly appreciated.
更新:
这是我用来将它发送到服务器的代码(一旦它到达服务器时它正在剪切哈希码中的+)
Here is the code I used to send it to the server (which is currently clipping the + in the hash code once it hits the server)
for (NSString* k in _post)
{
postDataStr = [NSString stringWithFormat:@"%@&%@=%@", postDataStr,k,_post[k]];
}
_req = [NSMutableURLRequest requestWithURL:_url cachePolicy:nil timeoutInterval:15.0f];
[_req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[_req setHTTPMethod:@"POST"];
[_req setHTTPBody:[postDataStr dataUsingEncoding:NSUTF8StringEncoding]];
答案:
当发送到服务器时,+已从我的字符串中删除。我没有做正确的URL编码。我用%2B取代了+它现在可以工作了
The + was getting removed from my string when being sent to server. I was not doing proper URL encoding. I replaced + with %2B and it works now
推荐答案
这是我用来将收据直接发送到Apple服务器的代码。
Here is the code I use to send the receipt directly to the Apple servers.
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receiptData = [NSData dataWithContentsOfURL:receiptURL];
[self checkTransactionWithAppleUseProduction:productionWebsite andData:receiptData];
NSString *string64=[receiptData base64EncodedStringWithOptions:kNilOptions];
NSString *payload = [NSString stringWithFormat:@"{\"receipt-data\" : \"%@\"}",string64];
NSData *payloadData = [payload dataUsingEncoding:NSUTF8StringEncoding];
NSString *serverURL;
if(productionWebsite)serverURL= @"https://buy.itunes.apple.com/verifyReceipt";
if(!productionWebsite)serverURL=@"https://sandbox.itunes.apple.com/verifyReceipt";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:serverURL]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:payloadData];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[conn start];
这篇关于PHP服务器上的iOS 7收据验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!