Skip to content

Commit

Permalink
update something
Browse files Browse the repository at this point in the history
  • Loading branch information
fmz200 committed Mar 30, 2024
1 parent 4b2980f commit 96f1fb5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 43 deletions.
6 changes: 4 additions & 2 deletions QuantumultX/rewrite/cookies.snippet
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,11 @@ https:\/\/www.hifini.com\/my.htm url script-request-header https://raw.githubuse
# >>>>>>>>>>>>>>> ✅ M ✅ <<<<<<<<<<<<<<
# > 美团
# hostname = open.meituan.com, gaea.meituan.com
# 获取token,美团APP点击“我的-个人主页”进入“完善资料”,这一步可以获取到用户ID用于更新多账号信息
# 获取token,美团APP点击“我的-个人主页”
# 新版本
https://open.meituan.com/user/v1/info/audit url script-request-header https://raw.githubusercontent.com/fmz200/wool_scripts/main/Scripts/cookie/get_cookie.js
# 进入“完善资料”,这一步可以获取到用户ID用于更新多账号信息
https://open.meituan.com/user/v1/info/auditting url script-response-body https://raw.githubusercontent.com/fmz200/wool_scripts/main/Scripts/cookie/get_cookie.js
;https://open.meituan.com/user/v1/info/audit url script-request-header https://raw.githubusercontent.com/fmz200/wool_scripts/main/Scripts/cookie/get_cookie.js
# 旧版本
https://gaea.meituan.com/mapi/usercenter url script-request-header https://raw.githubusercontent.com/fmz200/wool_scripts/main/Scripts/cookie/get_cookie.js
# 小象买菜 每日自动签到cookie, 打开美团App,选择“美团买菜” - “我的” - “天天领钱”
Expand Down
90 changes: 51 additions & 39 deletions Scripts/cookie/get_cookie.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @author fmz200
* @function 获取应用的cookie或token通用脚本
* @date 2024-02-03 21:30:00
* @date 2024-03-30 10:30:00
*/

////////////////////////////////
Expand Down Expand Up @@ -38,21 +38,7 @@ try {
let cache = $.read("#fmz200_smzdm_cookie") || "[]";
console.log("读取缓存数据:" + cache);
let json_data = JSON.parse(cache);
let hasKey = false;
// 遍历集合中的每一个对象
for (let obj of json_data) {
// 如果当前对象的 key 属性值匹配给定的 key
if (obj.smzdm_id === smzdm_id) {
// 更新该对象的 cookie 值
obj.cookie = cookie;
hasKey = true;
break; // 更新后直接返回,无需继续遍历
}
}
// 如果集合中没有匹配的 key,则新增一个对象
if (!hasKey) {
json_data.push({smzdm_id: smzdm_id, cookie: cookie});
}
updateOrAddObject(json_data, "smzdm_id", smzdm_id, "cookie", cookie);
const cacheValue = JSON.stringify(json_data, null, "\t");

$.write(cookie, '#SMZDM_COOKIE');
Expand Down Expand Up @@ -81,17 +67,34 @@ try {

/**
* 美团获取token
* 点击“我的”-“个人头像”,在请求头request-header中搜索token
* 点击“我的”-“个人头像”-"完善资料",在请求头request-header中搜索token
* @keyword meituanCookie
* @keyword fmz200_meituan_cookie
*/
if (req_url.includes("/user/v1/info/audit") || req_url.includes("/mapi/usercenter")) {
if (req_url.includes("/user/v1/info/auditting") || req_url.includes("/mapi/usercenter")) {
console.log('美团获取token 开始');
const token = req_headers['token'] || req_headers['Token'];
console.log("获取到token:" + token);
$.write(token, '#meituanCookie');
$.write(token, '#fmz200_meituan_cookie');
$.notify('美团获取token 获取成功✅', token, token);
console.log('美团获取token 获取到的内容为:' + token);
$.notify('美团获取token成功✅', "单账号更新成功,多账号更新中", token);

console.log("开始更新多账号");
let data = JSON.parse(rsp_body);
if (data.user) {
let uid = data.user.id;
let username = data.user.username;
console.log(`获取到uid:${uid},username:${username}`);

let cache = $.read("#fmz200_meituan_cookie") || "[]";
console.log("读取缓存数据:" + cache);

let json_data = JSON.parse(cache);
updateOrAddObject(json_data, "meituan_id", uid, "username", username, "token", token);
const cacheValue = JSON.stringify(json_data, null, "\t");

$.write(cacheValue, '#fmz200_meituan_cookie');
$.notify('美团多账号更新token成功✅', "", "");
}
}

/**
Expand Down Expand Up @@ -205,26 +208,35 @@ function parseDataString(dataString) {
return data;
}

// 这个函数接受一个集合(数组)、一个属性id、一个key、一个属性id2以及一个value作为参数。
// 它会查找集合中是否存在属性id等于key的对象,如果找到了,则更新该对象的属性id2为给定的value;
// 如果未找到,则创建一个新对象,属性id为key,属性id2为value,并将其添加到集合中。
// 最后,函数返回更新后的集合。
function updateOrAddObject(collection, id, key, id2, value) {
// 查找集合中是否存在属性id等于key的对象
const index = collection.findIndex(obj => obj[id] === key);

if (index !== -1) {
// 如果找到了,则更新属性id2的值为value
collection[index][id2] = value;
} else {
// 如果未找到,则新增一个对象并添加到集合中
const newObj = {};
newObj[id] = key;
newObj[id2] = value;
collection.push(newObj);
// 接受可变数量的参数对(id, key),并使用循环来处理这些参数对。
// 如果找到了匹配的对象,则在后续参数对中更新对应的属性值;如果未找到,则创建一个新对象并将其添加到集合中。
function updateOrAddObject(collection, ...args) {
if (args.length % 2 !== 0) {
throw new Error('Arguments must be provided in pairs.');
}

return collection;
for (let i = 0; i < args.length; i += 2) {
const id = args[i];
const key = args[i + 1];
const index = collection.findIndex(obj => obj[id] === key);

if (index !== -1) {
// 如果找到了,则更新对应的属性值
for (let j = i + 2; j < args.length; j += 2) {
const id2 = args[j];
const value = args[j + 1];
collection[index][id2] = value;
}
} else {
// 如果未找到,则新增一个对象并添加到集合中
const newObj = {};
for (let j = i; j < args.length; j += 2) {
newObj[args[j]] = args[j + 1];
}
collection.push(newObj);
break;
}
}
}

// 更新数据对象中指定 UID 的 Token
Expand Down
4 changes: 2 additions & 2 deletions boxjs/fmz200_boxjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
"fmz200_meituan_cookie"
],
"descs_html": [
"打开美团查看个人资料,在请求头中搜索token"
"打开美团查看个人资料,在请求头中搜索token\n如果要获取多账号更新,点击完善资料进入页面获取[不需要真编辑]"
],
"settings": [
{
Expand All @@ -252,7 +252,7 @@
},
{
"id": "fmz200_meituan_cookie",
"name": "美团token-JSON格式",
"name": "美团token-json格式",
"val": "",
"desc": "多账号用JSON格式存储",
"type": "textarea",
Expand Down

0 comments on commit 96f1fb5

Please sign in to comment.