dongsi1954 2018-10-19 09:18
浏览 123

PHP PayPal API更改

I was using PHP code (below) but stopped to work. Did Paypal changed something about. It does not work anylonger.

print_r($res) gives this:

Invalid URL The requested URL "[no URL]", is invalid. Reference #9.67ac1002.1539939948.1d3bb0b6

The payment to Paypal works OK, Paypal returns to successfull page URL OK.

 <?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.0
";
$header .= "Content-Type: application/x-www-form-urlencoded
";
$header .= "Content-Length: " . strlen($req) . "

";
$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, "
") == 0) {
// read the header
$headerdone = true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}

// parse the data
$lines = explode("
", $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


");

echo ("<li>Name: $firstname $lastname</li>
");

echo ("<li>Item: $itemname</li>
");

echo ("<li>Amount: $amount</li>
");

echo ("");

}

else if (strcmp ($lines[0], "FAIL") == 0) {

// log for manual investigation

}


}


fclose ($fp);


?>
  • 写回答

1条回答 默认 最新

  • dsdqpdjpq16640651 2018-10-19 13:08
    关注

    add a host header

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

    on about september 7th, paypal moved their api behind akamai cdn, which requires a host header, but didn't tell anyone about it nor update all of their documentation.

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置