当前位置: 移动技术网 > IT编程>开发语言>PHP > paypal即时到账php实现代码

paypal即时到账php实现代码

2019年04月27日  | 移动技术网IT编程  | 我要评论

神秘人送来千斤蔬菜,高州一中校园网,歌瑞莎

http://paypal.ebay.cn/integrationcenter/list__resource_2.html

中文php开发简介:http://www.paypal-china.org/wangzhai/197.html
以下是ecshop中paypal的支付代码

这段代码是向paypal支付接口提交的
{{{

<form target="_blank" method="post" action="https://www.paypal.com/cgi-bin/webscr" style="text-align: center;"><input type="hidden" value="_xclick" name="cmd"/><input type="hidden" value="xfuajiao@hotmail.com" name="business"/> //商家注册的邮箱
<input type="hidden" value="2009102370175" name="item_name"/><input type="hidden" value="2888.00" name="amount"/><input type="hidden" value="usd" name="currency_code"/><input type="hidden" value="http://127.0.0.1/ecshop/respond.php?code=paypal" name="return"/><input type="hidden" value="3" name="invoice"/><input type="hidden" value="utf-8" name="charset"/><input type="hidden" value="1" name="no_shipping"/><input type="hidden" value="" name="no_note"/><input type="hidden" value="http://127.0.0.1/ecshop/respond.php?code=paypal" name="notify_url"/><input type="hidden" value="2" name="rm"/><input type="hidden" value="http://127.0.0.1/ecshop/" name="cancel_return"/><input type="submit" value="立即使用 paypal 支付"/></form>

}}}

以下是官方提供的,接受到paypal传回来的参数的,并且判断是否支付成功。

支持成功后由于提交表单中有


<input type="hidden" value="http://127.0.0.1/ecshop/respond.php?code=paypal" name="return"/>

paypal将会主动跳转到espond.php?code=paypal这个页面,页面可现实以下post得到的一些数据。



复制代码 代码如下:

// 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.paypal.com', 443, $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);
}
?>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网