Exemplo n.º 1
0
 def get_batch_contact(self):
     """
         获取群组联系人
     """
     jsondata = self.get_base_request()
     contact_list = [{
         "UserName": item,
         "EncryChatRoomId": ""
     } for item in self.__person_data["ChatSet"].split(",") if "@@" in item]
     jsondata.update({"Count": len(contact_list), "List": contact_list})
     resp = self.post(
         API_webwxbatchgetcontact,
         params={
             "type": "ex",
             "r": Device.get_timestamp(),
             "lang": "zh_CN",
             "pass_ticket": self.__auth_data["pass_ticket"],
         },
         json=jsondata,
     )
     self.__batch_contacts = resp.json()
     self.__person_map = Device.trans_map(self.__contacts,
                                          self.__batch_contacts)
     create_json(self.__batch_contacts,
                 API_static_path / "batch_contacts.json")
Exemplo n.º 2
0
 def login_success_init(self):
     """
         成功登陆并初始化wx
     """
     resp = self.post(
         API_webwxinit,
         params={
             "pass_ticket": self.__auth_data["pass_ticket"],
             "lang": "zh_CN"
         },
         json=self.get_base_request(),
     )
     resp.encoding = "utf8"
     self.__person_data = resp.json()
     self.__nick = self.__person_data["User"]["NickName"]
     conf.my_id = self.__person_data["User"]["UserName"]
     create_json(self.__person_data, API_static_path / "person_data.json")
     success(
         f"{'Welcome'.center(20,'*')}: [{self.__person_data['User']['NickName']}]"
     )
     save_worker(
         (
             self.__session,
             self.__auth_data,
             self.__person_data,
             self.__get_ticket_url,
         ),
         API_hotreload_file,
     )
Exemplo n.º 3
0
Arquivo: core.py Projeto: s045pd/Webot
    def get_batch_contact(self, contact_list: list = None):
        """
        获取群组联系人
        """
        if not contact_list:
            contact_list = self.__person_data["ChatSet"].split(",")

        contact_list = list(
            filter(lambda name: name in self.__person_map, contact_list))

        if not contact_list:
            return

        for contact_list in [{
                "UserName": item,
                "EncryChatRoomId": ""
        } for item in contact_list if "@@" in item]:
            contact_list = [contact_list]
            jsondata = self.get_base_request()
            jsondata.update({"Count": len(contact_list), "List": contact_list})
            resp = self.post(
                API_webwxbatchgetcontact,
                params={
                    "type": "ex",
                    "r": Device.get_timestamp(),
                    "lang": "zh_CN",
                    "pass_ticket": self.__auth_data["pass_ticket"],
                },
                json=jsondata,
            )
            self.__batch_contacts.update(resp.json())
        self.__person_map = Device.trans_map(self.__contacts,
                                             self.__batch_contacts)
        create_json(self.__batch_contacts,
                    API_static_path / "batch_contacts.json")
Exemplo n.º 4
0
 def get_contact(self):
     """
         获取基础联系人
     """
     resp = self.get(
         API_webwxgetcontact,
         params={
             "lang": "zh_CN",
             "pass_ticket": self.__auth_data["pass_ticket"],
             "r": Device.get_timestamp(),
             "seq": 0,
             "skey": self.__auth_data["skey"],
         },
     )
     self.__contacts = resp.json()
     create_json(self.__contacts, API_static_path / "contacts.json")
     info(f"Get friends: [{self.__contacts['MemberCount']}]")
Exemplo n.º 5
0
    def data_ctrl(self, msg):
        """
            打印基础消息并整理
        """
        msg_type = msg["MsgType"]
        sub_type = msg["SubMsgType"]
        is_me = self.msg_is_self(msg)
        is_group = "@@" in msg["FromUserName"]
        content_header = "👥" if is_group else "💬"
        to_user_name = "" if is_group else f'-> 【{msg["ToUserName"]}】'
        func = info if is_me else success
        content = f'{content_header}【{msg["FromUserName"]}】{to_user_name}:'
        create_json(msg, str(API_static_path / "⚡️current_msg.json"))  # 实时日志分析
        result = {
            "time": msg["CreateTime"],
            "from": msg["FromUserName"],
            "from_nick": self.translate_text(msg["FromUserName"]),
            "to": msg["ToUserName"],
            "to_nick": self.translate_text(msg["ToUserName"]),
            "type": MSG_TYPES[msg_type].lower(),
            "content": "",
            "raw_content": msg["Content"],
            "is_me": is_me,
            "is_group": is_group,
        }
        number = f"{result['time']}_{result['from_nick']}_{msg['MsgId']}"  # 消息编号
        if msg_type == MSGTYPE_TEXT:
            if sub_type == 0:
                result["content"] = msg["Content"]
            elif sub_type == 48:
                result["content"] = msg["Content"].split(":")[0]
            self.on_text(result)
        elif msg_type == MSGTYPE_VOICE:
            voice = self.get_voice(msg["MsgId"], conf.play_voice)
            filename = str(API_meida_voice_path / f"{number}.mp3")
            save_file(voice, filename)
            result["content"] = filename
            self.on_voice(result)
        elif msg_type == MSGTYPE_VIDEO:
            video = self.get_video(msg["MsgId"], True)
            filename = str(API_meida_video_path / f"{number}.mp4")
            save_file(video, filename)
            result["content"] = filename
            self.on_video(result)
        elif msg_type == MSGTYPE_IMAGE:
            image = self.get_image(msg["MsgId"], True)
            filename = str(API_meida_image_path / f"{number}.png")
            save_file(image, filename)
            result["content"] = filename
            self.on_image(result)
        elif msg_type == MSGTYPE_EMOTICON:
            urls = URLExtract().find_urls(msg["Content"])
            if not urls:
                return
            filename = str(API_meida_emoji_path / f"{number}.png")
            imgcat(get_pic(self.__session, urls[0], filename))
            result["content"] = urls[0]
            self.on_emoji(result)
        elif msg_type == MSGTYPE_APP:
            pass
            # content += "公众号推送"
        elif msg_type == MSGTYPE_STATUSNOTIFY:
            # content += "进入/退出"
            pass
        if msg_type not in [] and result["content"]:
            func(self.translate_text(content + result["content"]))

        return msg, result