This repository was archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcddaily-api.js
More file actions
139 lines (122 loc) · 4.31 KB
/
Copy pathmcddaily-api.js
File metadata and controls
139 lines (122 loc) · 4.31 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
function getStickerNum(token) {
try {
var result = apiRequest(token, "https://api1.mcddailyapp.com/sticker/get_list"), num = [0, 0];
if (result["rc"] != "1") throw result["rm"];
else {
for (i in result["results"]["stickers"]) {
var expireDate = Date.parse(result["results"]["stickers"][i]["object_info"]["expire_datetime"]),
curMonth = Date.parse(Utilities.formatDate(new Date(), "Asia/Taipei", "yyyy/MM/01 00:00:00"));
//31 DAYS = 2678400000
if (expireDate - curMonth <= 2678400000) num[0]++;
else num[1]++;
}
return num;
}
}
catch (e) {
return [-1, -1];
}
}
function getCouponList(token) {
try {
var result = apiRequest(token, "https://api1.mcddailyapp.com/coupon/get_list"), list = [];
if (result["rc"] != "1") throw result["rm"];
else {
for (i in result["results"]["coupons"]) {
if ("redeem_datetime" in result["results"]["coupons"][i]) continue;
else {
var expireDate = Date.parse(result["results"]["coupons"][i]["object_info"]["redeem_end_datetime"]),
curDate = Date.parse(Utilities.formatDate(new Date(), "Asia/Taipei", "yyyy/MM/dd HH:mm:ss"));
if (expireDate >= curDate) {
var cpnName = removeId(result["results"]["coupons"][i]["object_info"]["title"]),
cpnExpireTime = result["results"]["coupons"][i]["object_info"]["redeem_end_datetime"].split(" ")[0];
list.push([cpnName, cpnExpireTime]);
}
}
}
return list;
}
}
catch (e) {
return [];
}
}
function lottery(token) {
try {
var result = apiRequest(token, "https://api1.mcddailyapp.com/lottery/get_item");
if (result["rc"] != "1") throw result["rm"];
else {
var item = "";
if (Object.keys(result["results"])[0] == "coupon") {
item = result["results"]["coupon"]["object_info"]["title"];
}
else {
item = result["results"][Object.keys(result["results"])[0]]["object_info"]["title"];
}
return [true, removeId(item)];
}
}
catch (e) {
return [false, String(e)];
}
}
function checkToken(token) {
var curTime = new Date(),
payload = {
"access_token": token,
"OrderNo": deviceUuid + Utilities.formatDate(curTime, "Asia/Taipei", "yyyyMMddHHmmss"),
"mask": MD5("Mc" + deviceUuid +
Utilities.formatDate(curTime, "Asia/Taipei", "yyyyMMddHHmmss") +
platform + osVersion + deviceId + deviceUuid +
Utilities.formatDate(curTime, "Asia/Taipei", "yyyy/MM/dd HH:mm:ss") +
appVersion + token + "Donalds"),
"source_info": {
"model_id": deviceId,
"device_uuid": deviceUuid,
"platform": platform,
"os_version": osVersion,
"app_version": appVersion,
"device_time": Utilities.formatDate(curTime, "Asia/Taipei", "yyyy/MM/dd HH:mm:ss")
}
};
try {
var result = JSON.parse(UrlFetchApp.fetch("https://api.mcddaily.com.tw/verify_member_access_token",
{ method: "POST", contentType: "application/json", payload: JSON.stringify(payload) }));
return result["rc"] == "1";
}
catch (e) {
return false;
}
}
function getToken(account, password) {
var curTime = new Date(),
payload = {
"account": account,
"password": password,
"OrderNo": deviceUuid + Utilities.formatDate(curTime, "Asia/Taipei", "yyyyMMddHHmmss"),
"mask": MD5("Mc" + deviceUuid +
Utilities.formatDate(curTime, "Asia/Taipei", "yyyyMMddHHmmss") +
platform + osVersion + deviceId + deviceUuid +
Utilities.formatDate(curTime, "Asia/Taipei", "yyyy/MM/dd HH:mm:ss") +
appVersion + account + password + "Donalds"),
"source_info": {
"model_id": deviceId,
"device_uuid": deviceUuid,
"platform": platform,
"os_version": osVersion,
"app_version": appVersion,
"device_time": Utilities.formatDate(curTime, "Asia/Taipei", "yyyy/MM/dd HH:mm:ss")
}
};
try {
var result = JSON.parse(UrlFetchApp.fetch("https://api.mcddaily.com.tw/login_by_mobile",
{ method: "POST", contentType: "application/json", payload: JSON.stringify(payload) }));
if (result["rc"] != "1") throw result["rm"];
else {
return [true, result["results"]["member_info"]["access_token"]];
}
}
catch (e) {
return [false, String(e)];
}
}