春节来临期间互联网大鳄们纷纷祭出红包必杀技,各种抢红包。支付宝的整点抢红包形式是一个戳人的游戏。话说这个游戏比得就是手快,由此用过android monkey(猴子)工具的人自然可想到抢红包绝招了吧。对,没错这就是绝迹江湖的一阳指,又名adb monkey.下面我就来向大家演示下我是怎么用monkey 戳中支付宝抢红包游戏的每一个小人。


注意如果支付宝有无密码交易的设置请谨慎使用,否则monkey 乱点击可能造成误交易。

两种方式

  • shell 工具 适用于mac linux(android 客户端)
    代码:
echo 开始抓红包啦 ,good luck!
#抢红包持续的时间,单位是秒默认持续时间60秒!
tTime=60
count=$(($tTime*1000/10))
echo $count
adb shell monkey -p com.eg.android.AlipayGphone --pct-touch 100 --throttle 10 $count &while(true)
doread -p "停止抓红包(按任意键再回车,程序退出)" varcase "$var" in*)adb shell kill $(adb shell ps |awk '/monkey/{print $2}')echo good luckkill -9 $!exit 0;;      esac
done

com.eg.android.AlipayGphone :支付宝客户客户端packageName
--pct-touch 100 触摸占比(这里100%)
throttle 10 触摸点击间隔,时间单位毫秒(这里10毫秒点击一次)
$count 触摸次数(这里由总的点击持续时间计算出)
最后一个&符号表示此命令作为一个后台命令所以不会影响后续的命令执行。

后面的while 循环实时监控终端输入停止上面的monkey 点击事件。

  • 直接运行于android 的apk

需要手机root权限
上代码:

首先需要请求root权限执行 android 手机内部的monkey 命令(system/bin/monkey)/*
* commonds 执行的命令
* isRoot 是否需要root 权限
*/
public static CommandResult execCommand(String command, boolean isRoot,boolean isNeedResultMsg) {return execCommand(new String[] { command }, isRoot, isNeedResultMsg);}/*
* commonds 执行的命令
* isRoot 是否需要root 权限
*/
public static CommandResult execCommand(String[] commands, boolean isRoot,boolean isNeedResultMsg) {int result = -1;if (commands == null || commands.length == 0) {return new CommandResult(result, null, null);}Process process = null;BufferedReader successResult = null;BufferedReader errorResult = null;StringBuilder successMsg = null;StringBuilder errorMsg = null;DataOutputStream os = null;try {process = Runtime.getRuntime().exec(isRoot ? COMMAND_SU : COMMAND_SH);os = new DataOutputStream(process.getOutputStream());for (String command : commands) {if (command == null) {continue;}// donnot use os.writeBytes(commmand), avoid chinese charset// erroros.write(command.getBytes());os.writeBytes(COMMAND_LINE_END);os.flush();}os.writeBytes(COMMAND_EXIT);os.flush();result = process.waitFor();// get command resultif (isNeedResultMsg) {successMsg = new StringBuilder();errorMsg = new StringBuilder();successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));String s;while ((s = successResult.readLine()) != null) {successMsg.append(s);}while ((s = errorResult.readLine()) != null) {errorMsg.append(s);}}} catch (IOException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} finally {try {if (os != null) {os.close();}if (successResult != null) {successResult.close();}if (errorResult != null) {errorResult.close();}} catch (IOException e) {e.printStackTrace();}if (process != null) {process.destroy();}}return new CommandResult(result, successMsg == null ? null: successMsg.toString(), errorMsg == null ? null: errorMsg.toString());}/*
* 执行命令单独成一个服务这样避免阻塞ui线程造成无响应
*/public class StartService extends Service {private static String tag = "StartService";private static boolean isStart = false;public static int totalTime = 60;// secondpublic static int speed = 2;private static int count = totalTime * 1000 / 5;@Overridepublic IBinder onBind(Intent intent) {// TODO Auto-generated method stubLog.e(tag, "onBind");return null;}@Overridepublic void onCreate() {// TODO Auto-generated method stubLog.e(tag, "create");super.onCreate();}/** (non-Javadoc)* @see android.app.Service#onStartCommand(android.content.Intent, int, int)* */@Overridepublic int onStartCommand(Intent intent, int flags, int startId) {// TODO Auto-generated method stubLog.e(tag, "onStartCommond:flags:" + flags + ",startid:" + startId+ ";action:" + intent.getAction() + ";extra:"+ intent.getExtras().get("start"));start();return super.onStartCommand(intent, flags, startId);}/** 结束点击事件*/public static void stopMonkey() {isStart = false;String commond = "kill $(ps |awk '/monkey/{print $2}')";CommandResult result = ShellUtils.execCommand(commond, true, true);Log.e("stop Reuslt:", "successMsg:" + result.successMsg + "errorMsg:"+ result.errorMsg + "result:" + result.result);}
/** 启动服务*/public static void start() {if (isStart) {return;}isStart = true;String commond = "monkey -p com.eg.android.AlipayGphone --pct-touch 100 --throttle "+ speed + " " + count + "& >&/dev/null";CommandResult result = ShellUtils.execCommand(commond, true, true);Log.e("start Reuslt:", "successMsg:" + result.successMsg + "errorMsg:"+ result.errorMsg + "result:" + result.result);}
}/*
* activity 可配置抢红包持续时间以及速度
*/public class MainActivity extends ActionBarActivity {private CastReceive receiver;private static String tag = "MainActivity";private Notification notifi;private NotificationManager nm;@Overrideprotected void onCreate(Bundle savedInstanceState) {this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initViews();registReceive();}private void initViews() {Button btn = (Button) findViewById(R.id.done);btn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubcreateNotifaction();EditText speed = (EditText) findViewById(R.id.speed);String speedStr = speed.getEditableText().toString();int speedInteger = Integer.valueOf(speedStr);if (speedInteger != 0) {StartService.speed = 5 / speedInteger;}EditText total = (EditText) findViewById(R.id.total);int totalInteger = Integer.valueOf(total.getEditableText().toString());if (totalInteger != 0) {StartService.totalTime = totalInteger;}}});Button start = (Button) findViewById(R.id.start);start.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubStartService.start();}});}private void registReceive() {IntentFilter filter = new IntentFilter();filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);filter.addAction(Intent.ACTION_SCREEN_OFF);receiver = new CastReceive();registerReceiver(receiver, filter);}private void unRegistReceiver() {if (receiver != null) {this.unregisterReceiver(receiver);}}
/*** 创建通知*/private void createNotifaction() {NotificationCompat.Builder builder = new NotificationCompat.Builder(this);nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);builder.setAutoCancel(false);builder.setOngoing(true);notifi = builder.build();Intent intent = new Intent();intent.setClass(getApplicationContext(), StartService.class);intent.putExtra("start", "hehe");PendingIntent pendingIntent = PendingIntent.getService(this.getApplicationContext(), 0, intent, 0);notifi.when = System.currentTimeMillis();notifi.icon = R.drawable.ic_launcher;notifi.tickerText = "asdfsda";RemoteViews remote = new RemoteViews(getPackageName(), R.layout.remote);remote.setOnClickPendingIntent(R.id.iambtn, pendingIntent);notifi.contentView = remote;Log.e(tag, "createNOtofiy");nm.notify(R.string.app_name, notifi);}@Overrideprotected void onDestroy() {// TODO Auto-generated method stubsuper.onDestroy();//移除通知,结束监听服务nm.cancelAll();try {unRegistReceiver();Intent intent = new Intent();intent.setClass(getApplicationContext(), StartService.class);stopService(intent);} catch (Exception e) {// TODO: handle exceptione.printStackTrace();}}
}

完整代码就不贴了,如有需要请留言。
此案例可延伸为更丰富的压力测试,通过配置adb monkey 其他的参数。

关于android monkey 更多地使用自行脑补了。

利用android monkey 抢支付宝红包相关推荐

  1. Android通过辅助功能实现抢微信红包原理简单介绍

    简书文章:https://www.jianshu.com/p/e1099a94b979 附抢红包开源项目地址,代码已全改为Kotlin了,已适配到最新微信7.0.5版本,如果对你有所帮助赏个star吧 ...

  2. python发微信红包群二维码_小伙利用Python群发“支付宝”红包短信,一天赏金可达上千元...

    原标题:小伙利用Python群发"支付宝"红包短信,一天赏金可达上千元 注:以下教程仅供学习交流,娱乐而已,切勿用在非法途径 前言 最近朋友圈.微信群.QQ群里面全是什么扫码领取支 ...

  3. android集成支付宝红包功能.你想要的就在这里

    废话不说直接上干货! 先带你跑通支付宝demo 1.支付宝demo下载地址点击打开链接 2.有两个参数需要填写如下图(如果没有那么找申请支付业务的人要);其中RSA2_PRIVATE和RSA_PRIV ...

  4. python图片裁剪对比_Python自动抢视频红包,仅供学习!

    本文来源于公众号: AirPython 1 目 标 场 景 如今短视频横行的时代,以某短视频为首的,背后依靠着强大的资金后盾,疯狂地对平台用户进行红包轰炸. 与传统的红包不一样,视频红包包含位置的不确 ...

  5. 如果要用运营的姿势,发支付宝红包

    作者:柳不浪 全文共 4365 字 1 图,阅读需要 10 分钟 ---- / BEGIN / ---- 本文仅从用户个体的角度,来聊聊至今不绝于微信群的吱口令红包. 邀请朋友领红包,当TA到店付款后 ...

  6. python抢红包脚本_Python自动抢视频红包,仅供学习!

    本文来源于公众号: AirPyt hon 1 目 标 场 景 如今短视频横行的时代,以某短视频为首的,背后依靠着强大的资金后盾,疯狂地对平台用户进行红包轰炸. 与传统的红包不一样,视频红包包含位置的不 ...

  7. 吐槽支付宝红包:逼公鸡下蛋的后果

    摘要 : 虽然对支付宝红包会坑爹有所准备,但没有想到,结果会是从妙龄少女变为绝经大妈一样大. 支付宝决定在春节发红包那一刻,相信很多人心里就已经认定,没有社交属性的支付宝,在此次的红包大战中很可能会遭 ...

  8. python实时抢网页红包_Python实现自动抢红包功能

    目 标 场 景 可能有人每天都忙碌于各类微信群中,专注抢红包.那是否可以利用 Python 实现自动抢红包呢? image 当然在学习Python的道路上肯定会困难,没有好的学习资料,怎么去学习呢? ...

  9. 安卓支付宝红包密码的图片的处理实践_图文

    有一天,群里面有一个群员发来一个图片,图片上面有支付宝红包的密码,于是我就想能不能做成类似于抢QQ红包一样的东西,经过几天的实践,思路如下: 1.      监听QQ群或者微信群里的图片红包消息(使用 ...

  10. python模拟春节集五福_用Python分析支付宝红包和2018年集五福活动,你准备好了吗?...

    想必各位对于支付宝"集五福"活动一定都有深入的了解,从2016年开始,中国网友们关于过年的记忆再次更新,除了看春晚,年夜饭以外,集"五福"突然成了一个全家参与的 ...

最新文章

  1. iOS-UIButton防止重复点击(三种办法)
  2. SetGet and MACRO
  3. 图像柔光效果(SoftGlow)的原理及其实现。
  4. php如何给进入网页加入密码,怎么给一个PHP密码访问页面加超链接
  5. 死锁产生的原因及四个必要条件
  6. what is the thing you fear most?
  7. Tornado 使用手册(一)---------- 简单的tornado配置
  8. Flume:使用Apache Flume收集客户产品搜索点击数据
  9. 【Flink】Flink Container exited with a non-zero exit code 143
  10. C++的三种交换数值的方式(值传递、地址传递、引用传递)
  11. 觉得清楚,跟说清楚写清楚,两回事
  12. 2022年05月系统集成项目管理工程师考试知识点分布
  13. 通达OA任意用户登录漏洞手工复现
  14. 一副眼镜一千多贵吗_眼镜片的价格差距为什么那么大
  15. TP99 TP999
  16. 致敬!向中外9名杰出女数学家
  17. 整合策划和跨界活动的方法
  18. 数字图像处理习题(一)
  19. 开发一款系统软件的流程步骤是什么
  20. 【密码学】DES加解密原理及其Java实现算法

热门文章

  1. 大数据战略能不能打造第二个百度?
  2. BEEF的搭建与使用
  3. android studio Statistic插件不显示
  4. 【转ITAA上justdoit的一篇帖子】 验证OSPF中对外部路由路由的选择规则【留档】
  5. hr面试性格测试30题_HR经典面试30题
  6. SpringBoot集成EasyExcel的使用
  7. 雨天的尾巴——LCA+树上差分+动态开点+线段树合并
  8. ESP-MESH 无线组网,让智能家居通信组网更方便 | ESP32轻松学(Arduino版)
  9. python中类名(..)(..)的情况及_call_函数解析
  10. 基于jsp+mysql+Spring+mybatis java的SSM健身房管理系统