演示查看:http://www.erdangjiade.com/ph…
php给客户开发网站的时候需要用到各大平台付款功能,下面就免费分享给大家,此类是个成熟类,网上down下来的,经过修改测试了(可以直接拿来使用,附带使用方法,有需要的朋友请拿走。),如果有需要安装的演示请登陆“二当家的”查看:http://www.erdangjiade.com/ph…
““学生”或“还没有工作的童鞋”可以无条件享用本站所有素材资源
目前包含了支付宝pc版、支付宝wap版、palpay、yeepay、unionpay、kuaiqian、财付通tenpay等,这几个常用的支付平台,支付方式均为即时到账,不包含担保支付。
支付配置ThinkPayApplicationCommonConfconfig.php
array(
/ 支付设置 /
‘payment’ => array(
‘tenpay’ => array(
// 加密key,开通财付通账户后给予
‘key’ => ‘e82573dc7e6136ba414f2e2affbe39fa’,
// 合作者ID,财付通有该配置,开通财付通账户后给予
‘partner’ => ‘1900000113’
),
‘alipay’ => array(
// 收款账号邮箱
’email’ => ‘chenf003@yahoo .cn’,
// 加密key,开通支付宝账户后给予
‘key’ => ‘aaa’,
// 合作者ID,支付宝有该配置,开通易宝账户后给予
‘partner’ => ‘2088101000137799’
),
‘aliwappay’ => array(
// 收款账号邮箱
’email’ => ‘chenf003@yahoo .cn’,
// 加密key,开通支付宝账户后给予
‘key’ => ‘aaa’,
// 合作者ID,支付宝有该配置,开通易宝账户后给予
‘partner’ => ‘2088101000137799’
),
‘palpay’ => array(
‘business’ => ‘zyj@qq .com’
),
‘yeepay’ => array(
‘key’ => ’69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl’,
‘partner’ => ‘10001126856’
),
‘kuaiqian’ => array(
‘key’ => ‘1234567897654321’,
‘partner’ => ‘1000300079901’
),
‘unionpay’ => array(
‘key’ => ‘88888888’,
‘partner’ => ‘105550149170027’
)
)
);
支付生成订单 ThinkPayThinkPHPLibraryThinkPay.class.php
function buildRequestForm(PayPayVo $vo) {
$this->payer->check();
//生成本地记录数据
$check = M(“Pay”)->add(array(
‘out_trade_no’ => $vo->getOrderNo(),
‘money’ => $vo->getFee(),
‘status’ => 0,
‘callback’ => $vo->getCallback(),
‘url’ => $vo->getUrl(),
‘param’ => serialize($vo->getParam()),
‘create_time’ => time(),
‘update_time’ => time()
));
if ($check !== false) {
return $this->payer->buildRequestForm($vo);
} else {
E(M(“Pay”)->getDbError());
}
}
支付订单表
/**
数据库
CREATE TABLE think_pay
(out_trade_no
varchar(100) NOT NULL,money
decimal(10,2) NOT NULL,status
tinyint(1) NOT NULL DEFAULT ‘0’,callback
varchar(255) NOT NULL,url
varchar(255) NOT NULL,param
text NOT NULL,create_time
int(11) NOT NULL,update_time
int(11) NOT NULL,
PRIMARY KEY (out_trade_no
)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
*/
alipay配置ThinkPayThinkPHPLibraryThinkPayDriverAlipay.class.php
protected $gateway = ‘https://mapi.alipay.com/gatew…‘;
protected $verify_url = ‘http://notify.alipay.com/trad…‘;
protected $config = array(
’email’ => ”,
‘key’ => ”,
‘partner’ => ”
);
md5加密
public function buildRequestForm(ThinkPayPayVo $vo) {
$param = array(
‘service’ => ‘create_direct_pay_by_user’,
‘payment_type’ => ‘1’,
‘_input_charset’ => ‘utf-8’,
‘seller_email’ => $this->config[’email’],
‘partner’ => $this->config[‘partner’],
‘notify_url’ => $this->config[‘notify_url’],
‘return_url’ => $this->config[‘return_url’],
‘out_trade_no’ => $vo->getOrderNo(),
‘subject’ => $vo->gettitle(),
‘body’ => $vo->getBody(),
‘total_fee’ => $vo->getFee()
);
ksort($param);
reset($param);
$arg = ”;
foreach ($param as $key => $value) {
if ($value) {
$arg .= “$key=$value&”;
}
}
$param[‘sign’] = md5(substr($arg, 0, -1) . $this->config[‘key’]);
$param[‘sign_type’] = ‘MD5’;
$sHtml = $this->_buildForm($param, $this->gateway, ‘get’);
return $sHtml;
}
支付成功后回调地址ThinkPayApplicationHomeControllerPublicController.class.php
public function notify() {
$apitype = I(‘get.apitype’);
$pay = new ThinkPay($apitype, C(‘payment.’ . $apitype));
if (IS_POST && !empty($_POST)) {
$notify = $_POST;
} elseif (IS_GET && !empty($_GET)) {
$notify = $_GET;
unset($notify[‘method’]);
unset($notify[‘apitype’]);
} else {
exit(‘Access Denied’);
}
//验证
if ($pay->verifyNotify($notify)) {
//获取订单信息
$info = $pay->getInfo();
if ($info[‘status’]) {
$payinfo = M(“Pay”)->field(true)->where(array(‘out_trade_no’ => $info[‘out_trade_no’]))->find();
if ($payinfo[‘status’] == 0 && $payinfo[‘callback’]) {
session(“pay_verify”, true);
$check = R($payinfo[‘callback’], array(‘money’ => $payinfo[‘money’], ‘param’ => unserialize($payinfo[‘param’])));
if ($check !== false) {
M(“Pay”)->where(array(‘out_trade_no’ => $info[‘out_trade_no’]))->setField(array(‘update_time’ => time(), ‘status’ => 1));
}
}
if (I(‘get.method’) == “return”) {
redirect($payinfo[‘url’]);
} else {
$pay->notifySuccess();
}
} else {
$this->error(“支付失败!”);
}
} else {
E(“Access Denied”);
}
}