我目前正在尝试使用服务器端验证(在 PHP 中)通过 AppStore 验证我的应用内购买收据。
这是我的代码:
// ViewController.m:
NSString *receiptDataString = [[NSString alloc] initWithData:[transaction transactionReceipt] encoding:NSUTF8StringEncoding];
NSString *verificationDataString = [NSString stringWithFormat:@"receiptData=%@", receiptDataString];
NSData *verificationData = [NSData dataWithBytes:[verificationDataString UTF8String] length:[verificationDataString length]];
NSMutableURLRequest *verificationRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://update.csundm.de/inapp/verifyReceipt.php"]];
[verificationRequest setHTTPMethod:@"POST"];
[verificationRequest setHTTPBody:verificationData];
NSData *verificationResultData = [NSURLConnection sendSynchronousRequest:verificationRequest returningResponse:nil error:nil];
NSString *verificationResultString = [[NSString alloc] initWithData:verificationResultData encoding:NSUTF8StringEncoding];
NSLog(@"%@", verificationResultString);
********************************************************
// verifyReceipt.php:
$receiptData = $_POST["receiptData"];
$receiptDataEncoded = base64_encode($receiptData);
$receiptJSONString = json_encode(Array("receipt-data" => $receiptDataEncoded));
$contextData = array (
"method" => "POST",
"header" => "Connection: close\r\n".
"Content-Length: ".strlen($receiptJSONString)."\r\n",
"content" => $receiptJSONString);
$context = stream_context_create (array ( 'https' => $contextData ));
$result = file_get_contents ("https://sandbox.itunes.apple.com/verifyReceipt", false, $context);
$jsonResult = json_decode($result);
if ($jsonResult -> {"status"} != 0) {
echo "Receipt invalid: ".$result;
}
else {
echo "Receipt valid";
}
不幸的是,我收到 »Receipt invalid: {"status":21000}« 谁能想象问题出在哪里?我什至无法在互联网上找到有关此错误代码的信息。我发现了一个错误描述,但他们说这仅适用于不可更新的订阅。
非常感谢,致以诚挚的问候,朱利安