<?php
if (!defined(‘IN_ECS‘))
{
die(‘Hacking attempt‘);
}
$payment_lang = ROOT_PATH . ‘languages/‘ . $GLOBALS[‘_CFG‘][‘lang‘] . ‘/payment/icbc.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‘] = ‘工行B2C支付接口‘;
/* 是否支持货到付款 */
$modules[$i][‘is_cod‘] = ‘0‘; //否
/* 是否支持在线支付 */
$modules[$i][‘is_online‘] = ‘1‘; //是
/* 作者 */
$modules[$i][‘author‘] = ‘ECSHOP TEAM‘;
/* 网址 */
$modules[$i][‘website‘] = ‘http://www.icbc.com.cn‘;
/* 版本号 */
$modules[$i][‘version‘] = ‘1.0.0.11‘;
/* 配置信息 */
$modules[$i][‘config‘] = array(
array(‘name‘ => ‘merID‘, ‘type‘ => ‘text‘, ‘value‘ => ‘‘),//商户代码
array(‘name‘ => ‘merAcct‘, ‘type‘ => ‘text‘, ‘value‘ => ‘‘),//商户帐号
array(‘name‘ => ‘curType‘, ‘type‘ => ‘text‘, ‘value‘ => ‘‘),//支付币种
);
return;
}
class icbc
{
/**
* 构造函数
*
* @access public
* @param
*
* @return void
*/
function icbc()
{
}
function __construct()
{
//$this->icbc();
}
/**
* 生成支付代码
* @param array $order 订单信息
* @param array $payment 支付方式信息
*/
function get_code($order, $payment)
{
$source="1";
//构造参数
$a_parameter = array(
//私有证书地址
‘cert_private_file‘ => ROOT_PATH."includes/modules/payment/icbc/th222.crt",
//私钥地址
‘cert_key_file‘ => ROOT_PATH."includes/modules/payment/icbc/th222.key",
//私钥口令
‘cert_key_password‘ => ‘th6688‘,
//接口名称
‘interfaceName‘ => ‘ICBC_PERBANK_B2C‘,
//接口版本
‘interfaceVersion‘ => ‘1.0.0.11‘,
//商城代码
‘merID‘ => $payment[‘merID‘],
//商户帐号
‘merAcct‘ => $payment[‘merAcct‘],
// 支持订单支付的银行卡种类 0表示仅允许使用借记卡支付,1表示仅允许使用信用卡支付,2表示借记卡和信用卡都能对订单进行支付
‘creditType‘ => 2,
//HS方式实时发送通知 AG方式不发送通知
‘notifyType‘ => ‘HS‘,
//订单号
‘orderid‘ => $order[‘order_sn‘],
//金额以分为单位
‘amount‘ => number_format($order[‘order_amount‘], 2, ‘.‘, ‘‘) * 100,
//币种目前只支持人民币,代码为001
‘curType‘ => ‘001‘,
//对于HS方式 0: 发送成功或者失败信息 1: 只发送交易成功信息
‘resultType‘ => 0,
//14位时间戳
‘orderDate‘ => local_date(‘YmdHis‘, gmtime()),
‘orderDate‘ => ‘20161201‘.local_date(‘His‘, gmtime()),
//商户联名,一般用0
‘verifyJoinFlag‘ => 0,
//语言 默认为中文版 EN_US:英文版
‘Language‘ => ‘‘,
//商品ID
‘goodsID‘ => ‘‘,
//商品名称
‘goodsName‘ => $order[‘order_sn‘],
//商品数量
‘goodsNum‘ => 1,
//运费金额以分为单位
‘carriageAmt‘ => 0,
// 虚拟商品/实物商品标志位 0 虚拟商品 1 实物商品
‘goodsType‘ => 1,
//商城提示,备注1,备注2
‘merHint‘ => ‘0‘,
‘remark1‘ => ‘‘,
‘remark2‘ => ‘‘,
//返回商户变量
‘merVAR‘ => $order[‘log_id‘].‘-‘.$order[‘order_sn‘],
//接收银行通知地址,目前只支持http协议80端口
‘merURL‘ => return_url(basename(__FILE__, ‘.php‘)),
//1.0.0.7加入 分期数,全额为1
‘installmentTimes‘ => 1,
‘CustomIp‘=>real_ip()
);
@ file_put_contents(ROOT_PATH.‘_icbc_config.txt‘, serialize($a_parameter));
//构造V3版的xml
$s_tran_data = ‘
<?xml version="1.0" encoding="GBK" standalone="no"?>
<B2CReq>
<interfaceName>‘ . $a_parameter[‘interfaceName‘] . ‘</interfaceName>
<interfaceVersion>‘ . $a_parameter[‘interfaceVersion‘] . ‘</interfaceVersion>
<orderInfo>
<orderDate>‘ . $a_parameter[‘orderDate‘] . ‘</orderDate>
<curType>‘ . $a_parameter[‘curType‘] . ‘</curType>
<merID>‘ . $a_parameter[‘merID‘] . ‘</merID>
<subOrderInfoList>
<subOrderInfo>
<orderid>‘ . $a_parameter[‘orderid‘] . ‘</orderid>
<amount>‘ . $a_parameter[‘amount‘] . ‘</amount>
<installmentTimes>‘ . $a_parameter[‘installmentTimes‘] . ‘</installmentTimes>
<merAcct>‘ . $a_parameter[‘merAcct‘] . ‘</merAcct>
<goodsID>‘ . $a_parameter[‘goodsID‘] . ‘</goodsID>
<goodsName>‘ . $a_parameter[‘goodsName‘] . ‘</goodsName>
<goodsNum>‘ . $a_parameter[‘goodsNum‘] . ‘</goodsNum>
<carriageAmt>‘ . $a_parameter[‘carriageAmt‘] . ‘</carriageAmt>
</subOrderInfo>
</subOrderInfoList>
</orderInfo>
<custom>
<verifyJoinFlag>‘ . $a_parameter[‘verifyJoinFlag‘] . ‘</verifyJoinFlag>
<Language>‘ . $a_parameter[‘Language‘] . ‘</Language>
</custom>
<message>
<creditType>‘ . $a_parameter[‘creditType‘] . ‘</creditType>
<notifyType>‘ . $a_parameter[‘notifyType‘] . ‘</notifyType>
<resultType>‘ . $a_parameter[‘resultType‘] . ‘</resultType>
<merReference></merReference>
<merCustomIp>‘ . real_ip() . ‘</merCustomIp>
<goodsType>‘ . $a_parameter[‘goodsType‘] . ‘</goodsType>
<merCustomID></merCustomID>
<merCustomPhone></merCustomPhone>
<goodsAddress>地址</goodsAddress>
<merOrderRemark></merOrderRemark>
<merHint>‘ . $a_parameter[‘merHint‘] . ‘</merHint>
<remark1>‘ . $a_parameter[‘remark1‘] . ‘</remark1>
<remark2>‘ . $a_parameter[‘remark2‘] . ‘</remark2>
<merURL>‘ . $a_parameter[‘merURL‘] . ‘</merURL>
<merVAR>‘ . $a_parameter[‘merVAR‘] . ‘</merVAR>
</message>
</B2CReq>‘;
$s_tran_data = str_replace(‘ ‘, ‘‘, $s_tran_data);
$s_tran_data = str_replace("\r", ‘‘, $s_tran_data);
$s_tran_data = str_replace("\n", ‘‘, $s_tran_data);
try{
require_once("http://localhost:8080/JavaBridgeTemplate621/java/Java.inc");
java_set_file_encoding("GBK"); //设置java编码
$ta=new Java("com.php.payment.icbc.icbcindex");
$ta->crtPasswd=$a_parameter[‘cert_key_password‘];//口令卡密码
$ta->icbccrt=str_replace("/", ‘\\‘, $a_parameter[‘cert_private_file‘]);//商城证书
$ta->icbckey = str_replace("/", ‘\\‘, $a_parameter[‘cert_key_file‘]);//商城私钥
$icbcmode1= new Java("com.php.payment.icbc.icbcmode");
$s_tran_data=new java("java.lang.String", $s_tran_data);
$icbcmode1->setTranData($s_tran_data);
$icbcmode= new Java("com.php.payment.icbc.icbcmode");
$icbcmode=$ta->getBase64ICBC($icbcmode1);
if($icbcmode->getMerSignMsg()==‘‘)
{
return "<b style=‘color:red‘>工商银行签名失败,请检查配置</b>";
}
else
{
return ‘<div style="text-align:center">
<form method="post" id="form_icbc" action="https://myipad.dccnet.com.cn/servlet/ICBCINBSEBusinessServlet">
<input name="interfaceName" type="hidden" value="‘ . $icbcmode->getInterfaceName() . ‘" />
<input name="interfaceVersion" type="hidden" value="‘ .$icbcmode->getInterfaceVersion() . ‘" />
<input name="tranData" type="hidden" value="‘ . $icbcmode->getTranData(). ‘" />
<input name="merSignMsg" type="hidden" value="‘ .$icbcmode->getMerSignMsg(). ‘" />
<input name="merCert" type="hidden" value="‘ . $icbcmode->getMerCert() . ‘" />
</form>
<a class="bnt_number2" style="color:#CCCCCC" onclick="document.getElementById(\‘form_icbc\‘).submit();" >去工商银行支付</a>
</div>‘;
}
}catch (Exception $e) {
echo ‘Caught exception: ‘,$e,"\n";
} catch(JavaException $ee){
echo $e->getCause();
}
}
/**
* 响应操作
*/
function respond()
{
##########################################################
$content =@ file_get_contents(ROOT_PATH.‘_icbc_data.txt‘);
$content .= "respond load ! \n";
@ file_put_contents(ROOT_PATH.‘_icbc_data.txt‘, $content);
##########################################################
if (empty($_POST)) {
##########################################################
$content =@ file_get_contents(ROOT_PATH.‘_icbc_data.txt‘);
$content .= "post null ! \n";
@ file_put_contents(ROOT_PATH.‘_icbc_data.txt‘, $content);
##########################################################
return FALSE;
}
$s_mer_var =@ $_POST[‘merVAR‘]; //获取支付号
$s_notify_data =@ $_POST[‘notifyData‘];
$s_sign_msg =@ $_POST[‘signMsg‘];
$a_mer_var = explode(‘_‘, $s_mer_var);
$i_order_id = $a_mer_var[1];
$i_log_id = $a_mer_var[0];
##########################################################
$content =@ file_get_contents(ROOT_PATH.‘_icbc_data.txt‘);
$content .= "order transfer! log_id: $i_log_id \n";
@ file_put_contents(ROOT_PATH.‘_icbc_data.txt‘, $content);
##########################################################
//构造参数
$a_parameter = array(
//公共证书地址
‘cert_public_file‘ => ROOT_PATH."includes/modules/payment/icbc/ebb2cpublic.crt",
//私有证书地址
‘cert_private_file‘ => ROOT_PATH."includes/modules/payment/icbc/chamago.crt",
//私钥地址
‘cert_key_file‘ => ROOT_PATH."includes/modules/payment/icbc/chamago.key",
);
//解析数据
$s_notify_data = base64_decode($s_notify_data);
//验证签名
$o_icbc_b2cutil = new COM(‘ICBCEBANKUTIL.B2CUtil‘);
$o_icbc_b2cutil->init($a_parameter[‘cert_public_file‘], $a_parameter[‘cert_private_file‘], $a_parameter[‘cert_key_file‘], ‘12345678‘);
$i_is_ok = $o_icbc_b2cutil->verifySignC($s_notify_data, strlen($s_notify_data), $s_sign_msg, strlen($s_sign_msg));
if ($i_is_ok != 0) {
return FALSE;
}
$o_xml = new DOMDocument();
$o_xml->loadXML($s_notify_data);
$i_trade_status = $o_xml->getElementsByTagName(‘tranStat‘)->item(0)->textContent;
$d_pay_price = $o_xml->getElementsByTagName(‘amount‘)->item(0)->textContent;
$d_pay_price = number_format($d_pay_price / 100, 2, ‘.‘, ‘‘);
if ($i_trade_status != 1) {
##########################################################
$content =@ file_get_contents(ROOT_PATH.‘_icbc_data.txt‘);
$content .= "order trade status! log_id: $i_log_id , trade_status : false, $i_trade_status \n";
@ file_put_contents(ROOT_PATH.‘_icbc_data.txt‘, $content);
##########################################################
return FALSE;
}
/* 检查支付的金额是否相符 */
if (! check_money($i_log_id, $d_pay_price)) {
##########################################################
$content =@ file_get_contents(ROOT_PATH.‘_icbc_data.txt‘);
$content .= "order check money! log_id: $i_log_id , money : error, $d_pay_price \n";
@ file_put_contents(ROOT_PATH.‘_icbc_data.txt‘, $content);
##########################################################
return false;
}
/* 改变订单状态 */
order_paid($i_log_id);
##########################################################
$content =@ file_get_contents(ROOT_PATH.‘_icbc_data.txt‘);
$content .= "order pay success! log_id: $i_log_id , pay_price: $d_pay_price \n";
@ file_put_contents(ROOT_PATH.‘_icbc_data.txt‘, $content);
##########################################################
return TRUE;
}
}
?>
本文出自 “QQ3037704620” 博客,转载请与作者联系!
工商银行 B2C1.0.0.11 PHP ecshop(JAVA) 接口
原文地址:http://3037704620.blog.51cto.com/12162790/1888217