一道關於C#參數傳遞的面試題剖析。本站提示廣大學習愛好者:(一道關於C#參數傳遞的面試題剖析)文章只能為提供參考,不一定能成為您想要的結果。以下是一道關於C#參數傳遞的面試題剖析正文
空話不多說了,直接給年夜家貼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) 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); %> </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 = (String)keys.get(i); String value = (String)sPara.get(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>"); 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<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 = 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 (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<String, Object> maps){ ModelAndView model = new ModelAndView("***/payReturn"); /** * 代碼塊 */ return model; }
以上所述是小編給年夜家引見的基於Java代碼完成付出充值的通用流程的相干常識,願望對年夜家有所贊助,假如年夜家有任何疑問請給我留言,小編會實時答復年夜家的。在此也異常感激年夜家對網站的支撐!