码迷,mamicode.com
首页 > 移动开发 > 详细

AppStore 内购验证的方法

时间:2014-05-19 22:22:12      阅读:936      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   c   code   java   

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

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

产品用:

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

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

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

bubuko.com,布布扣
#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");
        }
}
bubuko.com,布布扣

 

AppStore 内购验证的方法,布布扣,bubuko.com

AppStore 内购验证的方法

标签:style   blog   class   c   code   java   

原文地址:http://www.cnblogs.com/dqshll/p/3731386.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!