#coding: utf-8
import sae
import web
import xml.etree.ElementTree as ET
urls = (
'/', 'Hello'
)
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")
Content=root.findtext(".//Content")
if Content=="1":
tpl='''<xml>
<ToUserName>'''+fromUser+'''</ToUserName>
<FromUserName>'''+toUser+'''</FromUserName>
<CreateTime>'''+CreateTime+'''</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[文本消息]]></Content>
</xml>'''
elif Content=="2":
tpl='''<xml>
<ToUserName>'''+fromUser+'''</ToUserName>
<FromUserName>'''+toUser+'''</FromUserName>
<CreateTime>'''+CreateTime+'''</CreateTime>
<MsgType><![CDATA[news]]></MsgType>
<ArticleCount>2</ArticleCount>
<Articles>
<item>
<Title><![CDATA[python微信]]></Title>
<Description><![CDATA[description1]]></Description>
<PicUrl><![CDATA[http://upload.wikimedia.org/wikipedia/commons/thumb/f/f8/Python_logo_and_wordmark.svg/486px-Python_logo_and_wordmark.svg.png]]></PicUrl>
<Url><![CDATA[url]]></Url>
</item>
<item>
<Title><![CDATA[python微信qq群 287714361]]></Title>
<Description><![CDATA[description]]></Description>
<PicUrl><![CDATA[http://upload.wikimedia.org/wikipedia/commons/thumb/f/f8/Python_logo_and_wordmark.svg/486px-Python_logo_and_wordmark.svg.png]]></PicUrl>
<Url><![CDATA[url]]></Url>
</item>
</Articles>
</xml>'''
return tpl
app = web.application(urls, globals()).wsgifunc()
application = sae.create_wsgi_app(app)