preface
The odds of winning are hell, and it takes time to draw, so write a program to draw him hundreds of times in a second.
The effect
code
package com.hxl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import static java.awt.Image.SCALE_DEFAULT;
public class JueJin extends JFrame {
private Executor threadPoolExecutor = new ThreadPoolExecutor(5.5.5,
TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(500));
private JPanel imageUIPanel;
private OkHttpClient okHttpClient;
private String cookie;
public JueJin(a) throws HeadlessException {
initUI();
initHttp();
this.setSize(600.400);
this.setVisible(true);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
showCookieInputDialog();
}
private void initHttp(a) {
okHttpClient = new OkHttpClient();
}
private int getCurPoint(a) {
try {
Response response = okHttpClient.newCall(new Request.Builder()
.url("https://api.juejin.cn/growth_api/v1/get_cur_point")
.get()
.header("cookie".this.cookie)
.build()).execute();
Map map = JSON.parseObject(response.body().string(), Map.class);
return Integer.parseInt(map.get("data") + "");
} catch (IOException e) {
e.printStackTrace();
}
return 0;
}
private Runnable createRunnable(a) {
return() - > {try {
Response response = okHttpClient.newCall(new Request.Builder()
.url("https://api.juejin.cn/growth_api/v1/lottery/draw")
.header("cookie", cookie)
.post(RequestBody.create("{}", MediaType.parse("application/json")))
.build()).execute();
Result result = JSON.parseObject(response.body().string(), Result.class);
addImage(result.getData().getLotteryImage());
} catch(IOException e) { e.printStackTrace(); }}; }private void start(int count) {
for (int i = 0; i < count; i++) { threadPoolExecutor.execute(createRunnable()); }}private void showCookieInputDialog(a) {
new CookieInputDialog(cookie -> {
this.cookie = cookie;
int curPoint = getCurPoint();
start(curPoint / 200);
});
}
private void initUI(a) {
imageUIPanel = new JPanel();
imageUIPanel.setLayout(new GridLayout(0.4));
JScrollPane scrollbar = new JScrollPane(imageUIPanel);
getContentPane().add(scrollbar);
}
public static ImageIcon createImageIcon(Image image) {
Image scaledInstance = image.getScaledInstance(60.60, SCALE_DEFAULT);
return new ImageIcon(scaledInstance);
}
private void addImage(String imgUrl) {
Image image = null;
try {
image = Toolkit.getDefaultToolkit().getImage(new URL(imgUrl));
JLabel jLabel = new JLabel(createImageIcon(image));
imageUIPanel.add(jLabel);
imageUIPanel.revalidate();
} catch(MalformedURLException e) { e.printStackTrace(); }}public static void main(String[] args) {
newJueJin(); }}Copy the code
Cookie input dialog box
package com.hxl;
import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class CookieInputDialog extends JDialog {
private ICookieCallback iCookieCallback;
private JTextField jTextField;
public CookieInputDialog(ICookieCallback iCookieCallback) {
this.iCookieCallback = iCookieCallback;
setTitle("Cookie input");
setModalityType(ModalityType.APPLICATION_MODAL);
jTextField = new JTextField();
getContentPane().add(jTextField);
setSize(300.100);
init(jTextField);
setLocationRelativeTo(null);
setVisible(true);
}
private void init(JTextField field) {
field.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == 10) { close(); }}}); }private void close(a) {
iCookieCallback.onCookie(jTextField.getText());
dispose();
}
public interface ICookieCallback {
public void onCookie(String cookie); }}Copy the code
Result contains the Result of the lottery.
package com.hxl;
public class Result {
private Integer errNo;
private String errMsg;
private DataDTO data;
public Integer getErrNo(a) {
return errNo;
}
public void setErrNo(Integer errNo) {
this.errNo = errNo;
}
public String getErrMsg(a) {
return errMsg;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
public DataDTO getData(a) {
return data;
}
public void setData(DataDTO data) {
this.data = data;
}
public static class DataDTO {
private Integer id;
private String lotteryId;
private String lotteryName;
private Integer lotteryType;
private String lotteryImage;
private String historyId;
public Integer getId(a) {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getLotteryId(a) {
return lotteryId;
}
public void setLotteryId(String lotteryId) {
this.lotteryId = lotteryId;
}
public String getLotteryName(a) {
return lotteryName;
}
public void setLotteryName(String lotteryName) {
this.lotteryName = lotteryName;
}
public Integer getLotteryType(a) {
return lotteryType;
}
public void setLotteryType(Integer lotteryType) {
this.lotteryType = lotteryType;
}
public String getLotteryImage(a) {
return lotteryImage;
}
public void setLotteryImage(String lotteryImage) {
this.lotteryImage = lotteryImage;
}
public String getHistoryId(a) {
return historyId;
}
public void setHistoryId(String historyId) {
this.historyId = historyId; }}}Copy the code