微信手表版 v1.7版本的 MD5 值为:074f4583232b28d7848c84aa13121302
以下内容为反编译后的 WxLogin.java 源代码,内容仅作参考
package com.chenls.weixin.util;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.Base64;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chenls.weixin.model.Token;
import com.chenls.weixin.util.Constants;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpCookie;
import java.net.UnknownHostException;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import javax.net.ssl.HttpsURLConnection;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class WxLogin {
public static final String AVATAR_KEY = "window.userAvatar";
private static final String CODE_KEY = "window.QRLogin.code";
public static final String DEFAULT_AVATAR = "data:img/jpg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABQODxIPDRQSEBIXFRQYHjIhHhwcHj0sLiQySUBMS0dARkVQWnNiUFVtVkVGZIhlbXd7gYKBTmCNl4x9lnN+gXz/wAALCACEAIQBAREA/8QAGQABAQEBAQEAAAAAAAAAAAAAAAMCAQQG/8QAIhABAAIBBAEFAQAAAAAAAAAAAAECEQMEITEFEhMyUWFB/9oACAEBAAA/APpa1rSsVpEVrEYiI6h0AAAAHk3Pi9lu9X3dxt6al8Y9UvWAAAAAAAAAAAAA7ETPTXtz9k6csdAAAAC0RiMOjF4zGUwAAAdr8oWByekQAAAdrxaFgcniEQAAAFazmGhjUn+JgAAAO0nFlnJ4hHsAAAAiM9KVpjmWxO1PpgAAAbrT7biIjp0ByaxPadqTH7DIAApSvGWwABPUjE5hgABWkx6YaAAE9SeoYAAAAAAAAAAAAAAAAAAT22pOrttLUtiJvSLTj9hQAAAAHzXnvObzYeQnQ0JpFIpE81zL/9k=";
private static final String JS_LOGIN_WX_URL = "https://login.wx2.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx2.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN&_=";
private static final String LOGIN_CHECK_URL = "https://login.wx2.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid=%s&tip=0&_=";
public static final String LOGIN_CODE_KEY = "window.code";
private static final String LOGIN_URL = "https://login.weixin.qq.com/l/";
private static final String PUSH_LOGIN = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxpushloginurl?uin=%s";
private static final String QR_URL = "https://login.weixin.qq.com/qrcode/";
public static final String REDIRECT_KEY = "window.redirect_uri";
private static final String REDIRECT_SUFFIX = "&fun=new&version=v2";
private static final String TAG = "WxLogin";
public static final String UNKNOWN_HOST = "UNKNOWN_HOST";
private static final String UUID_KEY = "window.QRLogin.uuid";
public static String formatQRUrl(String uuid) {
return QR_URL + uuid;
}
public static String getUUid() {
try {
Properties parseText = parseText(NetUtil.getHttpsResponse(JS_LOGIN_WX_URL + System.currentTimeMillis(), 0));
return Constants.LoginCode.LOGIN.equals(parseText.getProperty(CODE_KEY)) ? parseText.getProperty(UUID_KEY).replaceAll("\"", "") : "";
} catch (UnknownHostException unused) {
Log.w(TAG, "getUUid:unknownHostException");
return UNKNOWN_HOST;
} catch (IOException e) {
Log.w(TAG, "getUUid:exception", e);
return "";
}
}
public static String pushLogin(String wxuin, String cookie) {
try {
String httpsResponse = NetUtil.getHttpsResponse(String.format(PUSH_LOGIN, wxuin), 0, cookie);
Log.i(TAG, "pushLogin:httpRes=" + httpsResponse);
JSONObject parseObject = JSON.parseObject(httpsResponse);
return Constants.SyncCheckCode.SUCCESS.equals(parseObject.getString(Token.RET)) ? parseObject.getString("uuid") : "";
} catch (IOException e) {
Log.w(TAG, "fastLogin:exception", e);
return null;
}
}
public static Properties parseText(String text) {
Properties properties = new Properties();
if (text != null && !text.isEmpty()) {
char[] charArray = text.toCharArray();
StringBuilder sb = new StringBuilder();
String str = null;
boolean z = true;
boolean z2 = true;
for (int i = 0; i < charArray.length; i++) {
char c = charArray[i];
if (!z && '\"' != c) {
sb.append(charArray[i]);
} else if (!z2 && '\'' != c) {
sb.append(c);
} else if (c != '\t' && c != '\n' && c != '\r' && c != ' ') {
if (c == '\"') {
z = !z;
} else if (c == '\'') {
z2 = !z2;
} else if (c == ';') {
String sb2 = sb.toString();
sb.delete(0, sb.length());
properties.setProperty(str, sb2);
} else if (c == '=') {
str = sb.toString();
sb.delete(0, sb.length());
} else {
sb.append(c);
}
}
}
if (str != null && sb.length() != 0) {
String sb3 = sb.toString();
sb.delete(0, sb.length());
properties.setProperty(str, sb3);
}
}
return properties;
}
public static Properties checkLoginStatus(String uuid) {
try {
return parseText(NetUtil.getHttpsResponse(String.format(LOGIN_CHECK_URL, uuid) + System.currentTimeMillis(), 30000));
} catch (IOException e) {
Log.w(TAG, "checkLoginStatus:exception", e);
return null;
}
}
public static Token getToken(String url) {
Uri parse = Uri.parse(url);
WxHome.setWxBaseUri(parse.getScheme(), parse.getHost());
try {
HttpsURLConnection httpsConnection = NetUtil.getHttpsConnection(url + REDIRECT_SUFFIX, 30000);
httpsConnection.connect();
NodeList elementsByTagName = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(httpsConnection.getInputStream()).getElementsByTagName("error");
if (elementsByTagName != null && elementsByTagName.getLength() != 0) {
Token token = new Token();
token.cookie = cookiesToStr((List) httpsConnection.getHeaderFields().get("Set-Cookie"));
NodeList childNodes = elementsByTagName.item(0).getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node item = childNodes.item(i);
String trim = item.getTextContent().trim();
String nodeName = item.getNodeName();
char c = 65535;
switch (nodeName.hashCode()) {
case -1730959651:
if (nodeName.equals(Token.IS_GRAY_SCALE)) {
c = 6;
break;
}
break;
case 112801:
if (nodeName.equals(Token.RET)) {
c = 0;
break;
}
break;
case 3532044:
if (nodeName.equals(Token.SKEY)) {
c = 2;
break;
}
break;
case 113587789:
if (nodeName.equals(Token.WXSID)) {
c = 3;
break;
}
break;
case 113589721:
if (nodeName.equals(Token.WXUIN)) {
c = 4;
break;
}
break;
case 954925063:
if (nodeName.equals("message")) {
c = 1;
break;
}
break;
case 1713340154:
if (nodeName.equals(Token.PASS_TICKET)) {
c = 5;
break;
}
break;
}
switch (c) {
case 0:
token.ret = Integer.parseInt(trim);
break;
case 1:
token.message = trim;
break;
case 2:
token.setSkey(trim);
break;
case 3:
token.setWxsid(trim);
break;
case 4:
token.setWxuin(trim);
break;
case 5:
token.setPassTicket(trim);
break;
case 6:
token.setIsGrayScale(trim);
break;
}
}
httpsConnection.disconnect();
return token;
}
httpsConnection.disconnect();
return null;
} catch (Exception e) {
Log.w(TAG, "getToken:exception", e);
return null;
}
}
private static String cookiesToStr(List<String> cookies) {
StringBuilder sb = new StringBuilder();
Iterator<String> it = cookies.iterator();
while (it.hasNext()) {
sb.append(HttpCookie.parse(it.next()).get(0).toString() + ";");
}
return sb.toString();
}
public static Bitmap getURLImage(String url) {
Bitmap bitmap = null;
try {
HttpsURLConnection httpsConnection = NetUtil.getHttpsConnection(url, 6000);
httpsConnection.setUseCaches(false);
httpsConnection.connect();
InputStream inputStream = httpsConnection.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);
inputStream.close();
httpsConnection.disconnect();
return bitmap;
} catch (Exception e) {
Log.w(TAG, "getURLImage:exception", e);
return bitmap;
}
}
public static Bitmap getBase64Image(String avatarUrl) {
byte[] decode = Base64.decode(avatarUrl.replace("data:img/jpg;base64,", ""), 0);
return BitmapFactory.decodeByteArray(decode, 0, decode.length);
}
}