标签:request public webhooks 通知接受处理
以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; }
本文出自 “艺晨光的博客” 博客,请务必保留此出处http://ycgit.blog.51cto.com/8590215/1940886
标签:request public webhooks 通知接受处理
原文地址:http://ycgit.blog.51cto.com/8590215/1940886