-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbalance.py
91 lines (79 loc) · 2.62 KB
/
balance.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
import requests as req
import json
import datetime
from dateutil import tz
import os
token_url = "https://login.evepc.163.com/v2/oauth/token"
token = os.environ.get("REFRESH_TOKEN").strip()
appID = os.environ.get("APP_ID").strip()
appSecret = os.environ.get("APP_Secret").strip()
openID = os.environ.get("OPEN_ID").strip()
templateID = os.environ.get("TEMPLATE_ID").strip()
client_id = os.environ.get("CLIENT_ID").strip()
refresh_token = {
"grant_type": "refresh_token",
"refresh_token": token,
"client_id": client_id
}
access_token = ""
wechatAccess = ""
userName = ""
userID = -1
baseUrl = "https://ali-esi.evepc.163.com"
datasource = "serenity"
def checkAnUpdateToken():
global access_token
global refresh_token
head = {
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
"Connection": "close"
}
response = req.post(token_url, data=refresh_token, headers=head)
if response.status_code == 200:
access_token = json.loads(response.content)["access_token"]
def getCharacterIDAndName():
global access_token
global userName
global userID
checkAnUpdateToken()
response = req.get(
"https://ali-esi.evepc.163.com/verify?token={}".format(access_token))
if response.status_code == 200:
respon = json.loads(response.content)
userName = respon["CharacterName"]
userID = respon["CharacterID"]
def getWeChatAccess():
global wechatAccess
url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}' \
.format(appID, appSecret)
wechatAccess = json.loads(req.get(url).content)["access_token"]
def sendInfo(nowTime, userName, balance):
getWeChatAccess()
body = {
"touser": openID,
"template_id": templateID,
"url": "https://weixin.qq.com",
"data": {
"nowTime": {
"value": nowTime
},
"userName": {
"value": userName
},
"balance": {
"value": balance
}
}
}
url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={}'.format(
wechatAccess)
req.post(url, json.dumps(body)).text
if __name__ == "__main__":
getCharacterIDAndName()
url = baseUrl + "/legacy/characters/{}/wallet/?datasource={}&token={}".format(
str(userID), datasource, access_token)
balance = str('{:,}'.format(
round(float(json.loads(req.get(url).content)), 2)))
nowtime = datetime.datetime.now(tz=tz.gettz(
"Asia/China")).strftime("%Y-%m-%d %H:%M:%S")
sendInfo(nowtime, userName, balance)