예제 #1
0
 def get_msg_signal(self):
     """
         消息信号检查
     """
     call_back = {"retcode": "0", "selector": "0"}
     try:
         resp = self.get(
             API_synccheck,
             params={
                 "r": Device.get_timestamp(),
                 "skey": self.__auth_data["skey"],
                 "sid": self.__auth_data["wxsid"],
                 "uin": self.__auth_data["wxuin"],
                 "deviceid": self.__device_id,
                 "synckey": self.create_synckey(),
                 "_": Device.get_timestamp(),
             },
             timeout=API_checktimeout,
         )
         if not resp.status_code == 200:
             raise AssertionError()
         call_back = execjs.eval(resp.text.replace("window.synccheck=", ""))
     except requests.exceptions.ReadTimeout:
         pass
     except requests.exceptions.Timeout:
         pass
     except Exception as e:
         error(e)
     time.sleep(1)
     return call_back
예제 #2
0
 def login_wait(self, local=None):
     """
         登录过程
     """
     return self.get(
         API_login if local else API_check_login,
         params={
             "loginicon": "true",
             "uuid": self.__qr_code_uuid,
             "tip": 1 if local else 0,
             "r": Device.get_timestamp(True),
             "_": Device.get_timestamp(),
         },
         timeout=API_checktimeout,
     )
예제 #3
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")
예제 #4
0
파일: core.py 프로젝트: 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")
예제 #5
0
 def send_file(self, target, filename):
     """
         文本文件发送
     """
     with pathlib.Path(filename).open("rb") as file:
         datas = file.read()
         lens = len(datas)
         self.post(
             API_webwxuploadmedia,
             params={"f": "json"},
             json={
                 "id":
                 "WU_FILE_0",
                 "name":
                 filename,
                 "type":
                 filetype(BytesIO(data)).mime,
                 "lastModifiedDate":
                 "Tue May 21 2019 00:00:00 GMT 0800 (中国标准时间)",
                 "size":
                 lens,
                 "mediatype":
                 "pic",
                 "uploadmediarequest": {
                     "UploadType": 2,
                     "BaseRequest": self.get_base_request(),
                     "ClientMediaId": Device.get_timestamp(),
                     "TotalLen": lens,
                     "StartPos": 0,
                     "DataLen": lens,
                     "MediaType": 4,
                     "FromUserName": self.__person_data["User"]["UserName"],
                     "ToUserName": target,
                     "FileMd5": hashlib.new("md5", datas).hexdigest(),
                 },
                 "webwx_data_ticket":
                 self.__session.cookies.get("webwx_data_ticket", ""),
                 "pass_ticket":
                 self.__auth_data["pass_ticket"],
                 "filename":
                 datas,
             },
             headers={
                 "Content-Type":
                 "multipart/form-data; boundary=----WebKitFormBoundaryrUwfuyA8mLqHyBJP",
                 "DNT": "1",
                 "Origin": "https://wx.qq.com",
                 "Referer": "https://wx.qq.com/",
                 "User-Agent": "Webot/1.0",
             },
         )
예제 #6
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']}]")
예제 #7
0
 def get_ticket(self):
     """
         获取个人信息票据并更新部分cookie
     """
     info(f"Redirect to --> {self.__get_ticket_url}")
     resp = self.get(
         self.__get_ticket_url,
         params={
             "fun": "new",
             "lang": "zh_CN",
             "_": Device.get_timestamp()
         },
     )
     info(
         f"Get Ticket:{requests_html.requests.utils.dict_from_cookiejar(resp.cookies)}"
     )
     self.__auth_data = Parser.get_auth_data(resp)
     self.__session.cookies.update(
         requests_html.requests.utils.cookiejar_from_dict(
             {"last_wxuin": self.__auth_data["wxuin"]}))
     if list(filter(lambda item: item[1], self.__auth_data.items())):
         return True