以struts2中的写法为例,可自行用其他框架或servlet。
public String wxNotice() throws IOException{ HttpServletResponse response = ServletActionContext.getResponse(); HttpServletRequest request = ServletActionContext.getRequest(); // -------接受参数-------------------------------------// StringBuilder buffer = new StringBuilder(); BufferedReader reader = request.getReader(); String line; while ((line = reader.readLine()) != null) { buffer.append(line); } String requestBody = buffer.toString(); System.out.println("request boay:"+ requestBody); // -------签名验证-------------------------------------// String sign = request.getHeader("sign"); System.out.println("header sign:" + sign); boolean signCheck = RSA.verify(requestBody, sign, SignConfig.PAYMAX_PUBLIC_KEY);//签名规则根据你的项目来定 //-------处理状态返回-----------------------------------// response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8");//防止输出的信息出现乱码 PrintWriter out = null; out = response.getWriter(); if (!signCheck) { //签名验证失败 out.print("fail"); }else{ out.print("success"); } out.flush(); out.close(); return null; }
时间: 2024-10-01 02:42:01