php版交通银行网银支付接口开发入门教程
php  /  管理员 发布于 7年前   130
本文实例讲述了php版交通银行网银支付接口实现方法。分享给大家供大家参考,具体如下: 概述:网银支付接口 和支付宝接口大体上差不多,主要的区别是 交通银行提供的 接口核心的比如,加密等是通过java实现的,所以,要想办法使php和java能正常的通信,为此,官方也提供了两套实现方法,一个是通过 socket 进行通信,另一个方法是通过 java 桥接,下面演示的是 socket方法. 1. 配置运行环境 1.1 安装java,自行到oracle官网下载 java,然后安装,并配置正确的 环境变量. 1.2 把 测试的证书导入到java 虚拟机. keytool " -import -keystore "java虚拟机放置证书的地址" -storepass changeit -alias test_bocommca -file "证书路径" 完成导入。 例子:keytool" -import -keystore "C:\Program Files\Java\jre1.5\lib\security\cacerts" -storepass changeit -alias test_bocommca -file "C:\socket\cert\test_root.cer" 1.3 修改配置文件(in/B2CMerchantSocket.xml). 采用官方提供的测试 商号进行测试时,无需配置,否则要配置,具体看xml文件说明. 1.4 启动 socket 服务 window:启动 start.bat 及可. linux:启动 ohup sh.start,sh& //使当前脚本脱离终端,并在后台运行。 2. 将网银集成到现有的系统,以mvc的结构进行说明. 2.1 将不变的参数 配置 写入配置文件: 2.2 Model 2.3 控制器 支付方法: 通知: 更多关于PHP相关内容感兴趣的读者可查看本站专题:《php常见数据库操作技巧汇总》、《PHP数组(Array)操作技巧大全》、《php排序算法总结》、《PHP常用遍历算法与技巧总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《PHP数学运算技巧总结》、《php正则表达式用法总结》、《PHP运算与运算符用法总结》及《php字符串(string)用法总结》 希望本文所述对大家PHP程序设计有所帮助。$config['interfaceVersion'] = "1.0.0.0"; #接口版本$config['tranType'] =0; #交易类别 0:B:C$config['curType'] = 'CNY'; # 交易币种$config['notifyType'] =1; #0=不通知 1=通知 2=抓取$config['merURL'] = "/pay/notify"; # 主动通知url$config['goodsURL'] = '/goods/1.html'; #取货url$config['jumpSeconds'] =3; #跳转时间$config['payBatchNo'] = ''; #商户批次号$config['proxyMerName'] = ''; #代理商家名字$config['proxyMerType'] = ''; #代理商类型$config['proxyMerCredentials']= ''; #代理商家批次号$config['netType'] = 0; #渠道编号//以下是 新接口需要的参数$config['socketUrl'] ="tcp://127.0.0.1:8891"; #socket url$config['merID'] ='301310063009501'; #商户id 3013100630095012
/** * 交通银行支付类 */class Bocom extends CI_Model { private $arrReturn=array(); private $socket; public function __construct() { parent::__construct (); //加载交通银行配置文件 $this->config->load('bocom'); $this->socket=$this->config->item('socketUrl'); } /** * 支付方法 * * @param unknown $arr_data=array( * 'bill_no'=> * ) */ public function pay($arr_data){ //获得表单传过来的数据 $this->arrReturn['interfaceVersion'] = $this->config->item('interfaceVersion'); $this->arrReturn['merID'] = $this->config->item('merID'); //商户号为固定 $this->arrReturn['orderid'] = $arr_data['bill_no']; $this->arrReturn['orderDate'] = $arr_data['bill_date']; $this->arrReturn['orderTime'] = $arr_data['bill_time']; $this->arrReturn['tranType'] = $this->config->item('tranType'); $this->arrReturn['amount'] = $arr_data['bill_fee']; $this->arrReturn['curType'] = $this->config->item('curType'); $this->arrReturn['orderContent'] = isset($arr_data['bill_title'])?iconv('utf-8','gb2312',$arr_data["bill_title"]): ''; #订单内容 $this->arrReturn['orderMono'] = isset($arr_data['bill_mono'])? iconv('utf-8','gb2312',$arr_data['bill_mono']):''; #商家备注 $this->arrReturn['phdFlag'] = isset($arr_data['phpFlag'])?$arr_data['phpFlag']:''; $this->arrReturn['notifyType'] = $this->config->item('notifyType'); $this->arrReturn['merURL'] = $this->config->item('merURL'); $this->arrReturn['goodsURL'] = $this->config->item('goodsURL'); $this->arrReturn['jumpSeconds'] = $this->config->item('jumpSeconds'); $this->arrReturn['payBatchNo'] = $this->config->item('payBatchNo'); $this->arrReturn['proxyMerName'] = $this->config->item('proxyMerName'); $this->arrReturn['proxyMerType'] = $this->config->item('proxyMerType'); $this->arrReturn['proxyMerCredentials']= $this->config->item('proxyMerCredentials'); $this->arrReturn['netType'] = $this->config->item('netType'); //以下参数 不参与签名 $this->arrReturn['issBankNo'] =isset($arr_data['code_id'])? trim($arr_data['code_id']):''; $tranCode = "cb2200_sign"; $source=''; $len = count($this->arrReturn)-1;$j=1; foreach($this->arrReturn as $v){ if($j<=$len){ $source.=$v."|"; } $j++; } $source= substr($source, 0,strlen($source)-1); $fp= stream_socket_client($this->socket,$errno, $errstr, 30); $retMsg=""; if (!$fp) { log_message("info","socket连接失败"); return false; } else { $in = ""; $in .= "
\n"; log_message("error","$errstr ($errno)
\n"); } else{ $in = ""; $in .= "
"); return false; }else{ $arr = preg_split("/\|{1,}/",$srcMsg); if($arr[9]=="1"){ return $this->updateBill($arr[1]); } log_message("error","交易失败:".$arr[13]."
"); return false; } } private function updateBill($billNo){ // 更新 订单状态 } //end class}$this->load->model("Bocom");
$this->arrData =$this->Bocom->pay($this->data);
$this->arrData =$this->Bocom->notify();
您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号