腾讯翻译接口 破解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hujingshuang/article/details/80186576

前面分别介绍了《有道翻译接口 破解》《谷歌翻译接口 破解》及《百度翻译接口 破解》,下面来尝试一下腾讯翻译接口(Github地址,欢迎star)。
老规矩,上图:
审查元素
可得到 Request URL 和 Request Method,接着往下看:
审查元素
根据上图,我们知道未知的参数是 sessionUuid 。通过多次试验,发现从结构上,是由字符串“translate_uuid” + 随机数 得到。经过之前对另外几个接口的破解,我们大概可以猜测到这个随机数跟时间有关系。
猜测归猜测,动手验证一下。经过关键字搜索,我在 js 代码中发现了这个 uuid 的生成由来,如下:
审查元素
将上述 js 代码格式化,然后再次搜索关键字,得到:
js 代码片段
明显,这个 uuid 直接使用的系统时间,再次验证了我们的想法。
剩下的就是进行代码实现了,如下:

public class Tencent {
    public static void main(String[] args) throws Exception{
        String from = "en";
        String to = "zh";
        String q = "Who are you?What do you want to do?";

        Map<String, String> params = new HashMap<>();
        params.put("source", from);
        params.put("target", to);
        params.put("sourceText", q);
        params.put("sessionUuid", "translate_uuid" + String.valueOf(System.currentTimeMillis()));

        String url = "http://fanyi.qq.com/api/translate";

        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost request = new HttpPost(url);
        request.setEntity(new UrlEncodedFormEntity(util.convertParams(params), "UTF-8"));

        request.setHeader("Cookie", "fy_guid=d4480e20-1644-4a47-a98d-787cfa244fd2;qtv=45db6800eff8077d;qtk=vwCc8qMPUDnXjoyGCPEOWs/VJlGgE/T9rZxCBZ91BvuJncfjxAfUsureuGWhZFnF8L15Hyh/zO4Ari0fz2gOo/AaSpJmdRvReb95XBFWn14m+fRcQfq/LGYQ34KWxbXxJpxDtJyO+LPG6SpryVf1kg==;");
        request.setHeader("Origin", "http://fanyi.qq.com");

        CloseableHttpResponse response = httpClient.execute(request);
        HttpEntity entity = response.getEntity();
        String result = EntityUtils.toString(entity, "utf-8");
        System.out.println(result);
        EntityUtils.consume(entity);

        response.getEntity().getContent().close();
        response.close();
    }
}

注意:需要设置 cookie,否则会出错。

猜你喜欢

转载自blog.csdn.net/hujingshuang/article/details/80186576