Beispiel #1
0
	def POST(self):
		data = web.data()
		print data
		## 转成xml
		root = string2xml(data)
		## 交换发送者和接收者
		root = exchangeFromAndTo(root)   
		## 消息类型 
		msgType = root[3].text
		if 'event'==msgType: ## 事件消息
			event = root[4].text
			if 'subscribe'==event: ## 关注事件
				msg = getReply(1)
				msg = '%s%s' % (u'欢迎关注😈🐓! 我可以帮你把🔗变成😂哦!🙊', msg)
				root[3].text = 'text'
				root[4].tag = 'Content'
				root[4].text = msg
				root.remove(root[5])
		elif 'text'==msgType: ## 文本消息
			ct = root[4].text
			k = ct
                        if ct.startswith('/') or ct.startswith(':'):
                                ct = ct[1:len(ct)]
                                k = getReplyByKey(ct)
			elif validateUrl(ct):
				k = addUrl(ct)
				k = 'http://'+k+'.😇😈.ws'
			elif isCity(ct):
				k = tianqi(k)
			else:
				k = fanyi(k)
			#print 'from',fu,'to',tu
			root[4].text = k
		elif 'voice'==msgType:## 语音消息
			ct = root[7].text
			ct = ct.replace(u'!','')
		        msg = getReplyByKey(ct)
			root[3].text = 'text'
			root[4].tag = 'Content'
			root[4].text = msg
			root.remove(root[5])
			root.remove(root[5])
			root.remove(root[5])
		else:
			return 'success'
		
		
		web.header('Content-Type', 'text/xml')
		import sys
		reload(sys)
		sys.setdefaultencoding('utf-8')
		rst = xml2string(root)
		return rst
Beispiel #2
0
	def POST(self):
		param = web.input()
		k = addUrl(param.u)
		render = web.template.render('templates')
		return render.success(k)