The specific Java implementation code assisted by WeChat jump is for your reference. The specific content is as follows
1. Refer to Zhihu to teach you how to use Python to play WeChat. Given that I have always been a half-baked Python, I planned to use Python to score points before, but I had no choice but to install the Python environment and various modules were missing and reported errors. So I re-implemented it using Java.
2. Environment configuration and related instructions:
1) Windows system, I am win10
2) Install AVA environment, JDK7 or above
3) One Android phone, one data cable
4) Install the ADB driver for the computer, connect to the Android phone, and turn on USB debugging mode at the same time
5) Open the WeChat mini program's jump game, the JAVA program starts running, and read the specific code below
6) I use Meilan note2 Android phone, with a screen resolution of 1920x1080. Different models of mobile phones may need to adjust relevant parameters. Please refer to the code comments for details.
7) Added the function of automatically restarting the game after failing to score points
8) It’s just entertainment, don’t be serious. It is said that WeChat official has paid attention to it. If the score is too high, it may be cleared. Haha
3. Without further ado, please add the code:
package com.yihusitian.gamehelper; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.concurrent.TimeUnit; import javax.imageio.ImageIO; /** * Reference Zhihu* * @link <a href="https://zhuanlan.zhihu.com/p/32452473" rel="external nofollow" rel="external nofollow" target="_blank">https://zhuanlan.zhihu.com/p/32452473</a> * * Jump assist* * @author LeeHo */ public class JumpJumpHelper { private static final String IMAGE_NAME = "current.png"; private static final String STORE_DIR = "d:/jump_screencapture"; //Quantity private static final int imageLengthLength = 5; //Size of the image storage private static final long[] imageLength = new long[imageLengthLength]; private final RGBInfo rgbInfo = new RGBInfo(); private final String[] ADB_SCREEN_CAPTURE_CMDS = { "adb shell screencap -p /sdcard/" + IMAGE_NAME, "adb pull /sdcard/current.png " + STORE_DIR }; //The Y coordinate at the bottom of the game score display area in the screenshot, 300 is the value of 1920x1080. Modify private final int gameScoreBottomY = 300 according to the actual situation; //The press time coefficient can be appropriately adjusted according to the specific situation; private final double pressTimeCoefficient = 1.35; //The starting point coordinate of the press is also the starting point coordinate of the next game private final int swipeX = 550; private final int swipeY = 1580; //The base height of the chess piece is private final int halfBaseBoardHeight = 20; //The width of the chess piece is taken from the screenshot and adjust the private final int by yourself halmaBodyWidth = 74; //The midpoint coordinates of the two springboards in the game screenshot are mainly used to calculate the angle. The proportion of XY can be calculated based on the actual screenshot. Private final int boardX1 = 813; private final int boardY1 = 1122; private final int boardX2 = 310; private final int boardY2 = 813; /** * Get the checkers and the center coordinates of the next springboard* * @return * @author LeeHo * @throws IOException * @update December 31, 2017 at 12:18:22 pm */ private int[] getHalmaAndBoardXYValue(File currentImage) throws IOException { BufferedImage bufferedImage = ImageIO.read(currentImage); int width = bufferedImage.getWidth(); int height = bufferedImage.getHeight(); System.out.println("Width: " + width + ", height: " + height); int halmaXSum = 0; int halmaXCount = 0; int halmaYMax = 0; int boardX = 0; int boardY = 0; //Transfer the pixel points from the screenshot from top to bottom, and use the color of the chess piece as the basis for position recognition. Finally, the average value of all pixels on the lowest row of the chess piece color is taken out, that is, calculate the coordinates of the chess piece for (int y = gameScoreBottomY; y < height; y++) { for (int x = 0; x < width; x++) { processRGBInfo(bufferedImage, x, y); int rValue = this.rgbInfo.getRValue(); int gValue = this.rgbInfo.getGValue(); int bValue = this.rgbInfo.getBValue(); //Identify the position of the chess piece according to the color of RGB, if (rValue > 50 && rValue < 60 && gValue > 53 && gValue < 63 && bValue > 95 && bValue < 110) { halmaXSum += x; halmaXCount++; //Y coordinate value of the bottom row of the chess piece halmaYMax = y > halmaYMax ? y : halmaYMax; } } } if (halmaXSum != 0 && halmaXCount != 0) { //X coordinate value of the bottom row of the chess piece int halmaX = halmaXSum / halmaXCount; //Move half of the chess piece chassis height up int halmaY = halmaYMax - halfBaseBoardHeight; //Start from gameScoreBottomY for (int y = gameScoreBottomY; y < height; y++) { processRGBInfo(bufferedImage, 0, y); int lastPixelR = this.rgbInfo.getRValue(); int lastPixelG = this.rgbInfo.getGValue(); int lastPixelB = this.rgbInfo.getBValue(); //As long as the calculated boardX value is greater than 0, it means that the center coordinate X value of the next springboard has been obtained. if (boardX > 0) { break; } int boardXSum = 0; int boardXCount = 0; for (int x = 0; x < width; x++) { processRGBInfo(bufferedImage, x, y); int pixelR = this.rgbInfo.getRValue(); int pixelG = this.rgbInfo.getGValue(); int pixelB = this.rgbInfo.getBValue(); //Train the case where the head of the chess piece is higher than the next springboard if (Math.abs(x - halmaX) < halmaBodyWidth) { continue; } //Scan from top to bottom to the vertex position of the next springboard. The next springboard may be a circle or a box. Take multiple points and find the average if ((Math.abs(pixelR - lastPixelR) + Math.abs(pixelG - lastPixelG) + Math.abs(pixelB - lastPixelB)) > 10) { boardXSum += x; boardXCount++; } } if (boardXSum > 0) { boardX = boardXSum / boardXCount; } } //From the actual angle, find the coordinates close to the center of the next board. boardY = (int) (halmaY - Math.abs(boardX - halmaX) * Math.abs(boardY1 - boardY2) / Math.abs(boardX1 - boardX2)); if (boardX > 0 && boardY > 0) { int[] result = new int[4]; //The X coordinate result[0] = halmaX; //The Y coordinate result[1] = halmaY; //The X coordinate result[2] = boardX; //The Y coordinate result[3] = boardY; return result; } } return null; } /** * Execute the command* * @param command * @author LeeHo * @update December 31, 2017 at 12:13:39 pm */ private void executeCommand(String command) { Process process = null; try { process = Runtime.getRuntime().exec(command); System.out.println("exec command start: " + command); process.waitFor(); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream())); String line = bufferedReader.readLine(); if (line != null) { System.out.println(line); } System.out.println("exec command end: " + command); } catch (Exception e) { e.printStackTrace(); } finally { if (process != null) { process.destroy(); } } } /** * ADB gets Android screenshots* * @author LeeHo * @update December 31, 2017 at 12:11:42 pm */ private void executeADBCaptureCommands() { for (String command : ADB_SCREEN_CAPTURE_CMDS) { executeCommand(command); } } /** * Jump* * @param distance * @author LeeHo * @update December 31, 2017 at 12:23:19 pm */ private void doJump(double distance) { System.out.println("distance: " + distance); // Calculate the press time, minimum 200ms int pressTime = (int) Math.max(distance * pressTimeCoefficient, 200); System.out.println("pressTime: " + pressTime); //Execute the press operation String command = String.format("adb shell input swipe %s %s %s %s %s", swipeX, swipeY, swipeX, swipeY, pressTime); System.out.println(command); executeCommand(command); } /** * Another game* * @author LeeHo * @update December 31, 2017 at 12:47:06 pm */ private void replayGame() { String command = String.format("adb shell input tap %s %s", swipeX, swipeY); executeCommand(command); } /** * Calculate the distance of the jump, that is, the distance between two points* * @param halmaX * @param halmaY * @param boardX * @param boardY * @return * @author LeeHo * @update December 31, 2017 at 12:27:30 pm */ private double computeJumpDistance(int halmaX, int halmaY, int boardX, int boardY) { return Math.sqrt(Math.pow(Math.abs(boardX - halmaX), 2) + Math.pow(Math.abs(boardY - halmaY), 2)); } public static void main(String[] args) { try { File storeDir = new File(STORE_DIR); if (!storeDir.exists()) { boolean flag = storeDir.mkdir(); if (!flag) { System.err.println("Create image storage directory failed"); return; } } JumpJumpHelper jumpjumpHelper = new JumpJumpHelper(); //Number of executions int executeCount = 0; for (;;) { //Execute ADB command to get Android screenshot jumpjumpHelper.executeADBCaptureCommands(); File currentImage = new File(STORE_DIR, IMAGE_NAME); if (!currentImage.exists()) { System.out.println("The picture does not exist"); continue; } long length = currentImage.length(); imageLength[executeCount % imageLengthLength] = length; // Check whether you need to reopen jumpjumpHelper.checkDoReplay(); executeCount++; System.out.println("currentthrow" + executeCount + "execution!"); // Get the center coordinates of checkers and base plate int[] result = jumpjumpHelper.getHalmaAndBoardXYValue(currentImage); if (result == null) { System.out.println("The result of method getHalmaAndBoardXYValue is null!"); continue; } int halmaX = result[0]; int halmaY = result[1]; int boardX = result[2]; int boardY = result[3]; System.out.println("halmaX: " + halmaX + ", halmaY: " + halmaY + ", boardX: " + boardX + ", boardY: " + boardY); //calculate the distance of the jump double jumpDistance = jumpjumpHelper.computeJumpDistance(halmaX, halmaY, boardX, boardY); jumpjumpHelper.doJump(jumpDistance); //Stay for 2.5 seconds each time TimeUnit.MILLISECONDS.sleep(2500); } } catch (Exception e) { e.printStackTrace(); } } /** * Check whether you need to restart* * @author LeeHo * @update December 31, 2017 1:39:18 pm */ private void checkDoReplay() { if (imageLength[0] > 0 && imageLength[0] == imageLength[1] && imageLength[1] == imageLength[2] && imageLength[2] == imageLength[2] == imageLength[2] imageLength[3] && imageLength[3] == imageLength[4]) { //This means that the image size has been the same for 5 consecutive times. You can know that the current screen is in another game Arrays.fill(imageLength, 0); //Simulate and click the button to start the game replayGame(); } } /** * Get the RGB value of the specified coordinates* * @param bufferedImage * @param x * @param y * @author LeeHo * @update December 31, 2017 at 12:12:43 pm */ private void processRGBInfo(BufferedImage bufferedImage, int x, int y) { this.rgbInfo.reset(); int pixel = bufferedImage.getRGB(x, y); //Convert to RGB number this.rgbInfo.setRValue((pixel & 0xff0000) >> 16); this.rgbInfo.setGValue((pixel & 0xff00) >> 8); this.rgbInfo.setBValue((pixel & 0xff)); } class RGBInfo { private int RValue; private int GValue; private int BValue; public int getRValue() { return RValue; } public void setRValue(int rValue) { RValue = rValue; } public int getGValue() { return GValue; } public void setGValue(int gValue) { GValue = gValue; } public int getBValue() { return BValue; } public void setBValue(int bValue) { BValue = bValue; } public void reset() { this.RValue = 0; this.GValue = 0; this.BValue = 0; } } }For more content, you can refer to the special topic "Jump on WeChat" to learn.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.