贝宝集成 HTTP 错误
PayPal Integration HTTP Error
我的网站上集成了 PayPal。我的网站上有一个表格,可以将客户带到 PayPal 以完成付款,然后 returns 他们到我的网站。然后,我的网站将带有 PDT 交易令牌的请求发送回 PayPal,这样我就可以 运行 几张支票,然后将我的客户购买的产品自动记入贷方。
系统使用PHP和cURL发送处理所有这些。
当我使用:"www.sandbox.paypal.com/cgi-bin/webscr"
连同沙箱凭据,一切正常,一切正常。
一旦我将其全部更改为"www.paypal.com/cgi-bin/webscr"
它不起作用,我的代码告诉我请求失败。
我的代码:
$pp_hostname = "www.paypal.com";
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';
$tx_token = $_GET['tx'];
$auth_token = "#######-hashed_out_here-########";
$req .= "&tx=$tx_token&at=$auth_token";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
//set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here,
//if your server does not bundled with default verisign certificates.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname"));
$res = curl_exec($ch);
curl_close($ch);
if(!$res){
$this->twig->error("Request failed.");
}else{
$lines = explode("\n", $res);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i='1'; $i<count($lines);$i++){
$test = explode("=", $lines[$i]);
if(empty($test[1])){
$keyarray[urldecode($test[0])] = '';
}else{
$keyarray[urldecode($test[0])] = urldecode($test[1]);
}
}
//give product
} else if (strcmp ($lines[0], "FAIL") == 0) {
$this->twig->error('Transaction failed!');
}
}
不确定我为什么会遇到问题,所以我不知道如何解决。
我的 PayPal 账户设置为企业账户,开启了 PDT 和 IPN 以及 Auto-Return
我似乎收到了 HTTP 错误,但我不能说,如果我记录 curl_error 它只是说“”,如果我记录 curl_errno 我得到 0。
我设法解决了这个问题。这是因为我的服务器没有安装 ssl 证书,一旦我这样做就可以正常工作。
我的网站上集成了 PayPal。我的网站上有一个表格,可以将客户带到 PayPal 以完成付款,然后 returns 他们到我的网站。然后,我的网站将带有 PDT 交易令牌的请求发送回 PayPal,这样我就可以 运行 几张支票,然后将我的客户购买的产品自动记入贷方。
系统使用PHP和cURL发送处理所有这些。
当我使用:"www.sandbox.paypal.com/cgi-bin/webscr"
连同沙箱凭据,一切正常,一切正常。
一旦我将其全部更改为"www.paypal.com/cgi-bin/webscr"
它不起作用,我的代码告诉我请求失败。 我的代码:
$pp_hostname = "www.paypal.com";
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';
$tx_token = $_GET['tx'];
$auth_token = "#######-hashed_out_here-########";
$req .= "&tx=$tx_token&at=$auth_token";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
//set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here,
//if your server does not bundled with default verisign certificates.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname"));
$res = curl_exec($ch);
curl_close($ch);
if(!$res){
$this->twig->error("Request failed.");
}else{
$lines = explode("\n", $res);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i='1'; $i<count($lines);$i++){
$test = explode("=", $lines[$i]);
if(empty($test[1])){
$keyarray[urldecode($test[0])] = '';
}else{
$keyarray[urldecode($test[0])] = urldecode($test[1]);
}
}
//give product
} else if (strcmp ($lines[0], "FAIL") == 0) {
$this->twig->error('Transaction failed!');
}
}
不确定我为什么会遇到问题,所以我不知道如何解决。 我的 PayPal 账户设置为企业账户,开启了 PDT 和 IPN 以及 Auto-Return
我似乎收到了 HTTP 错误,但我不能说,如果我记录 curl_error 它只是说“”,如果我记录 curl_errno 我得到 0。
我设法解决了这个问题。这是因为我的服务器没有安装 ssl 证书,一旦我这样做就可以正常工作。