-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvalidate.php
More file actions
54 lines (42 loc) · 1.21 KB
/
validate.php
File metadata and controls
54 lines (42 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
$hex = $_POST['receipt'];
$testing = $_POST['testing'];
$password = "Your Shared Secret Key Here";
echo $hex;
if ($testing == 1)
$url = 'https://sandbox.itunes.apple.com/verifyReceipt';
else
$url = 'https://buy.itunes.apple.com/verifyReceipt';
$postData = json_encode
(
array(
'receipt-data' => $hex,
'password' => $password,
)
);
// If Json is not installed in your server, You can comment out the lines which use json_encode and
// include the following lines instead
// $postData = '{"receipt-data":"'.$hex.'","password":"'.$password.'"}';
function do_post_request($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
$response = do_post_request($url, $postData);
echo $response;
?>