【问题标题】:Paypal PDT curl request errorPaypal PDT curl 请求错误
【发布时间】:2016-06-18 10:50:47
【问题描述】:

下面是我使用 paypal PDT 的 paypal 接收文件的代码

<?php

  $tx = $_GET['tx'];
  $ID = $_GET['cm'];
  $amount = $_GET['amt'];
  $currency = $_GET['cc'];
  $auth = "#####";

  // Init cURL
  $ch = curl_init(); 

  // Set request options
  $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
  $fields = array(
      'cmd' => '_notify-synch',
      'tx' => $tx,
      'at' => $auth
  );
  curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');
  curl_setopt($ch,CURLOPT_URL, $url);
  curl_setopt($ch,CURLOPT_POST, count($fields));
  curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($fields));
  curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch,CURLOPT_HEADER, FALSE);

  // Execute request and get response and status code
  $response = curl_exec($ch);
  $status   = curl_getinfo($ch, CURLINFO_HTTP_CODE);

  // Close connection
  curl_close($ch);
  print_r($response);
  if($status == 200 AND strpos($response, 'SUCCESS') === 0)
  {
      //wp_redirect(home_url('/account'));
      exit;
  } else {
     // wp_redirect(home_url());
      exit;
  }
?>

我已经尝试了很多次了..但它仍然抛出错误...我有 测试服务器的 curl 及其与其他文件的工作......任何人都可以 知道为什么这不起作用

每当我尝试 print_r th 响应时..它是空的并且什么都不显示

【问题讨论】:

  • "它仍然抛出错误" -> 如果您不提供错误,我们将无法提供帮助?
  • 它抛出了什么错误?使用curl_errors() 获取更多详细信息。仅供参考,最好使用Guzzle 而不是普通的curl。它将使您免于调试。
  • 对不起,让我澄清一下……它什么也没显示……我的意思是绝对没有……即使我打印了响应。在 print_r 上显示为 0
  • 0 == false - 您的请求不成功。检查return values
  • @LukasHajdu 我有 print_r 响应和它的空..我的意思是什么都没有打印

标签: php curl paypal


【解决方案1】:

恢复对话:

  $tx = $_GET['tx'];
  $ID = $_GET['cm'];
  $amount = $_GET['amt'];
  $currency = $_GET['cc'];
  $auth = "#####";

  // Init cURL
  $ch = curl_init(); 

  // Set request options
  $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
  $fields = array(
      'cmd' => '_notify-synch',
      'tx' => $tx,
      'at' => $auth
  );
  curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, 6);   //force TLS 1.2
  curl_setopt($ch,CURLOPT_CAINFO, realpath('cacert.pem'));
  curl_setopt($ch,CURLOPT_URL, $url);
  curl_setopt($ch,CURLOPT_POST, count($fields));
  curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($fields));
  curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
  curl_setopt($ch,CURLOPT_HEADER, FALSE);

  // Execute request and get response and status code
  $response = curl_exec($ch);
  $status   = curl_getinfo($ch, CURLINFO_HTTP_CODE);

  // Close connection
  curl_close($ch);
  print_r($response);
  if($status == 200 AND strpos($response, 'SUCCESS') === 0)
  {
      //wp_redirect(home_url('/account'));
      exit;
  } else {
     // wp_redirect(home_url());
      exit;
  }
?>

【讨论】:

  • 我不知道如何解决,但错误已解决..我只是把 cecert 文件的绝对路径....现在 curl 响应正确来了...谢谢大家的支持。对不起,迟到的消息...:)
  • 我很高兴它终于为你工作了!有一个好的开发者!如果有一个答案可以提供很好的更正,请不要忘记接受它以帮助社区。​​span>
猜你喜欢
  • 2015-11-28
  • 2018-12-23
  • 2016-04-28
  • 2016-06-02
  • 1970-01-01
  • 2017-12-29
  • 2014-05-28
  • 2012-08-02
  • 1970-01-01
相关资源
最近更新 更多