1 Star 0 Fork 0

微笑的小小刀/wx-public

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
handle.py 2.19 KB
一键复制 编辑 原始数据 按行查看 历史
# -*- coding: utf-8 -*-
# filename: handle.py
import hashlib
import reply
import receive
import web
import wiki_api
class Handle(object):
def POST(self):
try:
webData = web.data()
print "Handle Post webdata is ", webData #后台打日志
recMsg = receive.parse_xml(webData)
if isinstance(recMsg, receive.Msg):
toUser = recMsg.FromUserName
fromUser = recMsg.ToUserName
if recMsg.MsgType == 'text':
content = recMsg.Content
print "接收到的content为", content
return_content = wiki_api.get_wiki_page(content)
str_content = str(return_content)
str_length = len(str_content)
start = 0
while start < str_length:
replyMsg = reply.TextMsg(toUser, fromUser, str_content[0:100])
return replyMsg.send()
if recMsg.MsgType == 'image':
mediaId = recMsg.MediaId
replyMsg = reply.ImageMsg(toUser, fromUser, mediaId)
return replyMsg.send()
else:
return reply.Msg().send()
else:
print "暂且不处理"
return reply.Msg().send()
except Exception, Argment:
return Argment
def GET(self):
try:
data = web.input()
if len(data) == 0:
return "hello, this is handle view"
signature = data.signature
timestamp = data.timestamp
nonce = data.nonce
echostr = data.echostr
token = "hello" # 请按照公众平台官网\基本配置中信息填写
list = [token, timestamp, nonce]
list.sort()
sha1 = hashlib.sha1()
map(sha1.update, list)
hashcode = sha1.hexdigest()
print "handle/GET func: hashcode, signature: ", hashcode, signature
if hashcode == signature:
return echostr
else:
return ""
except Exception, Argument:
return Argument
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/xiaodaojava/wx-public.git
[email protected]:xiaodaojava/wx-public.git
xiaodaojava
wx-public
wx-public
master

搜索帮助