自定义菜单接口

class wechatpy.client.api.WeChatMenu(client=None)[源代码]
add_conditional(menu_data)[源代码]

创建个性化菜单

from wechatpy import WeChatClient

client = WeChatClient("appid", "secret")
client.menu.add_conditional({
    "button":[
        {
            "type":"click",
            "name":"今日歌曲",
            "key":"V1001_TODAY_MUSIC"
        },
        {
            "type":"click",
            "name":"歌手简介",
            "key":"V1001_TODAY_SINGER"
        },
        {
            "name":"菜单",
            "sub_button":[
                {
                    "type":"view",
                    "name":"搜索",
                    "url":"http://www.soso.com/"
                },
                {
                    "type":"view",
                    "name":"视频",
                    "url":"http://v.qq.com/"
                },
                {
                    "type":"click",
                    "name":"赞一下我们",
                    "key":"V1001_GOOD"
                }
            ]
        }
    ],
    "matchrule":{
      "group_id":"2",
      "sex":"1",
      "country":"中国",
      "province":"广东",
      "city":"广州",
      "client_platform_type":"2"
    }
})

详情请参考 http://mp.weixin.qq.com/wiki/0/c48ccd12b69ae023159b4bfaa7c39c20.html

参数:menu_data – Python 字典
返回:返回的 JSON 数据包
create(menu_data)[源代码]

创建自定义菜单

from wechatpy import WeChatClient

client = WeChatClient("appid", "secret")
client.menu.create({
    "button":[
        {
            "type":"click",
            "name":"今日歌曲",
            "key":"V1001_TODAY_MUSIC"
        },
        {
            "type":"click",
            "name":"歌手简介",
            "key":"V1001_TODAY_SINGER"
        },
        {
            "name":"菜单",
            "sub_button":[
                {
                    "type":"view",
                    "name":"搜索",
                    "url":"http://www.soso.com/"
                },
                {
                    "type":"view",
                    "name":"视频",
                    "url":"http://v.qq.com/"
                },
                {
                    "type":"click",
                    "name":"赞一下我们",
                    "key":"V1001_GOOD"
                }
            ]
        }
    ]
})

详情请参考 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html

参数:menu_data – Python 字典
返回:返回的 JSON 数据包
del_conditional(menu_id)[源代码]

删除个性化菜单

详情请参考 http://mp.weixin.qq.com/wiki/0/c48ccd12b69ae023159b4bfaa7c39c20.html

参数:menu_id – 菜单ID
返回:返回的 JSON 数据包

使用示例:

from wechatpy import WeChatClient

client = WeChatClient('appid', 'secret')
res = client.menu.del_conditional('menu_id')
delete()[源代码]

删除自定义菜单。 详情请参考 http://mp.weixin.qq.com/wiki/16/8ed41ba931e4845844ad6d1eeb8060c8.html

返回:返回的 JSON 数据包

使用示例:

from wechatpy import WeChatClient

client = WeChatClient('appid', 'secret')
res = client.menu.delete()
get()[源代码]

查询自定义菜单。 详情请参考 http://mp.weixin.qq.com/wiki/16/ff9b7b85220e1396ffa16794a9d95adc.html

返回:返回的 JSON 数据包

使用示例:

from wechatpy import WeChatClient

client = WeChatClient('appid', 'secret')
menu = client.menu.get()
get_menu_info()[源代码]

获取自定义菜单配置 详情请参考 http://mp.weixin.qq.com/wiki/17/4dc4b0514fdad7a5fbbd477aa9aab5ed.html

返回:返回的 JSON 数据包

使用示例:

from wechatpy import WeChatClient

client = WeChatClient('appid', 'secret')
menu_info = client.menu.get_menu_info()
try_match(user_id)[源代码]

测试个性化菜单匹配结果

详情请参考 http://mp.weixin.qq.com/wiki/0/c48ccd12b69ae023159b4bfaa7c39c20.html

参数:user_id – 可以是粉丝的OpenID,也可以是粉丝的微信号。
返回:该接口将返回菜单配置

使用示例:

from wechatpy import WeChatClient

client = WeChatClient('appid', 'secret')
res = client.menu.try_match('openid')
update(menu_data)

创建自定义菜单

from wechatpy import WeChatClient

client = WeChatClient("appid", "secret")
client.menu.create({
    "button":[
        {
            "type":"click",
            "name":"今日歌曲",
            "key":"V1001_TODAY_MUSIC"
        },
        {
            "type":"click",
            "name":"歌手简介",
            "key":"V1001_TODAY_SINGER"
        },
        {
            "name":"菜单",
            "sub_button":[
                {
                    "type":"view",
                    "name":"搜索",
                    "url":"http://www.soso.com/"
                },
                {
                    "type":"view",
                    "name":"视频",
                    "url":"http://v.qq.com/"
                },
                {
                    "type":"click",
                    "name":"赞一下我们",
                    "key":"V1001_GOOD"
                }
            ]
        }
    ]
})

详情请参考 http://mp.weixin.qq.com/wiki/13/43de8269be54a0a6f64413e4dfa94f39.html

参数:menu_data – Python 字典
返回:返回的 JSON 数据包