ck_smzdm_app.Smzdm.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
"""
3
cron: 51 9 * * *
4
new Env('什么值得买APP');
5
"""
6
7
8
import requests
9
import json
10
import time
11
import hashlib
12
13
from notify_mtr import send
14
from utils import get_data
15
16
17
class Smzdm:
18
    def __init__(self, check_items):
19
        self.check_items = check_items
20
21
    @staticmethod
22
    def sign(cookie):
23
        try:
24
            ts = int(round(time.time() * 1000))
25
            url = 'https://user-api.smzdm.com/robot/token'
26
            headers = {
27
                'Host': 'user-api.smzdm.com',
28
                'Content-Type': 'application/x-www-form-urlencoded',
29
                'Cookie': f'{cookie}',
30
                'User-Agent': 'smzdm_android_V10.4.1 rv:841 (22021211RC;Android12;zh)smzdmapp',
31
            }
32
            data = {
33
                "f": "android",
34
                "v": "10.4.1",
35
                "weixin": 1,
36
                "time": ts,
37
                "sign": hashlib.md5(bytes(f'f=android&time={ts}&v=10.4.1&weixin=1&key=apr1$AwP!wRRT$gJ/q.X24poeBInlUJC', encoding='utf-8')).hexdigest().upper()
38
            }
39
            html = requests.post(url=url, headers=headers, data=data)
40
            res = html.json()
41
            token = res['data']['token']
42
43
            Timestamp = int(round(time.time() * 1000))
44
            data = {
45
                "f": "android",
46
                "v": "10.4.1",
47
                "sk": "ierkM0OZZbsuBKLoAgQ6OJneLMXBQXmzX+LXkNTuKch8Ui2jGlahuFyWIzBiDq/L",
48
                "weixin": 1,
49
                "time": Timestamp,
50
                "token": token,
51
                "sign": hashlib.md5(bytes(f'f=android&sk=ierkM0OZZbsuBKLoAgQ6OJneLMXBQXmzX+LXkNTuKch8Ui2jGlahuFyWIzBiDq/L&time={Timestamp}&token={token}&v=10.4.1&weixin=1&key=apr1$AwP!wRRT$gJ/q.X24poeBInlUJC', encoding='utf-8')).hexdigest().upper()
52
            }
53
            url = 'https://user-api.smzdm.com/checkin'
54
            url2 = 'https://user-api.smzdm.com/checkin/all_reward'
55
            headers = {
56
                'Host': 'user-api.smzdm.com',
57
                'Content-Type': 'application/x-www-form-urlencoded',
58
                'Cookie': f'{cookie}',
59
                'User-Agent': 'smzdm_android_V10.4.1 rv:841 (22021211RC;Android12;zh)smzdmapp',
60
            }
61
            html = requests.post(url=url, headers=headers, data=data)
62
            html2 = requests.post(url=url2, headers=headers, data=data)
63
            res = json.loads(html.text)
64
            res2 = json.loads(html2.text)
65
            if res2['error_code'] == '0':
66
                msg = res2["title"] + res2["sub_title"]
67
            else:
68
                msg = res['error_msg']
69
        except Exception as e:
70
            msg = f"签到状态: 签到失败\n错误信息: {e},请重新获取 cookie"
71
        return msg
72
73
    def main(self):
74
        msg_all = ""
75
76
        for check_item in self.check_items:
77
            msg = self.sign(check_item.get("cookie"))
78
            msg_all += msg + "\n\n"
79
        return msg_all
80
81
82
if __name__ == "__main__":
83
    _data = get_data()
84
    _check_items = _data.get("SMZDM", [])
85
    result = Smzdm(check_items=_check_items).main()
86
    send("什么值得买APP", result)
87