码迷,mamicode.com
首页 > 其他好文 > 详细

接收用户消息

时间:2019-12-14 09:28:30      阅读:100      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!