在集成paypal时不能收到IPN

恰好 2012-08-10 04:36:04
1. 采用标准集成的方式,按钮进行支付(已经成功)
2. return 能收到。
3. IPN不能收到。。。但是在卖家账号设置里可以看到ipn已经发出去了。
4. sandbox环境

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="abc@qq.com" />
<input name="item_name" value="Widget" />
<input name="amount" value="1"/>
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="return" value="http://www.abc.com">
<input type="hidden" name="notify_url" value="http://www.abc.com/notify.php">
<input type="submit" name="button" id="button" value="pay now" />
</form>


<?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.paypal.com', 80, $errno, $errstr, 30);
//将 POST 变量记录在本地变量中
//该付款明细所有变量可参考:
//https://www.paypal.com/IntegrationCenter/ic_ipn-pdt-variable-reference.htm
$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) {

@$fp = fopen("aaa.txt","w");
if(!$fp){
echo "system error";
exit();
}else {
fwrite($fp,"完成");
fclose($fp);
}

//检查付款状态
//检查 txn_id 是否已经处理过
//检查 receiver_email 是否是您的 PayPal 账户中的 EMAIL 地址
//检查付款金额和货币单位是否正确
//处理这次付款,包括写数据库
}else if (strcmp ($res, "INVALID") == 0) {
//未通过认证,有可能是编码错误或非法的 POST
@$fp = fopen("bbb.txt","w");
if(!$fp){
echo "system error";
exit();
}else {
fwrite($fp,"有错");
fclose($fp);
}


}
}
fclose ($fp);
}
?>
...全文
390 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
paypalwilling 2012-09-04
  • 打赏
  • 举报
回复
为什么不找一个顾问呢 我们可以申请技术协助的。

QQ 185922973
peace_d641 2012-08-14
  • 打赏
  • 举报
回复

//session_start();

$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$url='https://www.paypal.com/cgi-bin/webscr';
$curl_result=$curl_err='';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
curl_setopt($ch, CURLOPT_HEADER , 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 3000);

$curl_result = @curl_exec($ch);
$curl_err = curl_error($ch);
curl_close($ch);


$mc_gross = $_POST['mc_gross'];


剩下的你就知道该怎么弄了。。
paypal_Charles 2012-08-13
  • 打赏
  • 举报
回复
我这里有一个文档,你加我Q 1137842635 我发你
paypal_Charles 2012-08-13
  • 打赏
  • 举报
回复
我这里有一份文档,里面有太多的太多的,API,IPN,sandbox环境等。 你加下我QQ1137842635
helloyou0 2012-08-10
  • 打赏
  • 举报
回复
notify_url必须能让paypal那边访问到, 所以不能在内网里,无需用户验证...等等
黄袍披身 2012-08-10
  • 打赏
  • 举报
回复
这个需要payp专员来联系你咯,相信很快就有了。
PP_IPN_PDT_Guide_CHN.pdf PaypalIPN和PDT变量对照表(中文版) Instant Payment Notification (即付款通知) & Payment Data Transfer (付款数据传输) 说明 目录 1 付款数据传输 PDT.....................................................................................................................3 1.1 什么是PDT........................................................................................................................3 1.2 如何启用PDT...................................................................................................................3 1.3 PDT 示例代码....................................................................................................................6 1.3.1 PDT for PHP 示例代码...........................................................................................6 1.3.2 PDT for ASP 示例代码............................................................................................7 2 即付款通知 IPN ....................................................................................................................10 2.1 什么是即付款通知 IPN .............................................................................................10 2.2 如何启用IPN? ..............................................................................................................11 2.3 通知确认 - 给PayPal 的HTTPS 回发.........................................................................12 2.4 处理IPN 的示例代码.....................................................................................................13 2.4.1 IPN for JAVA 示例代码........................................................................................13 2.4.2 IPN for Perl 示例代码..........................................................................................14 2.4.3 IPN for PHP 示例代码.........................................................................................16 2.4.4 IPN for ASP/VBScript 示例代码.........................................................................17 2.4.5 IPN for .NET/VB 示例代码.................................................................................18 2.4.6 IPN for .NET/C# 示例代码..................................................................................19 3 集成PayPal 建议........................................................................................................................21 4 附录5:IPN 和PDT 变量列表.................................................................................................21

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧