Java微信公众号菜单关联小程序-小程序怎么放到公众号菜单里-公众号菜单链接小程序
1.
最近微信公众号开发了菜单关联小程序功能,实现代码如下
/***自定义菜单工具类*@authorwhy**/publicclassMenuUtil{privatestaticLoggerloggerLogger.getLogger(MenuUtil.class);//日志//创建菜单接口地址publicfinalstaticStringmenu_create_url"https://api.weixin.qq.com/cgi-bin/menu/create?access_tokenACCESS_TOKEN";/***创建菜单*@parammenu菜单实例*@paramaccessToken凭证*@returntrue成功false失败*/publicstaticbooleancreateMenu(Menumenu,StringaccessToken){booleanresultfalse;Stringurlmenu_create_url.replace("ACCESS_TOKEN",accessToken);//将菜单对象转换成JSON字符串StringjsonMenuJSONObject.fromObject(menu).toString();//发起post请求创建菜单JSONObjectjsonObjectWeixinUtil.httpRequest(url,"POST",jsonMenu);if(null!jsonObject){interrorCodejsonObject.getInt("errcode");StringerrorMsgjsonObject.getString("errmsg");System.out.println(""+errorCode+""+errorMsg);if(0errorCode){resulttrue;}else{resultfalse;logger.error("创建菜单失败errorCode:{"+errorCode+"}errorMsg:{"+errorMsg+"}");System.out.println(errorCode+""+errorMsg);}}returnresult;}}/***类名称:ToXcx.java*类描述:小程序菜单实体类*作者:why*时间:2017年4月21日*/publicclassToXcxextendsButton{privateStringtype;//类型privateStringname;//菜单名称privateStringurl;//不支持小程序跳转地址privateStringappid;//小程序appidprivateStringpagepath;//小程序页面路径publicStringgetType(){returntype;}publicvoidsetType(Stringtype){this.typetype;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.namename;}publicStringgetUrl(){returnurl;}publicvoidsetUrl(Stringurl){this.urlurl;}publicStringgetAppid(){returnappid;}publicvoidsetAppid(Stringappid){this.appidappid;}publicStringgetPagepath(){returnpagepath;}publicvoidsetPagepath(Stringpagepath){this.pagepathpagepath;}}创建菜单ToXcxxcxBtn1newToXcx();xcxBtn1.setName("我要寄件");xcxBtn1.setType("miniprogram");xcxBtn1.setUrl("");xcxBtn1.setAppid("");xcxBtn1.setPagepath("pages/send/send");调用MenuUtil.createMenu(菜单json,token);声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

