代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from time import sleep
import json
import requests
import logging
import ddddocr
import re

ocr = ddddocr.DdddOcr()

LOG_FORMAT = '%(asctime)s %(levelname)s\t %(thread)d %(lineno)d %(funcName)s\t\t%(message)s'
# logging.basicConfig(handlers=[logging.FileHandler('log.log', 'a', 'utf-8')],level=logging.INFO, format=LOG_FORMAT)
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)

headers = {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest'
}


# 加入的钉钉通知功能
# def dingtalk(content):
# """
# 钉钉通知函数
# :param content: 要通知的内容
# :return: none
# """
# webhook_url = ''
# dd_headers = {
# "Content-Type": "application/json",
# "Charset": "UTF-8"
# }
# dd_message = {
# "msgtype": "text",
# "text": {
# "content": f'BugKu 签到通知\n{content}'
# }
# }
#
# r = requests.post(url=webhook_url, headers=dd_headers, data=json.dumps(dd_message))


class bugku():
def __init__(self) -> None:
self.session = requests.session()
self.session.headers.update(headers)
self.num = 10
self.is_login = False

# 将函数写入到类里面,直接使用openai,香的一批
def dingtalk(self, content):
"""
Send a notification to the DingTalk webhook

Parameters:
content (str): The content of the notification

Returns:
None
"""
webhook_url = ''
dd_headers = {
"Content-Type": "application/json",
"Charset": "UTF-8"
}
dd_message = {
"msgtype": "text",
"text": {
"content": f'BugKu 签到通知\n{content}'
}
}

r = self.session.post(url=webhook_url, headers=dd_headers, data=json.dumps(dd_message))
def get_captcha(self):
if self.num <= 0:
logging.warning('验证码重试次数太多')
exit(0)
url = 'https://ctf.bugku.com/captcha.html0.9004209313422487'
res = self.session.get(url)
if res.status_code == 200:
code = ocr.classification(res.content)
c = ''.join(re.findall('\w', code))
if len(c) == 4:
logging.info('验证码成功:' + c)
# self.session.headers.update(res.headers)
return c
else:
sleep(3)
self.num -= 1
self.get_captcha()
else:
sleep(3)
self.num -= 1
self.get_captcha()

def login(self, username, password):
if self.num <= 0:
logging.warning('登录重试次数太多')
exit(0)
login_url = 'https://ctf.bugku.com/login/check.html'
code = self.get_captcha()
data = {'username': username, 'password': password, 'vcode': code, 'autologin': '1'}
res = self.session.post(url=login_url, data=data, headers=headers)

if '登录成功' in res.text:
logging.info(f'{username} 登录成功:{res.text}')
# self.session.headers.update(res.headers)
self.is_login = True
else:
logging.error('登录失败:' + res.text)
sleep(3)
self.num -= 1
self.login(username, password)

def checkin(self, username, password):
if self.is_login:
response = self.session.get('https://ctf.bugku.com/user/checkin')
print(response.text)
# {"code":1,"msg":"签到成功","data":{"user_id":59654,"count":1,"coin":1},"url":"","wait":3}
if '成功' in response.text:
logging.info('签到成功:' + response.text)
else:
logging.error('失败')

else:
self.login(username, password)
response = self.session.get('https://ctf.bugku.com/user/checkin')
print(response.text)
# dingtalk(response.text) # 取巧在这直接调用一次就行了,反正也是自己用
bg = bugku()
bg.dingtalk(response.text) # 调用类里面的dingtalk 函数
if '成功' in response.text:
logging.info('签到成功:' + response.text)

else:
logging.error('失败')



if __name__ == '__main__':
_bk = bugku()
_bk.checkin('', '')

食用步骤

  1. 将脚本中的 _bk.checkin(‘’, ‘’)中加上你的账号和密码

    1
    _bk.checkin('账号xxxxxx', '密码xxxxxx')
  2. 钉钉机器人配置教程:python实现钉钉机器人消息自动化通知,获取到自己的钉钉机器人的token

  3. 配置钉钉机器人的token,在代码中的 webhook_url = ‘’加上自己的机器人的token

    1
    webhook_url = 'xxxxxxxxxxxxxx'