测试公众号接收关注/取消关注事件?
能接收到并打印出来的用户取消关注/关注公众号市的xml数据包。但是我用xml.etree.ElemenTree解析的时候只返回了200ok,我里面写了一个打印字典都打印不出来。PS:xml.etree.ElemenTree我用新的.py文件测试一下,是可以解析的。
try
import xml.etree.cElementTree as ET
except ImportError
import xml.etree.ElementTree as ET
def POST(self): # Post,向指定的资源提交数据
try:
post_xml = web.data() # 获得Post得来的数据(data type:str)
# print type(post_xml)
print "data:", "\n", post_xml
root = ET.fromstring(post_xml) # 直接从字符串中解析xml数据包
touser = root.find("ToUserName").text # 开发者微信号
self.fromuser = root.find("FromUerName").text # 发送方帐号(一个OpenID)
createtime = root.find("CreateTime").text # 消息创建时间(微信服务器)
msgtype = root.find("MsgType").text # 消息类型(text/event/image/voice/location/link/...)
event = root.find("Event").text # 事件类型:subscribe(订阅)、unsubscribe(取消订阅))
dict1 = {
"ToUserName": touser,
"FromUerName": self.fromuser,
"CreateTime": createtime,
"MsgType": msgtype,
"Event": event
}
print dict1
# if msgtype == 'event' and event == 'subscribe':
# return self.follows(fromuser)
# if msgtype == 'event' and event == 'unsubscribe':
# return self.unfollows(fromuser)
except Exception, e:
return e