# jsyso-weixin **Repository Path**: geekforjava/jsyso-weixin ## Basic Information - **Project Name**: jsyso-weixin - **Description**: jsyso-weixin是基于jsyso的极速微信开发框架,以处理器方式开发微信,无任何继承关系,对代码无侵入。 - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2018-06-11 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ### jsyso-weixin:处理器方式开发微信 jsyso-weixin是基于jsyso的极速微信开发框架,以处理器方式开发微信,无任何继承关系,对代码无侵入。 ### 使用 1、配置web.xml 在`init-param`配置多公众号支持,`param-value`给JSON方式字符串: ```xml weixinServlet com.jsyso.weixin.web.WeixinServlet wx4011a5d808f730e5 { "appSecret": "943a3e7e8f83a8ec9e2f5f99a5689cf9", "token": "weixin" } 2 weixinServlet /servlet/weixin ``` 2、微信服务器配置 微信服务器参数带`appid`以区分不同微信公众号: ```html http://jadmin.jsyso.com/servlet/weixin?appid=wx4011a5d808f730e5 ``` 3、接收:实现处理器接口`RequestHandler<处理器类型>` ```java /** * 关注事件处理 * @author janjan, xujian_jason@163.com * */ @Component public class InFollowEventHandler implements RequestHandler { @Override public OutMsg onHandle(InFollowEvent inMsg) { String appid = inMsg.getAppid(); String openid = inMsg.getFromUserName(); final OutTextMsg textMsg = new OutTextMsg(inMsg); textMsg.setContent("尊敬的未知用户,欢迎您归来!"); API.create(UserAPI.class).getUserInfo(appid, openid).get(new Success() { @Override public void onSuccess(JsMap data, String content) { textMsg.setContent("尊敬的"+(data.get("nickname", String.class))+",欢迎您归来,输入任意关键字查看测试!"); } }); // 回复给发送者的信息 return textMsg; } } ``` 4、发送:使用API ```java // 获取用户信息成功,则调用onSuccess API.create(UserAPI.class).getUserInfo(appid, openid).get(new Success() { @Override public void onSuccess(JsMap data, String content) { textMsg.setContent("尊敬的"+(data.get("nickname", String.class))+",欢迎您归来,输入任意关键字查看测试!"); } }); ``` 5、小程序:返回JSON格式的html,让小程序支持html解析 html解析成json对象 ```java String html = "
" + "

sample text with inline tag

" + "
foo
" + "
goo
" + "" + "" + "
"; root = JParser.parseHTML(html); ``` 返回json: ```json { "nodeName": "root", "childs": [ { "nodeName": "element", "childs": [ { "nodeName": "element", "childs": [ { "nodeName": "text", "text": "sample text with ", "nodeType": "text" }, { "nodeName": "element", "childs": [ { "nodeName": "text", "text": "inline tag", "nodeType": "text" } ], "nodeType": "view", "tagName": "code" } ], "nodeType": "view", "tagName": "h2" }, { "nodeName": "element", "childs": [ { "nodeName": "text", "text": "foo", "nodeType": "text" } ], "nodeType": "view", "tagName": "pre", "attr": { "id": "demo", "class": "foo bar" } }, { "nodeName": "element", "childs": [ { "nodeName": "text", "text": "goo", "nodeType": "text" } ], "nodeType": "view", "tagName": "pre", "attr": { "id": "output", "class": "goo" } }, { "nodeName": "element", "nodeType": "view", "tagName": "input", "attr": { "id": "execute", "type": "button", "value": "execute" } }, { "nodeName": "element", "nodeType": "img", "tagName": "img", "attr": { "src": "http://upload-images.jianshu.io/upload_images/4177877-0c5ab7b2cd6156ec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240", "style": "cursor: zoom-in;" } } ], "nodeType": "view", "tagName": "div", "attr": { "id": "1", "class": "foo" } } ], "nodeType": "root", "imageUrls": [ "http://upload-images.jianshu.io/upload_images/4177877-0c5ab7b2cd6156ec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" ] } ``` ### 案例:jadmin 测试公众号: ![测试公众号](images/test_qrcode.jpg) **jadmin**是基于jsyso + LayUI搭建的后台管理系统,实现了微信关注、回复信息处理、回复信息、获取用户信息。 [https://git.oschina.net/xujian_jason/jadmin](https://git.oschina.net/xujian_jason/jadmin) ### 更多问题 更多问题欢迎QQ加好友:514737546(加时还请说明(~ ̄▽ ̄)~)