def __init__(self, key, secret): """ | 需要通过注册获得 key 和 secret | 免费申请: http://cloud.xiaoi.com/ :param key: 你申请的 key :param secret: 你申请的 secret """ self.key = key self.secret = secret self.realm = "xiaoi.com" self.http_method = "POST" self.uri = "/ask.do" self.url = "http://nlp.xiaoi.com/ask.do?platform=custom" xauth = self._make_http_header_xauth() headers = { "Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain", } headers.update(xauth) self.session = requests.Session() self.session.headers.update(headers) enhance_connection(self.session)
def __init__(self): self.session = requests.Session() enhance_connection(self.session) # noinspection SpellCheckingInspection self.last_member = dict()
def __init__(self, cache_path=None, console_qr=False, qr_path=None, qr_callback=None, login_callback=None, logout_callback=None): """ :param cache_path: * 设置当前会话的缓存路径,并开启缓存功能;为 `None` (默认) 则不开启缓存功能。 * 开启缓存后可在短时间内避免重复扫码,缓存失效时会重新要求登陆。 * 设为 `True` 时,使用默认的缓存路径 'wxpy.pkl'。 :param console_qr: * 在终端中显示登陆二维码,需要安装 pillow 模块 (`pip3 install pillow`)。 * 可为整数(int),表示二维码单元格的宽度,通常为 2 (当被设为 `True` 时,也将在内部当作 2)。 * 也可为负数,表示以反色显示二维码,适用于浅底深字的命令行界面。 * 例如: 在大部分 Linux 系统中可设为 `True` 或 2,而在 macOS Terminal 的默认白底配色中,应设为 -2。 :param qr_path: 保存二维码的路径 :param qr_callback: 获得二维码后的回调,接收参数: uuid, status, qrcode :param login_callback: 登陆成功后的回调,接收参数同上 :param logout_callback: 登出时的回调,接收参数同上 """ self.core = itchat.Core() itchat.instanceList.append(self) enhance_connection(self.core.s) if cache_path is True: cache_path = 'wxpy.pkl' self.cache_path = cache_path if console_qr is True: console_qr = 2 self.core.auto_login(hotReload=bool(cache_path), statusStorageDir=cache_path, enableCmdQR=console_qr, picDir=qr_path, qrCallback=qr_callback, loginCallback=login_callback, exitCallback=logout_callback) self.self = Friend(self.core.loginInfo['User'], self) self.file_helper = Chat(wrap_user_name('filehelper'), self) self.messages = Messages() self.registered = Registered(self) self.is_listening = False self.listening_thread = None self.temp_dir = tempfile.TemporaryDirectory(prefix='wxpy_') self.start() atexit.register(self._cleanup)
def __init__(self, api_key=None): """ | 内置的 api key 存在调用限制,建议自行申请。 | 免费申请: http://www.tuling123.com/ :param api_key: 你申请的 api key """ self.session = requests.Session() enhance_connection(self.session) # noinspection SpellCheckingInspection self.api_key = api_key or '7c8cdb56b0dc4450a8deef30a496bd4c' self.last_member = dict()
def __init__(self): self.master = False self.core = itchat.Core() itchat.instanceList.append(self) # 用于 "synccheck" 请求的 "_" 参数,每次请求时 + 1 self._sync_check_iterations = int(time.time() * 1000) self.auto_mark_as_read = False enhance_connection(self.core.s) self.cache_path = None self.messages = Messages() self.registered = Registered(self) self.isLogging = True self.puid_map = None self.auto_send = False self.is_listening = False self.listening_thread = None self.crawler_articles = True self.app_id = None self.auto_accept = False self.notify_dingding = False self.master_phone = None self.last_msg = time.time() if PY2: from wxpy.compatible.utils import TemporaryDirectory self.temp_dir = TemporaryDirectory(prefix='wxpy_') else: self.temp_dir = tempfile.TemporaryDirectory(prefix='wxpy_') atexit.register(self._cleanup)
def __init__(self, api_key=None): self.session = requests.Session() enhance_connection(self.session) # noinspection SpellCheckingInspection self.api_key = api_key or '7c8cdb56b0dc4450a8deef30a496bd4c' self.last_member = dict()