Sec-MS-GEC生成,这个方法目前可以跑,不用外挂代理类抓取
Closed this issue · 1 comments
ref:rany2/edge-tts#290
目前得到的算法如下:
使用 GetSystemTimeAsFileTime 取得系统时间 t(自 1601年1月1日(UTC) 起的 UTC 时间,单位是 100 纳秒)。
将 t 设为不超过 t 的最大的 3,000,000,000 的倍数。(因此每 5 分钟生成一个新 key)
将 t 转为字符串,后面接上 6A5AA1D4EAFF4E9FB37E23D68491D6F4,构成新字符串 str。
计算 str 的 SHA-256 哈希值,再转为十六进制字符串(每个字节对应两个大写十六进制数位,中间无分隔符),就得到了当前时间对应的 Sec-MS-GEC。
nodejs:
import { createHash } from 'node:crypto'
export const CHROMIUM_FULL_VERSION = '130.0.2849.68'
export const TRUSTED_CLIENT_TOKEN = '6A5AA1D4EAFF4E9FB37E23D68491D6F4'
const WINDOWS_FILE_TIME_EPOCH = 11644473600n
export function generateSecMsGecToken() {
const ticks = BigInt(Math.floor((Date.now() / 1000) + Number(WINDOWS_FILE_TIME_EPOCH))) * 10000000n
const roundedTicks = ticks - (ticks % 3000000000n)
const strToHash = ${roundedTicks}${TRUSTED_CLIENT_TOKEN}
const hash = createHash('sha256')
hash.update(strToHash, 'ascii')
return hash.digest('hex').toUpperCase()
}
java去掉锁,貌似也可以:
public static void UpdateSec_MS_GEC() {
long currentTime = System.currentTimeMillis();
if (currentTime - lastUpdateTimestamp < COOLDOWN_PERIOD_MS) {
return;
}
lastUpdateTimestamp = currentTime;
try {
String SEC_MS_GEC_Version = "1-130.0.2849.68";
long ticks = (long) (Math.floor((System.currentTimeMillis()/1000.0)+11644473600l)*10000000);
long roundedTicks =ticks-(ticks % 3000000000L);
String str = roundedTicks+"6A5AA1D4EAFF4E9FB37E23D68491D6F4";
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
byte[] hash = sha256.digest(String.valueOf(roundedTicks).concat("6A5AA1D4EAFF4E9FB37E23D68491D6F4").getBytes(StandardCharsets.UTF_8));
StringBuilder hexString = new StringBuilder();
for (byte b : hash) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
String SEC_MS_GEC = hexString.toString().toUpperCase();
URL = String.format(
"wss://speech.platform.bing.com/consumer/speech/synthesize/readaloud/edge/v1?TrustedClientToken=6A5AA1D4EAFF4E9FB37E23D68491D6F4&Sec-MS-GEC=%s&Sec-MS-GEC-Version=%s",
SEC_MS_GEC, SEC_MS_GEC_Version);
System.out.println("Adjusted SEC_MS_GEC to : " + SEC_MS_GEC);
System.out.println("Adjusted SEC_MS_GEC_Version to : " + SEC_MS_GEC_Version);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
非常感谢!good job!