应用内购买收据验证
我想在我的应用程序中验证交易收据,
这是我的代码,
- (void)recordTransaction:(SKPaymentTransaction *)transaction {
NSData *receiptData = [NSData dataWithData:transaction.transactionReceipt];
NSString *encodedString = [Base64 encode:receiptData];
NSURL *url = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];
ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];
[request setPostValue:encodedString forKey:@"receipt-data"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request startAsynchronous];
}
我得到输出:
{“status”:21002,“异常”:“java.lang.NullPointerException”}
有人可以帮助我获得正确的收据验证吗?
I want to verify the transaction receipt within my app,
Here is my code,
- (void)recordTransaction:(SKPaymentTransaction *)transaction {
NSData *receiptData = [NSData dataWithData:transaction.transactionReceipt];
NSString *encodedString = [Base64 encode:receiptData];
NSURL *url = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];
ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url];
[request setPostValue:encodedString forKey:@"receipt-data"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request startAsynchronous];
}
I am getting output:
{"status":21002, "exception":"java.lang.NullPointerException"}
Can someone help me to get proper receipt verification?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
仅供那些可能觉得有帮助的人使用。我注意到苹果已经更新了应用程序内购买指南,其中包含一些用于自动更新订阅购买的状态代码,但似乎也适用于此处。
用于验证的沙箱服务。
重要提示:此处的非零状态代码仅在恢复有关自动续订订阅的信息时适用。在测试其他类型产品的响应时,请勿使用这些状态代码。 (真的吗?)
我希望这可以作为参考。我得到了 21007。Apple
网站上的状态代码列表: https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html
Just for those who may find it helpful. I noticed that apple has updated the In App Purchasing Guide with some status code that are for the auto renewable subscription purchases but seem to apply here as well.
sandbox service for verification.
Important: The non-zero status codes here apply only when recovering information about a auto-renewable subscription. Do not use these status codes when testing responses for other kinds of products. (Really?)
I hope this helps as a reference. I got nailed with 21007.
List of status codes on Apple's website: https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html
经过多次尝试,我决定从服务器端进行收据验证。实际上这是推荐的方式。
这是我的代码,
我找到了帮助表单,
http://gamesfromwithin.com/in-app -购买-第3部分
After number of tries, I decided to do the receipt verification from server side. Actually this is the recommended way.
Here is my code,
I found help form,
http://gamesfromwithin.com/in-app-purchases-part-3
...您没有触发您的请求。所以您的回复为空,因为您尚未提出请求!
添加
[request startSynchronous]
调用(这通常是一个坏主意,您应该始终异步运行网络调用),或者更好地重写代码以支持异步网络调用,并使用[请求 startAsynchronous]
相反。如果您需要更多信息,我建议您查看 ASI 文档:
http://allseeing-i.com/ASIHTTPRequest/How-to-use
...you're not firing your request. So your response is null, because you haven't made the request yet!
Either add a
[request startSynchronous]
call (which is generally a bad idea, you should always run your network calls asynchronously), or better yet rewrite your code to support an asynchronous network call, and use[request startAsynchronous]
instead.I would suggest reviewing the ASI documentation if you need more information:
http://allseeing-i.com/ASIHTTPRequest/How-to-use
从以下参考文献中,我了解到您的应用程序需要使用单独的服务器来“验证商店收据”。我认为对于收据验证,我们需要使用来自静态 IP 的请求。
谢谢,
参考
From the following reference I understand that your application need to use separate server for "Verifying Store Receipts". I think for receipts verification we need to use a request from static ip.
thanks,
Reference