def exit_callback(self): if self.stop_polling: return msg = EFBMsg(self) msg.source = MsgSource.System msg.origin = { 'name': '%s System' % self.channel_name, 'alias': '%s System' % self.channel_name, 'uid': -1 } msg.text = "WeChat server logged out the user." msg.type = MsgType.Text on_log_out = self._flag("on_log_out", "command") on_log_out = on_log_out if on_log_out in ("command", "idle", "reauth") else "command" if on_log_out == "command": msg.type = MsgType.Command msg.attributes = { "commands": [{ "name": "Log in", "callable": "reauth", "args": [], "kwargs": { "command": True } }] } elif on_log_out == "reauth": if self._flag("qr_reload", "master_qr_code") == "console_qr_code": msg.text += "\nPlease visit your console or log for QR code and further instructions." self.reauth() self.queue.put(msg)
def master_qr_code(self, uuid, status, qrcode): status = int(status) msg = EFBMsg(self) msg.type = MsgType.Text msg.source = MsgSource.System msg.origin = { 'name': '%s Auth' % self.channel_name, 'alias': '%s Auth' % self.channel_name, 'uid': -1 } if status == 201: msg.type = MsgType.Text msg.text = 'Tap "Confirm" to continue.' elif status == 200: msg.type = MsgType.Text msg.text = "Successfully authenticated." elif uuid != self.qr_uuid: msg.type = MsgType.Image path = os.path.join("storage", self.channel_id) if not os.path.exists(path): os.makedirs(path) path = os.path.join(path, 'QR-%s.jpg' % int(time.time())) self.logger.debug("master_qr_code file path: %s", path) qr_url = "https://login.weixin.qq.com/l/" + uuid QRCode(qr_url).png(path, scale=10) msg.text = 'Scan this QR Code with WeChat to continue.' msg.path = path msg.file = open(path, 'rb') msg.mime = 'image/jpeg' if status in (200, 201) or uuid != self.qr_uuid: self.queue.put(msg) self.qr_uuid = uuid
def exit_callback(self): msg = EFBMsg(self) msg.type = MsgType.Text msg.source = MsgSource.System msg.origin = { 'name': 'WeChat System Message', 'alias': 'WeChat System Message', 'uid': -1 } msg.text = "WeChat system logged out the user." self.queue.put(msg)