标签:event def res lin format type receive request bsp
微信公众账号能够接收用户发送的六种格式的消息:文本,图片,语音,视频(短视频),地理位置,链接。
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
标签:event def res lin format type receive request bsp
原文地址:https://www.cnblogs.com/ahMay/p/12038125.html