This article mainly introduces the Python implementation of custom menu instances for the public platform. This article provides the implementation code directly. if you need it, you can refer to the following to obtain the access_token first, and save it with the global
def token(requset): url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s' % ( Config.AppID, Config.AppSecret) result = urllib2.urlopen(url).read() Config.access_token = json.loads(result).get('access_token') print 'access_token===%s' % Config.access_token return HttpResponse(result)
Use the access_token obtained above to create a custom form
Def createMenu (request): url =" https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s "% Config. access_token data = {"button": [{"name": "", "sub_button": [{"type": "click", "name ": "meitu", "key": "meitu" },{ "type": "view", "name": "selected", "url ":" http://m.bitsCN.com/photos "},{" Type ":" view "," name ":" review "," url ":" http://m.qzone.com/infocenter?g_f=#2378686916/mine "},{" Type ":" view "," name ":" Meitu app "," url ":" http://bitsCN.com/app/app.html "}] },{" Name ":" Case Study "," sub_button ": [{" type ":" click "," name ":" All styles ", "key": "style" },{ "type": "click", "name": "All units", "key": "houseType "}, {"type": "click", "name": "All area", "key": "area" },{ "type": "view", "name ": "More cases", "url ":" http://m.bitsCN.com/projects "}] },{" Type ":" view "," name ":" design application "," url ":" http://bitsCN.com/zhuanti/freedesign.jsp?src=3 "}]} # Data = json. loads (data) # data = urllib. urlencode (data) req = urllib2.Request (url) req. add_header ('content-type', 'application/json') req. add_header ('encoding', 'utf-8') response = urllib2.urlopen (req, json. dumps (data, ensure_ascii = False) result = response. read () return HttpResponse (result)