下列代码为什么在测试付款成功后接收不到paypal的返回变量?我设置的notify_url地址是没有问题的。
<?php
 //从 PayPal 出读取 POST 信息同时添加变量„cmd‟
 $req = 'cmd=_notify-validate';
 foreach ($_POST as $key => $value) {
 $value = urlencode(stripslashes($value));
 $req .= "&$key=$value";
 }
 //建议在此将接受到的信息记录到日志文件中以确认是否收到 IPN 信息
 //将信息 POST 回给 PayPal 进行验证
 $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
 $header .= "Content-Type:application/x-www-form-urlencoded\r\n";
 $header .= "Content-Length:" . strlen($req) ."\r\n\r\n";
 //在 Sandbox 情况下,设置:
 //$fp = fsockopen(„www.sandbox.paypal.com‟,80,$errno,$errstr,30);
$fp = fsockopen(„www.sandbox.paypal.com‟,80,$errno,$errstr,30);  
 //该付款明细所有变量可参考:
 //https://www.paypal.com/IntegrationCenter/ic_ipn-pdt-variable-reference.html
 $item_name = $_POST['item_name'];
 $item_number = $_POST['item_number'];
 $payment_status = $_POST['payment_status'];
 $payment_amount = $_POST['mc_gross'];
 $payment_currency = $_POST['mc_currency'];
 $txn_id = $_POST['txn_id'];
 $receiver_email = $_POST['receiver_email'];
 $payer_email = $_POST['payer_email'];
 //…
 //判断回复 POST 是否创建成功
 if (!$fp) {
 //HTTP 错误
 }else {
 //将回复 POST 信息写入 SOCKET 端口
 fputs ($fp, $header .$req);
 //开始接受 PayPal 对回复 POST 信息的认证信息
 while (!feof($fp)) {
 $res = fgets ($fp, 1024);
 //已经通过认证
 if (strcmp ($res, "VERIFIED") == 0) {
 //检查付款状态
 //检查 txn_id 是否已经处理过
 //检查 receiver_email 是否是您的 PayPal 账户中的 EMAIL 地址
 //检查付款金额和货币单位是否正确
//处理这次付款,包括写数据库
  $items_status=$res;
  $rs = $db->execute("update cquote set itemstatus='$items_status' where ProId=3147"); 
}else if (strcmp ($res, "INVALID") == 0) {
 //未通过认证,有可能是编码错误或非法的 POST 信息
 }
 }
 fclose ($fp);
}
?>

解决方案 »

  1.   

    返回地址是什么?自己手动POST数据过去,看能不能接收到...
      

  2.   

    返回地址就是接受paypal参数的这一页,这地址应当是没有问题的,因为付款结束后这一页的程序确实是执行了,只是不是我要的结果。
      

  3.   

    付款结束后这一页的程序确实是执行了 。。 那paypal已经返回东西了啊。。 你要贴接收返回的php代码
      

  4.   

    我用的不是本地测试,是上传到FileZilla上进行的测试,我把返回结果插入到数据库中没有得到任何的值,帮帮忙,现在急用啊
      

  5.   

    没有得到值就是没返回东西囖~~~把你提交的form表单贴出来看看吧
      

  6.   

    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_blank" id="book1"> <input type="hidden" name="item_name2" value="物品" /> <input type="hidden" name="amount" value="20"> 
    <input type="hidden" name="quantity" value="1">  
    <input type="hidden" name="cmd" value="_xclick">  
    <input type="hidden" name="add" value="1">  
    <input type="hidden" name="business" value="[email protected]">   
    <input type="hidden" name="cancel_return" value="http://www.baidu.com">  
    <input type="hidden" name="lc" value="US">   
    <input type="hidden" name="item_name" value="<?php echo $projectname;?>">  
    <input type="hidden" name="amount" value="20">  
    <input type="hidden" name="currency_code" value="USD"> 
    <input type="hidden" name="return" value="http://www.transally.com">  
    <input type="hidden" name="no_note" value="1">  
    <input type="hidden" name="no_shipping" value="1"> 
    <input type="hidden" name="rm" value="2">  
    <input type="hidden" name="item_number" value="20">   
    <input type="hidden" name="cbt" value="click to complete"/>
    <input type="hidden" name="notify_url" value="http://test.transally.com/nancy/transally/cn/paypalsecurity.php">       
      

  7.   

    表单无问题...访问这个链接notify_url是否需要什么权限,自己手动POST数据看能不能接收到.
      

  8.   

    你这里说的连接权限是什么意思啊?是要在paypal商家账户里进行设置么?之前在他们提供的帮助文档里没有看到要进行什么设置。
      

  9.   

    我记得上次用$fp = fsockopen(„www.sandbox.paypal.com‟,80,$errno,$errstr,30); 没有成功,
    后来改为$fp =@fsockopen("ssl://www.sandbox.paypal.com","443",$err_num,$err_str,30); 才可以,
    如果有问题可以用写文件的方式进行调试。
    另外ipn功能需要到paypal网站上设置url。
    好像信用卡的货币跟支付货币不一样的话,用sandbox总是会返回pending状态。
      

  10.   

    直接用你的demo代码来支付试试.
      

  11.   


    我也遇到pending,我是在付款的时候没有选择地址,就是地址显示了,但是我没有勾选,之后勾选了,就是completed了。你看看是不是这个原因