微信公众号关联不了小程序-Java微信公众号菜单关联小程序-微信关联小程序
1.最近微信公众号开发了菜单关联小程序功能,实现代码如下
/***自定义菜单工具类*@authorwhy**/publicclassMenuUtil{privatestaticLoggerlogger=Logger.getLogger(MenuUtil.class);//日志//创建菜单接口地址publicfinalstaticStringmenu_create_url="https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN";/***创建菜单*@parammenu菜单实例*@paramaccessToken凭证*@returntrue成功false失败*/publicstaticbooleancreateMenu(Menumenu,StringaccessToken){booleanresult=false;Stringurl=menu_create_url.replace("ACCESS_TOKEN",accessToken);//将菜单对象转换成JSON字符串StringjsonMenu=JSONObject.fromObject(menu).toString();//发起post请求创建菜单JSONObjectjsonObject=WeixinUtil.httpRequest(url,"POST",jsonMenu);if(null!=jsonObject){interrorCode=jsonObject.getInt("errcode");StringerrorMsg=jsonObject.getString("errmsg");System.out.println("====================="+errorCode+""+errorMsg);if(0==errorCode){result=true;}else{result=false;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.type=type;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringgetUrl(){returnurl;}publicvoidsetUrl(Stringurl){this.url=url;}publicStringgetAppid(){returnappid;}publicvoidsetAppid(Stringappid){this.appid=appid;}publicStringgetPagepath(){returnpagepath;}publicvoidsetPagepath(Stringpagepath){this.pagepath=pagepath;}}创建菜单ToXcxxcxBtn1=newToXcx();xcxBtn1.setName("我要寄件");xcxBtn1.setType("miniprogram");xcxBtn1.setUrl("");xcxBtn1.setAppid("");xcxBtn1.setPagepath("pages/send/send");调用MenuUtil.createMenu(菜单json,token);TAG标签: 微信小程序微信公众号关联不了小程序微信关联小程序
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

