>백엔드 개발 >PHP 튜토리얼 >微信公众平台自定义菜单开发示例_PHP教程

微信公众平台自定义菜单开发示例_PHP教程

WBOY
WBOY원래의
2016-07-13 10:43:541168검색

微信公众平台推出一自定义菜单功能,我们可以简单的直接在后台编辑自定义菜单,也可以利用api来设置菜单,下面我来介绍一下操作方法

 腾讯微信3月19日正式公布公众平台自定义菜单功能。目前该功能仅提供给企业和机构,且内测资格需要申请。对于这一新增功能,目前仅有少数账号已经开通。至此,微信的商业化价值被进一步挖掘出来。

 

微信公众平台推出自定义菜单功能

 

   开发者可利用该功能为公众账号的会话界面底部增加自定义菜单。用户点击菜单中的选项,可以调出相应的回复信息或网页链接。

菜单创建
接口说明
通过POST一个特定结构体,实现在微信客户端创建自定义菜单。
请求说明
http请求方式:POST

https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN

结构体其实就是一个json格式的字符串,相信很多朋友就卡在这里了,怎么往这个接口地址 post 一个结构体呢,实现代码如下:

 代码如下 复制代码

public static void main(String[] args) throws Exception {
    URL url = new URL("https://api.weixin.qq.com/cgi-bin
                                 /menu/create?access_token=TOKEN");
        String responeJsonStr = "{"+
                                     ""button":["+
                                     "{"name":"酒店预订","+
                                     ""sub_button":["+
                             "{"+
                                ""type":"click","+
                                ""name":"附近酒店","+
                                ""key":"jintoneinn488878-1""+
                            "},"+
                            "{"+
                                ""type":"click","+
                                ""name":"查找酒店","+
                                ""key":"jintoneinn488878-2""+
                            "}"+
                        "]"+
                    "}"
                "]"+
            "}";
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        conn.connect();
        conn.getOutputStream().write(responeJsonStr.getBytes("utf-8"));
        InputStream is = conn.getInputStream();
        BufferedReader in = new BufferedReader(new InputStreamReader(is,"utf-8"));
        StringBuffer buffer = new StringBuffer();
        String line = "";
        while ((line = in.readLine()) != null) {
            buffer.append(line);
        }
        System.out.println(buffer.toString()); 
    }


菜单查询
接口说明

查询当前使用的自定义菜单结构。

请求说明

http请求方式:GET

https://api.weixin.qq.com/cgi-bin/menu/get?access_token=ACCESS_TOKEN
返回说明

对应创建接口,正确的Json返回结果:

 代码如下 复制代码

{"menu":{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC","sub_button":[]},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER","sub_button":[]},{"name":"菜单","sub_button":[{"type":"click","name":"hello word","key":"V1001_HELLO_WORLD","sub_button":[]},{"type":"click","name":"赞一下我们","key":"V1001_GOOD","sub_button":[]}]}]}}


菜单删除
接口说明

取消当前使用的自定义菜单。

请求说明

http请求方式:GET
https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN
返回说明

对应创建接口,正确的Json返回结果:

 代码如下 复制代码
{"errcode":0,"errmsg":"ok"}

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/633140.htmlTechArticle微信公众平台推出一自定义菜单功能,我们可以简单的直接在后台编辑自定义菜单,也可以利用api来设置菜单,下面我来介绍一下操作方法...
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.