E企盈营销工具技术服务商 热线:4006-838-530

微信公众号开发创建菜单

E企盈直播平台营销卖货系统

微信公众号开发文章目录1.微信公众号开发 – 环境搭建2.微信公众号开发 – 配置表设计以及接入公众号接口开发3.微信公众号开发 – token获取(保证同一时间段内只请求一次)4.微信公众号开发 – 菜单按钮bean封装5.微信公众号开发 – 创建菜单6.微信公众号开发 – 事件处理和回复消息7.微信公众号开发 – 发送Emoji表情项目完整代码请访问github:https://github.com/liaozq0426/wx.git在上篇文章中完成了菜单、按钮bean的封装,现在来实现微信公众号菜单的创建向wx_cfg配置表中插入若干菜单记录INSERT INTO `wx_cfg` (`id`, `type`, `name`, `value`, `parent_id`, `sort`, `platform`, `wx_type`, `enabled`, `desc`) VALUES (‘4’, ‘app_url’, ‘appUrl’, ‘http://www.gavin.com’, NULL, NULL, ‘gavin’, ‘service’, ‘1’, ‘公众号域名’);INSERT INTO `wx_cfg` (`id`, `type`, `name`, `value`, `parent_id`, `sort`, `platform`, `wx_type`, `enabled`, `desc`) VALUES (‘5’, ‘menu’, ‘view1’, ‘/transfer/index.html’, NULL, ‘1’, ‘gavin’, ‘service’, ‘1’, ‘学习资料’);INSERT INTO `wx_cfg` (`id`, `type`, `name`, `value`, `parent_id`, `sort`, `platform`, `wx_type`, `enabled`, `desc`) VALUES (‘6’, ‘menu’, ‘view2’, ‘/transfer/index.html’, NULL, ‘2’, ‘gavin’, ‘service’, ‘1’, ‘在线题库’);INSERT INTO `wx_cfg` (`id`, `type`, `name`, `value`, `parent_id`, `sort`, `platform`, `wx_type`, `enabled`, `desc`) VALUES (‘7’, ‘menu’, ‘click1’, ‘/transfer/index.html’, NULL, ‘3’, ‘gavin’, ‘service’, ‘1’, ‘关于’);INSERT INTO `wx_cfg` (`id`, `type`, `name`, `value`, `parent_id`, `sort`, `platform`, `wx_type`, `enabled`, `desc`) VALUES (‘8’, ‘menu’, ‘view11’, ‘/transfer/index.html’, ‘5’, ‘1’, ‘gavin’, ‘service’, ‘1’, ‘JAVA’);INSERT INTO `wx_cfg` (`id`, `type`, `name`, `value`, `parent_id`, `sort`, `platform`, `wx_type`, `enabled`, `desc`) VALUES (‘9’, ‘menu’, ‘view12’, ‘/transfer/index.html’, ‘5’, ‘2’, ‘gavin’, ‘service’, ‘1’, ‘MySQL’);编写代码创建WxMenuService接口package com.gavin.service;import com.gavin.pojo.Menu;public interface WxMenuService {public Menu makeMenu(String platform) throws Exception;}创建实现类WxMenuServiceImpl,代码如下package com.gavin.service.impl;import java.util.ArrayList;import java.util.List;import java.util.Map;import org.apache.commons.lang3.StringUtils;import org.apache.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import com.gavin.cfg.WxCfgEnum;import com.gavin.pojo.AccessToken;import com.gavin.pojo.Button;import com.gavin.pojo.ClickButton;import com.gavin.pojo.ComplexButton;import com.gavin.pojo.Menu;import com.gavin.pojo.ViewButton;import com.gavin.pojo.WxApiCfg;import com.gavin.pojo.WxCfg;import com.gavin.service.WxCfgService;import com.gavin.service.WxMenuService;import com.gavin.service.WxTokenService;import com.gavin.util.EncryptionUtil;import com.gavin.util.WxUtil;import com.google.gson.Gson;@Servicepublic class WxMenuServiceImpl implements WxMenuService{private Logger logger = Logger.getLogger(this.getClass());@Autowiredprivate WxTokenService wxTokenService;@Autowiredprivate WxCfgService wxCfgService;/** * @title 根据平台创建微信公众号菜单 * @author gavin * @date 2019年5月23日 * @param platform * @return * @throws Exception */@Overridepublic Menu makeMenu(String platform) throws Exception {// 查询一级菜单System.out.println(platform);WxCfg parentParam = new WxCfg();parentParam.setType(WxCfgEnum.MENU.getType());parentParam.setEnabled(true);parentParam.setPlatform(platform);parentParam.setOrderBy(“sort asc”);ListWxCfg cfgList = this.wxCfgService.select(parentParam);if (cfgList.size() 0) {Menu menu = new Menu();ListButton buttons = new ArrayListButton();for (WxCfg cfg : cfgList) {WxCfg subParam = new WxCfg();subParam.setType(WxCfgEnum.MENU.getType());subParam.setParentId(cfg.getId());subParam.setEnabled(true);subParam.setPlatform(platform);// 查询二级菜单ListWxCfg subCfgList = this.wxCfgService.select(subParam);if (subCfgList.size() 0) {// 构建多级按钮ListButton subButtons = new ArrayListButton();for (WxCfg subCfg : subCfgList) {Button sub = createButton(subCfg);subButtons.add(sub);}ComplexButton complexButton = new ComplexButton();complexButton.setName(cfg.getDesc());complexButton.setSub_button(subButtons.toArray(new Button[subButtons.size()]));buttons.add(complexButton);} else {Button button = createButton(cfg

赞(0) 打赏
未经允许不得转载:E企盈小程序开发-热线:4006-838-530 » 微信公众号开发创建菜单
分享到: 更多 (0)
E企盈小程序直播营销卖货系统
E企盈直播平台营销卖货系统

评论 抢沙发

E企盈小程序开发

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏