AppStore method of internal purchase verification

Source: Internet
Author: User

AppStore added a way to validate the in App purchasement, which is that Apple provides a URL address for development testing:

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

Products by:

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

When the purchase is successful, you will get a receipt from Apple (receipt), Apple recommends the method is to send the receipt to the developer's server, the server like the above address post HTTP message, to verify that Apple will return the results. Whether it is a real purchase or a fake purchase.

Small partners without their own servers can be sent using the app, the code below.

#defineItms_sandbox_verify_receipt_url @ "https://Sandbox.itunes.apple.com/verifyreceipt "#pragmamark-verifyfinishedtransaction-(void) Verifyfinishedtransaction: (Skpaymenttransaction *) transaction{if(Transaction.transactionstate = =skpaymenttransactionstatepurchased) {NSString*transactionidentifier =Transaction.transactionidentifier; NSData*transactionreceipt =Transaction.transactionreceipt; //Send Transactionidentifer and encrypted transactionreceipt data to the server sideNSString* Receipent = [NSString stringWithFormat:@"%s", Transactionreceipt.bytes]; NSLog (@"receipent =%@", receipent); //validation on the app, only for testingNSString *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"); }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.