日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 公众号菜单_Python脚本--微信公众号自定义菜单的创建及获取

發布時間:2025/3/12 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 公众号菜单_Python脚本--微信公众号自定义菜单的创建及获取 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#-*- coding: utf-8 -*

importtkMessageBoximporturllib2importjsonimportsys

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": "騰訊網","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/"}

]

}

]

}defgetMenuRequest():

gettoken= 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + appID + '&secret=' +appsecret

f=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_token

req=urllib2.Request(posturl)

data=urllib2.urlopen(req).read()

data=json.loads(data)returndatadefcreateMenuRequest(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=' +appsecret

f=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_token

req=urllib2.Request(postcreateurl)

response=urllib2.urlopen(req, menu)

result=response.read()

result= json.loads(result) //到這步就可以了,下面的只是提示框顯示結果而已if result["errcode"] ==0:

tkMessageBox.showinfo('成功!',"errmsg:"+str(result["errmsg"]))else:

tkMessageBox.showinfo('失敗!', "errcode:"+str(result["errcode"])+"\n"+"errmsg:" + str(result["errmsg"]))

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的python 公众号菜单_Python脚本--微信公众号自定义菜单的创建及获取的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。