使用python+GitHub实现CSDN的自动签到,并用钉钉通知加入自动抽奖

仓库地址

  • 地址
  • 下面代码为部分代码,去仓库获取完整代码
  • 加入网易云音乐签到

自动签到代码

查看代码

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
import requests
import os #加入环境变量
if __name__ == '__main__':
COOKIE = os.environ["COOKIE"] # 点击签到后在控制台从heard里面找到COOKIE
USERNAME = os.environ["USERNAME"] # 这里是’CSDN‘的用户名,链接后面的
DDSECRET = os.environ["DDSECRET"] # 钉钉通知加签
DDPOSTURL = os.environ["DDPOSTURL"] # 钉钉通知机器人的链接地址

headers = {
'accept': 'application/json, text/plain, */*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
'content-length': '246',
'content-type': 'application/json;charset=UTF-8',
'cookie': COOKIE,
'origin': 'https://i.csdn.net',
'referer': 'https://i.csdn.net/',
'sec-ch-ua': '"Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"',
'sec-ch-ua-mobile': '?0',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
}

data = {
'ip': '',
'platform': 'pc-my',
'product': 'pc',
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36',
'username': USERNAME,
'uuid': '10_10212595300-1608558661367-119405',
}

r = requests.post("https://me.csdn.net/api/LuckyDraw_v2/signIn",headers=headers,data=data).content.decode("unicode_escape")
print(r) # 输出结果
import json
timedata = json.loads(r)
# 将json转化为数组形式
print(timedata)
isSign = timedata['data']['isSigned']
# print(isSign) #返回签到逻辑值
t = timedata['data']['msg']
print(t) # 返回签到结果


# 钉钉通知模块
import time
import hmac
import hashlib
import base64
import urllib.parse
import requests, json

timestamp = str(round(time.time() * 1000))
secret = DDSECRET
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode('utf-8')
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
# 导入依赖库
headers = {'Content-Type': 'application/json'} # 定义数据类型
# 截至到&timestamp之前
webhook = DDPOSTURL + timestamp + "&sign=" + sign
# 定义要发送的数据
# "at": {"atMobiles": "['"+ mobile + "']"
if isSign:
data = {
#定义内容
"msgtype": "markdown",
"markdown": {
"title":"CSDN签到通知",
"text": ">CSDN 签到已成功\n - 签到详情:" + t + "\n⭐项目地址:[https://github.com/Rr210/qiandao](https://github.com/Rr210/qiandao)"
}
}
res = requests.post(webhook, data=json.dumps(data), headers=headers) #发送post请求
print(res.text)
else:
data = {
# 定义内容
"msgtype": "markdown",
"markdown": {
"title": "CSDN签到通知",
"text": "签到失败" + '\n 签到详情' + t + "\n项目地址:[https://github.com/Rr210/qiandao](https://github.com/Rr210/qiandao)"
}
}
res = requests.post(webhook, data=json.dumps(data), headers=headers) # 发送post请求
print(res.text)

py加入自动抽奖操作

查看部分代码

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
import requests
import os #加入环境变量
if __name__ == '__main__':
COOKIE = os.environ["COOKIE"] # 点击签到后在控制台从heard里面找到COOKIE
USERNAME = os.environ["USERNAME"] # 这里是’CSDN‘的用户名,链接后面的
DDSECRET = os.environ["DDSECRET"] # 钉钉通知加签
DDPOSTURL = os.environ["DDPOSTURL"] # 钉钉通知机器人的链接地址

headers = {
'accept': 'application/json, text/plain, */*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
'content-length': '246',
'content-type': 'application/json;charset=UTF-8',
'cookie': COOKIE,
'origin': 'https://i.csdn.net',
'referer': 'https://i.csdn.net/',
'sec-ch-ua': '"Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"',
'sec-ch-ua-mobile': '?0',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36'
}

data = {
'ip': '',
'platform': 'pc-my',
'product': 'pc',
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36',
'username': USERNAME,
'uuid': '10_10212595300-1608558661367-119405',
}

r = requests.post("https://me.csdn.net/api/LuckyDraw_v2/signIn",headers=headers,data=data).content.decode("unicode_escape")
print(r) # 输出结果
import json
timedata = json.loads(r)
# 将json转化为数组形式
print(timedata)
message = timedata['message'] # 返回签到的结果
isSign = timedata['data']['isSigned']
# print(isSign) #返回签到逻辑值
t = timedata['data']['msg']
print(t) # 返回签到结果
# 返回签到天数,如果到了5天执行csdnlucky.py



# 钉钉通知模块
import time
import hmac
import hashlib
import base64
import urllib.parse
import requests, json

timestamp = str(round(time.time() * 1000))
secret = DDSECRET
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode('utf-8')
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
# 导入依赖库
headers = {'Content-Type': 'application/json'} # 定义数据类型
# 截至到&timestamp之前
webhook = DDPOSTURL + timestamp + "&sign=" + sign
# 定义要发送的数据
# "at": {"atMobiles": "['"+ mobile + "']"
if message == '成功':
data = {
#定义内容
"msgtype": "markdown",
"markdown": {
"title":"CSDN签到通知",
"text": ">CSDN 签到已成功\n - 签到详情:" + t + "\n------------⭐项目地址:[https://github.com/Rr210/qiandao](https://github.com/Rr210/qiandao)"
}
}
res = requests.post(webhook, data=json.dumps(data), headers=headers) #发送post请求
print(res.text)
else:
data = {
# 定义内容
"msgtype": "markdown",
"markdown": {
"title": "CSDN签到通知",
"text": ">CSDN 签到失败\n - 签到详情:"+ timedata + "\n项目地址:[https://github.com/Rr210/qiandao](https://github.com/Rr210/qiandao)"
}
}
res = requests.post(webhook, data=json.dumps(data), headers=headers) # 发送post请求
print(res.text)

使用方法

  1. 将以上代码中headersdata替换成你自己的
  2. 点击这里【签到地址】,打开浏览器调式工具consoleF12或者ctrl+shift+i,点击network后点击签到控制台会生成新的文件,点击后获得此时的headerdatactrl+c复制下来
  3. 转换成字典形式,转换方法【查看方法】,当然嫌麻烦可以手动修改成字典形式

Github配置

  1. 将你的COOKIE和USERNAME 保存替换成以上样式,记得保存好COOKIE,将COOKIE使用环境变量放到GitHub仓库的secrets里面,如图所示
  2. 修改代码第15行,第31行,第56行,第65行 将自己的信息修改

    查看图例

  3. 各个参数介绍
Secrets参数介绍
COOKIE这个时签到csdn所需的COOKIE,识别用户身份必须获得
USERNAME你的CSDN的用户名
DDPOSTURL钉钉群机器人的webhook地址,参考钉钉官方文档
DDSECRET设置钉钉机器人时的加签密钥
LUCKYCOOLKIE执行抽奖时所需的COOKIR,获取方法与签到的cookie相同
WYYCOOKIE获取方法相同
WYYCSRFTOKEN在控制台获取 csrf_token 的值
  1. 设置完成后可以手动执行或者点击star
  2. 如图已设置成功

    查看结果

  3. 通知成功

    查看结果

网易云音乐签到

  • 获取cookie与以上方法一致

查看图例

设置定时

  1. .github文件下的workflows中的csdn.yml中的corn的属性值修改
  2. 注意时差mg比我们地区快8个小时

参考

业余大佬们勿喷