共计 859 个字符,预计需要花费 3 分钟才能阅读完成。
当用户关注和取消关注时 MsgType 的类型均为 event
,我们可以在此时进行一些业务处理
接收样例:
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[FromUser]]></FromUserName>
<CreateTime>123456789</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[subscribe]]></Event>
</xml>
from django.shortcuts import render, HttpResponse
from django.views.decorators.csrf import csrf_exempt
import hashlib
import xmltodict
import time
from myApp.accessToken import AccessToken
def index(request):
pass
def responseXML(ToUserName, FromUserName, MsgType, **kwargs):
pass
@csrf_exempt
def weixin(request):
if request.method == "GET":
pass
else:
pass
if MsgType == "text":
pass
elif MsgType == "event":
Event = reqDict.get("Event")
if Event == "subscribe":
# 业务逻辑
resXml = responseXML(FromUserName, ToUserName, "text", Content="欢迎光临红浪漫,三楼男宾一位")
return HttpResponse(resXml)
elif Event == "unsubscribe":
# 业务逻辑
return HttpResponse("")
else:
pass
def access(request):
pass
正文完
星哥玩云-微信公众号