微信公众帐号自定义菜单创建的python脚本
2015-12-21 11:17
881 查看
http://blog.csdn.net/arccreator/article/details/10579411
[python]
view plaincopy
# -*- encoding: utf-8 -*-
import urllib
import urllib2
from urllib import urlencode
import json
import sys
reload(sys)
sys.setdefaultencoding('UTF-8')
appid = 'xxxx'
secret = '000000'
gettoken = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + appid + '&secret=' + secret
f = urllib2.urlopen( gettoken )
stringjson = f.read()
access_token = json.loads(stringjson)['access_token']
#print access_token
posturl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token
menu = '''''{
"button":[
{
"name":"SPLUNK助手",
"sub_button":
[{
"type":"click",
"name":"告警助手",
"key":"V1001_ALERT"
},
{
"type":"click",
"name":"帮助系统",
"key":"V1001_HELP"
}
]
},
{
"name":"网站",
"sub_button":
[{
"type":"view",
"name":"精诚集团",
"url":"http://www.systex.com.tw/"
},
{
"type":"view",
"name":"splunk",
"url":"http://www.splunk.com/"
},
{
"type":"view",
"name":"SplunkLab",
"url":"http://www.splunklab.com/"
}
]
},
{
"name":"我们的团队",
"sub_button":
[{
"type":"click",
"name":"精诚集团",
"key":"V1001_SYSTEX"
},
{
"type":"click",
"name":"华北团队",
"key":"V1001_huabei"
},
{
"type":"click",
"name":"华东团队",
"key":"V1001_huadong"
},
{
"type":"click",
"name":"华南团队",
"key":"V1001_huanan"
},
{
"type":"click",
"name":"香港团队",
"key":"V1001_hongkong"
}
]
}]
}'''
request = urllib2.urlopen(posturl, menu.encode('utf-8') )
print request.read()
[python]
view plaincopy
# -*- encoding: utf-8 -*-
import urllib
import urllib2
from urllib import urlencode
import json
import sys
reload(sys)
sys.setdefaultencoding('UTF-8')
appid = 'xxxx'
secret = '000000'
gettoken = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + appid + '&secret=' + secret
f = urllib2.urlopen( gettoken )
stringjson = f.read()
access_token = json.loads(stringjson)['access_token']
#print access_token
posturl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token
menu = '''''{
"button":[
{
"name":"SPLUNK助手",
"sub_button":
[{
"type":"click",
"name":"告警助手",
"key":"V1001_ALERT"
},
{
"type":"click",
"name":"帮助系统",
"key":"V1001_HELP"
}
]
},
{
"name":"网站",
"sub_button":
[{
"type":"view",
"name":"精诚集团",
"url":"http://www.systex.com.tw/"
},
{
"type":"view",
"name":"splunk",
"url":"http://www.splunk.com/"
},
{
"type":"view",
"name":"SplunkLab",
"url":"http://www.splunklab.com/"
}
]
},
{
"name":"我们的团队",
"sub_button":
[{
"type":"click",
"name":"精诚集团",
"key":"V1001_SYSTEX"
},
{
"type":"click",
"name":"华北团队",
"key":"V1001_huabei"
},
{
"type":"click",
"name":"华东团队",
"key":"V1001_huadong"
},
{
"type":"click",
"name":"华南团队",
"key":"V1001_huanan"
},
{
"type":"click",
"name":"香港团队",
"key":"V1001_hongkong"
}
]
}]
}'''
request = urllib2.urlopen(posturl, menu.encode('utf-8') )
print request.read()
相关文章推荐
- 测试python代码在博客的显示
- Python -- 标准库 文件管理 (部分os包,shutil包)
- Python Network Programming(5)---套接字超时时间
- Python Bayes
- 近期用到的python知识列表
- ubuntu14.04LTS 搭建 python2.7+Qt 5.5+PyQt5开发环境
- dblp 数据集之python lxml解析
- python下载网页源码 写入文本
- python3 抓取必应bing首页图片作为桌面背景
- 利用Python脚本一键备份Mysql数据库
- 【详解】Python建立Map写Excel表
- Python 奇技淫巧
- python os.system() 支持中文路径名
- Operation on Excel by Python
- 零基础自学Python两个月小结
- 从一个例子看频率学派与贝叶斯学派的不同(Python)
- python对文件及文件夹的一些操作
- python计算分位数
- python模块
- python读写word、excel、csv、json文件