帮客户集成接口时候发现客户网站PHP版本达不到要求 只要调用JAVA来解决问题<?php
/**
* ECSHOP 银联电子支付(ChinaPay)插件
* ============================================================================
* @author: qq:3037704620
* @email: 3037704620#qq.com
* @date: 2017-01-02
*/
if (!defined(‘IN_ECS‘))
{
die(‘Hacking attempt‘);
}
$payment_lang = ROOT_PATH . ‘languages/‘ .$GLOBALS[‘_CFG‘][‘lang‘]. ‘/payment/chinapay.php‘;
include ROOT_PATH .‘includes/modules/payment/chinapay/common.php‘;
include ROOT_PATH .‘includes/modules/payment/chinapay/SecssUtil.class.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‘] = ‘chinapay_desc‘;
/* 是否支持货到付款 */
$modules[$i][‘is_cod‘] = ‘0‘;
/* 是否支持在线支付 */
$modules[$i][‘is_online‘] = ‘1‘;
/* 支付费用 */
//$modules[$i][‘pay_fee‘] = ‘1.5%‘;
/* 作者 */
$modules[$i][‘author‘] = ‘qq:3037704620‘;
/* 网址 */
$modules[$i][‘website‘] = ‘http://www.chinapay.com‘;
/* 版本号 */
$modules[$i][‘version‘] = ‘V2.8.3‘;
/* 配置信息 */
$modules[$i][‘config‘] = array(
array(‘name‘ => ‘MerId‘, ‘type‘ => ‘text‘, ‘value‘ => ‘000000000017‘)
//array(‘name‘ => ‘chinapay_MerPrk‘, ‘type‘ => ‘text‘, ‘value‘ => ‘可以不填‘),
//array(‘name‘ => ‘chinapay_PgPubk‘, ‘type‘ => ‘text‘, ‘value‘ => ‘可以不填‘)
);
return;
}
/**
* 类
*/
class chinapay
{
/**
* 构造函数
* @access public
* @param
* @return void
*/
private $securityPropFile = ‘‘;//配置文件
private $pay_url = ‘‘;//配置文件
function chinapay()
{
//$this->pay_url="https://payment.chinapay.com/CTITS/service/rest/page/nref/000000000017/0/0/0/0/0";
//$this->securityPropFile = ROOT_PATH."includes/modules/payment/chinapay/security.properties";
$this->securityPropFile = ROOT_PATH."includes/modules/payment/chinapay/security_test.properties";
$this->pay_url="http://newpayment-test.chinapay.com/CTITS/service/rest/page/nref/000000000017/0/0/0/0/0";
}
function __construct()
{
$this->chinapay();
}
/**
* 生成支付代码
* @param array $order 订单信息
* @param array $payment 支付方式信息
*/
function get_code($order, $payment)
{
//$MerId = trim($payment[‘chinapay_account‘]);
$orderNo = pad(mt_rand(), "l", 16, "0");
//echo $payment[‘MerId‘];
/**
* 配置
* Enter description here ...
* @var unknown_type
*/
$Config=Array (
‘MerId‘ => trim($payment[‘MerId‘]),//商户号
‘MerOrderNo‘ =>pad(mt_rand(), "l", 16, "0") ,//订单长度16位置
//‘MerOrderNo‘ =>ecshopsn2chinapaysn($order[‘order_sn‘],$payment[‘chinapay_account‘]),//订单长度16位置
‘OrderAmt‘ =>intval(floor($order[‘order_amount‘]*100)),
‘TranDate‘ => date(‘Ymd‘, time()) ,
‘TranTime‘ => date(‘His‘,time()),
‘TranType‘ => "0001" ,
‘BusiType‘ => "0001" ,
‘Version‘ => "20140728" ,
‘SplitType‘ =>" ",
‘SplitMethod‘ =>"" ,
‘MerSplitMsg‘ =>"" ,
‘BankInstNo‘ =>"" ,
‘PayTimeOut‘ =>"" ,
‘TimeStamp‘ => " ",
‘RemoteAddr‘ => " " ,
‘CurryNo‘ => "CNY" ,
‘AccessType‘ => "0" ,
‘AcqCode‘ => "000000000000014" ,
‘CommodityMsg‘ => "" ,
‘MerPageUrl‘ =>return_url(basename(__FILE__, ‘.php‘)),//返回地址
‘MerBgUrl‘ => return_url(basename(__FILE__, ‘.php‘)),//返回地址
‘MerResv‘ => $order[‘order_sn‘],
// ‘TranReserved‘=>‘{" BusiId ":"00000001","P1":"123"," P2":"756"," P3":"123","P4":"23"}‘,
‘trans_BusiId‘ => " " ,
‘trans_P1‘ => "" ,
‘trans_P2‘ => "" ,
‘trans_P3‘ => "" ,
‘trans_P4‘ => "" ,
‘trans_P5‘ => "" ,
‘trans_P6‘ => "" ,
‘trans_P7‘ => " " ,
‘trans_P8‘ => " " ,
‘trans_P9‘ => " " ,
‘trans_P10‘ =>" "
);
/**
* 签名部分开始
* Enter description here ...
* @var unknown_type
*/
try{
require_once("http://localhost:8080/JavaBridgeTemplate621/java/Java.inc");
java_set_file_encoding("utf-8");
$map=new Java("java.util.HashMap");
foreach ($Config as $l=>$s){
$l=new Java("java.lang.String", $l);
$s=new Java("java.lang.String", $s);
$map->put($l, $s);// 商户号
}
$index=new Java("com.chinapay.util.index");
$Path=new Java("java.lang.String", $this->securityPropFile);
$index->quest=$map;
$respone=java_values($index->GetSign($Path));//读取签名信息
$def_url = "<form name=‘payment‘ id=‘payment‘ action=‘".$this->pay_url."‘ method=‘POST‘ target=‘_blank‘>";
$params = "TranReserved;MerId;MerOrderNo;OrderAmt;CurryNo;TranDate;SplitMethod;BusiType;MerPageUrl;MerBgUrl;SplitType;MerSplitMsg;PayTimeOut;MerResv;Version;BankInstNo;CommodityMsg;Signature;AccessType;AcqCode;OrderExpiryTime;TranType;RemoteAddr;Referred;TranTime;TimeStamp;CardTranData";
foreach ($respone as $k => $v)
{
if (strstr($params, $k))
{
$def_url .="<input type=‘text‘ name = ‘".$k."‘ value=‘".$v."‘/>";
}
}
$def_url.= "<input type=‘submit‘ value=‘" . $GLOBALS[‘_LANG‘][‘pay_button‘] . "‘>";
$def_url .= "</form>";
return $def_url;
}
catch (Exception $e)
{
return "<br><font color=‘#FF0000‘>系统错误: ".$e."</font>";
}
}
/**
* 响应操作
*/
function respond()
{
$payment = get_payment(basename(__FILE__, ‘.php‘));
$return=false;
if (count($_POST) > 0)
{
$MerOrderNo = trim($_POST[‘MerOrderNo‘]);
$OrderStatus = trim($_POST[‘OrderStatus‘]);
$MerResv=trim($_POST[‘MerResv‘]);
if($OrderStatus==‘0000‘)
{
try
{
require_once("http://localhost:8080/JavaBridgeTemplate621/java/Java.inc");
java_set_file_encoding("utf-8");
$resultMap=new Java("java.util.HashMap");
foreach ($_POST as $l=>$s)
{
$l=new Java("java.lang.String", $l);
$s=new Java("java.lang.String", $s);
$resultMap->put($l, $s);// 商户号
}
$SignUtil=new Java("com.chinapay.util.SignUtil");
//验证签名
if($SignUtil->verify($resultMap))
{
/* 改变订单状态 */
$order_id = get_order_id_by_sn($MerResv);
if(!$order_id)
{
$order_id = get_order_id_by_sn($MerResv, "true");//会员充值
}
order_paid($order_id,2);
$return=true;
}
else
{
$return=false;
}
}
catch (Exception $e)
{
echo "Caught exception: ".$e."\n";
}
}
}
return $return;
}
}
?>