PHP PayPal API changes



我正在使用PHP代码(下图(,但停止工作。PayPal改变了什么吗?它不再起作用了。

print_r($res(给出:

网址无效 请求的 URL "[无 URL]" 无效。 参考 #9.67ac1002.1539939948.1d3bb0b6

向PayPal付款工作正常,PayPal返回到成功的页面 URL 正常。

<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';
$tx_token = $_GET['tx'];
$auth_token = "my_very_long_token_goes_here";
$req .= "&tx;=$tx_token&at;=$auth_token";

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0rn";
$header .= "Content-Type: application/x-www-form-urlencodedrn";
$header .= "Content-Length: " . strlen($req) . "rnrn";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
// read the body data
$res = '';
$headerdone = false;
while (!feof($fp)) {
$line = fgets ($fp, 1024);
if (strcmp($line, "rn") == 0) {
// read the header
$headerdone = true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}
// parse the data
$lines = explode("n", $res);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
$firstname = $keyarray['first_name'];
$lastname = $keyarray['last_name'];
$itemname = $keyarray['item_name'];
$amount = $keyarray['mc_gross'];
echo ("
Thank you for your purchase!
");

echo ("Payment Details
n");
echo ("<li>Name: $firstname $lastname</li>n");
echo ("<li>Item: $itemname</li>n");
echo ("<li>Amount: $amount</li>n");
echo ("");
}
else if (strcmp ($lines[0], "FAIL") == 0) {
// log for manual investigation
}

}

fclose ($fp);

?>

添加主机标头

$header .= "POST /cgi-bin/webscr HTTP/1.0rn";
$header .= "Host: www.sandbox.paypal.comrn";
$header .= "Content-Type: application/x-www-form-urlencodedrn";
$header .= "Content-Length: " . strlen($req) . "rnrn";

大约在 9 月 7 日,PayPal 将他们的 API 移到了需要主机标头的 Akamai CDN 后面,但没有告诉任何人,也没有更新他们的所有文档。

最新更新