当前位置:网站首页>微信小程序开发之菜单的创建
微信小程序开发之菜单的创建
2022-06-09 08:49:00 【种豆走天下】
微信小程序开发之菜单的创建
package com.qfjy.project.weixin.main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qfjy.project.weixin.pojo.AccessToken;
import com.qfjy.project.weixin.pojo.Button;
import com.qfjy.project.weixin.pojo.CommonButton;
import com.qfjy.project.weixin.pojo.ComplexButton;
import com.qfjy.project.weixin.pojo.Menu;
import com.qfjy.project.weixin.pojo.ViewButton;
import com.qfjy.project.weixin.util.WeixinUtil;
/** * 菜单管理器类 * */
public class MenuManager {
private static Logger log = LoggerFactory.getLogger(MenuManager.class);
/*** * 自定义菜单的创建步骤 1、找到AppId和AppSecret。自定义菜单申请成功后,在“高级功能”-“开发模式”-“接口配置信息”的最后两项就是; 2、根据AppId和AppSecret,以https get方式获取访问特殊接口所必须的凭证access_token; 3、根据access_token,将json格式的菜单数据通过https post方式提交。 */
public final static String REAL_URL="http://njqfjy.natapp1.cc/"; //个人花生壳
//public final static String REAL_URL = "http://wxmobsa.yidatec.com/weixin/"; //正式号服务器
public final static String appId="wxe4325a93f6dacc7b";
public final static String appSecret = "e754d645a9d14a2fd497aa065e9ec6b6";
public static void resultMenu(){
// 调用接口获取access_token
AccessToken at = WeixinUtil.getAccessToken(appId, appSecret);
if (null != at) {
// 调用接口创建菜单
int result = WeixinUtil.createMenu(getMenu(), at.getToken());
// 判断菜单创建结果
if (0 == result)
log.info("菜单创建成功!");
else
log.info("菜单创建失败,错误码:" + result);
}
}
public static void main(String[] args) {
// 第三方用户唯一凭证
String appId = MenuManager.appId;
// 第三方用户唯一凭证密钥
String appSecret = MenuManager.appSecret;
// 调用接口获取access_token
AccessToken at = WeixinUtil.getAccessToken(appId, appSecret);
if (null != at) {
// 调用接口创建菜单
int result = WeixinUtil.createMenu(getMenu(),at.getToken());
// 判断菜单创建结果
if (0 == result)
log.info("菜单创建成功!");
else
log.info("菜单创建失败,错误码:" + result);
}
}
/** * 组装菜单数据 * * @return */
private static Menu getMenu() {
ViewButton btn10 = new ViewButton();
btn10.setName("会议发布");
btn10.setType("view");
btn10.setUrl(MenuManager.REAL_URL+"weixinMenu/meetingPub");
CommonButton btn11 = new CommonButton();
btn11.setName("会议枪单");
btn11.setType("click");
btn11.setKey("11");
//-------------------------------------------------------
CommonButton btn20 = new CommonButton();
btn20.setName("每日签到");
btn20.setType("click");
btn20.setKey("20");
ViewButton btn21 = new ViewButton();
btn21.setName("发单排行榜");
btn21.setType("view");
btn21.setUrl("https://www.baidu.com/");
//------------------------------------------------------------
ViewButton btn30 = new ViewButton();
btn30.setName("个人中心");
btn30.setType("view");
btn30.setUrl(MenuManager.REAL_URL+"weixinMenu/userInfo");
CommonButton btn31 = new CommonButton(); //返回图文消息
btn31.setName("联系我们");
btn31.setType("click");
btn31.setKey("30");
CommonButton btn32 = new CommonButton(); //返回图文消息
btn32.setName("版本消息");
btn32.setType("click");
btn32.setKey("31");
//###############################################一级子菜单
ComplexButton mainBtn1 = new ComplexButton();
mainBtn1.setName("会议");
mainBtn1.setSub_button(new Button[] {
btn10,btn11});
ComplexButton mainBtn2 = new ComplexButton();
mainBtn2.setName("公告板"); //
mainBtn2.setSub_button(new Button[] {
btn20,btn21});
ComplexButton mainBtn3 = new ComplexButton();
mainBtn3.setName("系统消息");// btn31, btn32, btn33,
mainBtn3.setSub_button(new Button[] {
btn30,btn31,btn32});
/** * 这是公众号目前的菜单结构,每个一级菜单都有二级菜单项<br> */
Menu menu = new Menu();
menu.setButton(new Button[] {
mainBtn1, mainBtn2, mainBtn3});
return menu;
}
}
边栏推荐
- LeetCode 第 295 场周赛
- Document sorting (expansion)
- 成本节省 50%,9人团队使用函数计算开发 wolai 在线文档应用
- Sql: find duplicate email addresses
- Clickhouse data type sorting of system operation and maintenance series
- I met a big man!
- Is it safe for flush to open an account? Is it reliable?
- 探索MySQL not in到底走索引吗?
- JS realizes three-level linkage
- Summary of string inversion methods
猜你喜欢

安科瑞企业微电网能效管理平台推动电网向能源互联网升级

C语言指针

腾讯云宝塔搭建网站注意事项

Excel application of office software series 4

The energy efficiency management platform of the microgrid of the company promotes the upgrading of the power grid to the energy Internet

测试不会被开发取代吗?

Virtual machine installation and configuration
![[antenna] [2] explanation of some nouns and simple concepts, still](/img/84/7fb2b01dc717eb9196b33066ea3b4e.png)
[antenna] [2] explanation of some nouns and simple concepts, still

How to solve the problem of mouseup event invalidation

Compilation_ Basic concepts
随机推荐
RMAN backup concept_ Online backup and backup mode
Domain Driven Design (DDD)
Modifier le tableau des activités de marché
同花顺在上面开户安全吗?靠谱吗?
Configuring the environment for RMAN backups_ Configure the deletion policy for archived redo logs
Analysis methods of common problems in performance testing
Configure CONDA environment and pytoch installation
Web knowledge points 123
JS window object
3D编程模式:依赖隔离模式
安科瑞企业微电网能效管理平台推动电网向能源互联网升级
【程序人生】互联网岗位分工;互联网开发流程;职责分工
如何使用阿里云 CDN 对部署在函数计算上的静态网站进行缓存
Shared network port settings for Dell Idrac express version
【Redis学习12】分布式缓存之哨兵机制,分片集群
认识了一位大佬!
Summary of string inversion methods
剩余电流继电器用剩余电流互感器来检测剩余电流防止电气火灾的发生
清洗数据---2022/06/08
Will testing not be replaced by development?