问下做过paypal接口的朋友,使用paypal付款成功,然后接收paypal返回的值更改本网站订单状态,要怎样实现的! <input type="hidden" name="return" value="http://www.xxxx.com/dingdanreturn.php">
<!--交易完后自动返回的位置-->dingdanreturn.php页面怎样接收paypal返回的交易信息,网上查了多是不全面,请直接给代码,Thankyou!
<!--交易完后自动返回的位置-->dingdanreturn.php页面怎样接收paypal返回的交易信息,网上查了多是不全面,请直接给代码,Thankyou!
解决方案 »
- 问个数据库的问题~~
- 有没有简洁的方法可以计算出指定日期所在的周一和周日分别是哪一天?
- 话说 有人在用2003系统嘛...
- while(mysql_fetch_array($result))问题
- 模糊匹配问题
- 急,求助 php中,session变量不能在页面间传递吗??
- php.ini中upload_max_filesize=32M现上载11M文件不成功,小一点的则可,怎么回事?
- 请问获取文件的文件名和扩展名的函数怎么写?
- 请教一下,如何在win2k下编译一个模块到php中去
- 问题二:关于最后回复和论坛的帖子自动排序
- 请问怎么把txt文件导入到mysql里面
- 请同时了解java加密和PHP的帅哥,帮我解决哈。
paypal 有提供交易后返回值的接口么? 交易是跳转到 paypal上处理的
$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 ('www.paypal.com', 80, $errno, $errstr, 30);
if (!$fp) {
// ERROR
echo "$errstr ($errno)";
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
// echo "WE ARE IN THE VERIFIED CYCLE<br>";
if ($payment_status == "Completed"){}
} else if (strcmp ($res, "INVALID") == 0) {
if ($_REQUEST['table'] != 100) {
}
}
fclose ($fp);
}
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_blank"><input type="hidden" name="cmd" value="_xclick">
<!--// "_xclick" 立即购买--><input type="hidden" name="business" value="[email protected]">
<!--//PayPal测试账户上的电子邮件地址--><input type="hidden" name="item_name" value="<? echo 'svnshops'.$dingdanhao; ?>">
<!-- //物品名称--><input type="hidden" name="item_number" value="<? echo $dingdanhao; ?>">
<!-- //购物单号--><input type="hidden" name="currency_code" value="GBP">
<!--//定义币种以标示货币变量 值可以为 "USD"、"EUR"、"GBP"、"CAD"、"JPY"。 --><input type="hidden" name="amount" value="<? echo $yinfu; ?>">
<!-- //物品的价格--><input type="hidden" name="return" value="http://www.xxxx.com/dingdanreturn.php">
<!--交易完后自动返回的位置--> <input type="image" src="http://www.paypal.com/zh_XC/i/btn/x-click-but01.gif" name="submit" alt="PayPal"></form>
支付完成后从paypal跳转本网站的页面地址为:
http://www.xxx.com/dingdanreturn.php?merchant_return_link=Return+to+fan+guanghong%27s+Test+Store为了弄清从paypal回传回来的信息用下面方法显示:
foreach($_GET as $key => $value)
{
echo " Data: ".$key." Values: ".$value." ----<br>";
}显示的结果为:
Data: merchant_return_link Values: Return to fan guanghong\'s Test Store ----
请问dingdanreturn.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 .= "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 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>Payment 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);?>现在支付完后跳转的地址为:http://www.xxx.com/dingdanreturn.php?merchant_return_link=Return+to+fan+guanghong%27s+Test+Store
,明显地址里的参数并没有dingdanreturn所需要的参数,从这个地址再往前一步,估计就是购买提交表单页面的问题,可能少了某些要提交的参数,还在分析解决中,望大家指教!
return_url只是给用户支付完毕后返回的页面,一般只显示"谢谢"等信息
notify_url是用来给paypal在处理该交易过程中通知你网站的(不一定是支付成功),从该页面就可以读到完整的信息代码,在paypal上有demo code,基本照着改就行
结贴给大家散分了!