本文只限用于官网下载的11.3.0 版本的app。其他版本可能造成不适用。如有其他问题欢迎加Q探讨:1249789250
直接上代码:
/**
* 获取自己账号信息(user_id、头像、昵称等)
*
* @return 用户信息
*/
public static User getCurrentUser() {
Object userManager = HookUtil.callStaticMethod("com.ss.android.ugc.aweme.user.c", "a");
Object myUser = XposedHelpers.callMethod(userManager, "b");
return User.obj2User(myUser);
}
HookUtil.java
public static Object callStaticMethod(String className, String methodName, Object... args) {
Class clz = findClass(className);
return XposedHelpers.callStaticMethod(clz, methodName, args);
}
User.java
import android.text.TextUtils;
import android.util.Log;
import java.io.Serializable;
import java.util.List;
import de.robv.android.xposed.XposedHelpers;
import dongdong.douyin.fit.Fit;
public class User implements Serializable {
private static final String TAG = "User";
private String uniqueId;
private String uid;
private String secUid;
private String nickName;
/**
* 0未知, 1男, 2女
*/
private int gender;
private String birthday;
private String city;
private int followerCount;
private int followingCount;
private int awemeCount;
private long totalFavorited;
private String avatarMediumUrl;
private String avatarLargerUrl;
private String signature;
public void setSignature(String signature) {
this.signature = signature;
}
public String getAvatarMediumUrl() {
return avatarMediumUrl;
}
public void setAvatarMediumUrl(String avatarMediumUrl) {
this.avatarMediumUrl = avatarMediumUrl;
}
public String getAvatarLargerUrl() {
return avatarLargerUrl;
}
public void setAvatarLargerUrl(String avatarLargerUrl) {
this.avatarLargerUrl = avatarLargerUrl;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public int getGender() {
return gender;
}
public void setGender(int gender) {
this.gender = gender;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public int getFollowerCount() {
return followerCount;
}
public void setFollowerCount(int followerCount) {
this.followerCount = followerCount;
}
public int getFollowingCount() {
return followingCount;
}
public void setFollowingCount(int followingCount) {
this.followingCount = followingCount;
}
public int getAwemeCount() {
return awemeCount;
}
public void setAwemeCount(int awemeCount) {
this.awemeCount = awemeCount;
}
public String getUniqueId() {
return uniqueId;
}
public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getSecUid() {
return secUid;
}
public void setSecUid(String secUid) {
this.secUid = secUid;
}
public long getTotalFavorited() {
return totalFavorited;
}
public void setTotalFavorited(long totalFavorited) {
this.totalFavorited = totalFavorited;
}
@Override
public String toString() {
return "User{" +
"uniqueId='" + uniqueId + '\'' +
", uid='" + uid + '\'' +
", secUid='" + secUid + '\'' +
", nickName='" + nickName + '\'' +
", gender=" + gender +
", birthday='" + birthday + '\'' +
", city='" + city + '\'' +
", followerCount=" + followerCount +
", followingCount=" + followingCount +
", awemeCount=" + awemeCount +
", totalFavorited=" + totalFavorited +
", avatarMediumUrl='" + avatarMediumUrl + '\'' +
", avatarLargerUrl='" + avatarLargerUrl + '\'' +
", signature='" + signature + '\'' +
'}';
}
public static User obj2User(Object userObj) {
User user = new User();
try {
/*抖音uid*/
user.setUid((String) XposedHelpers.getObjectField(userObj, "uid"));
user.setSecUid((String) XposedHelpers.getObjectField(userObj, "secUid"));
user.setAwemeCount(XposedHelpers.getIntField(userObj, "awemeCount"));
user.setBirthday((String) XposedHelpers.getObjectField(userObj, "birthday"));
String city = (String) XposedHelpers.getObjectField(userObj, "city");
user.setCity(TextUtils.isEmpty(city) ? cityName : city);
String cityName = (String) XposedHelpers.getObjectField(userObj, "cityName");
String shortId = (String) XposedHelpers.getObjectField(userObj, "shortId");
String uniqueId = (String) XposedHelpers.getObjectField(userObj, "uniqueId");
user.setUniqueId(TextUtils.isEmpty(uniqueId) ? shortId : uniqueId);
user.setNickName((String) XposedHelpers.getObjectField(userObj, "nickname"));
user.setGender(XposedHelpers.getIntField(userObj, "gender"));
/*粉丝数*/
user.setFollowerCount(XposedHelpers.getIntField(userObj, "followerCount"));
/*关注数*/
user.setFollowingCount(XposedHelpers.getIntField(userObj, "followingCount"));
/*喜欢数*/
user.setTotalFavorited(XposedHelpers.getLongField(userObj, "totalFavorited"));
/*签名*/
user.setSignature((String) XposedHelpers.getObjectField("signature"));
/*头像*/
Object avatarLarger = XposedHelpers.getObjectField(userObj, "avatarLarger");
if (avatarLarger == null) {
user.setAvatarLargerUrl("");
} else {
List> list = (List>) XposedHelpers.getObjectField(avatarLarger, "urlList");
user.setAvatarLargerUrl(list.size() <= 0 ? "" : (String) list.get(0));
}
Object avatarMedium = XposedHelpers.getObjectField(userObj, "avatarMedium");
if (avatarMedium == null) {
user.setAvatarMediumUrl("");
} else {
List> list = (List>) XposedHelpers.getObjectField(avatarMedium, "urlList");
user.setAvatarMediumUrl(list.size() <= 0 ? "" : (String) list.get(0));
}
} catch (Throwable t) {
Log.e(TAG, "getUserInfo: ", t);
}
return user;
}
}