1. 程式人生 > >Thinkphp各大支付平臺在線支付集成源碼

Thinkphp各大支付平臺在線支付集成源碼

itl ucc serial eat nes 使用 sign 賬戶 常用


用Thinkphp給客戶開發網站的時候需要用到各大平臺付款功能,下面就免費分享給大家,此類是個成熟類,經過測試了(可以直接拿來使用,附帶使用方法,有需要的朋友請拿走。),
如果有需要安裝的演示請登陸“二當家的”查看:http://www.erdangjiade.com/php/524.html目前包含了支付寶pc版、支付寶wap版、palpay、yeepay、unionpay、kuaiqian、財付通tenpay等,這幾個常用的支付平臺,支付方式均為即時到賬,不包含擔保支付。
支付配置ThinkPay\Application\Common\Conf\config.php

array(
/* 支付設置 */
‘payment‘ => array(
‘tenpay‘ => array(
// 加密key,開通財付通賬戶後給予
‘key‘ => ‘e82573dc7e6136ba414f2e2affbe39fa‘,
// 合作者ID,財付通有該配置,開通財付通賬戶後給予
‘partner‘ => ‘1900000113‘
),
‘alipay‘ => array(
// 收款賬號郵箱
‘email‘ => ‘[email protected]‘,
// 加密key,開通支付寶賬戶後給予
‘key‘ => ‘aaa‘,
// 合作者ID,支付寶有該配置,開通易寶賬戶後給予
‘partner‘ => ‘2088101000137799‘
),
‘aliwappay‘ => array(
// 收款賬號郵箱
‘email‘ => ‘[email protected]‘,
// 加密key,開通支付寶賬戶後給予
‘key‘ => ‘aaa‘,
// 合作者ID,支付寶有該配置,開通易寶賬戶後給予
‘partner‘ => ‘2088101000137799‘
),
‘palpay‘ => array(
‘business‘ => ‘[email protected]‘
),
‘yeepay‘ => array(
‘key‘ => ‘69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl‘,
‘partner‘ => ‘10001126856‘
),
‘kuaiqian‘ => array(
‘key‘ => ‘1234567897654321‘,
‘partner‘ => ‘1000300079901‘
),
‘unionpay‘ => array(
‘key‘ => ‘88888888‘,
‘partner‘ => ‘105550149170027‘
)
)
);

支付生成訂單 ThinkPay\ThinkPHP\Library\Think\Pay.class.php

function buildRequestForm(Pay\PayVo $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配置ThinkPay\ThinkPHP\Library\Think\Pay\Driver\Alipay.class.php

protected $gateway = ‘https://mapi.alipay.com/gateway.do‘;
protected $verify_url = ‘http://notify.alipay.com/trade/notify_query.do‘;
protected $config = array(
‘email‘ => ‘‘,
‘key‘ => ‘‘,
‘partner‘ => ‘‘
);

md5加密

public function buildRequestForm(\Think\Pay\PayVo $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;
}

支付成功後回調地址ThinkPay\Application\Home\Controller\PublicController.class.php

public function notify() {
$apitype = I(‘get.apitype‘);

$pay = new \Think\Pay($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");
}
}

Thinkphp各大支付平臺在線支付集成源碼