我的网站上集成了PayPal。我的网站上有一张表格,将客户带到PayPal完成付款,然后将其返回到我的网站。然后,我的网站向PayPal发送一个带有PDT交易令牌的请求,这样我就可以进行一些检查,然后用他们购买的产品自动贷记我的客户。
系统使用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账户设置为Business,打开了PDT和IPN以及自动返回
我似乎收到了HTTP错误,但我不能说,如果我记录curl_Error,它只是说",如果我日志curl_errno,我得到0。
我设法解决了这个问题。这是因为我的服务器没有安装ssl证书,一旦我安装了,它就正常工作了。