Browse Source

新增直播间弹幕转粉功能

master
b504165808 3 years ago
parent
commit
7846c2ce62
  1. 40
      app/src/main/java/com/example/myapplication/MainActivity.java
  2. 5
      app/src/main/java/com/example/myapplication/Tools/Common.java
  3. 39
      app/src/main/java/com/example/myapplication/Tools/DyUtils.java
  4. 43
      app/src/main/java/com/example/myapplication/autoCtrlers/autoTkScriptServer.java

40
app/src/main/java/com/example/myapplication/MainActivity.java

@ -18,7 +18,10 @@ import android.widget.Toast;
import com.example.myapplication.autoCtrlers.autoTkScriptServer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends Activity {
@ -38,8 +41,11 @@ public class MainActivity extends Activity {
public String videoId = "7063085154138459424";
// 私信内容从后台获取
String msgContext = "文字,此信息由“抖音涨粉宝app”发送。下载:http://www.szctyx.com/?from_id=123456";
// 初始化直播间任务列表 存放user_id和room_id
public List<Map<String, String>> liveRoomMissionList = new ArrayList<Map<String, String>>();
// 是否开启直播弹幕任务 方便调试
public boolean startLiveMission = true;
// 私信所需短视频链接,拼接得来
String videoUrl = "snssdk1128://aweme/detail/".concat(videoId);
private boolean checkAppInstalled(Context context, String pkgName) {
@ -97,13 +103,13 @@ public class MainActivity extends Activity {
if (b) {
Intent intent = new Intent();
// 传入用户个人主页
//snssdk1128://webview?url=https%3A%2F%2Fhaohuo.jinritemai.com%2Fviews%2Fproduct%2Fitem2%3Fid%3D3478598732738653081 打开商品详情页
//snssdk1128://webview?url=https%3A%2F%2Fhaohuo.jinritemai.com%2Fviews%2Fproduct%2Fitem2%3Fid%3D 打开商品详情页
if(focusMissionList.length>0){
Integer temp_index = 0;
String [] msgContentList = {};
for(String userId: focusMissionList){
// 传入用户个人主页
intent.setData(Uri.parse("snssdk1128://user/profile/" + userId));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Thread.sleep(5000);
@ -147,7 +153,33 @@ public class MainActivity extends Activity {
}
}
}
if(startLiveMission){
Integer temp_index = 0;
boolean isSuccessed = false;
String [] saySomthingWordsList = {"太值了吧", "爱了爱了", "这件衣服还有货吗?我要买三件!", "这家店的衣服还可以,我朋友的孩子穿好看!"};
// snssdk1128://live?room_id={undefined{room_id}}&user_id={undefined{user_id}}&u_code={undefined{u_code}}&from=webview&refer=web
// 将直播间任务数据赋值到map数组
Map<String, String> map = new HashMap<String, String>();
map.put("userId", "1987550452917454");
map.put("roomId", "7072542761229716231");
liveRoomMissionList.add(map);
map = new HashMap<String, String>();
map.put("userId", "78913505358");
map.put("roomId", "7072628504071883534");
liveRoomMissionList.add(map);
for (Map roomInfo: liveRoomMissionList){
intent.setData(Uri.parse(String.format("snssdk1128://live?room_id=%s&user_id=%s&from=webview&refer=web", roomInfo.get("roomId"), roomInfo.get("userId"))));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
isSuccessed = autoTkScriptServer.startMission(intent, saySomthingWordsList,4);
temp_index += 1;
if(temp_index< autoPrivateMsgList.length&&isSuccessed){
Log.d("myapp", String.format("第%d个直播间弹幕及转粉任务完成!", temp_index));
}
}
}
} else {
Toast.makeText(MainActivity.this, "您未安装最新版抖音,请安装后再启动噢!", Toast.LENGTH_SHORT).show();

5
app/src/main/java/com/example/myapplication/Tools/Common.java

@ -14,5 +14,8 @@ public class Common {
public static final String SEND_MSG_BOX_ID = "com.ss.android.ugc.aweme:id/ij=";
public static final String SHOW_SEND_MSG_BOX_CLASS = "android.widget.ImageView";
// public static final String = "";
public static final String VIDEO_SELECT_BUTTON_VIEW_CLASS = "com.bytedance.ies.dmt.ui.widget.DmtTextView";
public static final String LIVE_SEND_MSG_BOX_ID = "com.ss.android.ugc.aweme:id/ddg";
public static final String LIVE_SEND_BTN_ID = "com.ss.android.ugc.aweme:id/ll6";
public static final String LIVE_USER_INFO_BTN_ID = "com.ss.android.ugc.aweme:id/t5";
public static final String VIDEO_SELECT_BUTTON_VIEW_CLASS = "com.bytedance.ies.dmt.ui.widget.DmtTextView";
}

39
app/src/main/java/com/example/myapplication/Tools/DyUtils.java

@ -643,6 +643,45 @@ public class DyUtils {
e.printStackTrace();
}
}
public static AccessibilityNodeInfo findNodeLiveSendBox(AccessibilityService accessibilityService, String str) {
AccessibilityNodeInfo root = accessibilityService.getRootInActiveWindow();
if(root!=null){
AccessibilityNodeInfo node = root.findAccessibilityNodeInfosByText("说点什么...").get(0).getParent();
node = node.getChild(0).getChild(0);
return node;
}else{
return null;
}
}
public static boolean clickLiveFocusBtn(AccessibilityService accessibilityService, String str) {
AccessibilityNodeInfo root = accessibilityService.getRootInActiveWindow();
if(root!=null){
Log.d("myapp", "找到的关注控件个数"+root.findAccessibilityNodeInfosByText("关注").size());
for(AccessibilityNodeInfo node:root.findAccessibilityNodeInfosByText("关注")){
String parttenStr = ".*text: "+"关注"+";.*";
boolean isMatch = Pattern.matches(parttenStr, node.toString());
if(isMatch){
Log.d("myapp", node.toString());
node = node.getParent().getParent().getParent();
Log.d("myapp父控件信息", node.toString());
Log.d("myapp", "父类名:"+node.getClassName().toString()+" 目标类名:"+str);
Log.d("myapp是否相同:", Boolean.toString(node.getClassName().toString().equals(str)));
if(node.getClassName().toString().equals(str)){
Log.d("myapp", "找到了目标关注控件,正在点击");
performClick(node);
return true;
}
}
}
}
return false;
}
public void recycle(AccessibilityNodeInfo info) {
if (info.getChildCount() == 0) {
Log.i(TAG, "child widget----------------------------" + info.getClassName());

43
app/src/main/java/com/example/myapplication/autoCtrlers/autoTkScriptServer.java

@ -42,7 +42,7 @@ public class autoTkScriptServer extends AccessibilityService {
String eventText = "";
switch (eventType) {
case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
Log.d("myapp","屏幕内容变化");
break;
case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
@ -109,10 +109,51 @@ public class autoTkScriptServer extends AccessibilityService {
execResult = tkScriptService.startPrivateMsgMission(intent, msgContent[1]);
}else if(startMode == 3){
execResult = tkScriptService.startDoLikeVideoMission(intent);
}else if(startMode == 4){
execResult = tkScriptService.startLiveWordsMission(intent, msgContent);
}
return execResult;
}
private boolean startLiveWordsMission(Intent intent, String [] msgContent) throws InterruptedException{
boolean execResult = false;
Log.d("myapp","--------------正在执行直播间弹幕转粉任务------------------");
try{
DyUtils.startAcessActity((AccessibilityService) this, intent);
Thread.sleep(22000);
for(int sendTimes = 0; sendTimes < 2; sendTimes++){
DyUtils.findViewTextAndClick((AccessibilityService) this, "说点什么...",0);
Thread.sleep(4000);
AccessibilityNodeInfo node = DyUtils.findNodeLiveSendBox((AccessibilityService) this,"android.widget.EditText");
if(node!=null){
Log.d("myapp","找到发送按钮");
String msg = msgContent[(int) (Math.random() * msgContent.length)];
execResult = DyUtils.putTextOnMsgBox((AccessibilityService) this, node,msg);
if(execResult){
Thread.sleep(3000);
execResult = DyUtils.findViewIdAndClick((AccessibilityService) this, Common.LIVE_SEND_BTN_ID);
}
Thread.sleep(7000);
}
}
if(execResult){
Log.d("myapp","开始点击主播信息,进行关注动作");
Thread.sleep(3000);
execResult = DyUtils.findViewIdAndClick((AccessibilityService) this, Common.LIVE_USER_INFO_BTN_ID);
Thread.sleep(7000);
execResult = DyUtils.clickLiveFocusBtn((AccessibilityService) this, "android.widget.FrameLayout");
Thread.sleep(3000);
return true;
}
}catch (Exception e){
e.printStackTrace();
}
return false;
}
private boolean startFocusMission(Intent intent) throws InterruptedException {
boolean execResult = false;

Loading…
Cancel
Save