您现在的位置是:首页 > 教程 > ecshop商城教程ecshop商城教程

ecshop支付接口我国银行对接示例

如萱2024-12-23 16:57:13ecshop商城教程已有人查阅

导读我国银行的支付接口只提供有Java版,众所周之ecshop是采用php开发的,这让我们如何用php开发java的东东呢?办法始终是有的,我们可以先在ecshop里用php生成订单,提交给nginx,nginx转

我国银行的支付接口只提供有Java版,众所周之ecshop是采用php开发的,这让我们如何用php开发java的东东呢?办法始终是有的,我们可以先在ecshop里用php生成订单,提交给nginx,nginx转发的tomcat,再通过jsp文件完成订单签名,将订单数据发送给我国银行处理。
先看这个处理订单签名,发送B2C支付数据的jsp文件,我将它命名为index.jsp
[java] view plain copy
<%@ page contentType=”text/html; charset=UTF-8″ language=”java” import=”java.sql.*” errorPage=”” %>
<%@ page import=”java.io.*” %>
<%@ page import=”java.util.*” %>
<%@ page import=”com.bocnet.common.security.PKCS7Tool” %>
<%
String merchantNo = request.getParameter(“merchantNo”);
String payType = request.getParameter(“payType”);
String orderNo = request.getParameter(“orderNo”);
String curCode = request.getParameter(“curCode”);
String orderAmount = request.getParameter(“orderAmount”);
String orderTime = request.getParameter(“orderTime”);
String orderNote = request.getParameter(“orderNote”);
//String orderUrl = request.getParameter(“orderUrl”);
String orderUrl = “http:// .***.com/webapps/boc/notify.jsp”; //根据自己网站的实际情况修改 String keyStorePath = “/home/ /bankey/boc.pfx”;
String keyStorePassword = “111111″;
String keyPassword = “111111″; try {
PKCS7Tool tool = PKCS7Tool.getSigner(keyStorePath, keyStorePassword, keyPassword);
String dataStr = orderNo + “|” + orderTime + “|” + curCode + “|” + orderAmount + “|” + merchantNo;
byte[] data = dataStr.getBytes(“UTF-8″);
String signData = tool.sign(data);
signData = signData.replace(“\n”, “”);
signData = signData.replace(“\r”, “”); out.println(“<div style=’text-align:center’><form name=’form1′ method=’post’ action=’http://180.168.146.75:81/PGWPortal/RecvOrder.do’><INPUT NAME=’merchantNo’ TYPE=’hidden’ value=’”+merchantNo+”‘><INPUT NAME=’payType’ TYPE=’hidden’ value=’”+payType+”‘><INPUT NAME=’orderNo’ TYPE=’hidden’ value=’”+orderNo+”‘ ><INPUT NAME=’curCode’ TYPE=’hidden’ value=’”+curCode+”‘><INPUT NAME=’orderAmount’ TYPE=’hidden’ value=’”+orderAmount+
“‘><INPUT TYPE=’HIDDEN’ NAME=’orderTime’ VALUE=’”+orderTime+”‘><INPUT TYPE=’HIDDEN’ NAME=’orderNote’ VALUE=’”+orderNote+”‘><INPUT TYPE=’HIDDEN’ NAME=’orderUrl’ VALUE=’”+orderUrl+”‘><INPUT TYPE=’HIDDEN’ NAME=’signData’ VALUE=’”+signData+”‘></form>正在去往工行支付页面…<script>document.all.form1.submit();</script></div>”); } catch (Exception e) {
// TODO Auto-generated catch block
out.println(e);
}
%>
当jsp文件发送数据给我国银行后,页面会跳转到我国银行的支付页面,客户完成一系列的支付操作后,页面会跳转回商城网站。同时我国银行会向网站返回B2C支付结果通知数据,这些数据需要使用java验签,验签通过后再把数据发送给ecshop的respond.php文件,完成数据验证,改变订单状态,这样一次完整的支付就算完成了。以下是notify.jsp文件源码。
[java] view plain copy
<%@ page contentType=”text/html; charset=UTF-8″ language=”java” import=”java.sql.*” errorPage=”” %>
<%@ page import=”java.io.*” %>
<%@ page import=”java.util.*” %>
<%@ page import=”java.security.GeneralSecurityException” %>
<%@ page import=”com.bocnet.common.security.PKCS7Tool” %> <%
//获取银行返回数据
String merchantNo = request.getParameter(“merchantNo”); // 商户号
String orderNo = request.getParameter(“orderNo”); // 商户订单号
String orderSeq = request.getParameter(“orderSeq”); // 银行订单流水号
String cardTyp = request.getParameter(“cardTyp”); // 银行卡类别
String payTime = request.getParameter(“payTime”); // 支付交易的日期时间
String orderStatus = request.getParameter(“orderStatus”); // 订单状态
String payAmount = request.getParameter(“payAmount”); // 支付金额
String orderIp = request.getParameter(“orderIp”); // 客户支付IP地址
String orderRefer = request.getParameter(“orderRefer”); // 客户浏览器Refer信息
String bankTranSeq = request.getParameter(“bankTranSeq”); // 银行交易流水号
String returnActFlag = request.getParameter(“returnActFlag”); // 返回操作类型
String signData = request.getParameter(“signData”); //签名数据
String rootCertificatePath = “/home/ /bankey/BOCCAU3.cer”; try {
String path=request.getSession().getServletContext().getRealPath(“/boc/tranData.d”);
FileWriter fw=new FileWriter(path + “/report.txt”); //保存接口开发中的调试信息
fw.write(merchantNo+” “+orderNo+” “+payTime+” “+orderStatus+” “+payAmount+” “+signData+”\n”); PKCS7Tool tool = PKCS7Tool.getVerifier(rootCertificatePath);
String signature = signData;
String dataStr = merchantNo + “|” + orderNo + “|” + orderSeq + “|” + cardTyp + “|” + payTime + “|” + orderStatus + “|” + payAmount;
byte[] data = dataStr.getBytes(“UTF-8″);
String dn = null;
tool.verify(signature, data, dn);
if(orderStatus.equals(“1″)) {
//支付成功处理代码
fw.write(merchantNo+”订单支付成功\n”);
response.sendRedirect(“http:// .***.com/respond.php?code=boc&orderNo=”+orderNo+”&orderStatus=”+orderStatus+”&payAmount=”+payAmount);
} else{
//支付失败处理代码
fw.write(merchantNo+”订单支付失败\n”);
}
} catch (Exception e) {
out.println(e);
}
%>
以上就是处理订单的两个jsp文件,至于ecshop中的我国银行支付插件开发就比较简单了

本文标签:

很赞哦! ()

留言与评论 (共有 条评论)
验证码:

本栏推荐

相关标签