微信群控系统制作系列一——java模拟登录网页版微信
PS:很多人咨询我怎么做手机群控系统,因此我开了个制作群控系统的系列,准备分五期讲解群控系统的制作。前两篇是基础内容。
今天做个简单的java模拟登录网页版微信。
既然要做模拟登录,那么我们一定要了解整个登录过程,我们这就来真实操作一遍:当我们登录网页版微信后会出现个扫码登录的窗口,我们扫码二维码成功后就跳转到登录成功页面并重定向到网页版微信。
那么我们的目标是做一个工具,当启动会帮我们调用微信的二维码接口,下载二维码图片,然后在后台展示二维码让我们扫码,扫码成功后跳转到网页版微信。
梳理后我们将进行下面的动作:
1 获取二维码
2 下载图片
3 弹出二维码扫码框
4 检查是否登录
5 登录网页版
请求的地址就直接贴出来了,需要的自行抓包(可以使用charles,fiddler,鲨鱼,浏览器F12)
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
/**
* @作者: LYB
* @创建日期: 2018/9/25
* @描述: 模拟登录网页版微信
*/
public class WeixinLogin {
//=====================================请求地址==========================================
static String WEIXIN_LOGIN_URL = "https://wx.qq.com/";//初始化请求地址
static String APID_URL = "https://login.wx.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN&_=";//获取appid请求地址
static String QRCODE_URL = "https://login.weixin.qq.com/qrcode/";//获取二维码地址
//=====================================请求地址==========================================
//=====================================变量存储==========================================
static CloseableHttpClient https = HttpClients.createDefault();
static String LOGIN_URL = "";
static String qrCodeUrl = "";
static String appid = "";
public static Boolean isScan = false;
//=====================================变量存储==========================================
//第一步:获取二维码完整地址
public static String getQrCodeURL() {
try {
//1 拿到登录页面
HttpGet httpGet = new HttpGet(WEIXIN_LOGIN_URL);
HttpResponse loginResp = https.execute(httpGet);
HttpEntity loginEntitySort = loginResp.getEntity();
String loginPage = EntityUtils.toString(loginEntitySort, "utf-8");
//2 获取appid 根据抓包可知道要拿到二维码需要先请求获取appid
String url = APID_URL + System.currentTimeMillis();
HttpGet httpPost = new HttpGet(url);
HttpResponse response = https.execute(httpPost);
HttpEntity entitySort = response.getEntity();
String html = EntityUtils.toString(entitySort, "utf-8");
//发送请求拿到的是串window.QRLogin.code = 200; window.QRLogin.uuid = 'XXX'的字符串,而xxx就是appid
if (html.indexOf("window.QRLogin.code = 200") != -1) {
appid = html.replace("window.QRLogin.code = 200; window.QRLogin.uuid = \"", "").replace("\";", "");
}
//3 获取二维码地址 获取二维码地址需要拼接appid后请求得到
String codeUrl = QRCODE_URL + appid;
HttpGet httpget = new HttpGet(codeUrl);
qrCodeUrl = httpget.getURI().toString();
System.out.println("获取到的二维码地址是:" + qrCodeUrl);//开始
return qrCodeUrl;
} catch (Exception e) {
return null;
}
}
//第二步:下载图片 拿到地址后下一步就是下载图片啦(其实可以不下载的,直接在Swing中展示),下载的代码就不说了,也懒得优化。
private static void downloadPicture(String imgURL, String path) {
URL url = null;
FileOutputStream fileOutputStream = null;
DataInputStream dataInputStream = null;
ByteArrayOutputStream output = null;
try {
url = new URL(imgURL);
dataInputStream = new DataInputStream(url.openStream());
fileOutputStream = new FileOutputStream(new File(path));
output = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = dataInputStream.read(buffer)) > 0) {
output.write(buffer, 0, length);
}
fileOutputStream.write(output.toByteArray());
dataInputStream.close();
fileOutputStream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {//千万记得关闭流
org.apache.commons.io.IOUtils.closeQuietly(fileOutputStream);
org.apache.commons.io.IOUtils.closeQuietly(dataInputStream);
org.apache.commons.io.IOUtils.closeQuietly(output);
}
}
//第三步:将二维码在后台展示
public static Boolean showQrCode() {
//为了后面main方便调用先将前面两步方法引入代码中
//第一步: 获取二维码地址
if(qrCodeUrl.equals("")){
qrCodeUrl = getQrCodeURL();
}
//第二步: 下载二维码图片
String downLoadHere = "C:\\Users\\abc\\Desktop\\qrCode.png";
downloadPicture(qrCodeUrl, downLoadHere);
//第三步开始
//1 配置后台二维码展示窗口
final JFrame frame = new JFrame("请扫描二维码完成登录");
//设置frame窗口
frame.setSize(550, 550);
frame.setLocation(580, 200);
frame.setLayout(null);
JLabel label = new JLabel();
//2 根据图片创建ImageIcon对象
ImageIcon imageIcon = new ImageIcon(downLoadHere);
//设置ImageIcon
label.setIcon(imageIcon);
//label的大小设置为ImageIcon,否则显示不完整
label.setBounds(50, 50, imageIcon.getIconWidth(), imageIcon.getIconHeight());
//将label放入frame
frame.add(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
//3 添加button按钮 当用户扫码完点击之后关闭扫码窗口
JButton button = new JButton("扫描完请点击");
button.setBounds(210, 460, 120, 30);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
frame.dispose();
System.out.println("关闭扫码窗口!");
WeixinLogin.isScan=true;
}
});
frame.add(button);
return isScan;
}
//第四步: 检查是否登录 关闭扫码窗口后需要判断是否登录了
public static int checklogin()
{
if(appid.equals("")){
appid = getQrCodeURL();
}
//1 配置爬虫:这里模拟的是谷歌浏览器 其它请求头是抓包拿到的,没具体校验是否都需要
//抓包拿到的检验登录的地址,不提取出去了。
String url="https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid="+appid+"&tip=0&r=123&_="+System.currentTimeMillis();//检查登录地址
HttpGet httpPost=new HttpGet(url);
httpPost.setHeader("Host", "login.wx.qq.com");
httpPost.setHeader("Pragma", "no-cache");
httpPost.setHeader("Referer", "https://wx.qq.com/");
httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
httpPost.setHeader("Connection", "keep-alive");
int timeout = 200000;//设置超时时间
RequestConfig config = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout)
.setConnectionRequestTimeout(timeout).build();
httpPost.setConfig(config);
//2 发送请求判断是否登录 返回的是window.code = xxx的字符串,xxx是200证明登录成功
String html="";
try {
HttpResponse response = https.execute(httpPost);
HttpEntity entitySort = response.getEntity();
html=EntityUtils.toString(entitySort, "utf-8");
//System.out.println("检查登录回调内容: "+html);
if(html.indexOf("408")!=-1)
{
return 1;
}
if(html.indexOf("400")!=-1)
{
return 2;
}
if(html.indexOf("200")!=-1)
{
//3 登录成功拼接登录地址
int start=html.indexOf("https");
html=html.substring(start).replace("\";", "");
LOGIN_URL=html;
System.out.println("成功登录,登录地址: "+LOGIN_URL);
return 3;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return 0;
}
public static void login()
{
HttpGet httpPost=new HttpGet(LOGIN_URL);
httpPost.setHeader("Host", "wx.qq.com");
httpPost.setHeader("Pragma", "no-cache");
httpPost.setHeader("Referer", "https://wx.qq.com/?&lang=zh_CN");
httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
httpPost.setHeader("Connection", "keep-alive");
String html="";
try {
HttpResponse response = https.execute(httpPost);
HttpEntity entitySort = response.getEntity();
html= EntityUtils.toString(entitySort, "utf-8");
//System.out.println("登录成功回调: "+html);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
//第五步: 在浏览器打开登录后的地址 最后步登录成功后我们调用浏览器打开登录页面
public static void openLoginPage() {
try {
Desktop desk=Desktop.getDesktop();
URI path=new URI(LOGIN_URL);
desk.browse(path);
} catch (Exception e) {
System.out.println("打开异常!");
}
}
public static void main(String[] args) {
//展示二维码:包含第一二三步
Boolean isScan = showQrCode();
for(int i=0;;i++)
{
//校验是否登录
int cf=checklogin();
if(cf==3)
{
//如果登录就打开二维码
openLoginPage();//打开
break;
}
if(cf==2)
{
//如果没登录就重新打卡二维码
System.out.println("未扫码二维码,正在重试!");
showQrCode();
}
if(cf==1)
{
continue;
}
try {
Thread.sleep(13000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
微信群控系统制作系列一——java模拟登录网页版微信相关推荐
- 利用python实现微信自动回复群发等操作(不需要登录网页版微信)
目前微信网页版限制登录,wxpy等模块操作微信的手段都无法使用了,前阵时间发现了WechatPCAPI这个模块,通过dll注入的手段实现操作微信,下面分享一下该模块的使用方法. 运行环境 Wechat ...
- 为什么你会被限制登录网页版微信?
有一个词叫做"三月爬虫",指的是有些学生临到毕业了,需要收集数据写毕业论文,于是在网上随便找了几篇教程,学了点requests甚至是urllib和正则表达式的皮毛,就开始写爬虫疯狂 ...
- 快速解决无法登录网页版微信的问题,亲测有效
在公司开发测试阶段,需要使用网页版微信对开发页面进行调试,但是我的两个微信号在扫码登录网页版微信时,都出现了以下提示: 为了你的帐号安全,此微信号不能登录网页微信.你可以使用Windows微信或Mac ...
- 微信公众号java模拟登录_【微信公众平台改版后】Java模拟登录微信平台,主动推送消息给用户...
一.简要说明 在博文<Java模拟登录微信公众平台,主动推送图文消息给用户>中提到使用Java语言登录微信公众平台,然后发送图文消息给用户,基本可以符合使用要求,但是在今年10月23日,微 ...
- python登录网页版微信发送消息
# coding=utf-8 import datetime import time from selenium import webdriverurl = "https://wx2.qq. ...
- Python+机器人:(wxpy问题)我的微信号不能登录网页版微信,还能使用微信机器人吗?
- python爬虫+网页版微信实时获取消息程序
项目需求: 目的是24小时爬取各种软件的讯息并且以一种统一的方式集中发送给自己. 实现方法: 利用python的requests库以及wxpy库,前者用来爬取网页,后者用来将爬到的内容发送给自己. 程 ...
- 再见,itchat!再见,网页版微信!
点击上方"编程派",选择设为"设为星标" 优质文章,第一时间送达! 有一个词叫做"三月爬虫",指的是有些学生临到毕业了,需要收集数据写毕业论 ...
- java微信群自动回复_功能强大,手机微信群控系统和云控哪个好?
互联网信息技术在发展的同时,也在不断刷新我们对新科技的认知.随着微营销发展的风生水起,手机微信群控和云控出现了,主要就是通过一台电脑控制几十上百部手机,场面十分震撼,这样的黑科技,你了解过吗? 了 ...
最新文章
- 二维非稳态导热微分方程_第三章非稳态导热分析解法
- TCP/IP学习入门笔记
- openAI general intuition
- 隐身专家 FreeEIM 合作版
- 嵌入式系统开发快速体验
- java token 超时_前后端分离——token超时刷新策略
- 2017全国省市区县 json数据
- 弦图(Echarts)
- stata输出相关系数表到word
- 对比性句子sentiment analysis
- ZigBee 3.0实战教程-Silicon Labs EFR32+EmberZnet:学习教程目录
- stm32F105的Canable开源usb-can项目
- discuz插入幻灯片_如何将符号插入Google文档和幻灯片
- 在二维平面上,有一个机器人从原点 (0, 0) 开始。给出它的移动顺序,判断这个机器人在完成移动后是否在 (0, 0) 处结束。
- Long call,Short call与Long put, Short put的联系与区别
- SpringBoot自动装配原理浅析
- oracle.net.ns.NetException:Socket read timed out update
- 计算机网络设备互连与管理,软考网络管理员备考知识点精讲之计算机网络互连设备...
- 【实战问题】【3】iPhone无法播放video标签中的视频
- 【c语言入门】有10个学生,每个学生的数据包含学号、姓名、3门课的成绩,从键盘输入10个学生的数据,要求打印输出3门课程的总平均成绩。