php - iOS7 - receipts not validating at sandbox - error 21002 (java.lang.IllegalArgumentException) -


i'm converting app ios6 ios7. before used deprecated transactionreceipt method i'm trying recommended methods retrieve receipt, , encode in base 64:

nsdata *working = [nsdata datawithcontentsofurl:[[nsbundle mainbundle] appstorereceipturl]]; // tried 64 or 76 chars/line , lf or cr line endings nsstring *receipt = [working base64encodedstringwithoptions:kniloptions]; 

the above change in code. below how validate it, no changes:

dispatch_queue_t queue = dispatch_get_global_queue(dispatch_queue_priority_default, 0); dispatch_async(queue,      ^{          nsmutablestring *url = [nsmutablestring string];           [url appendformat:@"%@", web_service];          [url appendformat:@"receipt=%@", receipt];           nsstringencoding encoding;          nserror *error = [nserror new];          nsurl *url = [nsurl urlwithstring:url];          nsstring *json = [nsstring stringwithcontentsofurl:url usedencoding:&encoding error:&error];           // check json , error          // ... code omitted     } 

on server side, php code use verify receipt, no change other trying sandbox error:

// encode json $json = json_encode(array('receipt-data' => $receipt)); // try production first, if doesn't work, try sandbox $working = postjsontourl('https://buy.itunes.apple.com/verifyreceipt', $json, false); error_log('production - '.print_r($working, true)); if (@$working['status'] !== 0) // === 21007)     $working = postjsontourl('https://sandbox.itunes.apple.com/verifyreceipt', $json, true); error_log('sandbox - '.print_r($working, true)); 

this error log output:

production - array\n(\n    [status] => 21002\n    [exception] => java.lang.illegalargumentexception\n)\n sandbox - array\n(\n    [status] => 21002\n    [exception] => java.lang.illegalargumentexception\n)\n 

it looks i'm throwing kinds of exceptions on @ apple!

again difference how receipt retrieved , encoded. has encountered problem , fixed it?

thanks reading.

/yr

as requested, code postjsontourl:

function postjsontourl($url, $json, $disablesslverify = false) {     $resource = curl_init($url);     curl_setopt($resource, curlopt_customrequest, 'post');     curl_setopt($resource, curlopt_postfields, $json);     curl_setopt($resource, curlopt_returntransfer, true);     curl_setopt($resource, curlopt_httpheader, array(         'content-type: application/json',         'content-length: '.strlen($json)));     curl_setopt($resource, curlopt_header, 0);     if ($disablesslverify)     {         curl_setopt($resource, curlopt_ssl_verifyhost, 0);         curl_setopt($resource, curlopt_ssl_verifypeer, 0);     }     //curl_setopt($resource, curlopt_verbose, true);     //curl_setopt($resource, curlopt_stderr, $fp = fopen('/tmp/curl_output'.rand(1000, 9999).'.txt', 'w'));     $contents = json_decode(curl_exec($resource), true);     if (!$contents)         $contents = array();     curl_close($resource);     //fclose($fp);     return $contents; } 

new details after experimenting, have determined sending existing data base 64 encoded encroaching on internal limit. if exceeds internal limit, data isn't sent, fails locally on device, below that, sent. columns are: data format, size of encoded data, whether reached server:

raw receipt data         5k  n/a base64 no options     6.66k  yes base64 76 chars/line  6.75k  no base64 64 chars/line  6.77k  no hex coded               10k  no 

note difference between sending , not sending less 100 bytes.

i've had problem , looked everywhere, including on apple's development forums. apple give couple of stock replies, , that's it. think it's bug on apple's side. validation locally on device work, try convert that. if absolutely must use server side validation, transactionreceipt seems work right now.

the function deprecated, not banned, use , hope apple approves of app. in fact, it's did, fingers crossed, waiting approval.

you can turn off warning in xcode bracketing code this:

#pragma clang diagnostic push #pragma clang diagnostic ignored "-wdeprecated-declarations" // code using transactionreceipt #pragma clang diagnostic pop 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -