NETSHARP微信开发说明

一、微信开发介绍1.微信分为个人号,订阅号、服务号,需要去理解三个号的区别,对于开发来说也需要了解不同的账号所提供的功能2.微信号需要审批,审批之后有一些功能才能使用二、netsharp微信开发配置netsharp平台可以支持多个微信公众号,具体配置如下列表和明细图,一些字段的意思保持和微信开发者一直便于理解1.列表 2.表单3.微信开发和netsharp的绑定http://host/wx?oid=gh_befcc6d4c40d其中oid参数是微信的originalId 4.netsharp微信开发服务器接收代码
 1 package org.netsharp.servlet;
 2 
 3 import java.io.IOException;
 4 import java.io.InputStream;
 5 
 6 import javax.servlet.ServletException;
 7 import javax.servlet.annotation.WebServlet;
 8 import javax.servlet.http.HttpServlet;
 9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 
12 import org.apache.commons.logging.Log;
13 import org.apache.commons.logging.LogFactory;
14 import org.netsharp.wx.mp.message.WeixinMessageDispatcher;
15 import org.netsharp.wx.mp.sdk.WeixinRequestParameters;
16 
17 @WebServlet(name = "weixin", urlPatterns = "/wx")
18 public class WeixinServlet extends HttpServlet {
19 
20     private static final long serialVersionUID = 1L;
21     private static Log logger = LogFactory.getLog("weixin." + WeixinServlet.class.getSimpleName());
22 
23     public WeixinServlet() {
24         super();
25     }
26 
27     // http://121.40.86.55/wx?oid=gh_befcc6d4c40d
28     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
29 
30         response.setCharacterEncoding("utf-8");
31 
32         logger.error("微信开发者配置验证开始");
33 
34         response.getWriter().write("");
35 
36         WeixinRequestParameters par = this.getWeixinParameter(request);
37 
38         try {
39             WeixinMessageDispatcher mc = new WeixinMessageDispatcher();
40             mc.validate(par);
41             response.getWriter().write(par.Echostr);
42         } catch (Exception ex) {
43             logger.error("servlet 微信get异常", ex);
44         }
45 
46         logger.error("微信开发者配置验证结束");
47     }
48 
49     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
50 
51         response.setCharacterEncoding("utf-8");
52 
53         response.getWriter().write("");
54 
55         WeixinRequestParameters par = this.getWeixinParameter(request);
56         InputStream stream = request.getInputStream();
57 //        String xml = FileManager.read(stream);
58 //        logger.error("[收到微信消息]:" + xml);
59 
60         try {
61             WeixinMessageDispatcher mc = new WeixinMessageDispatcher();
62             String content = mc.processRequest(par, stream);
63 
64             logger.error("[回复消息]:" + content);
65 
66             response.getWriter().write(content);
67         } catch (Exception ex) {
68             logger.error("servlet 微信post异常", ex);
69         }
70     }
71 
72     private WeixinRequestParameters getWeixinParameter(HttpServletRequest request) {
73 
74         WeixinRequestParameters par = new WeixinRequestParameters();
75         {
76             par.Signature = request.getParameter("signature");
77             par.Timestamp = request.getParameter("timestamp");
78             par.Nonce = request.getParameter("nonce");
79             par.Echostr = request.getParameter("echostr");
80             par.Oid = request.getParameter("oid");
81         }
82 
83         logger.error(par.toString());
84 
85         return par;
86     }
87 }
View Code 三、Netsharp微信其他配置1.菜单配置微信启动二次开发了之后,菜单则需要通过接口创建,netsharp进行了封装并且提供了工具,菜单设置好以后在列表上点击“同步"按钮即可现在netsharp的菜单还不能处理父子关系的菜单,但是数据库可以修改parent_id来修改其关系,界面会自动显示树状关系netsharp提供了一些默认配置, 四、Netsharp微信框架介绍 

相关内容推荐