paypal即时到账php实现代码


Posted in PHP onNovember 28, 2010

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); 
} 
?>
PHP 相关文章推荐
JAVA/JSP学习系列之二
Oct 09 PHP
PHP开发中常用的8个小技巧
Aug 27 PHP
用php获取本周,上周,本月,上月,本季度日期的代码
Aug 05 PHP
php判断上传的Excel文件中是否有图片及PHPExcel库认识
Jan 11 PHP
如何利用php array_multisort函数 对数据库结果进行复杂排序
Jun 08 PHP
解析php addslashes()与addclashes()函数的区别和比较
Jun 24 PHP
PHP SPL使用方法和他的威力
Nov 12 PHP
php时间戳转换的示例
Mar 31 PHP
PHP函数实现分页含文本分页和数字分页
Oct 23 PHP
php基于Fleaphp框架实现cvs数据导入MySQL的方法
Feb 23 PHP
php+jQuery+Ajax简单实现页面异步刷新
Aug 08 PHP
php版银联支付接口开发简明教程
Oct 14 PHP
解析PayPal支付接口的PHP开发方式
Nov 28 #PHP
php购物网站支付paypal使用方法
Nov 28 #PHP
IP攻击升级,程序改进以对付新的攻击
Nov 23 #PHP
php下封装较好的数字分页方法
Nov 23 #PHP
php下使用iconv需要注意的问题
Nov 20 #PHP
批量修改RAR文件注释的php代码
Nov 20 #PHP
为PHP初学者的8点有效建议
Nov 20 #PHP
You might like
PHP中的超全局变量
2006/10/09 PHP
hadoop常见错误以及处理方法详解
2013/06/19 PHP
CentOS下PHP安装Oracle扩展
2015/02/15 PHP
PHP实现删除字符串中任何字符的函数
2015/08/11 PHP
php将数组存储为文本文件方法汇总
2015/10/28 PHP
PHP中常用的数组操作方法笔记整理
2016/05/16 PHP
PHP+MariaDB数据库操作基本技巧备忘总结
2018/05/21 PHP
学习jquery之一
2007/04/27 Javascript
用javascript实现画板的代码
2007/09/05 Javascript
Prototype源码浅析 String部分(二)
2012/01/16 Javascript
javascript 事件处理程序介绍
2012/06/27 Javascript
实测jquery data()如何存值
2013/08/18 Javascript
使用jquery解析XML示例代码
2014/09/05 Javascript
JS+CSS实现美化的下拉列表框效果
2015/08/11 Javascript
jquery实现图片水平滚动效果代码分享
2015/08/26 Javascript
基于jquery实现的鼠标悬停提示案例
2016/12/11 Javascript
Iview Table组件中各种组件扩展的使用
2018/10/20 Javascript
Vue如何使用混合Mixins和插件开发详解
2020/02/05 Javascript
通过实例解析jQ Ajax操作相关原理
2020/09/23 Javascript
jQuery实现简单轮播图效果
2020/12/27 jQuery
python网络编程学习笔记(九):数据库客户端 DB-API
2014/06/09 Python
pandas 选择某几列的方法
2018/07/03 Python
对Python实现简单的API接口实例讲解
2018/12/10 Python
Python3 log10()函数简单用法
2019/02/19 Python
浅谈python 中类属性共享的问题
2019/07/02 Python
pycharm如何实现跨目录调用文件
2020/02/28 Python
css3 box-sizing属性使用参考指南
2013/01/08 HTML / CSS
在数据文件自动增长时,自动增长是否会阻塞对文件的更新
2014/05/01 面试题
材料采购员岗位职责
2013/12/17 职场文书
一年级班主任寄语
2014/01/19 职场文书
电大会计学自我鉴定
2014/02/06 职场文书
常务副总经理岗位职责
2014/04/12 职场文书
2014年党员自我剖析材料
2014/10/07 职场文书
元旦主持词开场白
2015/05/29 职场文书
快速学习Oracle触发器和游标
2021/06/30 Oracle
HTML静态页面获取url参数和UserAgent的实现
2022/08/05 HTML / CSS