在php

时间:2018-06-12 21:51:36

标签: php curl nginx paypal

我想发送POST请求到PHP中的paypal模拟Pay Now html按钮,发生的是我在我的实时服务器(nginx)上将standard html表格发送到php文件,添加一些Variable并发送POST请求,我期待用户重定向到paypal网站,但我得到空白页,没有错误

 <?php
// PayPal settings
$paypal_email = 'test@me.com';
$return_url = 'https://example.com/payment-successful.html';
$cancel_url = 'https://example.com/payment-cancelled.html';
$notify_url = 'https://example.com/payments.php';

$item_name = 'Test Item';
$item_amount = 10.00;


$querystring = '';
$querystring .= "?business=".urlencode($paypal_email)."&";
$querystring .= "item_name=".urlencode($item_name)."&"; 
$querystring .= "amount=".urlencode($item_amount)."&";
foreach($_POST as $key => $value){
    $value = urlencode(stripslashes($value));
    $querystring .= "$key=$value&";
}
$querystring .= "return=".urlencode(stripslashes($return_url))."&";
$querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
$querystring .= "notify_url=".urlencode($notify_url);

// POST data to paypal 
$ch =curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.sandbox.paypal.com/cgi-bin/webscr");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $querystring);
curl_exec($ch);

curl_close();

1 个答案:

答案 0 :(得分:0)

您需要为curl_exec调用分配一个变量,并对此变量执行var_dump以查看发生了什么。空白页面听起来很合适。

如果你仍然对这篇文章有疑问,那就是curl_exec的结果,我们会从那里弄清楚。