IAP verification.

Source: Internet
Author: User

-(BOOL) Putstringtoitunes: (nsdata*) iapdata{//The transactionreceipt of the user's successful purchase

Base64encodedstring

NSSTRING*ENCODINGSTR = [Iapdata base64encoding];

NSString *[email protected] "https://sandbox.itunes.apple.com/verifyReceipt";

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

Nsmutableurlrequest *request = [[Nsmutableurlrequest alloc] init];//autorelease];

[Request Seturl:[nsurl Urlwithstring:url];

[Request sethttpmethod:@ "POST"];

Set ContentType

[Request addvalue:@ "Application/json" forhttpheaderfield:@ "Content-type"];

Set Content-length

[Request setvalue:[nsstring stringwithformat:@ "%d", [encodingstr length]] forhttpheaderfield:@ "content-length"];

nsdictionary* BODY = [Nsdictionary dictionarywithobjectsandkeys:encodingstr, @ "Receipt-data", nil];

Sbjsonwriter *writer = [Sbjsonwriter new];

[Request Sethttpbody:[[body Jsonrepresentation] datausingencoding:nsasciistringencoding AllowLossyConversion:YES] ;

[Request Sethttpbody:[[writer Stringwithobject:body] Datausingencoding:nsasciistringencoding Allowlossyconversion:yes]];

Nshttpurlresponse *urlresponse=nil;

Nserror *errorr=nil;

NSData *receiveddata = [Nsurlconnection sendsynchronousrequest:request

Returningresponse:&urlresponse

error:&errorr];

Analytical

NSString *results=[[nsstring alloc]initwithbytes:[receiveddata bytes] length:[receiveddata length] Encoding: Nsutf8stringencoding];

Debuglog (@ "-results-%@", results);

Nsdictionary*dic = [Results jsonvalue];

if ([[DiC objectforkey:@ "status"] intvalue]==0) {//note, [email protected] "0" is the verification receipt successful

return true;

}

return false;

}

This validation is not recommended for clients and should be done by the server.

But my side of the situation is the service-side verification is always unsuccessful, in order to prove that I passed his credentials no problem, find this method, prove that I pass the voucher no problem.

IAP verification.

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.