Python脚本--微信公众号自定义菜单的创建及获取
生活随笔
收集整理的這篇文章主要介紹了
Python脚本--微信公众号自定义菜单的创建及获取
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
暑假寫的一個修改/獲取微信公眾號菜單的腳本,具體看微信公眾平臺的API:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1445241432
# -*- coding: utf-8 -* import tkMessageBox import urllib2 import json import sys reload(sys) sys.setdefaultencoding('UTF-8')appID = 'wxa46e26b3d591f9f2' //測試號信息 appsecret = '83ee70dbb6dbc1e090971554b1c7981b' //同上menu = { //菜單信息,包括一級菜單和二級菜單"button":[{"type": "view", //type還可以是微信小程序等,此例子只用了一種type。具體可以去看API"name": "百度","url": baidu,},{"name": "騰訊","sub_button": [{"type": "view","name": "騰訊主頁","url": "http://www.tencent.com"},{"type": "view","name": "騰訊招聘","url" : "https://join.qq.com/"},{"type": "view","name": "騰訊網(wǎng)","url": "https://www.qq.com/"},{"type": "view","name": "騰訊視頻","url": "https://v.qq.com/"}]},{"name": "博客園","sub_button": [{"type": "view","name": "我的博客","url": "https://www.cnblogs.com/cy708/"},{"type": "view","name": "博客園主頁","url": "https://www.cnblogs.com/"}]}] }def getMenuRequest():gettoken = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + appID + '&secret=' + appsecretf = urllib2.urlopen(gettoken)stringjson = f.read()access_token = json.loads(stringjson)['access_token']posturl = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + access_tokenreq = urllib2.Request(posturl)data = urllib2.urlopen(req).read()data = json.loads(data)return datadef createMenuRequest(menu):data = json.dumps(menu,ensure_ascii=False).encode('utf-8')gettoken = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + appID + '&secret=' + appsecretf = urllib2.urlopen(gettoken)stringjson = f.read()access_token = json.loads(stringjson)['access_token']postcreateurl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_tokenreq = urllib2.Request(postcreateurl)response = urllib2.urlopen(req, menu)result = response.read()result = json.loads(result) //到這步就可以了,下面的只是提示框顯示結(jié)果而已if result["errcode"] == 0:tkMessageBox.showinfo('成功!',"errmsg:"+str(result["errmsg"]))else:tkMessageBox.showinfo('失敗!', "errcode:"+str(result["errcode"])+"\n"+"errmsg:" + str(result["errmsg"]))?
轉(zhuǎn)載于:https://www.cnblogs.com/cy708/p/10049977.html
總結(jié)
以上是生活随笔為你收集整理的Python脚本--微信公众号自定义菜单的创建及获取的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pci枚举初始化部分(2)
- 下一篇: 思科交换机和路由器的远程配置