[关闭]
@Cesar 2016-01-16T16:33:54.000000Z 字数 6814 阅读 1479

微信网页版登录原理暨查看将自己删除掉的人项目

Java

访问115.29.55.54:8080/WXApi就可以使用本文提到的网页

目录

  1. 原理
  2. 流程和Java实现
  3. 封装为网页
  4. 参考文档及源码地址

原理

在微信中,将你删掉的好友是无法加入你创建的群聊的,而微信网页版也可以创建群聊,所以使用微信网页版的接口可以实现分辨一个好友是不是将你删除了。


流程和Java实现


  1. // 参考代码:
  2. // Java版本
  3. public String getUUID(){
  4. String url = "https://login.weixin.qq.com/jslogin?appid=%s&fun=new&lang=zh-CN&_=%s";
  5. url = String.format(url, appID,System.currentTimeMillis());
  6. httpGet = new HttpGet(url);
  7. try {
  8. response = httpClient.execute(httpGet);
  9. entity = response.getEntity();
  10. String result = EntityUtils.toString(entity);
  11. logger.debug(result);
  12. String[] res = result.split(";");
  13. if (res[0].replace("window.QRLogin.code = ", "").equals("200")) {
  14. uuid = res[1].replace(" window.QRLogin.uuid = ", "").replace("\"", "");
  15. return uuid;
  16. }
  17. } catch (ClientProtocolException e) {
  18. e.printStackTrace();
  19. } catch (IOException e) {
  20. e.printStackTrace();
  21. }
  22. return null;
  23. }
  1. # python版本
  2. def getuuid():
  3. global uuid
  4. url = 'https://login.weixin.qq.com/jslogin'
  5. params = {
  6. 'appid': 'wx782c26e4c19acffb',
  7. 'fun': 'new',
  8. 'lang': 'zh_CN',
  9. '_': int(time.time()),
  10. }
  11. request = urllib2.Request(url=url, data=urllib.urlencode(params))
  12. response = urllib2.urlopen(request)
  13. data = response.read()
  14. regx = r'window.QRLogin.code = (\d+); window.QRLogin.uuid = "(\S+?)"'
  15. pm = re.search(regx, data)
  16. code = pm.group(1)
  17. uuid = pm.group(2)
  18. if code == '200':
  19. return True
  20. return False

  1. //java版本
  2. // 如果忽略注释直接返回获取图片的url放在网页中的<img>的标签下可以直接显示,如果使用注释中的内容会将其下载为本地图片
  3. public String getQR(String uuid) {
  4. if (uuid == null || "".equals(uuid)) {
  5. return null;
  6. }
  7. String QRurl = "http://login.weixin.qq.com/qrcode/" + uuid;
  8. logger.debug(QRurl);
  9. return QRurl;
  10. // 同时提供使其变为本地图片的方法
  11. // httpGet = new HttpGet(QRurl);
  12. // response = httpClient.execute(httpGet);
  13. // entity = response.getEntity();
  14. // InputStream in = entity.getContent();
  15. // //注意这里要对filepath赋值
  16. // OutputStream out = new FileOutputStream(new File("FilePath"+".png"));
  17. // byte[] b = new byte[1024];
  18. // int t;
  19. // while((t=in.read())!=-1){
  20. // out.write(b, 0, t);
  21. // }
  22. // out.flush();
  23. // in.close();
  24. // out.close();
  25. }
  1. # Python版本
  2. def showQRImage():
  3. global tip
  4. url = 'https://login.weixin.qq.com/qrcode/' + uuid
  5. request = urllib2.Request(url=url)
  6. response = urllib2.urlopen(request)
  7. f = open(QRImagePath, 'wb')
  8. f.write(response.read())
  9. f.close() # 保存到本地

  1. //java版本
  2. public int waitForLogin(String uuid, int tip) {
  3. String urlString = "http://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip=%s&uuid=%s&_=%s";
  4. urlString = String.format(urlString, tip, uuid, System.currentTimeMillis());
  5. httpGet = new HttpGet(urlString);
  6. try {
  7. response = httpClient.execute(httpGet);
  8. String re = EntityUtils.toString(response.getEntity());
  9. String[] result = re.split(";");
  10. logger.debug(re);
  11. if (result[0].replace("window.code=", "").equals("201")) {
  12. tip = 0;
  13. return 201;
  14. } else if (result[0].replace("window.code=", "").equals("200")) {
  15. redirectUri = (result[1].replace("window.redirect_uri=", "").replace("\"", "") + "&fun=new").trim();
  16. return 200;
  17. } else {
  18. return 400;
  19. }
  20. } catch (ClientProtocolException e) {
  21. e.printStackTrace();
  22. } catch (IOException e) {
  23. e.printStackTrace();
  24. }
  25. return -1;
  26. }
  1. # python版本
  2. def waitForLogin():
  3. global tip, base_uri, redirect_uri
  4. url = 'https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip=%s&uuid=%s&_=%s' % (tip, uuid, int(time.time()))
  5. request = urllib2.Request(url = url)
  6. response = urllib2.urlopen(request)
  7. data = response.read()
  8. regx = r'window.code=(\d+);'
  9. pm = re.search(regx, data)
  10. code = pm.group(1)
  11. if code == '201': #已扫描
  12. print '成功扫描,请在手机上点击确认以登录'
  13. tip = 0
  14. elif code == '200': #已登录
  15. regx = r'window.redirect_uri="(\S+?)";'
  16. pm = re.search(regx, data)
  17. redirect_uri = pm.group(1) + '&fun=new'
  18. base_uri = redirect_uri[:redirect_uri.rfind('/')]
  19. elif code == '408': #超时
  20. pass
  21. return code
  1. int ret;//返回值为0时表示本次请求成功
  2. String message;//一些信息(比如失败原因等)
  3. String skey;//后面请求会用到的参数
  4. String wxsid;//同上
  5. Long wxuin;// 本人编码
  6. String pass_ticket;//重要!!后面很多请求都会用到这张通行证
  7. int isgrayscale;//不明

代码如下:

  1. //java
  2. private boolean login() {
  3. String url = redirectUri;
  4. httpGet = new HttpGet(url);
  5. try {
  6. response = httpClient.execute(httpGet);
  7. entity = response.getEntity();
  8. String data = EntityUtils.toString(entity);
  9. logger.debug(data);
  10. loginResponse = CommonUtil.parseLoginResult(data);
  11. baseRequest = new BaseRequest(loginResponse.getWxuin(), loginResponse.getWxsid(), loginResponse.getSkey(),
  12. loginResponse.getDeviceID());
  13. return true;
  14. } catch (ClientProtocolException e) {
  15. e.printStackTrace();
  16. } catch (IOException e) {
  17. e.printStackTrace();
  18. }
  19. return false;
  20. }
  1. #python版本
  2. def login():
  3. global skey, wxsid, wxuin, pass_ticket, BaseRequest
  4. request = urllib2.Request(url = redirect_uri)
  5. response = urllib2.urlopen(request)
  6. data = response.read()
  7. doc = xml.dom.minidom.parseString(data)
  8. root = doc.documentElement
  9. for node in root.childNodes:
  10. if node.nodeName == 'skey':
  11. skey = node.childNodes[0].data
  12. elif node.nodeName == 'wxsid':
  13. wxsid = node.childNodes[0].data
  14. elif node.nodeName == 'wxuin':
  15. wxuin = node.childNodes[0].data
  16. elif node.nodeName == 'pass_ticket':
  17. pass_ticket = node.childNodes[0].data
  18. if skey == '' or wxsid == '' or wxuin == '' or pass_ticket == '':
  19. return False
  20. BaseRequest = {
  21. 'Uin': int(wxuin),
  22. 'Sid': wxsid,
  23. 'Skey': skey,
  24. 'DeviceID': deviceId,
  25. }
  26. return True

  1. //java
  2. private void initWX() {
  3. String url = String.format("http://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?pass_ticket=%s&skey=%s&r=%s",
  4. loginResponse.getPass_ticket(), loginResponse.getSkey(), System.currentTimeMillis());
  5. InitRequestJson initRequestJson = new InitRequestJson(baseRequest);//Java中包含了BaseRequest的包装类
  6. String re = getResponse(url, gson.toJson(initRequestJson));//这是自己写的一个公有方法,可以直接看源码
  7. InitResponseJson initResponseJson = gson.fromJson(re, InitResponseJson.class);
  8. mine = initResponseJson.getUser();// 获取当前用户信息
  9. }
  1. def webwxinit():
  2. url = base_uri + '/webwxinit?pass_ticket=%s&skey=%s&r=%s' % (pass_ticket, skey, int(time.time()))
  3. params = {
  4. 'BaseRequest': json.dumps(BaseRequest)
  5. }
  6. request = urllib2.Request(url=url, data=json.dumps(params))
  7. request.add_header('ContentType', 'application/json; charset=UTF-8')
  8. response = urllib2.urlopen(request)
  9. data = response.read()
  10. global ContactList, My
  11. dic = json.loads(data)
  12. ContactList = dic['ContactList']
  13. My = dic['User']
  14. ErrMsg = dic['BaseResponse']['ErrMsg']
  15. if len(ErrMsg) > 0:
  16. print ErrMsg
  17. Ret = dic['BaseResponse']['Ret']
  18. if Ret != 0:
  19. return False
  20. return True

封装为网页

  1. 得到uuid,并将其包装直接插入标签中就可以在网页中显示该二维码
  2. 使用AJAX请求,请求waitforlogging()方法,当返回值为200时成功,此时遍历该用户每一个好友,判断其是否删除了该用户。
  3. 显示

参考文档

  1. 该功能的python实现
  2. 网页微信登录原理

项目源码

项目源码

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注