电信签到脚本修复

Dingdong

修复思路,因为兑换本还能用,所以借用兑换本的实现补环境以及搭建获取 Ruishu Cookie 的 API

兑换本 GitHub 上很多,搜搜就有,删除多余关于兑换的部分,添加获取 Ruishu Cookie 的 API

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
def get_cookie_value():
"""
获取瑞数加密后的cookie值
返回: tuple (cookie_name, cookie_value)
"""
if not rs:
return None, None

bd = js.call('main').split('=')
return bd[0], bd[1]

def main():
global wt,rs
r = ss.get('https://wapact.189.cn:9001/gateway/stand/detailNew/exchange')
if '$_ts=window' in r.text:
rs = 1
print("瑞数加密已开启")
first_request()
else:
print("瑞数加密已关闭")
rs = 0


ck={}

app = Flask(__name__)

@app.route('/api/get_cookie', methods=['GET'])
def api_get_cookie():
"""
Web API接口,返回所有cookie
返回格式:
{
"success": true/false,
"data": {
"cookies": {
"cookie_name1": "value1",
"cookie_name2": "value2",
...
}
},
"message": "获取成功/失败原因"
}
"""
try:
if not rs:
return jsonify({
"success": False,
"data": None,
"message": "瑞数加密未开启"
})

# 获取瑞数cookie并添加到ck字典中
cookie_name, cookie_value = get_cookie_value()
if cookie_name:
ck[cookie_name] = cookie_value

return jsonify({
"success": True,
"data": {
"cookies": ck
},
"message": "获取成功"
})
except Exception as e:
return jsonify({
"success": False,
"data": None,
"message": f"获取失败: {str(e)}"
})

@app.route('/api/refresh_cookie', methods=['GET'])
def api_refresh_cookie():
"""
刷新cookie的API接口
返回格式:
{
"success": true/false,
"data": {
"cookies": {
"cookie_name1": "value1",
"cookie_name2": "value2",
...
}
},
"message": "刷新成功/失败原因"
}
"""
try:
if not rs:
return jsonify({
"success": False,
"data": None,
"message": "瑞数加密未开启"
})

# 重新执行first_request获取新cookie
content_code, ts_code, new_ck = first_request()

# 获取瑞数cookie并添加到ck字典中
cookie_name, cookie_value = get_cookie_value()
if cookie_name:
ck[cookie_name] = cookie_value

return jsonify({
"success": True,
"data": {
"cookies": ck
},
"message": "cookie刷新成功"
})
except Exception as e:
return jsonify({
"success": False,
"data": None,
"message": f"刷新失败: {str(e)}"
})

然后修改签到脚本中的 request 函数

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
    // 请求 Cookie API
let cookieHeaders = {};
try {
const cookieResponse = await this.got({
url: "https://rs.example.com/api/get_cookie",
method: "GET",
responseType: "json",
timeout: 5000 // 设置超时时间
});
if (cookieResponse.body?.success && cookieResponse.body.data?.cookies) {
const cookies = cookieResponse.body.data.cookies;
const cookieString = Object.entries(cookies).map(([key, value]) => `${key}=${value}`).join("; ");
cookieHeaders["Cookie"] = cookieString;
}
} catch (error) {
this.log(`[Cookie API] 请求错误: ${error.message}`);
// 如果获取 Cookie 失败,可以根据需求决定是否继续进行请求,或直接返回错误
return Promise.resolve({
statusCode: -1,
headers: null,
result: "获取 Cookie 失败"
});
}

// 合并 Headers
const _0x1effd8 = {
Connection: "keep-alive",
"User-Agent": _0x3ed712,
...cookieHeaders
};
this.got = this.got.extend({
cookieJar: this.cookieJar,
headers: _0x1effd8
});

/** 省略 **/
// 检查响应的 statusCode
if (_0x208a74?.statusCode === 412) {
this.log("检测到状态码 412,开始调用新 API 进行处理");

// 这里可以发送新的 API 请求,假设是刷新 Token
const refreshResponse = await this.got({
url: "https://rs.example.com/api/refresh_cookie", // 你想要调用的新 API
method: "GET",
responseType: "json",
timeout: 5000
});

// 处理新 API 请求的响应数据
if (refreshResponse.body?.success) {
// 例如更新 `cookieHeaders` 或其他需要的信息
const newCookieString = Object.entries(refreshResponse.body.data.cookies)
.map(([key, value]) => `${key}=${value}`)
.join("; ");
cookieHeaders["Cookie"] = newCookieString;

// 重新合并 headers 和 cookie,准备重试原始请求
this.got = this.got.extend({
cookieJar: this.cookieJar,
headers: { ..._0x1effd8, ...cookieHeaders }
});

// 重新发送原始请求(或者根据新的 API 返回的内容决定是否重试)
return this.got(_0x29ad8a);
} else {
this.log("刷新 Token 失败");
return Promise.resolve({
statusCode: 412,
headers: null,
result: "刷新 Token 失败"
});
}
}


  • Title: 电信签到脚本修复
  • Author: Dingdong
  • Created at : 2024-12-04 18:50:01
  • Updated at : 2024-12-05 13:11:42
  • Link: https://www.dp0.cc/2024/12/04/电信签到脚本修复/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
电信签到脚本修复