Python implements custom menu instances on WeChat public platform and python instances

Source: Internet
Author: User

Python provides custom menu instances for public platforms and python instances.

First, obtain the access_token and save it to 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": "featured", "url": "http://m.jb51.net/photos "}, {"type": "view", "name": "Review", "url": "http://m.qzone.com/infocenter? G_f = #2378686916/mine "},{" type ":" view "," name ":" meitu app "," url ":" http://jb51.net/app/app.html "}]}, {"name": "Case study", "sub_button": [{"type": "click", "name": "All style", "key ": "style" },{ "type": "click", "name": "All units", "key": "houseType" },{ "type ": "click", "name": "All area", "key": "area" },{ "type": "view", "name ": "More cases", "url": "http://m.jb51.net/projects"}] },{ "type": "view", "name": "design application", "url ": "http: // Jb51.net/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)

Related Article

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.