Flask接口签名sign原理与实例代码浅析
373
2023-07-16
基于Java代码实现支付充值的通用流程
废话不多说了,直接给大家贴java代码了。
具体代码如下所示:
/*支付流程*/
/****Controller.java 代码如下:*/
@RequestMapping(value = "/paySubmit.htm", method = RequestMethod.POST)
public ModelAndView paySubmit(HttpServletRequest request,
HttpServletResponse response, @RequestParam Map
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" %>
<%
request.setCharacterEncoding("UTF-8");
String type = (String) request.getAttribute("type");
String sHtmlText = "";
if ("1".equals(type)){
sHtmlText = PayUtil.buildForm(
(String) request.getAttribute("orderNo"),
(String) request.getAttribute("amt"),type);
}else{
sHtmlText = PayUtil.allInPaybuildForm(
(String) request.getAttribute("orderNo"),
(String) request.getAttribute("amt"),type,request);
}
out.println(sHtmlText);
%>
/* PayUtil.java 代码如下:*/
/**
* 生成页面数据
* @param url 三方支付的URL
* @param sPara
* @param strMethod
* @return
*/
public static String buildRequest(String url, Map
ArrayList keys = new ArrayList(sPara.keySet());
StringBuffer sbHtml = new StringBuffer();
sbHtml.append("
for(int i = 0; i < keys.size(); ++i) {
String name = (String)keys.get(i);
String value = (String)sPara.get(name);
sbHtml.append("");
}
sbHtml.append("
sbHtml.append("");
return sbHtml.toString();
}
/**
* 以民生支付为例
* @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("CMBC.pay.type");//"empty";
//币 种 01 为cny
String currencytype = "01";
//自动调转取货页面0→不跳转;1→跳转
String autojump = "1";
//跳转等待时间
String waittime = "0";
//商户取货URL
String merurl = PropertiesRead.use_classLoador().getProperty("CMBC.pay.return.page.url");
//是否通知商户: 0→不通知;1→通知
String informmer = "1";
//商户通知URL
String informurl = PropertiesRead.use_classLoador().getProperty("CMBC.pay.return.notify.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("CMBC.pay.return.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="+autojump
+ "&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
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;
/**
*
Title: MD5加密算法
*
Description: 商户不需要进行修改
*
******科技发展公司 2009. All rights reserved.
*/
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 = strSrc.getBytes();
try {
md = MessageDigest.getInstance(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 http://(int i = 0; i < bts.length; i++) {
tmp = (Integer.toHexString(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
ModelAndView model = new ModelAndView("*ymkIOrBCPr**/payReturn");
/**
* 代码块
*/
return model;
}
以上所述是给大家介绍的基于Java代码实现支付充值的通用流程的相关知识,希望对大家有所帮助,如果大家有任何疑问请给我留言,会及时回复大家的。在此也非常感谢大家对我们网站的支持!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~