|
@@ -133,6 +133,13 @@ function handleTokenAndCookie() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async function doNetworkTest(){
|
|
|
|
|
+ const url = `https://${gCaiLeHost}/network-test?t=${Date.now()}`;
|
|
|
|
|
+ let result = await clyRequest('get', url);
|
|
|
|
|
+ return result == 'OK';
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
async function doTestBet(){
|
|
async function doTestBet(){
|
|
|
let drawIssue = magicJS.data.read('168_PksPlanDrawIssueCustom', null);
|
|
let drawIssue = magicJS.data.read('168_PksPlanDrawIssueCustom', null);
|
|
|
if(!drawIssue){
|
|
if(!drawIssue){
|
|
@@ -147,7 +154,15 @@ async function doTestBet(){
|
|
|
if(planStr.length == 0){
|
|
if(planStr.length == 0){
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- await doDragonBet(drawIssue, planStr, 1);
|
|
|
|
|
|
|
+ let betRet = await doDragonBet(drawIssue, planStr, 1);
|
|
|
|
|
+ if(!betRet){
|
|
|
|
|
+ let loginRet = await tryReLogin();
|
|
|
|
|
+ if(!loginRet){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ betRet = await doDragonBet(drawIssue, planStr, 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ return betRet;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async function doDragonBet(drawIssue, planStr, betAmount){
|
|
async function doDragonBet(drawIssue, planStr, betAmount){
|
|
@@ -179,6 +194,130 @@ async function doDragonBet(drawIssue, planStr, betAmount){
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+async function tryReLogin(){
|
|
|
|
|
+ let captchaRet = await doGenerateCaptcha();
|
|
|
|
|
+ if(!captchaRet || captchaRet.statusCode != 200){
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ let recognizeRet = await tryAutoRecognizeCaptcha('ddddocr', captchaRet.result);
|
|
|
|
|
+ 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 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 = {
|
|
|
|
|
+ puzzleImage: encodeURIComponent(puzzleImage),
|
|
|
|
|
+ backgroundImage: encodeURIComponent(backgroundImage),
|
|
|
|
|
+ positionY: positionY,
|
|
|
|
|
+ uuid: uuid,
|
|
|
|
|
+ }
|
|
|
|
|
+ let form = lk.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.uuid = uuid;
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function generateRandString(length) {
|
|
function generateRandString(length) {
|
|
|
let result = '';
|
|
let result = '';
|
|
|
let characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
let characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
@@ -214,16 +353,18 @@ async function clyRequest(method, url, reqData) {
|
|
|
// headers.apuid = 'sg282MjNFMbRl';
|
|
// headers.apuid = 'sg282MjNFMbRl';
|
|
|
|
|
|
|
|
let body = '';
|
|
let body = '';
|
|
|
- if (method == 'post') {
|
|
|
|
|
- let contentType = headers['Content-Type'];
|
|
|
|
|
- if (contentType && contentType.indexOf('form') > -1) {
|
|
|
|
|
- // 表单
|
|
|
|
|
- body = magicJS.objToQueryStr(reqData);
|
|
|
|
|
|
|
+ if (reqData) {
|
|
|
|
|
+ if (method == 'post') {
|
|
|
|
|
+ let contentType = headers['Content-Type'];
|
|
|
|
|
+ if (contentType && contentType.indexOf('form') > -1) {
|
|
|
|
|
+ // 表单
|
|
|
|
|
+ body = magicJS.objToQueryStr(reqData);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ body = JSON.stringify(reqData);
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
- body = JSON.stringify(reqData);
|
|
|
|
|
|
|
+ url = `${url}?${magicJS.objToQueryStr(reqData)}`;
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- url = `${url}?${magicJS.objToQueryStr(reqData)}`;
|
|
|
|
|
}
|
|
}
|
|
|
let options = {
|
|
let options = {
|
|
|
url: url,
|
|
url: url,
|
|
@@ -235,11 +376,7 @@ async function clyRequest(method, url, reqData) {
|
|
|
const body = response.body;
|
|
const body = response.body;
|
|
|
let rspData = null;
|
|
let rspData = null;
|
|
|
if (typeof body === "string") {
|
|
if (typeof body === "string") {
|
|
|
- magicJS.logger.info(`Response Exception Request By: ${API}`);
|
|
|
|
|
- return {
|
|
|
|
|
- code: -1,
|
|
|
|
|
- message: "Response Exception"
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ rspData = body;
|
|
|
} else if (typeof body === "object") {
|
|
} else if (typeof body === "object") {
|
|
|
rspData = body;
|
|
rspData = body;
|
|
|
}
|
|
}
|
|
@@ -266,6 +403,8 @@ async function clyRequest(method, url, reqData) {
|
|
|
if (err.response && err.response.body) {
|
|
if (err.response && err.response.body) {
|
|
|
if (err.response.statusCode == 401) {
|
|
if (err.response.statusCode == 401) {
|
|
|
// token失效
|
|
// token失效
|
|
|
|
|
+ magicJS.data.write('DIII_CaiLeYuan_Token', '');
|
|
|
|
|
+ magicJS.logger.info(`❌token已失效请重新登陆获取!`);
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|