如何⽤Autojs写⾃⼰的卡密验证界⾯?实战代码最近有朋友问我的卡密验证界⾯是怎么写的,今天把源码分享出来。先上⼀个卡密验证界⾯的效果图:
源码第646⾏中的main.js替换为你的卡密验证通过后要跳转的js⽂件。这⾥路径为相对路径,跟本卡密验证.js为同级⽬录。
完整源码:(遇到问题,咨询。)
"ui";
var storage = ate("攒外快⽹");
ui.layout(
//背景图
<vertical gravity="center" bg="file://bg.jpg">
<text textSize="19sp" textColor="red" w="auto"text="请输⼊攒外快⽹脚本通⽤卡密登录"/>
<input id="card" textSize="16sp" text="{{('卡密','')}}" textColorHint="yellow"hint="请输⼊您
的卡密"/>
<button id="login" text="登录"/>
<button id="gm" text="购买攒外快⽹脚本通⽤卡密"/>
<button id="logout" text="退出"/>
</vertical>
);
const PJYSDK = (function(){
function PJYSDK(app_key, app_secret){
http.__okhttp__.setMaxRetries(0);
http.__okhttp__.setTimeout(10*1000);
this.event = itter();
this.debug = true;
this._lib_version = "v1.08";
this._protocol = "https";
this._host = "api.paojiaoyun";
this._device_id = DeviceID();
this._retry_count = 9;
this._app_key = "c2tgra4o6itbdn9h98f6"
this._app_secret = "WS6RMyA35AgHq1NkHlo2Pb0pZtjd0jcm"
this._card = null;
this._username = null;
this._password = null;
this._token = null;
this.is_trial = false; // 是否是试⽤⽤户
this.login_result = {
"card_type": "",
"expires": "",
"expires_ts": 0,
"config": "",
};
this._auto_heartbeat = true; // 是否⾃动开启⼼跳任务
this._heartbeat_gap = 60 * 1000; // 默认60秒
this._heartbeat_task = null;
this._heartbeat_ret = {"code": -9, "message": "还未开始验证"};
this._prev_nonce = null;
}
PJYSDK.prototype.SetCard = function(card) {
this._card = im();
}
PJYSDK.prototype.SetUser = function(username, password) {
this._username = im();
this._password = password;
}
DeviceID = function() {
let id = device.serial;
if (id == null || id == "" || id == "unknown") {
id = AndroidId();
}
if (id == null || id == "" || id == "unknown") {
id = IMEI();
}
return id;
}
PJYSDK.prototype.MD5 = function(str) {
try {
let digest = java.Instance("md5");
let result = digest.digest(new java.lang.String(str).getBytes("UTF-8")); let buffer = new java.lang.StringBuffer();
for (let index = 0; index < result.length; index++) {
let b = result[index];
let number = b & 0xff;
let str = java.HexString(number);
if (str.length == 1) {
buffer.append("0");
}
buffer.append(str);
}
String();
} catch (error) {
alert(error);
return "";
}
}
Timestamp = function() {
try {
let res = ("aobao/rest/api3.do?Timestamp");
let data = res.body.json();
return Math.floor(data["data"]["t"]/1000);
} catch (error) {
return Math.floor(new Date().getTime()/1000);
}
}
Nonce = function() {
const ascii_str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; let tmp = '';
for(let i = 0; i < 20; i++) {
tmp += ascii_str.und(Math.random()*ascii_str.length));
}
return this.DeviceID() + tmp);
}
PJYSDK.prototype.joinParams = function(params) {
let ps = [];
for (let k in params) {
ps.push(k + "=" + params[k])
}
ps.sort()
return ps.join("&")
}
PJYSDK.prototype.CheckRespSign = function(resp) {
if (de != 0 && === "" && resp.sign === "") {
return resp
}
let ps = "";
if (resp["result"]) {
ps = this.joinParams(resp["result"]);
}
let s = resp["code"] + resp["message"] + ps + resp["nonce"] + this._app_secret;
let sign = this.MD5(s);
if (sign === resp["sign"]) {
if (this._prev_nonce === null) {
this._prev_nonce = resp["nonce"];
return {"code":0, "message":"OK"};
} else {
if (resp["nonce"] > this._prev_nonce) {
this._prev_nonce = resp["nonce"];
return {"code": 0, "message": "OK"};
} else {
return {"code": -98, "message": "轻点,疼~"};
}
}
}
return {"code": -99, "message": "轻点,疼~"};
}
_fib = function(num) {
if (num > 9) {
return 34
}
let a = 0;
let b = 1;
for (i = 0; i < num; i++) {
let tmp = a + b;
a = b
b = tmp
}
return a
}
PJYSDK.prototype._debug = function(path, params, result) {
log("\n" + path, "\nparams:", params, "\nresult:", result); }
}
PJYSDK.prototype.Request = function(method, path, params) { // 构建公共参数
params["app_key"] = this._app_key;
method = UpperCase();
let url = this._protocol + "://" + this._host + path
let max_retries = this._retry_count;
let retries_count = 0;
let data = {"code": -1, "message": "连接服务器失败"};
do {
retries_count++;
let sec = _fib(retries_count);
delete params["sign"]
params["nonce"] = Nonce();
params["timestamp"] = Timestamp();
let ps = this.joinParams(params);
let s = method + this._host + path + ps + this._app_secret; let sign = this.MD5(s);
params["sign"] = sign;
let resp, body;
try {
if (method === "GET") {
resp = (url + "?" + ps + "&sign=" + sign);
} else { // POST
resp = http.post(url, params);
}
body = resp.body.string();
data = JSON.parse(body);
this._debug(method+'-'+path+':', params, data);
let crs = this.CheckRespSign(data);
if (de !== 0) {
return crs;
} else {
return data;
}
} catch (error) {
log("[*] request error: ", error, sec + "s后重试");
this._debug(method+'-'+path+':', params, body)
sleep(sec*1000);
}
} while (retries_count < max_retries);
return data;
}
/* 通⽤ */
PJYSDK.prototype.GetHeartbeatResult = function() {
return this._heartbeat_ret;
}
PJYSDK.prototype.GetTimeRemaining = function() {
let g = this.pires_ts - Timestamp();
if (g < 0) {
return 0;
}
return g;
}
/* 卡密相关 */
PJYSDK.prototype.CardLogin = function() { // 卡密登录
return {"code": -4, "message": "请先填⼊卡密"};
}
let method = "POST";
let path = "/v1/card/login";
let data = {"card": this._card, "device_id": this._device_id};
let ret = this.Request(method, path, data);
if (de == 0) {
this._token = ken;
this.login_result = sult;
if (this._auto_heartbeat) {
this._startCardHeartheat();
}
}
return ret;
}
PJYSDK.prototype.CardHeartbeat = function() { // 卡密⼼跳,默认会⾃动调⽤
if (!this._token) {
return {"code": -2, "message": "请在卡密登录成功后调⽤"};
}
let method = "POST";
let path = "/v1/card/heartbeat";
let data = {"card": this._card, "token": this._token};
let ret = this.Request(method, path, data);
if (de == 0) {
this.pires = pires;
this.pires_ts = pires_ts;
}
return ret;
}
PJYSDK.prototype._startCardHeartheat = function() { // 开启卡密⼼跳任务
function怎么记忆if (this._heartbeat_task) {
this._heartbeat_task.interrupt();
this._heartbeat_task = null;
}
this._heartbeat_task = threads.start(function(){
setInterval(function(){}, 10000);
});
this._heartbeat_ret = this.CardHeartbeat();
this._heartbeat_task.setInterval((self) => {
self._heartbeat_ret = self.CardHeartbeat();
if (self._de != 0) {
it("heartbeat_failed", self._heartbeat_ret);
}
}, this._heartbeat_gap, this);
this._heartbeat_task.setInterval((self) => {
if (self.GetTimeRemaining() == 0) {
it("heartbeat_failed", {"code": 10210, "message": "卡密已过期!"}); }
}, 1000, this);
}
PJYSDK.prototype.CardLogout = function() { // 卡密退出登录
this._heartbeat_ret = {"code": -9, "message": "还未开始验证"};
if (this._heartbeat_task) { // 结束⼼跳任务
this._heartbeat_task.interrupt();
this._heartbeat_task = null;
}
if (!this._token) {
return {"code": 0, "message": "OK"};
}
let method = "POST";
let path = "/v1/card/logout";
let data = {"card": this._card, "token": this._token};
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论