Create and delete custom menu in python WeChat 6

Source: Internet
Author: User

Access the creat and del directories respectively.

#-*-Coding: UTF-8-*-import saeimport webimport xml. etree. elementTree as ETimport sae. constimport MySQLdbimport urllib2import jsonurls = ('/', 'Hello', '/creat', 'creatmenu ','/del ', 'deletemenu',) class Hello: def GET (self): data = web. input () echostr = data. echostr return echostr def POST (self): data = web. data () root = ET. fromstring (data) fromUser = root. findtext (". // FromUserName ") toUser = root. findtext (". // ToUserName ") CreateTime = root. findtext (". // CreateTime ") MsgType = root. findtext (". // MsgType ") Content = root. findtext (". // Content ") Content = Content. encode ('utf-8') db = MySQLdb. connect (host = sae. const. MYSQL_HOST, port = int (sae. const. MYSQL_PORT), user = sae. const. MYSQL_USER, passwd = sae. const. MYSQL_PASS, db = sae. const. MYSQL_DB, charset = 'utf8') c = db. cursor () SQL = "select * from py WHERE pro = '" + Content + "'" c.exe cute (SQL) rows = c. fetchone () tpl = '''
 
  
   
''' + FromUser + '''
  
  
   
''' + ToUser + '''
  
  
   
''' + CreateTime + '''
  
  text
  
  
   
''' + Rows [2] + '''
  
 '''Return tpl; # custom menu class creatmenu: def GET (self): appid = "wx7ced2a8593275753" secret = "71f475563d00103a356943875e96d43a" url = 'https: // logs? Grant_type = client_credential & appid = '+ appid +' & secret = '+ secret response = urllib2.urlopen (url) html = response. read () tokeninfo = json. loads (html) token = tokeninfo ['Access _ token'] post = ''' {"button": [{"type": "click", "name ": "Start", "key": "begin" },{ "type": "click", "name": "end", "key": "end "}, {"type": "click", "name": "game", "key": "play"}]} '''url = 'https: // api.weixin.qq.com/cgi-bin/menu/create? Access_token = '+ token req = urllib2.Request (url, post) response = urllib2.urlopen (req) return response # Delete menu class deletemenu: def GET (self ): appid = "wx7ced2a8593275753" secret = "71f475563d00103a356943875e96d43a" url = 'https: // api.weixin.qq.com/cgi-bin/token? Grant_type = client_credential & appid = '+ appid +' & secret = '+ secret response = urllib2.urlopen (url) html = response. read () tokeninfo = json. loads (html) token = tokeninfo ['Access _ token'] url = 'https: // api.weixin.qq.com/cgi-bin/menu/delete? Access_token = '+ token req = urllib2.Request (url) response = urllib2.urlopen (req) return responseapp = web. application (urls, globals ()). wsgifunc () application = sae. create_wsgi_app (app)


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.