接收用户消息
Posted ahmay
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了接收用户消息相关的知识,希望对你有一定的参考价值。
微信公众账号能够接收用户发送的六种格式的消息:文本,图片,语音,视频(短视频),地理位置,链接。
def responseMsg(self): encrypt_type = self.request.GET.get(‘encrypt_type‘, None) pc, postStr = self._encrypt_data(encrypt_type) postObj = self._parseMsg(postStr) print(postObj) msg_type = postObj[‘MsgType‘] result = ‘‘ if msg_type == ‘text‘: result = self._receiveText(postObj) elif msg_type == ‘image‘: result = self._receiveImage(postObj) elif msg_type == ‘voice‘: result = self._receiveVoice(postObj) elif msg_type == ‘video‘ or msg_type == ‘shortvideo‘: print(‘视频‘) print(msg_type) result = self._receiveVideo(postObj) elif msg_type == ‘location‘: result = self._receiveLocation(postObj) elif msg_type == ‘link‘: result = self._receiveLink(postObj) elif msg_type == ‘event‘: result = self._receiveEvent(postObj) else: result = ‘不能识别的 msg type: ‘ + msg_type
def _transmitText(self,obj,content): xmlTpl =‘‘‘ <xml> <ToUserName><![CDATA[{0}]]></ToUserName> <FromUserName><![CDATA[{1}]]></FromUserName> <CreateTime>{2}</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[{3}]]></Content> </xml> ‘‘‘ result = xmlTpl.format(obj[‘FromUserName‘],obj[‘ToUserName‘],int(time.time()),content) return result
以上是关于接收用户消息的主要内容,如果未能解决你的问题,请参考以下文章