Skip to content

Instantly share code, notes, and snippets.

@ChengLuffy
Last active January 13, 2020 16:05
Show Gist options
  • Save ChengLuffy/4ec724778820b51a20db73eca695f36d to your computer and use it in GitHub Desktop.
Save ChengLuffy/4ec724778820b51a20db73eca695f36d to your computer and use it in GitHub Desktop.
let URL = "https://v2ray.api.lanan.xyz/client/api.php"
function checkUserInfoCached() {
var username = "";
var password = "";
if ($cache.get("username") == null) {
$input.text({
placeholder: "用户名",
handler: function(text) {
$cache.set("username", text);
checkUserInfoCached();
}
});
return;
} else {
username = $cache.get("username");
}
if ($cache.get("password") == null) {
$input.text({
placeholder: "密码",
handler: function(text) {
$cache.set("password", text);
checkUserInfoCached();
}
});
return;
} else {
password = $cache.get("password");
}
if ($cache.get("token") == null) {
getToken(username, password);
} else {
loadPackages();
}
}
function getToken(username, password) {
let urlStr = URL + "?s=user.auth";
var params = {
"username": username,
"password": password
}
var formBody = [];
for (var property in params) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(params[property]);
formBody.push(encodedKey + "=" + encodedValue);
}
formBody = formBody.join("&");
$http.request({
method: "POST",
url: urlStr,
header: {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) lanan-mac/2.0.1 Chrome/59.0.3071.115 Electron/1.8.7 Safari/537.36",
"Accept": "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/x-www-form-urlencoded"
},
body: formBody,
handler: function(resp) {
if (resp.error != null) {
$ui.toast(resp.error);
$cache.remove("token");
} else if (resp.data.ret != 1) {
$ui.toast(resp.data.msg);
$cache.remove("token");
} else {
var data = resp.data.data;
$cache.set("token", data);
loadPackages();
}
}
});
}
function loadPackages() {
$http.get({
url: URL + '?s=whmcs.hosting&token=' + $cache.get("token"),
header: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) lanan-mac/2.0.0 Chrome/59.0.3071.115 Electron/1.8.7 Safari/537.36',
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate'
},
handler: function(resp) {
if (resp.error != null) {
$ui.toast(resp.error);
$cache.remove("token");
checkUserInfoCached();
} else {
$console.info(resp.data);
var data = resp.data;
var arr = data.data;
for (let i = 0; i < arr.length; i++) {
const element = arr[i];
loadUseage(element.serverId, element.packageId, element.name, element.regDate, element.expireDate)
}
// $ui.menu({
// items: titles,
// handler: function(title, idx) {
// var element = arr[idx];
// loadUseage(element.serverId, element.packageId);
// }
// });
}
}
});
}
function loadUseage(serverId, packageId, name, regDate, expireDate) {
$http.get({
url: URL + '?s=v2ray.userInfo&token=' + $cache.get("token") + "&serverId=" + serverId + "&packageId=" + packageId,
header: {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) lanan-mac/2.0.0 Chrome/59.0.3071.115 Electron/1.8.7 Safari/537.36',
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate'
},
handler: function(resp) {
if (resp.error != null) {
$ui.toast(resp.error);
$cache.remove("token");
checkUserInfoCached();
} else {
var data = resp.data;
var u = data.data.u / 1024.0 / 1024.0 / 1024.0;
var d = data.data.d / 1024.0 / 1024.0 / 1024.0;
var transfer_enable = data.data.transfer_enable / 1024.0 / 1024.0 / 1024.0;
// $ui.alert({
// title: "总量:\n" + transfer_enable + "\n\n已使用:\n" + (u + d),
// message: "",
// });
var body = "已使用:" + (u + d).toFixed(2) + "GB\n总量:" + transfer_enable + "GB\n注册时间:" + regDate + "\n到期时间:" + expireDate;
$push.schedule({
title: name,
body: body,
delay: 0.01,
handler: function(result) {
$intents.finish({ "title": name, "detail": body });
}
})
}
}
});
}
checkUserInfoCached();
@ChengLuffy
Copy link
Author

ChengLuffy commented Oct 21, 2019

安装链接 蓝岸流量查询

第一次运行需要您输入账号密码,账号密码存于 JSBox 缓存当中

添加到捷径自动化可以实现每天定时查询,需要 JSBox 具有通知权限

捷径

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment