PHP 服务器端代码,
首先要确 php的 curl 和 SSL (open_ssl)这两个模块开启,可以在 php.ini 中去掉 这两个dll前面的分号。
-
-
-
function getReceiptData($receipt, $isSandbox = false)
-
{
-
if ($isSandbox) {
-
$endpoint = '';
-
}
-
else {
-
$endpoint = '';
-
}
-
-
$postData = json_encode(
-
array('receipt-data' => $receipt)
-
);
-
-
$ch = curl_init($endpoint);
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-
curl_setopt($ch, CURLOPT_POST, true);
-
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
-
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
-
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
-
-
-
$response = curl_exec($ch);
-
$errno = curl_errno($ch);
-
$errmsg = curl_error($ch);
-
curl_close($ch);
-
-
if ($errno != 0) {
-
throw new Exception($errmsg, $errno);
-
}
-
-
$data = json_decode($response);
-
-
if (!is_object($data)) {
-
throw new Exception('Invalid response data');
-
}
-
-
if (!isset($data->status) || $data->status != 0) {
-
throw new Exception('Invalid receipt');
-
}
-
-
-
return array(
-
'quantity' => $data->receipt->quantity,
-
'product_id' => $data->receipt->product_id,
-
'transaction_id' => $data->receipt->transaction_id,
-
'purchase_date' => $data->receipt->purchase_date,
-
'app_item_id' => $data->receipt->app_item_id,
-
'bid' => $data->receipt->bid,
-
'bvrs' => $data->receipt->bvrs
-
);
-
}
-
-
-
$receipt = $_GET['data'];
-
$isSandbox = true;
-
-
try
-
{
-
$info = getReceiptData($receipt, $isSandbox);
-
-
switch($info['product_id']){
-
case 'com.application.xxxxx.xxxx':
-
Header("Location:xxxx.zip");
-
break;
-
}
-
}
-
-
catch(Exception $e)
-
{
-
echo 'Message: ' .$e->getMessage();
-
}
-
?>
-
阅读(2242) | 评论(0) | 转发(0) |