Вот сделал, проблема была в base64. После генерации Base64 надо заменить символы: base64encodedReceipt.replacingOccurrences(of: "+", with: "%2B")
let receiptUrl: URL = Bundle.main.appStoreReceiptURL!
var receipt: Data?
receipt = try! NSData.init(contentsOf: receiptUrl) as Data
print(receipt)
var base64encodedReceipt: String = receipt!.base64EncodedString()
base64encodedReceipt = base64encodedReceipt.replacingOccurrences(of: "+", with: "%2B")
let vkUrl = URL(string: "test.php")
var request = URLRequest(url: vkUrl!)
let postString: String = "receipt-data=" + base64encodedReceipt
request.httpBody = postString.data(using: String.Encoding.utf8);
request.httpMethod = "POST"
request.addValue("\(postString.count)", forHTTPHeaderField: "Content-Length")
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-type")
URLSession.shared.dataTask(with: request) {(data, response, error) in
guard let data = data else {
let error_code = String(error!._code)
let error_description = String(error!.localizedDescription)
let error_msg = "Ошибка соединения. Пожалуйста, попробуйте позже. \n Если ошибка будет повторяться, то сообщите в службу поддержки приложения. \n Код ошибки: " + error_code + " \n Описание ошибки: \n" + error_description
let alertVC = UIAlertController(title: "Ошибка", message: error_msg, preferredStyle: .alert)
let actionOK = UIAlertAction(title: "OK", style: .default)
alertVC.addAction(actionOK)
DispatchQueue.main.async(execute: {
self.present(alertVC, animated: true, completion: nil)
})
return
}
do {
json = data
k = true
}
}.resume()
Скрипт для серва.
<?php
$json['receipt-data'] = $_POST['receipt-data'];
$post = json_encode($json);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://buy.itunes.apple.com/verifyReceipt");
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;
?>