Php 真的对贝宝付款感到困惑吗

Php 真的对贝宝付款感到困惑吗,php,paypal,paypal-ipn,paypal-sandbox,Php,Paypal,Paypal Ipn,Paypal Sandbox,更新1: 将$res写入文本文件只会返回单词VERIFIED: <?php /* mysql_connect("localhost", "user", "password") or die(mysql_error()); mysql_select_db("PayPal") or die(mysql_error()); */ // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-val

更新1:

$res
写入文本文件只会返回单词
VERIFIED

<?php  
/*  
mysql_connect("localhost", "user", "password") or die(mysql_error());  
mysql_select_db("PayPal") or die(mysql_error());  
*/

// read the post from PayPal system and add 'cmd'  
$req = 'cmd=_notify-validate';  
foreach ($_POST as $key => $value) {  
$value = urlencode(stripslashes($value));  
$req .= "&$key=$value";  
}  
// post back to PayPal system to validate  
$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";  

$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);  

if (!$fp) {  
// HTTP ERROR  
} else {  
fputs ($fp, $header . $req);  
while (!feof($fp)) {  
$res = fgets ($fp, 1024);  
if (strcmp ($res, "VERIFIED") == 0) {  

$ourFileName = "payment_successful.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $res);
fclose($ourFileHandle);


}  

else if (strcmp ($res, "INVALID") == 0) {  

$ourFileName = "payment_failed.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fwrite($ourFileHandle, $res);
fclose($ourFileHandle);

}  
}  
fclose ($fp);  
}  
?> 

答案在通用脚本中

Paypal将在字符串中返回单词VERIFIED或INVALID

($res, "VERIFIED") == 0
一个很好的技巧是将$res的值写入日志,您将在末尾看到返回的结果

确保您也使用沙箱进行测试

还有一个论坛在(他们花了多少钱买这个域名?)


FWIW,Paypal的IPN是一个PITA。

嗨,我是这样实现我的IPN的

foreach ($_POST as $key => $value)
{
    $data[$key] = $value;
}

执行echo
“是否可以将$res的内容写入正在创建的文件中,因为我认为这是由paypal发起的页面,因此很难回显内容。你不能回显内容,或者更好,你可以,但谁在乎呢?IPN事务是server2server,因此只有服务器才会看到回音,您必须将其写入日志文件或数据库中,注意PayPal IPN以一种方式向您发送数据,并希望以相同的方式返回数据,或者更好:PayPal send to you var1=res1&var2=res2&var3=res3,您不能以var2=res2&var1=res1&var3=res3的形式将其发送回,你必须尊重秩序。。。好吧,当我写我自己的IPN时,我遇到了很多麻烦,因为在我看来,$\u POST[]不尊重数据顺序,所以我直接阅读php://input@MiPnamic,我将$res的内容写入一个文件,它只包含VARIFIED这个词。我不知道如何通过上面的IPN文件找出paypal正在确认的付款,这样我就可以在我的数据库中更新正确的记录。我已经更新了上面的问题,以显示将$res中的数据写入文本文件的当前代码。foreach($\u POST as$key=>$value){$value=urlencode(stripslashes($value));$req.=“&$key=$value”;}如您所见,这将通过$\u POST变量获取数据,因此如果您想跟踪付款(并且您“必须”这样做)你需要在某处写下$\u POST内容,在那里存储有关付款的信息。不管怎样,我知道paypal返回了什么。
cmd=_notify-validate
test_ipn=1
payment_type=echeck
payment_date=22:21:28 Mar 24, 2011 PDT
payment_status=Completed
address_status=confirmed
payer_status=verified
first_name=John
last_name=Smith
payer_email=buyer@paypalsandbox.com
payer_id=TESTBUYERID01
address_name=John+Smith
address_country=United+States
address_country_code=US
address_zip=95131
address_state=CA
address_city=San+Jose
address_street=123%2C+any+street
business=seller@paypalsandbox.com
receiver_email=seller@paypalsandbox.com
receiver_id=TESTSELLERID1
residence_country=US
item_name=something
item_number=AK-1234
quantity=1
shipping=3.04
tax=2.02
mc_currency=USD
mc_fee=0.44
mc_gross=12.34
txn_type=web_accept
txn_id=28325521
notify_version=2.1
custom=xyz123
invoice=abc1234
charset=windows-1252
verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AM3F5ODR-2hb2fIsWPHepIEPzAwg
cmd=_notify-validate
test_ipn=1
payment_type=echeck
payment_date=22:21:28 Mar 24, 2011 PDT
payment_status=Completed
address_status=confirmed
payer_status=verified
first_name=John
last_name=Smith
payer_email=buyer@paypalsandbox.com
payer_id=TESTBUYERID01
address_name=John+Smith
address_country=United+States
address_country_code=US
address_zip=95131
address_state=CA
address_city=San+Jose
address_street=123%2C+any+street
business=seller@paypalsandbox.com
receiver_email=seller@paypalsandbox.com
receiver_id=TESTSELLERID1
residence_country=US
item_name=something
item_number=AK-1234
quantity=1
shipping=3.04
tax=2.02
mc_currency=USD
mc_fee=0.44
mc_gross=12.34
txn_type=web_accept
txn_id=28325521
notify_version=2.1
custom=xyz123
invoice=abc1234
charset=windows-1252
verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AM3F5ODR-2hb2fIsWPHepIEPzAwg