Passed
Pull Request — master (#177)
by
unknown
02:27
created

ck_smzdm_app   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 65
dl 0
loc 86
rs 10
c 0
b 0
f 0

3 Methods

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