直接上代码
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
*@title WechatSphDecryptUtil
*@description 微信视频号解密工具类
*/
public class WechatSphDecryptUtil {
static String sphCommandPath = "D:\\sph.exe";
/**
* @description
* @param[1] wxChatSphUrl 视频博放加密链接
* @param[2] decodeKey 视频加密参数
* @param[3] savepath 视频解析后文件保存路径
*/
public static void decrypt(String wxChatSphUrl,String decodeKey,String savepath) {
// 构建命令
String[] commandArray = {
sphCommandPath,
"-url=" + wxChatSphUrl,
"-decodeKey=" + decodeKey,
"-savepath=" + savepath
};
// 创建 ProcessBuilder 对象
ProcessBuilder processBuilder = new ProcessBuilder(commandArray);
try {
// 启动进程
Process process = processBuilder.start();
// 获取标准输出
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println("Output: " + line);
}
// 获取错误输出
BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
while ((line = errorReader.readLine()) != null) {
System.err.println("Error: " + line);
}
// 等待命令执行完毕
int exitCode = process.waitFor();
if(exitCode == 0){
System.out.println("解密成功");
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
示例视频链接:
decodeKey:1578215299