发表时间:2015-06-11来源:网络
简单整理一下PHP项目整合PayPal支付功能。
一、表单的构建:
<form method="post" name="form" action="https://www.paypal.com/cgi-bin/webscr"> <input type="hidden" name="rm" value="2"/> <input type="hidden" name="cmd" value="_xclick"/> <input type="hidden" name="business" value="商家账号"/> <input type="hidden" name="return" value="返回网址"/> <input type="hidden" name="cancel_return" value="取消返回网址"/> <input type="hidden" name="notify_url" value="用于接收PayPal发送的即时付款通知的URL,必须是有效的URL"/> <input type="hidden" name="item_name" value="物品名称"/> <input type="hidden" name="item_number" value="可用于跟踪购买或捐赠的传递变量,在付款完成时传回给您"/> <input type="hidden" name="amount" value="物品的价格(购物车中所有物品的总价格"/> <input type="hidden" name="currency_code" value="币种"/> </form>
二、IPN验证部分
<?php
class paypal {
var $ipn_data = array(); // array contains the POST values for IPN
var $fields = array(); // 提交给Paypal的表单参数,例:item_name=iPhone 6,quantity=1,amount=499,currency_code=USD等所有表单信息,
// 在调用验证IPN之前事先需要初始化好
var $paypal_url = 'https://www.paypal.com/cgi-bin/webscr';//sandbox:https://www.sandbox.paypal.com/cgi-bin/webscr
function validate_ipn() {//验证IPN
// parse the paypal URL
$url_par=parse_url($this->paypal_url);
// generate the post string from the _POST vars aswell as load the
// _POST vars into an arry so we can play with them from the calling
// script.
$post_str = '';
foreach ($_POST as $field=>$value) {
$this->ipn_data["$field"] = $value;
$post_str .= $field.'='.urlencode(stripslashes($value)).'&';
}
$post_str.="cmd=_notify-validate"; // append ipn command
// open the connection to paypal
$fp = fsockopen($url_par[host],"80",$errnum,$errstr,30);
if(!$fp) {
// could not open the connection.
return false;
} else {
// Post the data back to paypal
fputs($fp, "POST ".$url_par[path]." HTTP/1.1rn");
fputs($fp, "Host: ".$url_par[host]."rn");
fputs($fp, "Content-type: application/x-www-form-urlencodedrn");
fputs($fp, "Content-length: ".strlen($post_str)."rn");
fputs($fp, "Connection: closernrn");
fputs($fp, $post_str . "rnrn");
// loop through the response from the server and append to variable
while(!feof($fp)) {
$this->validate_ipn_response .= fgets($fp, 1024);
}
fclose($fp); // close connection
}
if (eregi("VERIFIED",$this->validate_ipn_response)) {
return true;
} else {
return false;
}
}
}
?>
以上所述就是本文的全部内容了,希望大家能够喜欢。
上一篇:php正则替换变量指定字符的方法
下一篇:新手如何学习PHP
CI框架连接数据库配置操作以及多数据库操作
asp 简单读取数据表并列出来 ASP如何快速从数据库读取大量数据
C语言关键字及其解释介绍 C语言32个关键字详解
C语言中sizeof是什么意思 c语言里sizeof怎样用法详解
PHP中的魔术方法 :__construct, __destruct , __call, __callStatic,__get, __set, __isset, __unset , __sleep,
将视频设置为Android手机开机动画的教程
PHP中的(++i)前缀自增 和 (i++)后缀自增
最简单的asp登陆界面代码 asp登陆界面源代码详细介绍
常用dos命令及语法
PHP中include和require区别之我见
荆门市民卡最新版(i荆门)下载v2.5.6 安卓手机版
67.08MB |资讯阅读
时光手帐官方版下载v6.3.8 安卓版
61.31MB |生活服务
皮皮手账手机版(改名时光手帐)下载v6.3.8 安卓版
61.31MB |系统工具
定格动画工作室app(stop motion studio)下载v25.08.8578 安卓官方中文版
122.84MB |系统工具
宝地贵池新闻客户端下载v1.0.7 安卓版
114.26MB |资讯阅读
杭州办事服务官方版(杭州城市大脑)下载v4.0.2 安卓版
145.38MB |商务办公
生态鹤岗app下载v4.5.4 安卓版
105.42MB |资讯阅读
妈妈来了月嫂手机版下载v9.8.92 安卓最新版
185.21MB |生活服务
2014-09-05
2022-03-20
2022-03-21
2022-03-24
2014-09-05
2014-09-05
2015-07-05
2014-09-05
2022-03-21
2014-09-05
屠魔传奇2手游下载v2.5.5 安卓版
其它手游trials frontier游戏下载v7.9.4 安卓版
其它手游密室逃脱求生系列1极地冒险内购破解版下载v700.00.13 安卓无限提示版
其它手游特技摩托前线内购破解版下载v7.9.4 安卓版
其它手游特技摩托前线免验证版下载v7.9.4 安卓无限钻石版
其它手游密室逃脱求生系列2极限密探手游下载v700.00.02 安卓版
其它手游印度汽车驾驶模拟器最新版下载v41 安卓版
其它手游密室逃脱求生系列2极限密探九游最新版下载v700.00.02 安卓版
其它手游密室逃脱生存模拟游戏下载v2.0.2 安卓版
其它手游