完整的内购
创建App ID,并开启服务
添加Provisioning Profile
检查Provisiong Profile包含的服务内容
检查本地的Profile是否包含所需要的权限security cms -D -i /path/to/iOSTeamProfile.mobileprovision
安装Profile到Xcode
检查Xcode本地Provisioning Profile文件库
在Xcode里设置Provisioning Profile文件
检查编译出来的App是否包含正确的权限$ codesign -d --ent :- /path/to/the.app
应用自身的签名,内置的Profile
提交到苹果商店前检查权限设置
购买完成
在网络中传输数据,大多情况下是传输的是BASE64编码的字符串而不是二进制数据
BASE64 常用的编码方案,通常用于数据传输,以及加密算法的基础算法,传输过程中能够保证数据传输的稳定性
BASE64是可以编码和解码
file:///private/var/mobile/Containers/Data/Application/889C428B-1F0E-4ED2-A5CB-8E026087C97C/StoreKit/sandboxReceipt
https://sandbox.itunes.apple.com/verifyReceipt
file:///private/var/mobile/Containers/Data/Application/D2603752-19D1-43EE-A649-E4F828716E6F/StoreKit/sandboxReceipt
file:///private/var/mobile/Containers/Data/Application/32EC05B9-E188-490F-8B95-EF41F5CD9A69/StoreKit/sandboxReceipt
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL]; //交易完成后,会将凭据存放在该地址
NSData *receiptDataOnLocal = [NSData dataWithContentsOfURL:receiptURL]; // 从沙盒中获取到购买凭据
NSURL *url = [NSURL URLWithString:SANDBOX]; //对购买凭据进行验证
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0f];
request.HTTPMethod = @"POST";
NSString *encodeStr = [receiptDataOnLocal base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
NSString *payload = [NSString stringWithFormat:@"{\"receipt-data\" : \"%@\"}", encodeStr];
NSData *payloadData = [payload dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPBody = payloadData;
NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
if (result == nil)
{
NSLog(@"验证失败");
}
else
{
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:result options:NSJSONReadingAllowFragments error:nil];
NSLog(@"%@", dict);
if (dict != nil)
{
// bundle_id、application_version、product_id、transaction_id
NSLog(@"验证成功");
NSLog(@"bundle_id:%@ , application_version:%@", dict[@"receipt"][@"bundle_id"], dict[@"receipt"][@"application_version"]);
NSDictionary *dict1 = [dict[@"receipt"][@"in_app"] firstObject];
NSLog(@"product_id:%@ , transaction_id:%@", dict1[@"product_id"], dict1[@"transaction_id"]);
}
}
收据验收结果:
Printing description of jsonResponse:
{
environment = Sandbox;
receipt = {
"adam_id" = 0;
"app_item_id" = 0;
"application_version" = 1;
"bundle_id" = "com.51qiniu.pay";
"download_id" = 0;
"in_app" = (
{
"is_trial_period" = false;
"original_purchase_date" = "2016-11-16 02:37:07 Etc/GMT";
"original_purchase_date_ms" = 1479263827000;
"original_purchase_date_pst" = "2016-11-15 18:37:07 America/Los_Angeles";
"original_transaction_id" = 1000000250893517;
"product_id" = "com.51qiniu.pay.6coins";
"purchase_date" = "2016-11-16 02:37:07 Etc/GMT";
"purchase_date_ms" = 1479263827000;
"purchase_date_pst" = "2016-11-15 18:37:07 America/Los_Angeles";
quantity = 1;
"transaction_id" = 1000000250893517;
}
);
"original_application_version" = "1.0";
"original_purchase_date" = "2013-08-01 07:00:00 Etc/GMT";
"original_purchase_date_ms" = 1375340400000;
"original_purchase_date_pst" = "2013-08-01 00:00:00 America/Los_Angeles";
"receipt_creation_date" = "2016-11-16 02:37:07 Etc/GMT";
"receipt_creation_date_ms" = 1479263827000;
"receipt_creation_date_pst" = "2016-11-15 18:37:07 America/Los_Angeles";
"receipt_type" = ProductionSandbox;
"request_date" = "2016-11-16 02:37:18 Etc/GMT";
"request_date_ms" = 1479263838800;
"request_date_pst" = "2016-11-15 18:37:18 America/Los_Angeles";
"version_external_identifier" = 0;
};
status = 0;
}
1、是否在打开IAP以后重新生成过包含IAP许可的provisioning profile
2、是否重新导入了新的包含IAP的provisioning profile?建议在Organizer中先删掉原来设备上的老的provisioning profile
3、是否在运行应用前将设备上实际的Apple ID登出了?建议在设置->iTunes Store和App Stroe中将使用中的Apple ID登出,以未登录状态进入应用进行测试