Use Python to customize menu instances on WeChat public platform

Source: Internet
Author: User
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.