免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2359 | 回复: 1
打印 上一主题 下一主题

求教paypal支付后的验证 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-04-08 11:08 |只看该作者 |倒序浏览
Paypal交易成功后会post数据到你提交的IPN设置的页面,此页面的程序就可以按照数据判断交易的情况来更新定单状态或者发邮件给客户。

PHP代码:--------------------------------------------------------------------------------

<?
// 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 .= "OST /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);

// assign posted variables to local variables
$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'];

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED" == 0) {
// 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
}
else if (strcmp ($res, "INVALID" == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>;

--------------------------------------------------------------------------------


这段是第一次得到的code sample


PHP代码:--------------------------------------------------------------------------------

<?php
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-synch';

$tx_token = $_GET['tx'];
$auth_token = "GX_sTf5bW3wxRfFEbgofs88nQxvMQ7nsI8m21rzNESnl_79ccFTWj2aPgQ0";
$req .= "&tx=$tx_token&at=$auth_token";

// post back to PayPal system to validate
$header .= "OST /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 possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.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, "\r\n" == 0) {
// read the header
$headerdone = true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$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);
}
// 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['payment_gross'];

echo ("<p>;<h3>;Thank you for your purchase!</h3>;</p>;";

echo ("<b>ayment Details</b>;<br>;\n";
echo ("<li>;Name: $firstname $lastname</li>;\n";
echo ("<li>;Item: $itemname</li>;\n";
echo ("<li>;Amount: $amount</li>;\n";
echo ("";
}
else if (strcmp ($lines[0], "FAIL") == 0) {
// log for manual investigation
}

}

fclose ($fp);

?>;

--------------------------------------------------------------------------------


这个是第二次从https://www.paypal.com/cgi-bin/webscr?cmd=p/xcl/rec/pdt-code-outside得到的,但是说明看到晕

请有经验者赐教~~

PHP代码:--------------------------------------------------------------------------------
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">;
<input type="hidden" name="cmd" value="_xclick">;
<input type="hidden" name="business" value="">;
<input type="hidden" name="item_name" value="moneytest">;
<input type="hidden" name="amount" value="10.00">;
<input type="hidden" name="shipping" value="10.00">;
<input type="hidden" name="currency_code" value="USD">;
<input type="hidden" name="return" value="checkout_process.php">;
<input type="hidden" name="cancel_return" value="checkout_payment.php">;
<input type="image" src="button_confirm_order.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">;
</form>;

--------------------------------------------------------------------------------

现在是这样的提交方式

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
2 [报告]
发表于 2005-04-08 22:12 |只看该作者

求教paypal支付后的验证

关于支付验证,好像会提供一个调用库来作验证的,
也就是你传个他一个认证吗,操作完成之后,他会把操作码加密回传给你,而你的那个苦也可以用做类似的解密。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP