Webhooks 通知接收處理
阿新 • • 發佈:2017-06-22
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
Webhooks 通知接收處理