forked from Caryio/ChangeWechatSport
-
Notifications
You must be signed in to change notification settings - Fork 1
/
v2ray.py
69 lines (54 loc) · 2.19 KB
/
v2ray.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
import base64
import hashlib
import hmac
import urllib
import requests
from datetime import datetime
def v2ray_sign():
headers = {
'Content-Type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
'Cookie': v2ray_cookie
}
sign_url = "https://go.runba.cyou/user/checkin"
return_response = requests.post(sign_url, headers=headers, allow_redirects=False)
print(return_response.text)
ding_push(return_response.text)
headers = {
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 9; MI 6 MIUI/20.6.18)'
}
def get_time():
# url = 'http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp'
# url = 'https://worldtimeapi.org/api/timezone/Asia/ShangHai'
# response = requests.get(url, headers=headers).json()
# # t = response['data']['t']
# utc_time_str = response['utc_datetime']
# utc_time = datetime.fromisoformat(utc_time_str.replace("Z", "+00:00"))
# t = int(utc_time.timestamp() * 1000)
# return t
return int(datetime.now().timestamp() * 1000)
def ding_push(content):
timestamp = get_time()
secret_enc = ding_secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, ding_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))
url = f"https://oapi.dingtalk.com/robot/send?access_token={ding_access_token}×tamp={timestamp}&sign={sign}"
headers = {
"Content-Type": "application/json;charset=UTF-8",
}
data = ("{\"at\":{\"isAtAll\":true},\"msgtype\":\"text\",\"text\":{\"content\":" + content + "}}").encode(
'utf-8')
response = requests.post(url, data=data, headers=headers).json()
if response["errcode"] != 0:
print("钉钉推送失败")
def main():
v2ray_sign()
def main_handler(event, context):
return main()
if __name__ == '__main__':
ding_access_token = ''
ding_secret = ''
v2ray_cookie = ''
main()