Python realizes WeChat public platform custom menu instance

Source: Internet
Author: User
First get Access_token, and save and 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)

Create a custom form using the Access_token obtained above

def createmenu (request): url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s"% Config.access_token        data = {"button": [{"Name": "Look at the picture", "Sub_button": [{"Type": "click", "Name": "US Map",  "Key": "Meitu"}, {"Type": "View", "Name": "Featured", "url": "Http://m.bitsCN.com/photos"},        {"Type": "View", "Name": "Review", "url": "Http://m.qzone.com/infocenter?g_f= #2378686916/mine"}, {      "Type": "View", "name": "Beauty App", "url": "Http://bitsCN.com/app/app.html"}]}, {"name": "See Case", "Sub_button": [{"Type": "click", "Name": "All Styles", "key": "Style"}, {"Type": "Click", "Name": "All Units", "key": "Housetype"}, {"Type": "click", "Name": "Total area", "Ke      Y ":" area "}, {" Type ":" View "," name ":" More Cases "," url ":" Http://m.bitsCN.com/projects "}]}, { "Type": "View", "NAme ": Design Request", "url": "Http://bitsCN.com/zhuanti/freedesign.jsp?src=3"}]} #data = json.loads (data) #data = Urllib.ur Lencode (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.