Skip to content

Commit

Permalink
脚本归档;最新记录
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymou committed Jul 30, 2023
1 parent d0dd3d6 commit 89bc594
Show file tree
Hide file tree
Showing 5 changed files with 516 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ APP牛牛巴士:大麦抢票消息、波泼码生成、JJ20扫文识字搜答

### 日志记录

**07.28记录:最新技术**
**07.29记录:大麦更新8.5.8,脚本已更新适配**

**07.28记录:测试滑块模拟滑动脚本**

**07.27记录:0秒之后按钮会变"立即订购",继而一瞬间又变回"立即预约"按钮,说明APP,在0秒的时候还会再次请求服务器时间校正,所以`0727版本`添加了抖动。**

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
auto.waitFor();
app.launchApp("大麦");
console.show();

//本脚本是通过github大神们的脚本,模仿写出,用来学习使用
//预先说明,滑块问题,需要更换设备和路由器,或者直接用手机网络,到手机网络会慢,自己抉择


//步骤1:在显示倒计时的页面,填好观影人

//步骤2:在此处填好你想看的场次和票档
var ticketInfo = {
date: "周日",
price: 855
}

//步骤3:打开APP,进入有倒计时的页面

//步骤4:点击本脚本上方的"运行"按钮,即会自动跳转到APP


//下面不用管
main(ticketInfo);

function main(ticketInfo) {
// 从界面上获取开抢时间
var UIStartTime = id("tv_count_down_remind").findOne();
// 获取系统本地时间
var strStartTime = UIStartTime.text();
print("获取到的开抢时间: " + strStartTime);

// 通过viewId获取点击坐标
//todo 如果大麦更新该id,得重新获取jdxd
var btnBuy = id("trade_project_detail_purchase_status_bar_container_fl").findOne();
var rectBtnBuy = btnBuy.bounds();
var clickPosX = rectBtnBuy.centerX();
var clickPosY = rectBtnBuy.centerY();
print("获取到的点击坐标: " + clickPosX + ", " + clickPosY);

// 设置开抢时间
var year = new Date().getFullYear();
var month = strStartTime.slice(strStartTime.indexOf("月") - 2, strStartTime.indexOf("月")) - 1;
var day = strStartTime.slice(strStartTime.indexOf("日") - 2, strStartTime.indexOf("日"));
var hour = strStartTime.slice(strStartTime.indexOf(":") - 2, strStartTime.indexOf(":"));
var minute = strStartTime.slice(strStartTime.indexOf(":") + 1, strStartTime.indexOf(":") + 3);
var second = 0;
var msecond = 0;
var startTimestamp = new Date(year, month, day, hour, minute, second, msecond).getTime();
startTimestamp = startTimestamp - 40; // 减去 40ms 的网络延迟
var damaiTimestamp;
var startTime = convertToTime(startTimestamp);
print("开始时间:\n", startTime);
print("等待开抢...");
var i = 0;
// 循环等待
while (true) {
damaiTimestamp = getDamaiTimestamp();
if (damaiTimestamp >= startTimestamp) {
print("到点了,自动开始。");
break;
}
var mm = startTimestamp - damaiTimestamp;
var ss = mm/1000;
if(ss>300){
print("剩余:"+(ss)+"秒");
}else{print("剩余:"+(mm)+"毫秒");}

i++;
if(i%200==0){
print("清屏");
console.clear();

}

}

click(clickPosX, clickPosY);
print("点击立即购买按钮");

// 选择场次
textContains(ticketInfo.date).findOne().parent().parent().parent().parent().click();
print("选择场次ing");

//选择票档
textContains(ticketInfo.price).findOne().parent().parent().parent().parent().click();
print("选择票档ing");

id("btn_buy").findOne().click();
print("点击红色确定按钮");

//print("进入提交订单页面");

//获取按钮位置
text("提交订单").findOne().click();
print("点击提交订单按钮");


// 提交订单的大麦时间
var endTime = convertToTime(getDamaiTimestamp());
console.log("订单提交时间:" + endTime);
}


/**
* 感谢GitHub大佬提供
* @param {时间戳} timestamp
* @returns ISO 8601 格式的北京时间
*/
function convertToTime(timestamp) {
var date = new Date(Number(timestamp));
var year = date.getUTCFullYear();
var month = (date.getUTCMonth() + 1).toString().padStart(2, "0");
var day = date.getUTCDate().toString().padStart(2, "0");
var hours = (date.getUTCHours() + 8).toString().padStart(2, "0");
var minutes = date.getUTCMinutes().toString().padStart(2, "0");
var seconds = date.getUTCSeconds().toString().padStart(2, "0");
var milliseconds = date.getUTCMilliseconds().toString().padStart(3, "0");
var iso8601 = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
return iso8601;
}

/**
*
* @returns 大麦服务器时间戳
*/
function getDamaiTimestamp() {
return JSON.parse(http.get("https://mtop.damai.cn/gw/mtop.common.getTimestamp/", {
headers: {
'Host': 'mtop.damai.cn',
'Content-Type': 'application/json;charset=utf-8',
'Accept': '*/*',
'User-Agent': 'floattime/1.1.1 (iPhone; iOS 15.6; Scale/3.00)',
'Accept-Language': 'zh-Hans-CN;q=1, en-CN;q=0.9',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive'
}
}).body.string()).data.t;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
auto.waitFor();
app.launchApp("大麦");
console.show();
//欢迎进群604964470,一起学习、讨论

//本脚本单独执行,模拟点击脚本也单独执行

//步骤一:定义滑块标识
var reconizeSliper = ">>";
//var reconizeSliper = "厂牌号";//用于测试,这里"厂牌号"是APP中"话剧音乐剧"模块内的一个标识

//步骤二:根据手机情况定义滑块偏移量
//滑块横坐标偏移量
var offsetX = 0;//如果能识别出滑块的标识是>>,那此处就不需要修改
//如果滑块标识不是>>
//那就需要找到滑块上面的文字"验证通过后可继续正常访问哦"作为检测标识
//然后添加偏移量,找到滑块。这个不同手机屏幕分辨率不一样,需要自己测试
var offsetY = 150;

//步骤三:根据手机情况设置滑块的滑动距离
var swipeLength = 800;

//步骤四:设置多少毫秒内滑完滑块
var swipeTime = 300


//以上变量需要自己定义
/************************************************************************/
//以下程序不需要动

//清屏函数
var loopT = 1;
//找到滑块
var findSliper = false;

//浮窗指示器
var logThreads = threads.start(
function(){
while(!findSliper){
print("牛牛巴士");
print("检测滑块标识(" + reconizeSliper + ")ing:" + (loopT++) + "次");
sleep(200);
if(loopT%3==0){
//print("清屏,放内存")
console.clear()
}
}
}
)

//检测滑块方式一:假如命中滑块
threads.start(
function(){
while(true){
var tt = text(reconizeSliper).findOne();
var x = tt.bounds().centerX();
var y = tt.bounds().centerY();
print("找到滑块坐标(" + x + "," + y + ")尝试滑动")
findSliper = true;
swipe(x+offsetX, y+offsetY, x+swipeLength, y+offsetY, swipeTime);
sleep(2000)
findSliper=false

threads.start(
function(){
while(!findSliper){
print("牛牛巴士");
print("检测滑块标识(" + reconizeSliper + ")ing:" + (loopT++) + "次");
sleep(200);
if(loopT%3==0){
//print("清屏,放内存")
console.clear()
}
}
}
)
}
}
)


Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
auto.waitFor();
app.launchApp("大麦");
console.show();

//本脚本是通过github大神们的脚本,模仿写出,用来学习使用
//预先说明,滑块问题,需要更换设备和路由器,或者直接用手机网络,到手机网络会慢,自己抉择


//步骤1:在显示倒计时的页面,填好观影人

//步骤2:在此处填好你想看的场次和票档
var ticketInfo = {
date: "周六",
price: 680
}

//步骤2.1 0727记录:0秒之后按钮会变"立即订购",继而一瞬间又变回"立即预约",说明APP,在0秒的时候还会再次请求服务器时间,所以此处新添抖动
var zeroToWait = 500;

//步骤3:打开APP,进入有倒计时的页面

//步骤4:点击本脚本上方的"运行"按钮,即会自动跳转到APP


//下面不用管
main(ticketInfo);

function main(ticketInfo) {
// 从界面上获取开抢时间
var UIStartTime = id("tv_count_down_remind").findOne();
// 获取系统本地时间
var strStartTime = UIStartTime.text();
print("获取到的开抢时间: " + strStartTime);

// 通过viewId获取点击坐标
//todo 如果大麦更新该id,得重新获取jdxd
var btnBuy = id("trade_project_detail_purchase_status_bar_container_fl").findOne();
var rectBtnBuy = btnBuy.bounds();
var clickPosX = rectBtnBuy.centerX();
var clickPosY = rectBtnBuy.centerY();
print("获取到的点击坐标: " + clickPosX + ", " + clickPosY);

// 设置开抢时间
var year = new Date().getFullYear();
var month = strStartTime.slice(strStartTime.indexOf("月") - 2, strStartTime.indexOf("月")) - 1;
var day = strStartTime.slice(strStartTime.indexOf("日") - 2, strStartTime.indexOf("日"));
var hour = strStartTime.slice(strStartTime.indexOf(":") - 2, strStartTime.indexOf(":"));
var minute = strStartTime.slice(strStartTime.indexOf(":") + 1, strStartTime.indexOf(":") + 3);
var second = 0;
var msecond = 0;
var startTimestamp = new Date(year, month, day, hour, minute, second, msecond).getTime();
startTimestamp = startTimestamp - 40; // 减去 40ms 的网络延迟
var damaiTimestamp;
var startTime = convertToTime(startTimestamp);
print("开始时间:\n", startTime);
print("等待开抢...");
var i = 0;
// 循环等待
while (true) {
damaiTimestamp = getDamaiTimestamp();
if (damaiTimestamp >= startTimestamp) {
print("到点了,自动开始。");
break;
}
var mm = startTimestamp - damaiTimestamp;
var ss = mm/1000;
if(ss>300){
print("剩余:"+(ss)+"秒");
}else{print("剩余:"+(mm)+"毫秒");}

i++;
if(i%200==0){
print("清屏");
console.clear();
//break;
}

}

//2023.07.27 加个抖动,因为在0秒的时候,还会再次请求服务器时间回到APP校准,所以此处等几毫秒吧
print("加入抖动:" + zeroToWait + "ms");
sleep(zeroToWait);

click(clickPosX, clickPosY);
print("点击立即购买按钮");

// 选择场次
textContains(ticketInfo.date).findOne().parent().parent().parent().parent().click();
print("选择场次ing");

//选择票档
textContains(ticketInfo.price).findOne().parent().parent().parent().parent().click();
print("选择票档ing");

id("btn_buy").findOne().click();
print("点击红色确定按钮");

//print("进入提交订单页面");

//获取按钮位置
text("提交订单").findOne().click();
print("点击提交订单按钮");


// 提交订单的大麦时间
var endTime = convertToTime(getDamaiTimestamp());
console.log("订单提交时间:" + endTime);
}


/**
* 感谢GitHub大佬提供
* @param {时间戳} timestamp
* @returns ISO 8601 格式的北京时间
*/
function convertToTime(timestamp) {
var date = new Date(Number(timestamp));
var year = date.getUTCFullYear();
var month = (date.getUTCMonth() + 1).toString().padStart(2, "0");
var day = date.getUTCDate().toString().padStart(2, "0");
var hours = (date.getUTCHours() + 8).toString().padStart(2, "0");
var minutes = date.getUTCMinutes().toString().padStart(2, "0");
var seconds = date.getUTCSeconds().toString().padStart(2, "0");
var milliseconds = date.getUTCMilliseconds().toString().padStart(3, "0");
var iso8601 = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
return iso8601;
}

/**
*
* @returns 大麦服务器时间戳
*/
function getDamaiTimestamp() {
return JSON.parse(http.get("https://mtop.damai.cn/gw/mtop.common.getTimestamp/", {
headers: {
'Host': 'mtop.damai.cn',
'Content-Type': 'application/json;charset=utf-8',
'Accept': '*/*',
'User-Agent': 'floattime/1.1.1 (iPhone; iOS 15.6; Scale/3.00)',
'Accept-Language': 'zh-Hans-CN;q=1, en-CN;q=0.9',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive'
}
}).body.string()).data.t;
}

Loading

0 comments on commit 89bc594

Please sign in to comment.