标签:取消 创建 send ESS number 直接 cgi tar 平台
自定义菜单能够帮助公众号丰富界面,让用户更好更快地理解公众号的功能。
自定义菜单接口可实现多种类型按钮:
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[CLICK]]></Event> <EventKey><![CDATA[EVENTKEY]]></EventKey> </xml>
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[scancode_push]]></Event> <EventKey><![CDATA[EVENTKEY]]></EventKey> <ScanCodeInfo> <ScanType><![CDATA[qrcode]]></ScanType> <ScanResult><![CDATA[http://www.baidu.com]]></ScanResult> <EventKey><![CDATA[EVENTKEY]]></EventKey> </ScanCodeInfo> </xml>
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[scancode_waitmsg]]></Event> <EventKey><![CDATA[EVENTKEY]]></EventKey> <ScanCodeInfo> <ScanType><![CDATA[qrcode]]></ScanType> <ScanResult><![CDATA[http://www.baidu.com]]></ScanResult> <EventKey><![CDATA[EVENTKEY]]></EventKey> </ScanCodeInfo> </xml>
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1348831860</CreateTime> <MsgType><![CDATA[image]]></MsgType> <PicUrl><![CDATA[this is a url]]></PicUrl> <MediaId><![CDATA[media_id]]></MediaId> <MsgId>1234567890123456</MsgId> </xml>
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[pic_photo_or_album]]></Event> <EventKey><![CDATA[EVENTKEY]]></EventKey> <SendPicsInfo> <Count><![CDATA[1]]></Count> <PicList> <item> <PicMd5Sum><![CDATA[58f4xxxxxxxxxx]]></PicMd5Sum> </item> </PicList> </SendPicsInfo> </xml> <xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1348831860</CreateTime> <MsgType><![CDATA[image]]></MsgType> <PicUrl><![CDATA[this is a url]]></PicUrl> <MediaId><![CDATA[media_id]]></MediaId> <MsgId>1234567890123456</MsgId> </xml>
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[pic_weixin]]></Event> <EventKey><![CDATA[EVENTKEY]]></EventKey> <SendPicsInfo> <Count><![CDATA[3]]></Count> <PicList> <item> <PicMd5Sum><![CDATA[58f4xxxxxxxxxx]]></PicMd5Sum> </item> <item> <PicMd5Sum><![CDATA[58f4xxxxxxxxxx]]></PicMd5Sum> </item> <item> <PicMd5Sum><![CDATA[58f4xxxxxxxxxx]]></PicMd5Sum> </item> </PicList> </SendPicsInfo> </xml> <xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1348831860</CreateTime> <MsgType><![CDATA[image]]></MsgType> <PicUrl><![CDATA[this is a url]]></PicUrl> <MediaId><![CDATA[media_id]]></MediaId> <MsgId>123456789012345x</MsgId> </xml> <xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1348831860</CreateTime> <MsgType><![CDATA[image]]></MsgType> <PicUrl><![CDATA[this is a url]]></PicUrl> <MediaId><![CDATA[media_id]]></MediaId> <MsgId>1234567890123456</MsgId> </xml> <xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1348831860</CreateTime> <MsgType><![CDATA[image]]></MsgType> <PicUrl><![CDATA[this is a url]]></PicUrl> <MediaId><![CDATA[media_id]]></MediaId> <MsgId>1234567890123456</MsgId> </xml> 对于上述每个图片的消息,后台收到都能进行单独回应
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[FromUser]]></FromUserName> <CreateTime>123456789</CreateTime> <MsgType><![CDATA[event]]></MsgType> <Event><![CDATA[location_select]]></Event> <EventKey><![CDATA[EVENTKEY]]></EventKey> <SendLocationInfo> <Location_X><![CDATA[23.134521]]></Location_X> <Location_Y><![CDATA[113.358803]]></Location_Y> <Scale><![CDATA[20]]></Scale> <Label><![CDATA[位置信息]]></Label> <Poiname><![CDATA[]]></Poiname> <EventKey><![CDATA[EVENTKEY]]></EventKey> </SendLocationInfo> </xml> <xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1351776360</CreateTime> <MsgType><![CDATA[location]]></MsgType> <Location_X>23.134521</Location_X> <Location_Y>113.358803</Location_Y> <Scale>20</Scale> <Label><![CDATA[位置信息]]></Label> <MsgId>1234567890123456</MsgId> </xml>
9和10,是专门给第三方平台旗下未微信认证(具体而言,是资质认证未通过)的订阅号准备的事件类型,它们是没有事件推送的,能力相对受限,其他类型的公众号不必使用。
创建菜单:
接口: http请求方式:POST(请使用https协议) https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
返回:{"errcode":0,"errmsg":"ok"} 或
{"errcode":40018,"errmsg":"invalid button name size"}
def create_menu(access_token,json_menu):
print(json_menu)
headers = {
‘content_type‘: "application/json"
}
json_menu = json.dumps(json_menu,ensure_ascii=False)
create_url = ‘https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}‘.format(access_token)
response = requests.post(create_url,json_menu.encode(‘utf-8‘),headers=headers)
return json.loads(response.text)
注意:这个debug了好久。首先需要将 python的 dict转化为json 数据,然后在传入post 参数时进行 utf-8封装。不然 就是创建不成功,
总是返回:{‘errcode‘: 40016, ‘errmsg‘: ‘invalid button size hint
menu_data:
menu_data = {
"button": [
{
"name": "新手",
"sub_button": [
{
"type": "click",
"name": "点击拉歌曲",
"key": "click_music"
},
{
"type": "view",
"name": "查看百度",
"url": "http://www.baidu.com"
},
{
"type": "scancode_waitmsg",
"name": "扫码等消息",
"key": "scancode_waitmsg_event"
},
{
"type": "pic_sysphoto",
"name": "系统相册",
"key": "pic_sysphoto_event"
}
]
},
{
"name": "其他",
"sub_button": [
{
"type": "scancode_push",
"name": "扫码推事件",
"key": "scancode_push_event"
},
{
"type": "pic_photo_or_album",
"name": "拍照或选照片",
"key": "pic_photo_or_album_event"
},
{
"type": "pic_weixin",
"name": "微信相册",
"key": "pic_weixin_event"
},
{
"type": "location_select",
"name": "发送位置",
"key": "location_select_event"
}
]
}
]
}
查询菜单:
接口: http请求方式: GET(请使用https协议)https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=ACCESS_TOKEN
返回:https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Querying_Custom_Menus.html
alue、url、key等字段 对于不同的菜单类型,value的值意义不同。官网上设置的自定义菜单: Text:保存文字到value; Img、voice:保存mediaID到value;
Video:保存视频下载链接到value; News:保存图文消息到news_info,同时保存mediaID到value; View:保存链接到url。
使用API设置的自定义菜单: click、scancode_push、scancode_waitmsg、pic_sysphoto、pic_photo_or_album、
pic_weixin、location_select:保存值到key;view:保存链接到url
def query_menu(access_token):
query_url = ‘https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=%s‘% access_token
response = requests.get(query_url)
return json.loads(response.content)
删除菜单:
接口: http请求方式:GET https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=ACCESS_TOKEN
返回:对应创建接口,正确的Json返回结果:
{"errcode":0,"errmsg":"ok"}
注意: 在个性化菜单时,调用此接口会删除默认菜单及全部个性化菜单。
def delete_menu(access_token):
delete_url = ‘https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=%s‘% access_token
response = requests.get(delete_url)
return json.loads(response.text)
标签:取消 创建 send ESS number 直接 cgi tar 平台
原文地址:https://www.cnblogs.com/ahMay/p/12047826.html