Python——WeRobot(微信公众号开发)

自定义菜单栏

 1 from werobot import WeRoBot
 2 #定义app_id,app_secret
 3 robot = WeRoBot(token='tteexx',app_id='wx5460f356c8812eaa',app_secret= '59869174d649bfdb1e6cc1a2e8e91998')
 4 #继承client的方法
 5 client = robot.client
 6 #获取acceaccess token
 7 oken = client.grant_token()
 8 #刷新acceaccess token
 9 token = client.get_access_token()
10 #提交post请求
11 client.request(method='post',url=' https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' + str(token))
12 #自定义菜单
13 client.create_menu(
14 {
15      "button":[
16      {
17           "type":"click",
18           "name":"今日歌曲",
19           "key":"V1001_TODAY_MUSIC"
20       },
21       {
22            "name":"菜单",
23            "sub_button":[
24            {
25                "type":"view",
26                "name":"搜索",
27                "url":"http://www.soso.com/"
28             },
29             {
30                  "type":"miniprogram",
31                  "name":"wxa",
32                  "url":"http://mp.weixin.qq.com",
33                  "appid":"wx286b93c14bbf93aa",
34                  "pagepath":"pages/lunar/index"
35              },
36             {
37                "type":"click",
38                "name":"赞一下我们",
39                "key":"V1001_GOOD"
40             }]
41        }]
42  }
43 )
44 robot.config['HOST'] = '192.168.3.81'
45 robot.config['PORT'] = 443
46 robot.run()
自定义菜单栏

 注:1、40164报错:未将IP地址添加到白名单中,将提示的IP加入IP地址白名单中

   2、48001报错:非授权的账户不可使用自定义菜单栏

猜你喜欢

转载自www.cnblogs.com/cxys85/p/10270277.html