Posted on 2007-05-24 09:49
my 阅读(493)
评论(0) 编辑 收藏 所属分类:
PayPal
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';
$tx_token = $_GET['tx'];
$payer_email;
$receiver_email;
$item_number;
$auth_token = "i6QuA8_x0tzxn1EGSCSZQzvrVQvm0DjwF6JJcLBis0PcPxS81srjQBKR3wW";
$req .= "&tx=$tx_token&at=$auth_token";
// 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 ('www.paypal.com', 80, $errno, $errstr, 30);
if (!$fp) {
echo "HTTP ERROR";
}
else {
fputs ($fp, $header . $req);
$res = '';
$headerdone = false;
while (!feof($fp)) {
$line = fgets ($fp, 1024);
if (strcmp($line, "\r\n") == 0) {
$headerdone = true;
}
else if ($headerdone)
{
$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);
}
$payer_email = $keyarray['payer_email'];//付款人帐号
$receiver_email = $keyarray['receiver_email'];//收款帐号
$item_number = $keyarray['item_number'];//名称
....还有很多可以参考文档
se if (strcmp ($lines[0], "FAIL") == 0) {
echo "log for manual investigation";
}
}
fclose ($fp);