import hashlib
import time
import requests
# 这里是我自己写的解密数据接口 我本来想放在本地的 哎太麻烦了 不方便
def ase_cbc(encrypted_text):
server_url = ‘这个是我自己写的解密接口 需要的话私聊吧 我就不放了 但是下面有给出node js服务器接口’
response = requests.post(
server_url, json={'encryptedText': encrypted_text})
return response.json().get('decryptedText')
def generate_md5_hash_hex(data):
md5_hash = hashlib.md5()
md5_hash.update(str(data).encode('utf-8'))
return md5_hash.hexdigest()
# 这个接口收到的数据非明文的 需要进行aes cbc 128 解密
def youdao_webtranslate(translatefrom, to, text):
o = str(time.time() * 1000).split('.')[0]
e = f'client=fanyideskweb&mysticTime={o}&product=webfanyi&key=fsdsogkndfokasodnaso'
sign = generate_md5_hash_hex(e)
url = 'https://dict.youdao.com/webtranslate'
headers = {
"Host": "dict.youdao.com",
"Origin": "https://fanyi.youdao.com",
"Referer": "https://fanyi.youdao.com/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0",
"Cookie": ''
}
# 注意这里的cookie要跟请求有道第一次返回的cookie要一样 最好写成一个类 公用session
data = {"i": text,
"from": translatefrom,
"to": to,
"domain": "0",
"dictResult": "true",
"keyid": "webfanyi",
"sign": sign,
"client": "fanyideskweb",
"product": "webfanyi",
"appVersion": "1.0.0",
"vendor": "web",
"pointParam": "client,mysticTime,product",
"mysticTime": o,
"keyfrom": "fanyi.web",
"mid": "1",
"screen": "1",
"model": "1",
"network": "wifi",
"abtest": "0",
"yduuid": "abcdefg"}
respone = requests.post(url, headers=headers, data=data)
return respone.text
# 这个接口返回的是明文数据 我也不明白为什么他要搞两个接口 一个可以直接返回明文 一个返回的数据需要解密 不知道意义是什么
# 加密了就加密呗 反正我能解密
def youdao_translate():
url = 'https://dict.youdao.com/keyword/key'
headers = {
"Host": "dict.youdao.com",
"Origin": "https://fanyi.youdao.com",
"Referer": "https://fanyi.youdao.com/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0",
# 这里自己写入cookie吧 或者访问有道翻译 可以获取到cookie
"Cookie": ''
}
data = {"text": "你好啊",
"lang": "zh",
"to": "ja"}
respone = requests.post(url, headers=headers, data=data)
print(respone.text)
reponsetext = youdao_webtranslate('zh-CHS', 'en', '我是你爸爸')
print(ase_cbc(reponsetext))
js解密部分 喜欢的话可以放在服务器上面
const express = require('express');
const bodyParser = require('body-parser');
const crypto = require('crypto');
const app = express();
const port = 3000;
app.use(bodyParser.json());
app.post('/decrypt', (req, res) => {
const encryptedText = req.body.encryptedText;
const byteArray1 = [8, 20, 157, 167, 60, 89, 206, 98, 85, 91, 1, 233, 47, 52, 232, 56];
const keyBuffer = Buffer.from(byteArray1);
const byteArray2 = [210, 187, 27, 253, 232, 59, 56, 195, 68, 54, 99, 87, 183, 156, 174, 28];
const ivBuffer = Buffer.from(byteArray2);
const decipher = crypto.createDecipheriv('aes-128-cbc', keyBuffer, ivBuffer);
let decryptedText;
try {
decryptedText = decipher.update(encryptedText, 'base64', 'utf-8');
decryptedText += decipher.final('utf-8');
res.status(200).json({ decryptedText });
} catch (error) {
console.error('Error during decryption:', error);
res.status(500).json({ error: 'Error during decryption' });
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
注:若转载请注明大神论坛来源(本贴地址)与作者信息。