Home > Backend Development > PHP Tutorial > Bank of Communications online banking online payment interface ECSHOP plug-in and usage examples implemented in PHP_PHP tutorial

Bank of Communications online banking online payment interface ECSHOP plug-in and usage examples implemented in PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:29:55
Original
1446 people have browsed it

Recently, a project required Bank of Communications online payment. ECShop itself did not have an interface for this, so after some time of research, I made a plug-in. If you have good things, of course you have to share them. I share them here. I hope it can help people who are in need like me and reduce the burden of development for everyone. I also ask everyone to point out some good methods and suggestions and learn from each other. ,progress!


Before using the plug-in, please configure the Bank of Communications online payment environment (the specific installation method is available in the demo provided by the Bank of Communications, and it is not difficult, just pay attention to the details). After installation, please save the following plug-in source code and language pack source code to the corresponding files according to the path, and finally enter the payment module in the background to install.


Plugin source code (includes/modules/payment/bankcomm.php):

Copy the code The code is as follows:

/**
* 交通银行在线支付插件 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'] = 'http://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);

//Connection address
$socketUrl = "tcp://127.0.0.1:8080"; //The port here is based on your own configuration
$fp = stream_socket_client($socketUrl, $errno, $ errstr, 30);
$retMsg="";
//
if (!$fp) {
echo "$errstr ($errno)
n";
} else
{
$in = "";
$in .= "";
$in .= "".$tranCode."";
$in .= "".$source."";
$in .= "
";
fwrite($fp, $in);
while (!feof($fp)) {
$retMsg =$retMsg.fgets ($fp, 1024);
}
fclose($fp);
}
//Parse and return 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 "Transaction return code: ".$retCode_value."
";
//echo "Transaction error message:" .$errMsg_value."
";
return "Transaction error message:" .$errMsg_value."
";
}else{
$param['signMsg_value'] = $ signMsg_value;
$param['orderUrl_value'] = $orderUrl_value;
$form_code = $this->create_html($param); //Create submission form
return $form_code;
}

}

 /**
  * 创建提交表单
  */
 function create_html($param){
  $pay_html ='


  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

  
  
';
  return $pay_html;
 }

 /**
* Processing function
*/
 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)
n";
   return false;
  }else{
   $in  = "";
   $in .= "";
   $in .= "".$tranCode."";
   $in .= "".$notifyMsg."";
   $in .= "
";
   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."
";
   //echo "交易错误信息:" .$errMsg_value."
";
   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):
复制代码 代码如下:

/**
* Bank of Communications language file
* 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; //即此时已经生成了一个支付按钮

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/768140.htmlTechArticle最近,一个项目要求做交通银行在线支付,ecshop本身没有这方面的接口,于是通过一些时间的专研,做了一个插件出来。有好的东西,当然...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template