|
|
@@ -769,6 +769,13 @@ async function tryDragonBet(drawIssue, planStr, betAmount, maxBetAmount = 96) {
|
|
|
betAmount = maxBetAmount;
|
|
|
}
|
|
|
let result = await doDragonBet(drawIssue, planStr, betAmount);
|
|
|
+ if (!result) {
|
|
|
+ let loginRet = await tryReLogin();
|
|
|
+ if (!loginRet) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ result = await doDragonBet(drawIssue, planStr, betAmount);
|
|
|
+ }
|
|
|
if (result && result.statusCode == 200) {
|
|
|
if (checkBetResult(result)) {
|
|
|
magicJS.notification.post(magicJS.scriptName, `🎉下注成功 号码:${planStr} 单注:${betAmount}`);
|
|
|
@@ -825,6 +832,154 @@ async function doDragonBet(drawIssue, planStr, betAmount) {
|
|
|
}
|
|
|
|
|
|
|
|
|
+async function tryReLogin() {
|
|
|
+ let recognizeRet = await tryGenerateCaptchaAndRecognize(3);
|
|
|
+ if (!recognizeRet) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let validateRet = await doValidateCaptcha(recognizeRet.uuid, recognizeRet.positionX, recognizeRet.positionY);
|
|
|
+ if (!validateRet || validateRet.statusCode != 200) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let vFinalResult = validateRet.result;
|
|
|
+ if (vFinalResult.status != 'OK') {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let username = 'aiyo21';
|
|
|
+ let password = 'aiyo510520';
|
|
|
+ let loginRet = await doLogin(username, password, vFinalResult.code, vFinalResult.cryptograph);
|
|
|
+ if (!loginRet || loginRet.statusCode != 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let newToken = loginRet.token;
|
|
|
+ gCaiLeToken = newToken;
|
|
|
+ gCaiLeHeaders['token'] = gCaiLeToken;
|
|
|
+ magicJS.data.write('DIII_CaiLeYuan_Token', newToken);
|
|
|
+ magicJS.notification.appendNotifyInfo(`🎉重登成功,最新token已刷新`);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+async function tryGenerateCaptchaAndRecognize(tryCount = 1) {
|
|
|
+ let captchaRet = null;
|
|
|
+ let recognizeRet = null;
|
|
|
+ for(let i = i; i < tryCount; i++) {
|
|
|
+ captchaRet = await doGenerateCaptcha();
|
|
|
+ if (!captchaRet || captchaRet.statusCode != 200) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ recognizeRet = await tryAutoRecognizeCaptcha('ddddocr', captchaRet.result);
|
|
|
+ if (!recognizeRet) {
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return recognizeRet;
|
|
|
+}
|
|
|
+
|
|
|
+async function doLogin(username, password, code, cryptograph) {
|
|
|
+ const url = `https://${gCaiLeHost}/rest/login`;
|
|
|
+ let reqData = {
|
|
|
+ username: username,
|
|
|
+ password: password,
|
|
|
+ code: code,
|
|
|
+ cryptograph: cryptograph,
|
|
|
+ platform: "ios",
|
|
|
+ version: "3.0.48",
|
|
|
+ };
|
|
|
+ let result = await clyRequest('post', url, reqData);
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+async function doValidateCaptcha(uuid, positionX, positionY) {
|
|
|
+ const url = `https://${gCaiLeHost}/rest/captcha/validate`;
|
|
|
+ let reqData = {
|
|
|
+ uuid: uuid,
|
|
|
+ positionX: positionX,
|
|
|
+ positionY: positionY,
|
|
|
+ };
|
|
|
+ let result = await clyRequest('post', url, reqData);
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+async function doGenerateCaptcha() {
|
|
|
+ const url = `https://${gCaiLeHost}/rest/captcha/generate`;
|
|
|
+ let result = await clyRequest('get', url);
|
|
|
+ return result;
|
|
|
+}
|
|
|
+
|
|
|
+async function tryAutoRecognizeCaptcha(typeStr, captchaInfo) {
|
|
|
+ switch (typeStr) {
|
|
|
+ case 'ddddocr':
|
|
|
+ return recognizeCaptchaByDdddocr(captchaInfo);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function recognizeCaptchaByDdddocr(captchaInfo) {
|
|
|
+ let puzzleImage = captchaInfo.puzzleImage;
|
|
|
+ let backgroundImage = captchaInfo.backgroundImage;
|
|
|
+ let positionY = captchaInfo.positionY;
|
|
|
+ let uuid = captchaInfo.uuid;
|
|
|
+ let reqData = {
|
|
|
+ recognize_type: 'slide',
|
|
|
+ puzzle_image: encodeURIComponent(puzzleImage),
|
|
|
+ background_image: encodeURIComponent(backgroundImage),
|
|
|
+ position_y: positionY,
|
|
|
+ uuid: uuid,
|
|
|
+ }
|
|
|
+ let form = magicJS.objToQueryStr(reqData);
|
|
|
+ let headers = {
|
|
|
+ 'Accept': `application/json`,
|
|
|
+ 'Origin': `https://api.jojo21.com`,
|
|
|
+ 'Connection': `keep-alive`,
|
|
|
+ 'Host': `api.jojo21.com`,
|
|
|
+ 'User-Agent': gCaiLeUserAgent,
|
|
|
+ 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
+ };
|
|
|
+ let options = {
|
|
|
+ url: 'http://api.jojo21.com/captcha/ddddocr',
|
|
|
+ headers: headers,
|
|
|
+ body: form,
|
|
|
+ };
|
|
|
+
|
|
|
+ let result = await magicJS.http.post(options).then(response => {
|
|
|
+ try {
|
|
|
+ const body = response.body;
|
|
|
+ let rspData = null;
|
|
|
+ if (typeof body === "string") {
|
|
|
+ return {
|
|
|
+ code: -1,
|
|
|
+ message: "Response Exception"
|
|
|
+ };
|
|
|
+ } else if (typeof body === "object") {
|
|
|
+ rspData = body;
|
|
|
+ }
|
|
|
+ magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
|
|
|
+ return rspData;
|
|
|
+ } catch (e) {
|
|
|
+ magicJS.logger.error(e);
|
|
|
+ }
|
|
|
+ }).catch(err => {
|
|
|
+ const msg = `请求滑块验证异常\n${JSON.stringify(err)}`;
|
|
|
+ magicJS.logger.error(msg);
|
|
|
+ });
|
|
|
+ if (result && result.code == 1) {
|
|
|
+ let targetInfo = result.result.target;
|
|
|
+ if (Math.abs(targetInfo[1] - positionY) > 4){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ result.positionX = targetInfo[0] + randomFloat(0, 0.5);
|
|
|
+ result.positionY = positionY;
|
|
|
+ result.uuid = uuid;
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+}
|
|
|
+
|
|
|
+function randomFloat(min, max) {
|
|
|
+ return Math.random() * (max - min) + min;
|
|
|
+}
|
|
|
+
|
|
|
function generateRandString(length) {
|
|
|
let result = '';
|
|
|
let characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
@@ -835,7 +990,7 @@ function generateRandString(length) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-async function clyRequest(method, url, reqData) {
|
|
|
+async function clyRequest(method, url, reqData, printRspData=true) {
|
|
|
if (!gCaiLeHeaders['token'] || gCaiLeHeaders['token'].length == 0) {
|
|
|
magicJS.logger.info(`❌token已失效请重新登陆获取!`);
|
|
|
return;
|
|
|
@@ -893,7 +1048,9 @@ async function clyRequest(method, url, reqData) {
|
|
|
} else if (typeof body === "object") {
|
|
|
rspData = body;
|
|
|
}
|
|
|
- magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
|
|
|
+ if (printRspData) {
|
|
|
+ magicJS.logger.info(`rspData=${JSON.stringify(rspData)}`);
|
|
|
+ }
|
|
|
if (rspData) {
|
|
|
return rspData;
|
|
|
} else {
|