简体   繁体   English

贝宝PDT卷曲请求错误

[英]Paypal PDT curl request error

Below is the code for my paypal receive file for using paypal PDT 以下是我使用贝宝PDT的贝宝接收文件的代码

<?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;
  }
?>

I have tried many times now..but it is still throwing error...i have tested server for curl and its working with other file...can anyone has any idea why this is not working 我已经尝试了很多次..但是它仍然抛出错误...我已经测试了服务器的curl及其与其他文件的关系...任何人都可以知道为什么这不起作用

Whenever i try to print_r th response ..its empty and show nothing 每当我尝试print_r th响应..它为空并且什么也不显示时

To resume the conversation : 要恢复对话:

  • You have to use realpath() on your cert to be sure it finds it. 您必须在证书上使用realpath()才能确保找到它。
  • Since 17th June 2016, Paypal upgraded its API. 自2016年6月17日起,Paypal对其API进行了升级。 You have to use TLS 1.2 now (CURLOPT_SSL_VERIFYHOST = 6 for cURL use) (see more here : https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US ) 您必须立即使用TLS 1.2(用于cURL的使用CURLOPT_SSL_VERIFYHOST = 6)(在此处查看更多信息: https ://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US)

  $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;
  }
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM