被用户关注之后,微信会发送一个 MsgType 为 Event 、Event 为 subscribe 的事件(你给的文章里已经写到了啊)
用 Bottle 写出来的话,大概是这样的:
from bottle import Bottle, request, response
from xml.etree import ElementTree
app = Bottle()
@app.post('/')
def handle():
xml = request.body.read()
msg = dict((child.tag, to_unicode(child.text))
for child in ElementTree.fromstring(xml))
if msg.get("MsgType", None) == "Event" and msg.get("Event", None) == "subscribe":
#被用户关注
pass
为什么不用框架开发呢?比如 WeRoBot