【问题标题】:Simulate Paypal html button POST request in php在php中模拟Paypal html按钮POST请求
【发布时间】:2018-11-22 09:25:47
【问题描述】:

我想在 php 中向 paypal 发送 POST 请求,模拟立即付款 html 按钮,发生的情况是我将 standard html 表单发布到我的实时服务器(nginx)上的 php 文件,添加一些 Variable 并发送 POST请求,我期待用户重定向到贝宝网站,但我得到没有错误的空白页面

 <?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();

【问题讨论】:

    标签: php curl nginx paypal


    【解决方案1】:

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

    如果您对这篇文章仍有疑问,请查看 curl_exec 的结果,我们会从那里解决问题。

    【讨论】:

      猜你喜欢
      • 2011-01-01
      • 2012-01-10
      • 2012-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-08
      • 2021-06-13
      相关资源
      最近更新 更多