共计 1403 个字符,预计需要花费 4 分钟才能阅读完成。
-
接收样例
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1348831860</CreateTime> <MsgType><![CDATA[image]]></MsgType> <PicUrl><![CDATA[this is a url]]></PicUrl> <MediaId><![CDATA[media_id]]></MediaId> <MsgId>1234567890123456</MsgId> </xml>
-
回复样例
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>12345678</CreateTime> <MsgType><![CDATA[image]]></MsgType> <Image> <MediaId><![CDATA[media_id]]></MediaId> </Image> </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):
resDict = {"ToUserName": ToUserName,
"FromUserName": FromUserName,
"CreateTime": int(time.time()),
"MsgType": MsgType,
}
if MsgType == "text":
resDict["Content"] = kwargs.get("Content")
elif MsgType == "image":
resDict["Image"] = {"MediaId": kwargs.get("MediaId")}
resXml = xmltodict.unparse({"xml": resDict})
return resXml
@csrf_exempt
def weixin(request):
if request.method == "GET":
pass
else:
pass
if MsgType == "text":
pass
elif MsgType == "event":
pass
elif MsgType == "image":
PicUrl = reqDict.get("PicUrl")
MediaId = reqDict.get("MediaId")
MsgId = reqDict.get("MsgId")
resXml = responseXML(FromUserName, ToUserName, "image", MediaId=MediaId)
return HttpResponse(resXml)
else:
pass
def access(request):
pass
正文完
星哥玩云-微信公众号