怎样在Auto.js中添加卡密验证功能?跟着泡椒云的步骤来操作!
最编程
2024-01-16 16:59:42
...
//下面是PJYSDK.js源码
const PJYSDK = (function(){
function PJYSDK(app_key, app_secret){
http.__okhttp__.setMaxRetries(0);
http.__okhttp__.setTimeout(10*1000);
this.event = events.emitter();
this.debug = true;
this._lib_version = "v1.08";
this._protocol = "https";
this._host = "api.paojiaoyun.com";
this._device_id = this.getDeviceID();
this._retry_count = 9;
this._app_key = app_key;
this._app_secret = app_secret;
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 = card.trim();
}
PJYSDK.prototype.SetUser = function(username, password) {
this._username = username.trim();
this._password = password;
}
PJYSDK.prototype.getDeviceID = function() {
let id = device.serial;
if (id == null || id == "" || id == "unknown") {
id = device.getAndroidId();
}
if (id == null || id == "" || id == "unknown") {
id = device.getIMEI();
}
return id;
}
PJYSDK.prototype.MD5 = function(str) {
try {
let digest = java.security.MessageDigest.getInstance("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.lang.Integer.toHexString(number);
if (str.length == 1) {
buffer.append("0");
}
buffer.append(str);
}
return buffer.toString();
} catch (error) {
alert(error);
return "";
}
}
PJYSDK.prototype.getTimestamp = function() {
try {
let res = http.get("http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp");
let data = res.body.json();
return Math.floor(data["data"]["t"]/1000);
} catch (error) {
return Math.floor(new Date().getTime()/1000);
}
}
PJYSDK.prototype.genNonce = function() {
const ascii_str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let tmp = '';
for(let i = 0; i < 20; i++) {
tmp += ascii_str.charAt(Math.round(Math.random()*ascii_str.length));
}
return this.MD5(this.getDeviceID() + 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 (resp.code != 0 && resp.nonce === "" && 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": "轻点,疼~"};
}
PJYSDK.prototype.retry_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) {
if (this.debug) {
log("\n" + path, "\nparams:", params, "\nresult:", result);
}
}
PJYSDK.prototype.Request = function(method, path, params) {
// 构建公共参数
params["app_key"] = this._app_key;
method = method.toUpperCase();
let url = this._protocol + "://" + this._host + path
let max_retries = this._retry_count;
let retries_count = 0;
let data = {"code": -1, "message": "连接服务器失败"};
上一篇: 简单易做!酸辣开胃的泡椒凉拌荞麦粉条,让你轻松享瘦!
下一篇: qq_1059136269