简单实现了微信自己主动抢红包的服务,原理就是依据keyword找到对应的View, 然后自己主动点击。主要是用到AccessibilityService这个辅助服务,基本能够满足自己主动抢红包的功能,可是有些逻辑须要优化,比方,拆完一个红包后,必须手动点击返回键,才干进行下一次自己主动抢红包。

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jackie.webchatenvelope" > <application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <service
android:enabled="true"
android:exported="true"
android:label="@string/app_name"
android:name=".EnvelopeService"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService"/>
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/envelope_service_config"/>
</service>
</application> </manifest>

envelope_service_config.xml

<?

xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeNotificationStateChanged|typeWindowStateChanged"
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags=""
android:canRetrieveWindowContent="true"
android:description="@string/accessibility_description"
android:notificationTimeout="100"
android:packageNames="com.tencent.mm" />

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"> <Button
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_centerInParent="true"
android:textSize="18sp"
android:text="打开辅助服务"/> </RelativeLayout>

MainActivity.java

package com.jackie.webchatenvelope;  

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast; public class MainActivity extends Activity {
private Button startBtn; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); startBtn = (Button) findViewById(R.id.start);
startBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
//打开系统设置中辅助功能
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivity(intent);
Toast.makeText(MainActivity.this, "找到抢红包,然后开启服务就可以", Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId(); //noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} return super.onOptionsItemSelected(item);
}
}

EnvelopeService.java

package com.jackie.webchatenvelope;

import android.accessibilityservice.AccessibilityService;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.PendingIntent;
import android.os.Build;
import android.os.Handler;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Toast; import java.util.List; /**
* <p>Created by Administrator</p>
* <p/>
* 抢红包外挂服务
*/
public class EnvelopeService extends AccessibilityService { static final String TAG = "Jackie"; /**
* 微信的包名
*/
static final String WECHAT_PACKAGENAME = "com.tencent.mm";
/**
* 红包消息的keyword
*/
static final String ENVELOPE_TEXT_KEY = "[微信红包]"; Handler handler = new Handler(); @Override
public void onAccessibilityEvent(AccessibilityEvent event) {
final int eventType = event.getEventType(); Log.d(TAG, "事件---->" + event); //通知栏事件
if (eventType == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) {
List<CharSequence> texts = event.getText();
if (!texts.isEmpty()) {
for (CharSequence t : texts) {
String text = String.valueOf(t);
if (text.contains(ENVELOPE_TEXT_KEY)) {
openNotification(event);
break;
}
}
}
} else if (eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
openEnvelope(event);
}
} /*@Override
protected boolean onKeyEvent(KeyEvent event) {
//return super.onKeyEvent(event);
return true;
}*/ @Override
public void onInterrupt() {
Toast.makeText(this, "中断抢红包服务", Toast.LENGTH_SHORT).show();
} @Override
protected void onServiceConnected() {
super.onServiceConnected();
Toast.makeText(this, "连接抢红包服务", Toast.LENGTH_SHORT).show();
} private void sendNotificationEvent() {
AccessibilityManager manager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);
if (!manager.isEnabled()) {
return;
}
AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
event.setPackageName(WECHAT_PACKAGENAME);
event.setClassName(Notification.class.getName());
CharSequence tickerText = ENVELOPE_TEXT_KEY;
event.getText().add(tickerText);
manager.sendAccessibilityEvent(event);
} /**
* 打开通知栏消息
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void openNotification(AccessibilityEvent event) {
if (event.getParcelableData() == null || !(event.getParcelableData() instanceof Notification)) {
return;
}
//下面是精华,将微信的通知栏消息打开
Notification notification = (Notification) event.getParcelableData();
PendingIntent pendingIntent = notification.contentIntent;
try {
pendingIntent.send();
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
} @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void openEnvelope(AccessibilityEvent event) {
if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyReceiveUI".equals(event.getClassName())) {
//点中了红包,下一步就是去拆红包
checkKey1();
} else if ("com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyDetailUI".equals(event.getClassName())) {
//拆完红包后看具体的纪录界面
//nonething
} else if ("com.tencent.mm.ui.LauncherUI".equals(event.getClassName())) {
//在聊天界面,去点中红包
checkKey2();
}
} @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void checkKey1() {
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
if (nodeInfo == null) {
Log.w(TAG, "rootWindow为空");
return;
}
List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText("拆红包");
for (AccessibilityNodeInfo n : list) {
n.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
} @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void checkKey2() {
AccessibilityNodeInfo nodeInfo = getRootInActiveWindow();
if (nodeInfo == null) {
Log.w(TAG, "rootWindow为空");
return;
}
List<AccessibilityNodeInfo> list = nodeInfo.findAccessibilityNodeInfosByText("领取红包");
if (list.isEmpty()) {
list = nodeInfo.findAccessibilityNodeInfosByText(ENVELOPE_TEXT_KEY);
for (AccessibilityNodeInfo n : list) {
Log.i(TAG, "-->微信红包:" + n);
n.performAction(AccessibilityNodeInfo.ACTION_CLICK);
break;
}
} else {
//最新的红包领起
for (int i = list.size() - 1; i >= 0; i--) {
AccessibilityNodeInfo parent = list.get(i).getParent();
Log.i(TAG, "-->领取红包:" + parent);
if (parent != null) {
parent.performAction(AccessibilityNodeInfo.ACTION_CLICK);
break;
}
}
}
}
}

Android实现微信自己主动抢红包的程序的更多相关文章

  1. 一步一步实现iOS微信自己主动抢红包(非越狱)

    前言:近期笔者在研究iOS逆向project,顺便拿微信来练手,在非越狱手机上实现了微信自己主动抢红包的功能. 题外话:此教程是一篇严肃的学术探讨类文章,只用于学习研究,也请读者不要用于商业或其它非法 ...

  2. 使用AccessibilityService实现微信自己主动抢红包

    近期要实现微信自己主动抢红包的功能.使用AccessibilityService来开发,这里主要写一下逻辑以及注意点. 注意点 1.搜索keyword 我们实现某个功能比方点击等须要找到相应的对象然后 ...

  3. android widget 开发实例 : 桌面便签程序的实现具体解释和源代码 (上)

    如有错漏请不吝拍砖指正,转载请注明出处,很感谢 桌面便签软件是android上经常使用软件的一种,比方比較早的Sticky Note,就曾很流行, Sticky Note的介绍能够參见 http:// ...

  4. 【转】手把手教你读取Android版微信和手Q的聊天记录(仅作技术研究学习)

    1.引言 特别说明:本文内容仅用于即时通讯技术研究和学习之用,请勿用于非法用途.如本文内容有不妥之处,请联系JackJiang进行处理!   我司有关部门为了获取黑产群的动态,有同事潜伏在大量的黑产群 ...

  5. 微信团队分享:Kotlin渐被认可,Android版微信的技术尝鲜之旅

    本文由微信开发团队工程是由“oneliang”原创发表于WeMobileDev公众号,内容稍有改动. 1.引言   Kotlin 是一个用于现代多平台应用的静态编程语言,由 JetBrains 开发( ...

  6. 手把手教你读取Android版微信和手Q的聊天记录(仅作技术研究学习)

    1.引言 特别说明:本文内容仅用于即时通讯技术研究和学习之用,请勿用于非法用途.如本文内容有不妥之处,请联系JackJiang进行处理!   我司有关部门为了获取黑产群的动态,有同事潜伏在大量的黑产群 ...

  7. 用Kotlin破解Android版微信小游戏-跳一跳

    前言 微信又更新了,从更新日志上来看,似乎只是一次不痛不痒的小更新.不过,很快就有人发现,原来微信这次搞了个大动作——在小程序里加入了小游戏.今天也是朋友圈被刷爆的缘故. 看到网上 有人弄了一个破解版 ...

  8. 微信正式开放内测“小程序”,不开发APP的日子真的来了?

    关注,QQ群,微信应用号社区 511389428 微信正式开放内测“小程序”,不开发APP的日子真的来了? 明星公司 缪定纯 • 2016-09-22 09:05 讨论了很久的微信应用号终于来了,不过 ...

  9. Android版-微信APP支付

    首发地址: Android版-微信APP支付 欢迎留言.转发 微信极速开发系列文章(微信支付.授权获取用户信息等):点击这里 目录 1.注册账号.开发者认证 2.添加应用 3.申请微信支付 4.技术开 ...

随机推荐

  1. Java并发包之闭锁/栅栏/信号量(转)

    本文转自http://blog.csdn.net/u010942020/article/details/79352560 感谢作者 一.Java多线程总结: 描述线程的类:Runable和Thread ...

  2. hive删除列

    hive中删除列时没有与mysql语句alter table <table> drop column <col>对应的语句. 然而依然可以完成此功能:使用ALTER TABLE ...

  3. Nokitjs 系列-01 - HelloWorld

    一.前言 本篇文章需要读者有一点 Node.js 基础的了解,并且已经安装了 Node.js (node.npm),但并不需要有 Nokit 的知识,本文将简单介绍 Nokitjs 的安装使用,并编写 ...

  4. Openshift中Configmap的使用

    先基于外部镜像构建一个deployment ericdeMacBook-Pro:nginx ericnie$ oc --allow-missing-images --name=nginx-demo - ...

  5. 判断客户端是PC还是手持设备的JS代码【转】

    1.第一种: 复制代码代码如下: function IsPC() {    var userAgentInfo = navigator.userAgent;    var Agents = [&quo ...

  6. Android(Fragment和Activity之间通信)

    Fragment的使用可以让我们的应用更灵活的适配各种型号的安卓设备,但是对于Fragment和Activity之间的通信,很多朋友应该比较陌生,下面我们就通过一个实例来看一看如何实现. 一.Acti ...

  7. jQuery对象的序列化详解

    一.param() 方法创建数组或对象的序列化表示. 该序列化值可在进行 AJAX 请求时在 URL 查询字符串中使用. 语法: jQuery.param(object,traditional) ob ...

  8. phantomjs 无法打开https网站解决方案

    最近测试原来的爬虫程序,发现phantomjs 无法打开https网站了,经过网上查下,发现需要在phantomjs定义的加以下参数 self.driver = webdriver.PhantomJS ...

  9. 《深入理解Java虚拟机》笔记4

    垃圾回收器是垃圾回收算法的实现,Java虚拟机的设计者为了 获取最大的性价比,也在不断改进中.硬件在不断变化,多核 的普及,基于单核的收集器应该已经没有太大意义了.Java7中 又新增了g1收集器,没 ...

  10. SSMybatis整合(二) -- 加入SpringMVC进行多表级联操作

    ---上节课我们讲了Mybatis的单表增删改查,关于代码我注释的比较详细,我相信初学的小伙伴还是多少能有一些收获的. - 第一集传送门:http://blog.csdn.net/jacxuan/ar ...