有道翻译接口逆向_python有道翻译api(2)

import hashlib
from urllib.parse import urlencode

def get_timestamp():
return int(datetime.datetime.now().timestamp() * 1000)

def get_key():
# 主要是获取key等参数
url = “https://dict.youdao.com/webtranslate/key”
mysticTime = get_timestamp()
tmp_sign = f"client=fanyideskweb&mysticTime={mysticTime}&product=webfanyi&key=asdjnjfenknafdfsdfsd"
sign = hashlib.md5(tmp_sign.encode(“utf8”)).hexdigest()
# 参数
params = {
‘keyid’: ‘webfanyi-key-getter’,
‘sign’: sign,
‘client’: ‘fanyideskweb’,
‘product’: ‘webfanyi’,
‘appVersion’: ‘1.0.0’,
‘vendor’: ‘web’,
‘pointParam’: ‘client,mysticTime,product’,
‘mysticTime’: mysticTime,
‘keyfrom’: ‘fanyi.web’,
‘mid’: 1,
‘screen’: 1,
‘model’: 1,
‘network’: ‘wifi’,
‘abtest’: ‘0’,
‘yduuid’: ‘abcdefg’,
}

url_with_params = f"{url}?{urlencode(params)}"

headers = {
    'Accept': 'application/json, text/plain, \*/\*',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Origin': 'https://fanyi.youdao.com',
    'Pragma': 'no-cache',
    'Referer': 'https://fanyi.youdao.com/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
    'Sec-Ch-Ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
    'Sec-Ch-Ua-Mobile': '?0',
    'Sec-Ch-Ua-Platform': '"Windows"'
}

# 请求
response = requests.get(url_with_params, headers=headers, data={})
json_data = json.loads(response.text)
# 获取 key
key = json_data['data']['secretKey']
return key

def send(chinese):
url = “https://dict.youdao.com/webtranslate”
mysticTime = get_timestamp()
# sign 是 client=fanyideskweb&mysticTime=1711295634744&product=webfanyi&key=fsdsogkndfokasodnaso
tmp_sign = f"client=fanyideskweb&mysticTime={mysticTime}&product=webfanyi&key={get_key()}"
sign = hashlib.md5(tmp_sign.encode(“utf8”)).hexdigest()

payload = {
    'i': chinese,
    'from': 'auto',
    'to': '',
    'domain': '0',
    'dictResult': 'true',
    'keyid': 'webfanyi',
    'sign': sign,
    'client': 'fanyideskweb',
    'product': 'webfanyi',
    'appVersion': '1.0.0',
    'vendor': 'web',
    'pointParam': 'client,mysticTime,product',
    'mysticTime': mysticTime,
    'keyfrom': 'fanyi.web',
    'mid': 1,
    'screen': 1,
    'model': 1,
    'network': 'wifi',
    'abtest': '0',
    'yduuid': 'abcdefg',
}

headers = {
    'Accept': 'application/json, text/plain, \*/\*',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Cookie': 'OUTFOX\_SEARCH\_USER\_ID=-1545431425@10.55.164.248; OUTFOX\_SEARCH\_USER\_ID\_NCOO=1617400304.3454392',
    'Origin': 'https://fanyi.youdao.com',
    'Pragma': 'no-cache',
    'Referer': 'https://fanyi.youdao.com/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
    'sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"'
}

response = requests.post(url, headers=headers, data=payload)

encode_data = response.text
# 开始解密数据
print(encode_data)

#### 解密返回的加密数据


但是通过测试发现,send() 这个方法返回的是加密数据,接下来探索如何解密,通过debug 发现解密在这行代码里面  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/ffa38f02e54849508084603ef4198a47.png)  
 观察这个方法,定义了一个变量a,通过调用一个解密方法,把乱码的字符给解密了  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/21d4697e6fac4a1497950498f854ca33.png)  
 关键代码



const a = Po[“a”].decodeData(o, Wo[“a”].state.text.decodeKey, Wo[“a”].state.text.decodeIv)
, n = a ? JSON.parse(a) : {};


看下 Po[“a”].decodeData 会跳转到哪个方法里面  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/5a9be82208804dd7a398949b62455eaa.png)  
 进入这个解密方法,框选的部分好像就是解码过程了  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/60611f0295ce4496a32fb41c30a6cf35.png)


Debug 看下是怎么解密的  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/cf02d4df02ea4b7199a81d99e62be72c.png)


使用模型分析下这个代码  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/2f124291a62d47f5a7915ac5eb2fe3c2.png)  
 原来 y() 这个函数是 md5 加密的方法  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/681663afc39e4a27b64d71c9937df3b1.png)


经过采纳考别人的经验,复现出了 python 代码



import requests
import datetime
import json
import hashlib
from urllib.parse import urlencode
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
import base64

def get_timestamp():
return int(datetime.datetime.now().timestamp() * 1000)

def init_data():
# 主要是获取key等参数
url = “https://dict.youdao.com/webtranslate/key”
mysticTime = get_timestamp()
tmp_sign = f"client=fanyideskweb&mysticTime={mysticTime}&product=webfanyi&key=asdjnjfenknafdfsdfsd"
sign = hashlib.md5(tmp_sign.encode(“utf8”)).hexdigest()
# 参数
params = {
‘keyid’: ‘webfanyi-key-getter’,
‘sign’: sign,
‘client’: ‘fanyideskweb’,
‘product’: ‘webfanyi’,
‘appVersion’: ‘1.0.0’,
‘vendor’: ‘web’,
‘pointParam’: ‘client,mysticTime,product’,
‘mysticTime’: mysticTime,
‘keyfrom’: ‘fanyi.web’,
‘mid’: 1,
‘screen’: 1,
‘model’: 1,
‘network’: ‘wifi’,
‘abtest’: ‘0’,
‘yduuid’: ‘abcdefg’,
}

url_with_params = f"{url}?{urlencode(params)}"

headers = {
    'Accept': 'application/json, text/plain, \*/\*',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Origin': 'https://fanyi.youdao.com',
    'Pragma': 'no-cache',
    'Referer': 'https://fanyi.youdao.com/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
    'Sec-Ch-Ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
    'Sec-Ch-Ua-Mobile': '?0',
    'Sec-Ch-Ua-Platform': '"Windows"'
}

# 请求
response = requests.get(url_with_params, headers=headers, data={})
json_data = json.loads(response.text)
# 获取 key

return json_data['data']

def send(chinese):
url = “https://dict.youdao.com/webtranslate”
mysticTime = get_timestamp()
data = init_data()
aesIv = data[‘aesIv’]
aesKey = data[‘aesKey’]
secretKey = data[‘secretKey’]
# sign 是 client=fanyideskweb&mysticTime=1711295634744&product=webfanyi&key=fsdsogkndfokasodnaso
tmp_sign = f"client=fanyideskweb&mysticTime={mysticTime}&product=webfanyi&key={secretKey}"
sign = hashlib.md5(tmp_sign.encode(“utf8”)).hexdigest()

payload = {
    'i': chinese,
    'from': 'auto',
    'to': '',
    'domain': '0',
    'dictResult': 'true',
    'keyid': 'webfanyi',
    'sign': sign,
    'client': 'fanyideskweb',
    'product': 'webfanyi',
    'appVersion': '1.0.0',
    'vendor': 'web',
    'pointParam': 'client,mysticTime,product',
    'mysticTime': mysticTime,
    'keyfrom': 'fanyi.web',
    'mid': 1,
    'screen': 1,
    'model': 1,
    'network': 'wifi',
    'abtest': '0',
    'yduuid': 'abcdefg',
}

headers = {
    'Accept': 'application/json, text/plain, \*/\*',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Cookie': 'OUTFOX\_SEARCH\_USER\_ID=-1545431425@10.55.164.248; OUTFOX\_SEARCH\_USER\_ID\_NCOO=1617400304.3454392',
    'Origin': 'https://fanyi.youdao.com',
    'Pragma': 'no-cache',
    'Referer': 'https://fanyi.youdao.com/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
    'sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"'
}

response = requests.post(url, headers=headers, data=payload)

encode_data = response.text
# 开始解密数据
print("encode\_data:", encode_data)
print("aesIv:", aesIv)
print("aesKey:", aesKey)
decode(encode_data, aesIv, aesKey)

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数Python工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Python开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以扫码获取!!!(备注:Python)

6381401c05e862fe4e9.png)

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新

如果你觉得这些内容对你有帮助,可以扫码获取!!!(备注:Python)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值