Compare commits
6 Commits
dependabot
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e13823d88 | ||
|
|
481a9c0310 | ||
|
|
43caf8fdc8 | ||
|
|
ac4abae019 | ||
|
|
08799d61f0 | ||
|
|
6e5ceca134 |
@@ -33,6 +33,11 @@ class Notification():
|
|||||||
self = cls()
|
self = cls()
|
||||||
self.send_email_by_smtp(to, title, content)
|
self.send_email_by_smtp(to, title, content)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def send_email_with_qrcode(cls, to, title='', qrcode_path=''):
|
||||||
|
self = cls()
|
||||||
|
self.send_email_by_smtp_with_qrcode(to, title, qrcode_path)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def send_to_telegram(cls, content=''):
|
def send_to_telegram(cls, content=''):
|
||||||
self = cls()
|
self = cls()
|
||||||
@@ -134,6 +139,46 @@ class Notification():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
CommonLog.add_quick_log(CommonLog.MESSAGE_SEND_EMAIL_FAIL.format(e)).flush()
|
CommonLog.add_quick_log(CommonLog.MESSAGE_SEND_EMAIL_FAIL.format(e)).flush()
|
||||||
|
|
||||||
|
def send_email_by_smtp_with_qrcode(self, to, title, qrcode_path):
|
||||||
|
import smtplib
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
from email.mime.image import MIMEImage
|
||||||
|
to = to if isinstance(to, list) else [to]
|
||||||
|
message = MIMEMultipart()
|
||||||
|
message['Subject'] = title
|
||||||
|
message['From'] = Config().EMAIL_SENDER
|
||||||
|
message['To'] = ", ".join(to)
|
||||||
|
htmlFile = """
|
||||||
|
<html>
|
||||||
|
<head></head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
这是你的二维码
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<br /><img src="cid:0", width=200, height=200 ></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
"""
|
||||||
|
htmlApart = MIMEText(htmlFile, 'html')
|
||||||
|
imageFile = qrcode_path
|
||||||
|
imageApart = MIMEImage(open(imageFile, 'rb').read(), imageFile.split('.')[-1])
|
||||||
|
imageApart.add_header('Content-ID', '<0>')
|
||||||
|
message.attach(imageApart)
|
||||||
|
message.attach(htmlApart)
|
||||||
|
try:
|
||||||
|
server = smtplib.SMTP(Config().EMAIL_SERVER_HOST)
|
||||||
|
server.ehlo()
|
||||||
|
server.starttls()
|
||||||
|
server.login(Config().EMAIL_SERVER_USER, Config().EMAIL_SERVER_PASSWORD)
|
||||||
|
server.send_message(message)
|
||||||
|
server.quit()
|
||||||
|
CommonLog.add_quick_log(CommonLog.MESSAGE_SEND_EMAIL_WITH_QRCODE_SUCCESS).flush()
|
||||||
|
self.push_bark(CommonLog.MESSAGE_SEND_EMAIL_WITH_QRCODE_SUCCESS)
|
||||||
|
except Exception as e:
|
||||||
|
CommonLog.add_quick_log(CommonLog.MESSAGE_SEND_EMAIL_FAIL.format(e)).flush()
|
||||||
|
|
||||||
def send_dingtalk_by_webbook(self, content):
|
def send_dingtalk_by_webbook(self, content):
|
||||||
from dingtalkchatbot.chatbot import DingtalkChatbot
|
from dingtalkchatbot.chatbot import DingtalkChatbot
|
||||||
webhook = Config().DINGTALK_WEBHOOK
|
webhook = Config().DINGTALK_WEBHOOK
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ class CommonLog(BaseLog):
|
|||||||
MESSAGE_SEND_EMAIL_SUCCESS = '邮件发送成功,请检查收件箱'
|
MESSAGE_SEND_EMAIL_SUCCESS = '邮件发送成功,请检查收件箱'
|
||||||
MESSAGE_SEND_EMAIL_FAIL = '邮件发送失败,请手动检查配置,错误原因 {}'
|
MESSAGE_SEND_EMAIL_FAIL = '邮件发送失败,请手动检查配置,错误原因 {}'
|
||||||
|
|
||||||
|
MESSAGE_SEND_EMAIL_WITH_QRCODE_SUCCESS = '二维码邮件发送成功,请检查收件箱扫描登陆'
|
||||||
|
|
||||||
MESSAGE_SEND_TELEGRAM_SUCCESS = 'Telegram推送成功'
|
MESSAGE_SEND_TELEGRAM_SUCCESS = 'Telegram推送成功'
|
||||||
MESSAGE_SEND_TELEGRAM_FAIL = 'Telegram推送失败,错误原因 {}'
|
MESSAGE_SEND_TELEGRAM_FAIL = 'Telegram推送失败,错误原因 {}'
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class UserJob:
|
|||||||
user_loaded = False # 用户是否已加载成功
|
user_loaded = False # 用户是否已加载成功
|
||||||
passengers = []
|
passengers = []
|
||||||
retry_time = 3
|
retry_time = 3
|
||||||
|
retry_count = 0
|
||||||
login_num = 0 # 尝试登录次数
|
login_num = 0 # 尝试登录次数
|
||||||
|
|
||||||
# Init page
|
# Init page
|
||||||
@@ -215,11 +216,20 @@ class UserJob:
|
|||||||
else:
|
else:
|
||||||
print_qrcode(png_path)
|
print_qrcode(png_path)
|
||||||
UserLog.add_log(UserLog.MESSAGE_QRCODE_DOWNLOADED.format(png_path)).flush()
|
UserLog.add_log(UserLog.MESSAGE_QRCODE_DOWNLOADED.format(png_path)).flush()
|
||||||
|
Notification.send_email_with_qrcode(Config().EMAIL_RECEIVER, '你有新的登录二维码啦!', png_path)
|
||||||
|
self.retry_count = 0
|
||||||
return result.get('uuid'), png_path
|
return result.get('uuid'), png_path
|
||||||
raise KeyError('获取二维码失败: {}'.format(result.get('result_message')))
|
raise KeyError('获取二维码失败: {}'.format(result.get('result_message')))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
UserLog.add_quick_log(
|
UserLog.add_quick_log(
|
||||||
UserLog.MESSAGE_QRCODE_FAIL.format(e, self.retry_time)).flush()
|
UserLog.MESSAGE_QRCODE_FAIL.format(e, self.retry_time)).flush()
|
||||||
|
self.retry_count = self.retry_count + 1
|
||||||
|
if self.retry_count == 20:
|
||||||
|
self.retry_count = 0
|
||||||
|
try:
|
||||||
|
os.remove(self.get_cookie_path())
|
||||||
|
except:
|
||||||
|
pass
|
||||||
time.sleep(self.retry_time)
|
time.sleep(self.retry_time)
|
||||||
return self.download_code()
|
return self.download_code()
|
||||||
|
|
||||||
@@ -262,7 +272,7 @@ class UserJob:
|
|||||||
try:
|
try:
|
||||||
result = json.loads(response.text)
|
result = json.loads(response.text)
|
||||||
headers = {
|
headers = {
|
||||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36"
|
||||||
}
|
}
|
||||||
self.session.headers.update(headers)
|
self.session.headers.update(headers)
|
||||||
response = self.session.get(base64.b64decode(result['id']).decode())
|
response = self.session.get(base64.b64decode(result['id']).decode())
|
||||||
|
|||||||
Reference in New Issue
Block a user