微信二次开发其实和web项目开发一样,只不过要使用微信的提供接口,遵循腾讯的接口规范.微信公众号就相当于前端页面,我们通过自己开发的后台来和前端页面交互,按照我们的需求拓展微信公众号的功能.
1.在eclipse里搭建一个web工程.
2.创建一个servlet类,因为后台和微信公众号是通过doGet方式交互的,我们在servlet里写一个doGet方法.
/**
*
*@author bym @date 2018年7月4日
*
*/
public class CoreServlet extends HttpServlet {
private static final long serialVersionUID = -6595792134085823033L;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String signature = request.getParameter("signature");
String timestamp = request.getParameter("timestamp");
String nonce = request.getParameter("nonce");
String echostr = request.getParameter("echostr");
PrintWriter out = response.getWriter();
if (SignUtil.checkSignature(signature, timestamp, nonce)) {
out.print(echostr);
}
out.close();
out = null;
}
/**
* Post方法