基于Java代码实现⽀付充值的通⽤流程废话不多说了,直接给⼤家贴java代码了。
具体代码如下所⽰:
/*⽀付流程*/
/****Controller.java 代码如下:*/
@RequestMapping(value = "/paySubmit.htm", method = RequestMethod.POST)
public ModelAndView paySubmit(HttpServletRequest request,
HttpServletResponse response, @RequestParam Map<String, Object> maps){
ModelAndView model = new ModelAndView("***/submit");
/**
* 代码块
*/
return model;
}
/*submit.jsp 代码如下:*/
<%@ page contentType="text/html;charset=UTF-8" language="java" trimDirectiveWhitespaces="true" %>
<%@ page import="com.***.util.PayUtil" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>⽀付</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String type = (String) Attribute("type");
String sHtmlText = "";
if ("1".equals(type)){
sHtmlText = PayUtil.buildForm(
(String) Attribute("orderNo"),
(String) Attribute("amt"),type);
}else{
sHtmlText = PayUtil.allInPaybuildForm(
(String) Attribute("orderNo"),
(String) Attribute("amt"),type,request);
}
out.println(sHtmlText);
%>
</body>
</html>
/* PayUtil.java 代码如下:*/
/**
* ⽣成页⾯数据
* @param url 三⽅⽀付的URL
* @param sPara
* @param strMethod
* @return
*/
public static String buildRequest(String url, Map<String, String> sPara, String strMethod) {
ArrayList keys = new ArrayList(sPara.keySet());
StringBuffer sbHtml = new StringBuffer();
sbHtml.append("<form id=\"paySubForm\" name=\"paySubForm\" action=\"" + url + "\" method=\"" + strMethod + "\">");
for(int i = 0; i < keys.size(); ++i) {
String name = ((i);
String value = ((name);
sbHtml.append("<input type=\"hidden\" name=\"" + name + "\" value=\"" + value + "\"/>");
}
sbHtml.append("<input type=\"submit\" name=\"b1\" value=\"确认\" style=\"display:none;\"></form>");
sbHtml.append("<script>document.forms[\'paySubForm\'].submit();</script>");
String();
}
/**
* 以民⽣⽀付为例
* @param orderNo
* @param amt
* @param type
* @return
*/
public static String buildForm(String orderNo, String amt,String type) {
//商户编号
String merchantid = PropertiesRead.use_classLoador().getProperty("CMBC.pay.id");
//订单编号商户的交易定单号,由商户⽹站⽣成,最⼤长度30
String merorderid = orderNo;
//⾦额
String amountsum = amt;
/
/商品种类
String subject = PropertiesRead.use_classLoador().getProperty("pe");//"empty";
//币种 01 为cny
String currencytype = "01";
//⾃动调转取货页⾯0→不跳转;1→跳转
String autojump = "1";
//跳转等待时间
String waittime = "0";
//商户取货URL
String merurl = PropertiesRead.use_classLoador().getProperty("urn.page.url");
//是否通知商户: 0→不通知;1→通知
String informmer = "1";
//商户通知URL
String informurl = PropertiesRead.use_classLoador().getProperty("ify.url");
/**
* 商户返回确认: 0→不返回;1→返回
*/
String confirm = "1";
//⽀付银⾏
String merbank = "empty";
//⽀付类型 0→即时到账;1→担保交易
String tradetype = "0";
/
/是否在商户端选择银⾏:0→其他;1→在商户端选择银⾏
String bankInput = "0";
//接⼝版本
String strInterface = "5.00";
//备注 (可选) ⽀付备注信息,最⼤长度50
String remark = "充值";
//⽀付银⾏卡类型 00→借贷混合;01→纯借记
String bankcardtype = "00";
//商品描述
String pdtdnm = "虚拟商品";
//商品描述地址
String pdtdetailurl = PropertiesRead.use_classLoador().getProperty("urn.detail.url");
//⽀付密钥(必填): 需在⽀付平台进⾏设置,可登录商户管理系统进⾏维护,⽤于上送商户⽀付及下传⽀付结果加密String MD5key = PropertiesRead.use_classLoador().getProperty("CMBC.pay.pwd");
//拼接加密的源字符串
String mac_src="merchantid="+merchantid+"&merorderid="+merorderid
+"&amountsum="+amountsum+"&subject="+subject
+"¤cytype="+currencytype+"&autojump="+autojumpjava源代码加密
+ "&waittime=" + waittime +"&merurl="+merurl
+ "&informmer=" + informmer +"&informurl=" +informurl
+ "&confirm=" + confirm + "&merbank=" + merbank
+ "&tradetype=" + tradetype + "&bankInput=" + bankInput
+ "&interface=" + strInterface + "&bankcardtype=" + bankcardtype
+ "&pdtdetailurl=" + pdtdetailurl + "&merkey="+MD5key;
String mac = Crypto.GetMessageDigest(mac_src);
// 把请求参数打包成map
Map<String, String> sParaTemp = new HashMap<String,String>();
sParaTemp.put("merchantid", merchantid);
sParaTemp.put("merorderid", merorderid);
sParaTemp.put("amountsum", amountsum);
sParaTemp.put("subject", subject);
sParaTemp.put("currencytype", currencytype);
sParaTemp.put("autojump", autojump);
sParaTemp.put("waittime", waittime);
sParaTemp.put("merurl", merurl);
sParaTemp.put("informmer", informmer);
sParaTemp.put("informurl", informurl);
sParaTemp.put("confirm", confirm);
sParaTemp.put("merbank", merbank);
sParaTemp.put("tradetype", tradetype);
sParaTemp.put("bankInput", bankInput);
sParaTemp.put("interface", strInterface);
sParaTemp.put("remark", remark);
sParaTemp.put("bankcardtype", bankcardtype);
sParaTemp.put("pdtdnm", pdtdnm);
sParaTemp.put("pdtdetailurl", pdtdetailurl);
sParaTemp.put("mac", mac);
//建⽴请求
String sHtmlText = buildRequest(PropertiesRead.use_classLoador().getProperty("CMBC.pay.url"), sParaTemp, "post");
logger.info("McPay request: {}", sHtmlText);
return sHtmlText;
}
/" Crypto.java 代码如下 "/
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* <p>Title: MD5加密算法</p>
* <p>Description: 商户不需要进⾏修改</p>
* <p>******科技发展公司 2009. All rights reserved.</p>
*/
public class Crypto {
/**
* 功能:MD5加密
* @param strSrc 加密的源字符串
* @return 加密串长度32位
*/
public static String GetMessageDigest(String strSrc) {
MessageDigest md = null;
String strDes = null;
final String ALGO_MD5 = "MD5";
byte[] bt = Bytes();
try {
md = Instance(ALGO_MD5);
md.update(bt);
strDes = bytes2Hex(md.digest());
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(
"系统不⽀持的MD5算法!");
}
return strDes;
}
/**
* 将字节数组转为HEX字符串(16进制串)
* @param bts 要转换的字节数组
* @return 转换后的HEX串
*/
public static String bytes2Hex(byte[] bts) {
String des = "";
String tmp = null;
for (int i = 0; i < bts.length; i++) {
tmp = (HexString(bts[i] & 0xFF));
if (tmp.length() == 1) {
des += "0";
}
des += tmp;
}
return des;
}
}
/**
* ⽀付返回调⽤url(返回页⾯)
* @param session
* @param request
* @return
*/
@RequestMapping(value = "/allPayReturn.htm", method = RequestMethod.POST)
public ModelAndView allInPayReturnCall(HttpServletRequest request,
HttpServletResponse response, @RequestParam Map<String, Object> maps){
ModelAndView model = new ModelAndView("***/payReturn");
/**
* 代码块
*/
return model;
}
以上所述是⼩编给⼤家介绍的基于Java代码实现⽀付充值的通⽤流程的相关知识,希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。在此也⾮常感谢⼤家对⽹站的⽀持!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论