@Karlatemp
/**
* 处理滑动验证码.
* 返回 null 以表示无法处理验证码, 将会刷新验证码或重试登录. 抛出一个 LoginFailedException 以正常地终止登录, 抛出任意其他 Exception 将视为异常终止
* Returns:
* 验证码解决成功后获得的 ticket.
*/
@SneakyThrows
@Override
public Object onSolveSliderCaptcha(@NotNull Bot bot, @NotNull String s, @NotNull Continuation<? super String> continuation) {
return SliderCaptchaWindows.instance(s).assembly().show(true);
}
/**
* 滑块验证码处理窗口
*
* @author LiaoJianbo
* @version 1.0.0
* @CreateTime: 2022-06-27 11:23
* @since 1.0.0
*/
@Data
@Accessors(chain = true)
public class SliderCaptchaWindows {
/**
* 窗体容器
*/
public Container contentPane;
/**
* 窗口
*/
private JFrame windows;
/**
* 滑块链接
*/
private String url;
/**
* 滑块结果
*/
private String ticket;
/**
* 单击结果
*/
private Boolean isClick = false;
private SliderCaptchaWindows() {
}
/**
* 获取实例
*
* @param url 滑块年纪额
* @return 当前对象
*/
public static SliderCaptchaWindows instance(String url) {
JFrame windows = new JFrame("滑块处理");
SliderCaptchaWindows sliderCaptchaWindows = new SliderCaptchaWindows()
.setWindows(windows).setContentPane(windows.getContentPane())
.setUrl(url);
windows.setSize(1000, 160);
windows.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
windows.setLayout(null);
windows.setResizable(false);
return sliderCaptchaWindows;
}
public static void main(String[] args) {
System.out.println(SliderCaptchaWindows.instance("www.baidu.com").assembly().show(true).ticket());
}
/**
* 窗口状态
*
* @param visible true开启,false关闭
*/
public SliderCaptchaWindows show(boolean visible) {
windows.setVisible(visible);
return this;
}
public SliderCaptchaWindows assembly() {
// 标签
JLabel tis = new JLabel("复制’滑块‘到浏览器,按F12打开控制台,电子network->HXR,拖动滑块,查看响应,复制ticket到ticket");
contentPane.add(tis);
tis.setBounds(5, 5, 1000, 20);
// url
JLabel urllabel = new JLabel("滑块");
contentPane.add(urllabel);
urllabel.setBounds(5, 30, 30, 20);
JTextField jTextField = new JTextField(this.url);
contentPane.add(jTextField);
jTextField.setBounds(40, 30, 950, 20);
// ticket
JLabel ticketlabel = new JLabel("ticket");
contentPane.add(ticketlabel);
ticketlabel.setBounds(5, 60, 30, 20);
JTextField ticketField = new JTextField();
contentPane.add(ticketField);
ticketField.setBounds(40, 60, 950, 20);
// 提交
JButton submit = new JButton("提交");
contentPane.add(submit);
submit.setBounds(450,85,60,30);
submit.addActionListener(listener -> {
setTicket(ticketField.getText().trim());
setIsClick(true);
this.show(false);
});
submit.doClick();
return this;
}
/**
* 获取滑块结果
* @return ticket
*/
public String ticket() {
while (!this.getIsClick()){
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
this.isClick = false;
return this.ticket;
}
}