当前位置:首页 > 编程开发

AppStore 内购验证的方法

webgou9年前 (2017-02-28)编程开发270

 

 

AppStore增加了验证内购(In App Purchasement)的方法, 就是苹果提供一个url地址, 开发测试用:

https://sandbox.itunes.apple.com/verifyReceipt

产品用:

https://buy.itunes.apple.com/verifyReceipt

当购买成功时, 会得到苹果返回的一个收据(receipt), 苹果推荐的方法是将收据发给开发者的server, 由server像上述地址post http消息, 进行验证, 苹果将结果返回.到底是真正的购买还是虚假的购买.

没有自己server的小伙伴可以用app进行发送, 代码如下.

复制代码
#define ITMS_SANDBOX_VERIFY_RECEIPT_URL     @"https://sandbox.itunes.apple.com/verifyReceipt"#pragma mark - VerifyFinishedTransaction-(void)verifyFinishedTransaction:(SKPaymentTransaction *)transaction{     if(transaction.transactionState == SKPaymentTransactionStatePurchased){         NSString *transactionIdentifier =  transaction.transactionIdentifier;         NSData *transactionReceipt  = transaction.transactionReceipt;         //将transactionIdentifer和加密后的transactionReceipt数据发送给server端                 NSString* receipent = [NSString stringWithFormat:@"%s", transactionReceipt.bytes];                  NSLog(@"receipent = %@", receipent);                  // 在app上做验证, 仅用于测试        NSString *payload = [NSString stringWithFormat:@"{\"receipt-data\" : \"%@\", \"password\" : \"%@\"}",                              receipent, transactionIdentifier];         NSData *payloadData = [payload dataUsingEncoding:NSUTF8StringEncoding];         NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:ITMS_SANDBOX_VERIFY_RECEIPT_URL]];         [request setHTTPMethod:@"POST"];         [request setHTTPBody:payloadData];         NSError* err;         NSURLResponse *theResponse = nil;         NSData *data=[NSURLConnection sendSynchronousRequest:request                                            returningResponse:&theResponse                                                        error:&err];         NSError *jsonParsingError = nil;         NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonParsingError];         NSLog(@"%@", dict);         NSLog(@"done");         } }

 

附:苹果支付错误目录

Status Code Description
21000 The App Store could not read the JSON object you provided.
21002 The data in the receipt-data property was malformed or missing.
21003 The receipt could not be authenticated.
21004 The shared secret you provided does not match the shared secret on file for your account.Only returned for iOS 6 style transaction receipts for auto-renewable subscriptions.
21005 The receipt server is not currently available.
21006 This receipt is valid but the subscription has expired. When this status code is returned to your server, the receipt data is also decoded and returned as part of the response.Only returned for iOS 6 style transaction receipts for auto-renewable subscriptions.
21007 This receipt is from the test environment, but it was sent to the production environment for verification. Send it to the test environment instead.
21008 This receipt is from the production environment, but it was sent to the test environment for verification. Send it to the production environment instead.
 

苹果官方文档:https://developer.apple.com/library/ios/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html

扫描二维码推送至手机访问。

版权声明:本文由知了博客发布,如需转载请注明出处。

本文链接:https://www.webgou.info/?id=603

标签: App Store
分享给朋友:

“AppStore 内购验证的方法” 的相关文章

Android选项卡具体代码编写方式介绍

在对Android操作系统进行相应修改中,我们可以发现,这一系统的编程方式非常简单易懂,方便开发人员实现各种功能需求。在这里就先从Android选项卡的实现来具体了解一下这一系统的编写方式。首先创建Android工程命名自己的Activity为HelloTabWidget在main.xml或者自己定…

Android初体验一

今天,在windows下搭建Android开发环境,步聚比较简洁。昨晚在自已电脑上,由于ADSL网速原因,安装ADT时卡住了,今天在公司很快就搞定了:1.安装android sdk 2.下载安装eclipse ADT 3.调试其中的例子,运行AVD查看效果...…

VC/MFC 临界区使用方法事例

    临界区的作用:避免临界区内的数据(一般为共享的资源)被不同的线程同时访问,实现线程的同步操作。保证只能由先进入临界区的一个线程访问结束后,其他线程才可以继续访问共享的资源。 以下为临界区的使用方法: *.h头文件: #include <winbase.h&…

作 业

作业对象:组合进程,单独操作,限制进程 通常,必须将一组进程当作单个实体来处理。例如,当让Microsoft Developer Studio为你创建一个应用程序项目时,它会生成C l . e x e,C l . e x e则必须生成其他的进程(比如编译器的各个函数传递)。如果用户想要永远停止该应用…

DirectShow编程(2)- 开始DirectShow旅程

2. 开始DirectShow旅程    这个章节的内容主要是编写DirectShow应用所需的一些基本概念,可以把它当作一个高级介绍,理解这些内容只需具备一般的编程和有关多媒体的知识。2.1. 设置DirectShow开发的编译环境   …

ubuntu 软件更新源收藏

1.sudo gedit /etc/apt/sources.list 编辑你的源列表,将原来的内容全部删除,添加下面列表中最适合你的源(注意不要全部添加),选择一个最合适你的即可,复制到你的列表中,然后保存列表。…

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。