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

AppStore 内购验证的方法

webgou10年前 (2017-02-28)编程开发298

 

 

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 内购验证的方法” 的相关文章

flex builder 3 debug

安装flex builder 3需要调试,那就需要下载调试的flash player ,并且要跟浏览器相对应的调试版本 。设置先项如下面: [IMG]zb_users/upload/legacy-upload/flexbuilderie.JPG[/IMG]…

Audio 组成

Audio 组成0.直接操作Mixer API 速度会比 waveform audio api速度要快1.Mixer api 控件范围要比waveform audio api 要快.2.Mixer api灵活,可以自行控件。…

Windows CE 内存管理

内存管理        如果你在写Windows CE 程序中遇到的最重要的问题,那一定是内存问题。一个WinCE 系统可能只有4MB 的RAM,这相对于个人电脑来说是十分少的,因为个人电脑的标准配置已经到了128MB 甚至更多。事实上,运…

MySQL优化笔记

˂一、查询优化使用EXPLAIN Java代码 1. EXPLAIN tbl_name EXPLAIN tbl_name 返回Field、Type、Null、Key、Default、Extra这几列对应的表中每个字段的值 相当于DESCRIBE tbl_name或SHOW COLUMNS FROM…

Shader 进度条/技能CD特效

用了几天弄明白了这个简单的进度条,不容易。主要是利用了三角函数反正切函数特性,在夹角范围内的值透明度设为0,不在范围内值设成1.对于shader 编辑器,可以用forge 以及amplify.贴上测试代码:// Made with Amplify Shader Editor// Available…

中国网络支付平台

这几天,关于电商京东收购网银在线的新闻所谓铺天盖地,下面也来看看几家比较有名的中国网络支付平台  支付宝建立于2004年,是国内领先的独立第三方支付平台,支付宝致力于为中国电子商务提供“简单、安全、快速”的在线支付解决方案。财付通是腾讯公司创办的中国领先的…

发表评论

访客

看不清,换一张

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