Snake's Home

自动化抢红包的实践

最近抢红包火热,基本上是全民抢红包。
大家为了几分钱,或者优惠券,时刻候着那个点,只能说支付宝太精明了。

借鉴了别人的代码,在模拟器上跑起来了。

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/pyton
#encoding=utf-8
import time
import sys

from com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImage

print('connect')
device = MonkeyRunner.waitForConnection()

#device.shell('am force-stop com.eztech.kylinlauncher')
device.shell('monkey -p com.eg.android.AlipayGphone -v 1')
print('start')
#device.startActivity(component='com.eg.android.AlipayGphone/com.alipay.android.launcher.TabLauncher')
device.shell('monkey -p com.alipay.android.launcher.TabLauncher -v 1')

w = 720
h = 1280
#raw_input("press Enter then press Ctrl+D to start!")
print('go')
while True:
for wi in xrange(100, w, w/6):
for hi in xrange(100, h, h/11):
device.drag((wi,hi),(765,1244),0.1,10)
#device.touch(wi, hi, MonkeyDevice.DOWN_AND_UP)

没有在真机上实践过。

现在缺点如下:

  1. 只是拖拽,不知道能否实现点击的功能。

  2. 点击速度太慢,模拟器上的缘故。

  3. 没有经过检验。

明天试下。

别人的脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# coding: utf-8
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
w = 720
h = 1280
raw_input("按 Enter后再按 Ctrl+D 后开始乱点")
print('go')
while True:
for wi in xrange(100, w, w/6):
for hi in xrange(100, h, h/11):
device.touch(wi, hi, MonkeyDevice.DOWN_AND_UP)
# Takes a screenshot
#result = device.takeSnapshot()
# Writes the screenshot to a file
#result.writeToFile('/tmp/shot1.png','png')

缺点: 很容易点到别的地方。

用monkey来实现

1
adb   shell monkey -p com.eg.android.AlipayGphone -s 500 --pct-touch 100 --ignore-crashes --ignore-timeouts --monitor-native-crashes -v -v 10000 > E:\monkey_log\java_monkey_log.txt

缺点: 完全不受控制。也很容易点到别的地方。