ECSHOP 大商创 对接易支付接口 1.languages/zh_cn/payment 新建ezhifu.php
<?php
global $_LANG;
$_LANG['ezhifu'] = '易支付';
$_LANG['ezhifu_desc'] = '易支付接口模块';
$_LANG['ezhifu_APPID'] = 'APPID';
$_LANG['ezhifu_APPKEY'] = 'APPKEY';
$_LANG['pay_button'] = '立即支付';
$_LANG['ezhifu_pay_method'] = '选择接口类型';
$_LANG['ezhifu_pay_method_desc'] = '控制支付接口类型';
$_LANG['ezhifu_pay_method_range'][0] = '微信+支付宝';
$_LANG['ezhifu_pay_method_range'][1] = '仅微信';
$_LANG['ezhifu_pay_method_range'][2] = '仅支付宝';
?>
2.includes/modules/payment 新建ezhifu.php
<?php
if (!defined('IN_ECS'))
{
exit('Hacking attempt');
}
$payment_lang = ROOT_PATH . 'languages/' .$GLOBALS['_CFG']['lang']. '/payment/ezhifu.php';
if (file_exists($payment_lang))
{
global $_LANG;
include_once($payment_lang);
}
if (isset($set_modules) && $set_modules == TRUE)
{
$i = isset($modules) ? count($modules) : 0;
$modules[$i]['code'] = basename(__FILE__, '.php');
$modules[$i]['desc'] = 'ezhifu_desc';
$modules[$i]['is_cod'] = '0';
$modules[$i]['is_online'] = '1';
$modules[$i]['author'] = '易支付';
$modules[$i]['website'] = '';
$modules[$i]['version'] = '1.0.0';
$modules[$i]['config'] = array(
array('name' => 'ezhifu_APPID', 'type' => 'text', 'value' => ''),
array('name' => 'ezhifu_APPKEY', 'type' => 'text', 'value' => ''),
array('name' => 'ezhifu_pay_method', 'type' => 'select', 'value' => '')
);
return;
}
class ezhifu
{
function __construct()
{}
function get_code($order, $payment)
{}
function respond()
{}
}
?>
3.app/Plugins/payment 新建eyizhifu.php
<?php
class ezhifu
{
function __construct()
{
$this->ezhifu();
}
function ezhifu()
{}
function get_code($order, $payment)
{
if (!defined('EC_CHARSET'))
{
$charset = 'utf-8';
}
else
{
$charset = EC_CHARSET;
}
include_once BASE_PATH . 'Helpers/payment_helper.php';
$returnurl = return_url(basename(__FILE__, '.php'));
$notifyurl = notify_url(basename(__FILE__, '.php'));
$returnurl = urlencode($returnurl);
$notifyurl = urlencode($notifyurl);
$url = "?appid={$payment['ezhifu_APPID']}&money={$order['order_amount']}&subject={$order['order_sn']}&logid={$order['log_id']}&returnurl=".$returnurl."¬ifyurl=".$notifyurl;
$real_method = $payment['ezhifu_pay_method'];
if(empty($real_method))$real_method = 0;
$html = "";
$gopayweb = "http://****自行替换提交页面地址*****/epayapi.php";
switch ($real_method){
case '0':
$html = '<a class="btn-reset box-flex" href="'.$gopayweb.$url.'&type=1" target="_blank">微信支付</a><a class="btn-reset box-flex" href="'.$gopayweb.$url.'&type=2" target="_blank">支付宝</a>';
break;
case '1':
$html = '<a class="btn-reset box-flex" href="'.$gopayweb.$url.'&type=1" target="_blank">微信支付</a>';
break;
case '2':
$html = '<a class="btn-reset box-flex" href="'.$gopayweb.$url.'&type=2" target="_blank">支付宝付款</a>';
break;
}
return $html;
}
function respond()
{
$this->write_log(json_encode($_GET),"paynotify_respond");
unset($_GET['code']);
include_once BASE_PATH . 'Helpers/payment_helper.php';
$payment = get_payment(basename(__FILE__, '.php'));
$sign = $_GET['sign'];
unset($_GET['sign']);
unset($_GET['sign_type']);
ksort($_GET);
if(md5(http_build_query($_GET).$payment['ezhifu_APPKEY'])!=$sign){
return false;
}
$out_trade_no = $_GET['out_trade_no'];
$trade_no = $_GET['trade_no'];
$trade_status = $_GET['trade_status'];
if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
if(stristr($out_trade_no,"_")!==false){
$logid = explode("_",$out_trade_no);
$logid = $logid[0];
echo $logid;
order_paid($logid);
return true;
}else{
return false;
}
}else{
return false;
}
}
function callback()
{
unset($_GET['code']);
include_once BASE_PATH . 'Helpers/payment_helper.php';
$payment = get_payment(basename(__FILE__, '.php'));
$sign = $_GET['sign'];
unset($_GET['sign']);
unset($_GET['sign_type']);
ksort($_GET);
if(md5(http_build_query($_GET).$payment['ezhifu_APPKEY'])!=$sign){
return false;
}
$out_trade_no = $_GET['out_trade_no'];
$trade_no = $_GET['trade_no'];
$trade_status = $_GET['trade_status'];
if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
if(stristr($out_trade_no,"_")!==false){
$logid = explode("_",$out_trade_no);
$logid = $logid[0];
order_paid($logid);
return true;
}else{
return false;
}
}else{
return false;
}
}
function notify($data)
{
include_once BASE_PATH . 'Helpers/payment_helper.php';
$payment = get_payment(basename(__FILE__, '.php'));
unset($_GET['code']);
$sign = $_GET['sign'];
unset($_GET['sign']);
unset($_GET['sign_type']);
ksort($_GET);
if(md5(http_build_query($_GET).$payment['ezhifu_APPKEY'])!=$sign){
return false;
}
$out_trade_no = $_GET['out_trade_no'];
$trade_no = $_GET['trade_no'];
$trade_status = $_GET['trade_status'];
if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
if(stristr($out_trade_no,"_")!==false){
$logid = explode("_",$out_trade_no);
$logid = $logid[0];
order_paid($logid);
return true;
}else{
return false;
}
}else{
return false;
}
}
}
?>
4 回调地址和返回地址分别是 mobile/public/notify/ezhifu.php mobile/respond.php?code=ezhifu 回调地址文件mobile/public/notify/ezhifu.php内容
<?php
define('BIND_MODULE', 'Respond');
define('BIND_CONTROLLER', 'Index');
define('BIND_ACTION', 'notify');
$_GET['code'] = basename(__FILE__, '.php');
require __DIR__ . '/../../index.php';
|