Beispiel #1
0
 def process_message(self, account, message, path):
     """根据消息类型,处理消息"""
     openid = message['FromUserName']
     fans = self.fans_manager.get_fans_by_openid_aid(openid, account.aid)
     if not fans:
         wei_api.get_user_info(account, openid, self._add_single_fan)
     msg_type = message['MsgType'].lower()
     if msg_type == 'text':
         return self._process_text_message(account, message, path)
     if msg_type == 'image':
         return self._process_image_message(account, message, path)
     if msg_type == 'voice':
         return self._process_voice_message(account.aid, message)
     if msg_type == 'video':
         return self._process_video_message(account.aid, message)
     if msg_type == 'location':
         return self._process_location_message(account.aid, message)
     if msg_type == 'link':
         return self._process_link_message(account.aid, message)
     if msg_type == 'event':
         event = message['Event'].lower()
         if event == 'subscribe':
             return self._process_subscribe_event(account, message, path)
         if event == 'unsubscribe':
             return self._process_unsubscribe_event(account, message)
         if event == 'click':
             return self._process_menu_click_event(account, message, path)
Beispiel #2
0
 def _process_subscribe_event(self, account, message, path):
     """
     处理用户关注账号的事件
         1. 将用户信息保存到数据库
         2. 如果有自动回复消息,则回复
     """
     openid = message['FromUserName']
     wei_api.get_user_info(account, openid, self._add_single_fan)
     auto = self.auto_manager.get_follow_auto(account.aid)
     if not auto:
         return
     if auto.type == 'text':
         return message_util.text_response_to_message(auto.re_content, message, path, account.wei_account)
     if auto.type == 'single':
         image_article = self.image_article_manager.get_image_article_by_id(auto.re_img_art_id)
         return message_util.image_article_group_to_message([image_article], message, path, account.wei_account)
     if auto.type == 'multi':
         image_article_group = self.image_article_manager.get_multi_image_article_by_id(auto.re_img_art_id)
         if not image_article_group:
             return None
         id_list = [image_article_group.id1, image_article_group.id2, image_article_group.id3,
                    image_article_group.id4,
                    image_article_group.id5]
         id_list = filter(lambda a: a != 0, id_list)
         article_list = []
         for _id in id_list:
             article_list.append(self.image_article_manager.get_image_article_by_id(_id))
         return message_util.image_article_group_to_message(article_list, message, path, account.wei_account)