-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.py
63 lines (55 loc) · 1.86 KB
/
menu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import requests,json
from basic import Basic
class Menu(object):
def __init__(self):
self.uri = "https://api.weixin.qq.com"
# 创建菜单
def create(self, data, accessToken):
createUrl = f"{self.uri}/cgi-bin/menu/create?access_token={accessToken}"
# python3 中 str 就是 unicode
if isinstance(data, str):
data = data.encode("utf-8")
res = requests.post(createUrl, data=data).json()
print(res)
if __name__ == '__main__':
myMenu = Menu()
postJson = """
{
"button":
[
{
"type": "click",
"name": "开发指引",
"key": "mpGuide"
},
{
"name": "公众平台",
"sub_button":
[
{
"type": "view",
"name": "更新公告",
"url": "http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1418702138&token=&lang=zh_CN"
},
{
"type": "view",
"name": "接口权限说明",
"url": "http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1418702138&token=&lang=zh_CN"
},
{
"type": "view",
"name": "返回码说明",
"url": "http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433747234&token=&lang=zh_CN"
}
]
},
{
"type": "media_id",
"name": "旅行",
"media_id": "z2zOokJvlzCXXNhSjF46gdx6rSghwX2xOD5GUV9nbX4"
}]
}
"""
accessToken = Basic().get_access_token()
print(accessToken)
myMenu.create(postJson, accessToken)