最近,一个项目要求做交通银行在线支付,ecshop本身没有这方面的接口,于是通过一些时间的专研,做了一个插件出来。有好的东西,当然要分享,在此特地分享出来,希望能够帮助到跟我一样有需要的人,为大家减轻一下开发的负担,也多请大家指出一些好的方法和建议,相互的学习、进步!
在使用插件之前,请配置好交通银行在线支付的环境(具体安装方法,交行提供的demo会有,也不是很难,注意好细节就行)。安装好之后,请将把下面的插件源码和语言包源码按路径保存到相应文件,最后进入后台的支付模块安装即可。
插件源码(includes/modules/payment/bankcomm.php):
复制代码 代码如下:
<?php
/**
* 交通银行在线支付插件 For Ecshop
* Author: Reson
* Date: 2014/03/31
*/
if (!defined('IN_ECS'))
{
die('Hacking attempt');
}
$payment_lang = ROOT_PATH . 'languages/' .$GLOBALS['_CFG']['lang']. '/payment/bankcomm.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'] = 'bankcomm_desc';
/* 是否支持货到付款 */
$modules[$i]['is_cod'] = '0';
/* 是否支持在线支付 */
$modules[$i]['is_online'] = '1';
/* 支付费用,由配送决定 */
$modules[$i]['pay_fee'] = '0';
/* 作者 */
$modules[$i]['author'] = 'Reson';
/* 网址 */
$modules[$i]['website'] = 'https://www.jb51.net';
/* 版本号 */
$modules[$i]['version'] = '1.0.0.0';
/* 配置信息 */
$modules[$i]['config'] = array();
return;
}
/**
* 类
*/
class bankcomm
{
/**
* 构造函数
*
* @return void
*/
function bankcomm()
{
}
function __construct()
{
$this->bankcomm();
}
/**
* 提交函数
*/
function get_code($order)
{
//获得表单传过来的数据
$param['interfaceVersion'] = '1.0.0.0'; //消息版本号*
$param['merID'] = '301310063009501'; //商户号 (测试号,后期可自行更改)
$param['orderid'] = $order['orderid']; //订单号*
$param['orderDate'] = local_date("Ymd",gmtime()); //商户订单日期* yyyyMMdd
$param['orderTime'] = local_date("His",gmtime()); //商户订单时间* HHmmss
$param['tranType'] = 0; //交易类别* 0:B2C
$param['amount'] = $order['amount']; //订单金额*
$param['curType'] = 'CNY'; //交易币种* 默认CNY
$param['orderContent'] = '';
$param['orderMono'] = $order['orderMono']; //商家备注
$param['phdFlag'] = ''; //物流配送标志
$param['notifyType'] = 1; //通知方式* 1 通知
$param['merURL'] = '';
$param['goodsURL'] = $order['goodsURL']; //取货URL
$param['jumpSeconds'] = '';
$param['payBatchNo'] = '';
$param['proxyMerName'] = '';
$param['proxyMerType'] = '';
$param['proxyMerCredentials'] = '';
$param['netType'] = 0; //渠道编号* 0:html渠道
$param['issBankNo'] = '';
$tranCode = "cb2200_sign";
htmlentities($param['orderMono'],"ENT_QUOTES","utf-8");
//连接字符串
$source = '';
foreach($param as $key=>$val){
if($key != 'issBankNo')
$source .= $val.'|';
}
$source = substr($source,0,strlen($source)-1);
//连接地址
$socketUrl = "tcp://127.0.0.1:8080"; //这里的端口根据自己配置的情况
$fp = stream_socket_client($socketUrl, $errno, $errstr, 30);
$retMsg="";
//
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else
{
$in = "<?xml version='1.0' encoding='UTF-8'?>";
$in .= "<Message>";
$in .= "<TranCode>".$tranCode."</TranCode>";
$in .= "<MsgContent>".$source."</MsgContent>";
$in .= "</Message>";
fwrite($fp, $in);
while (!feof($fp)) {
$retMsg =$retMsg.fgets($fp, 1024);
}
fclose($fp);
}
//解析返回xml
$dom = new DOMDocument;
$dom->loadXML($retMsg);
$retCode = $dom->getElementsByTagName('retCode');
$retCode_value = $retCode->item(0)->nodeValue;
$errMsg = $dom->getElementsByTagName('errMsg');
$errMsg_value = $errMsg->item(0)->nodeValue;
$signMsg = $dom->getElementsByTagName('signMsg');
$signMsg_value = $signMsg->item(0)->nodeValue;
$orderUrl = $dom->getElementsByTagName('orderUrl');
$orderUrl_value = $orderUrl->item(0)->nodeValue;
$MerchID = $dom->getElementsByTagName('MerchID');
$merID = $MerchID->item(0)->nodeValue;
//echo "retMsg=".$retMsg;
//echo $retCode_value." ".$errMsg_value." ".$signMsg_value." ".$orderUrl_value;
if($retCode_value != "0"){
//echo "交易返回码:".$retCode_value."<br>";
//echo "交易错误信息:" .$errMsg_value."<br>";
return "交易错误信息:" .$errMsg_value."<br>";
}else{
$param['signMsg_value'] = $signMsg_value;
$param['orderUrl_value'] = $orderUrl_value;
$form_code = $this->create_html($param); //创建提交表单
return $form_code;
}
}
/**
* 创建提交表单
*/
function create_html($param){
$pay_html ='<form name = "form1" method = "post" action = "'.$param['orderUrl_value'].'">
<input type = "hidden" name = "interfaceVersion" value = "'.$param['interfaceVersion'].'">
<input type = "hidden" name = "merID" value = "'.$param['merID'].'">
<input type = "hidden" name = "orderid" value = "'.$param['orderid'].'">
<input type = "hidden" name = "orderDate" value = "'.$param['orderDate'].'">
<input type = "hidden" name = "orderTime" value = "'.$param['orderTime'].'">
<input type = "hidden" name = "tranType" value = "'.$param['tranType'].'">
<input type = "hidden" name = "amount" value = "'.$param['amount'].'">
<input type = "hidden" name = "curType" value = "'.$param['curType'].'">
<input type = "hidden" name = "orderContent" value = "'.$param['orderContent'].'">
<input type = "hidden" name = "orderMono" value = "'.$param['orderMono'].'">
<input type = "hidden" name = "phdFlag" value = "'.$param['phdFlag'].'">
<input type = "hidden" name = "notifyType" value = "'.$param['notifyType'].'">
<input type = "hidden" name = "merURL" value = "'.$param['merURL'].'">
<input type = "hidden" name = "goodsURL" value = "'.$param['goodsURL'].'">
<input type = "hidden" name = "jumpSeconds" value = "'.$param['jumpSeconds'].'">
<input type = "hidden" name = "payBatchNo" value = "'.$param['payBatchNo'].'">
<input type = "hidden" name = "proxyMerName" value = "'.$param['proxyMerName'].'">
<input type = "hidden" name = "proxyMerType" value = "'.$param['proxyMerType'].'">
<input type = "hidden" name = "proxyMerCredentials" value = "'.$param['proxyMerCredentials'].'">
<input type = "hidden" name = "netType" value = "'.$param['netType'].'">
<input type = "hidden" name = "merSignMsg" value = "'.$param['signMsg_value'].'">
<input type = "hidden" name = "issBankNo" value = "'.$param['issBankNo'].'">
<input type="submit" value=" " class="pay_button" />
</form>';
return $pay_html;
}
/**
* 处理函数
*/
function respond()
{
$tranCode = "cb2200_verify";
$notifyMsg = $_REQUEST["notifyMsg"];
$lastIndex = strripos($notifyMsg,"|");
$signMsg = substr($notifyMsg,$lastIndex+1); //签名信息
$srcMsg = substr($notifyMsg,0,$lastIndex+1);//原文
//连接地址
$socketUrl = "tcp://127.0.0.1:8080";
$fp = stream_socket_client($socketUrl, $errno, $errstr, 30);
$retMsg="";
if (!$fp) {
//echo "$errstr ($errno)<br />\n";
return false;
}else{
$in = "<?xml version='1.0' encoding='UTF-8'?>";
$in .= "<Message>";
$in .= "<TranCode>".$tranCode."</TranCode>";
$in .= "<MsgContent>".$notifyMsg."</MsgContent>";
$in .= "</Message>";
fwrite($fp, $in);
while (!feof($fp)) {
$retMsg =$retMsg.fgets($fp, 1024);
}
fclose($fp);
}
//解析返回xml
$dom = new DOMDocument;
$dom->loadXML($retMsg);
$retCode = $dom->getElementsByTagName('retCode');
$retCode_value = $retCode->item(0)->nodeValue;
$errMsg = $dom->getElementsByTagName('errMsg');
$errMsg_value = $errMsg->item(0)->nodeValue;
$signMsg = $dom->getElementsByTagName('signMsg');
$signMsg_value = $signMsg->item(0)->nodeValue;
if($retCode_value != ''){
//echo "交易返回码:".$retCode_value."<br>";
//echo "交易错误信息:" .$errMsg_value."<br>";
return false;
}else{
$arr = preg_split("/\|{1,}/",$srcMsg);
$pay_id = $arr[1];
$action_note = base64_decode($arr[16]);
// 完成订单。
order_paid($pay_id, PS_PAYED, $action_note);
//告诉用户交易完成
return true;
}
///////////////// respond END ///////////////
}
}
?>
语言包源码(languages/zh_cn/payment/bankcomm.php):
复制代码 代码如下:
<?php
/**
* 交通银行语言文件
* by: Reson
* 2014/03/31
*/
global $_LANG;
$_LANG['bankcomm'] = '交通银行在线支付';
$_LANG['bankcomm_desc'] = '交通银行在线支付';
$_LANG['pay_button'] = '交通银行支付';
?>
以下是调用的范例:
复制代码 代码如下:
include_once(ROOT_PATH . 'includes/modules/payment/bankcomm.php');
$order_['orderid'] = $order['order_sn'];
$order_['amount'] = $order['yd_price'];
$order_['orderMono'] = '测试'; //商家备注
$order_['goodsURL'] = "http://".$_SERVER['HTTP_HOST'].'/respond.php?code=bankcomm'; //取货URL
$pay_code = new bankcomm;
$pay_button = $pay_code->get_code($order_);
$order['pay_button'] = $pay_button; //即此时已经生成了一个支付按钮
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]