基于微信7.0.3
发送文本
发送文件的方法都已经找到了(从其他地方复制到了)
但是发送图片方法一直找不到,就算找到了也会报错
插入代码
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import java.io.File;
import java.util.ArrayList;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
public class WXMessageUtils {
public static void sendText(final String wxId,
String strContent) {
if (MainXposed.classLoader == null) {
XposedBridge.log("微信助手未初始化");
return;
}
//构造new里面的参数:l iVar = new i(aao, str, hQ, i2, mVar.cvb().fD(talkerUserName, str));
//Class<?> classiVar = ;
Object objectiVar = XposedHelpers.newInstance(
XposedHelpers.findClassIfExists("com.tencent.mm.modelmulti.h", MainXposed.classLoader),
wxId, strContent, 1);
//创建静态实例对象au.DF(),转换为com.tencent.mm.ab.o对象
Object objectG = XposedHelpers.callStaticMethod(
XposedHelpers.findClassIfExists("com.tencent.mm.model.av", MainXposed.classLoader),
"Pw");
//调用发消息方法
try {
XposedHelpers.callMethod(objectG, "a", objectiVar, 0);
XposedBridge.log("发送消息成功-----");
} catch (Exception e) {
XposedBridge.log("发送消息失败XXXXXXX");
XposedBridge.log(e.getMessage());
}
}
public static void sendImage(final String wxId, String imgPath) {
Class findClass = XposedHelpers.findClass("com.tencent.mm.av.n", MainXposed.wxLpparam.classLoader);
Object obj = XposedHelpers.callStaticMethod(findClass, "alL");
if (obj == null) {
obj = XposedHelpers.newInstance(findClass);
}
XposedHelpers.callMethod(obj, "a", 0, 0, imgPath, wxId, Boolean.TRUE);
final ArrayList<String> arrayList = new ArrayList<>();
arrayList.add(imgPath);
final Object finalObj = obj;
XposedHelpers.callMethod(finalObj,"b", arrayList, Boolean.TRUE, 0, 0, wxId);
//-------------------------------------------------------------------------------------------------------------------------
// paramClassLoader, WechatEntity paramWechatEntity, paramString1, paramString2, paramString3,
// Object[] arrayOfObject = new Object[2];
// String sendPic_class_1 = "com.tencent.mm.av.n";
// String sendPic_class_2 = "com.tencent.mm.ae.n";
// String sendPic_field_1 = "hzX";
// String sendPic_method_1 = "a";
//
// arrayOfObject[0] = XposedHelpers.newInstance(XposedHelpers.findClass(sendPic_class_1, MainXposed.classLoader),
// new Object[]{Integer.valueOf(3), "", wxId, imgPath,
// Integer.valueOf(1), null, Integer.valueOf(1), "", "", Boolean.valueOf(true), Integer.valueOf(2130837923)});
//
// arrayOfObject[1] = Integer.valueOf(1);
//
// XposedHelpers.callMethod(XposedHelpers.getStaticObjectField(
// XposedHelpers.findClass(sendPic_class_2, MainXposed.classLoader), sendPic_field_1), sendPic_method_1, arrayOfObject);
//
}
/**
* 发送文件方法
*
* @param wxId 对方用户ID
* @param filePath 文件路径
*/
public static void sendFile(String wxId, String filePath) {
File file = new File(filePath);
ClassLoader cl = MainXposed.classLoader;
Class IMediaObject = XposedHelpers.findClass("com.tencent.mm.opensdk.modelmsg.WXMediaMessage$IMediaObject", cl);
Class fileObjectClz = XposedHelpers.findClass("com.tencent.mm.opensdk.modelmsg.WXFileObject", cl);
Class mediaMessageClz = XposedHelpers.findClass("com.tencent.mm.opensdk.modelmsg.WXMediaMessage", cl);
Class mediaMsgSenderClz = XposedHelpers.findClass("com.tencent.mm.pluginsdk.model.app.l", cl);
if (file.exists() && file.isFile()) {
Object fileObject = XposedHelpers.newInstance(fileObjectClz);
XposedHelpers.callMethod(fileObject, "setFilePath", filePath);
Object mediaObject = XposedHelpers.newInstance(mediaMessageClz);
XposedHelpers.setObjectField(mediaObject, "mediaObject", IMediaObject.cast(fileObject));
XposedHelpers.setObjectField(mediaObject, "title", file.getName());
XposedHelpers.setObjectField(mediaObject, "description", getFileDesc(file.length()));
XposedHelpers.callStaticMethod(mediaMsgSenderClz, "a", mediaObject, "", "", wxId, 4, null);
XposedBridge.log("发送完毕==" + filePath);
} else {
Log.e("文件不存在,无法发送 %s", filePath);
}
}
/**
* 获取文件大小
*
* @param filesize
* @return
*/
private static String getFileDesc(long filesize) {
long j = filesize;
if ((j >> 30) > 0) {
// GB
return (((double) Math.round((((double) j) * 10.0d) / 1.073741824E9d)) / 10.0d) + " GB";
}
if ((j >> 20) > 0) {
// MB
return (((double) Math.round((((double) j) * 10.0d) / 1048576.0d)) / 10.0d) + " MB";
}
if ((j >> 9) <= 0) {
return j + " B";
}
return (((double) Math.round((((double) j) * 10.0d) / 1024.0d)) / 10.0d) + " KB";
}
}
有没有大佬指导一下?
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!