Java爬虫携带sign签名

站点:https://www.mytokencap.com/

代码分析先不写了,大家自行解决,贴代码

1、业务请求设计

java 复制代码
public static void md5Pro() {
        String url = "https://api.mytokenapi.com/ticker/currencylistforall";
        Map<String, String> headers = new HashMap<>();
        headers.put("authority", "api.mytokenapi.com");
        headers.put("accept", "application/json, text/plain, */*");
        headers.put("accept-language", "en-GB,en;q=0.9,zh-CN;q=0.8,zh;q=0.7");
        headers.put("cache-control", "no-cache");
        headers.put("content-type", "application/x-www-form-urlencoded;charset=utf-8");
        headers.put("origin", "https://www.mytokencap.com");
        headers.put("pragma", "no-cache");
        headers.put("referer", "https://www.mytokencap.com/");
        headers.put("sec-ch-ua", "^\\^Not/A)Brand^^;v=^\\^99^^, ^\\^Google");
        headers.put("sec-ch-ua-mobile", "?0");
        headers.put("sec-ch-ua-platform", "^\\^Windows^^");
        headers.put("sec-fetch-dest", "empty");
        headers.put("sec-fetch-mode", "cors");
        headers.put("sec-fetch-site", "cross-site");
        headers.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36");

        long timestamp = System.currentTimeMillis();
        String code = MD5Example(timestamp + "9527" + String.valueOf(timestamp).substring(0, 6));
        System.out.println("签名---》" + code);
        Map<String, String> params = new HashMap<>();
        params.put("pages", "3,1");
        params.put("sizes", "100,100");
        params.put("subject", "market_cap");
        params.put("language", "en_US");
        params.put("timestamp", String.valueOf(timestamp));
        params.put("code", code);
        params.put("platform", "web_pc");
        params.put("v", "0.1.0");
        params.put("legal_currency", "USD");
        params.put("international", "1");

        try {
            String queryString = buildQueryString(params);
            String fullUrl = url + "?" + queryString;
            System.out.println("Full URL: " + fullUrl);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }


    }

2、MD5算法设计

java 复制代码
    public static String MD5Example(String text) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] messageDigest = md.digest(text.getBytes());
            StringBuilder hexString = new StringBuilder();
            for (byte b : messageDigest) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

3、查询参数拼接

java 复制代码
    public static String buildQueryString(Map<String, String> params) throws UnsupportedEncodingException {
        SortedMap<String, String> sortedParams = new TreeMap<>(params);
        StringBuilder query = new StringBuilder();
        for (Map.Entry<String, String> entry : sortedParams.entrySet()) {
            if (query.length() > 0) {
                query.append("&");
            }
            query.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
            query.append("=");
            query.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
        }
        return query.toString();
    }
相关推荐
永远睡不够的入3 分钟前
C++11新特性(2):深入 C++ 参数传递黑盒:从引用折叠到完美转发,再到可变参数模板
开发语言·c++
idolao3 分钟前
CentOS 7 安装 jprofiler_linux64_7_2_3.tar.gz 详细步骤(解压、配置、远程连接)
linux·python·centos
qq_206901395 分钟前
如何创建CDB公共用户_C##前缀强制规则与CONTAINER=ALL.txt
jvm·数据库·python
AndreasEmil5 分钟前
基于多设计模式的抽奖系统 - 测试报告
java·selenium·设计模式·postman
深度学习lover7 分钟前
<数据集>yolo 家庭垃圾识别<目标检测>
人工智能·python·yolo·目标检测·计算机视觉·家庭垃圾识别
无限进步_7 分钟前
【C++】寻找数组中出现次数超过一半的数字:三种解法深度剖析
开发语言·c++·git·算法·leetcode·github·visual studio
深邃-7 分钟前
【Web安全】-Kali,Linux配置(1):Kali网络配置,LinuxEnvConfig配置脚本,APT源的讲解,Kali设置中文
linux·运维·开发语言·网络·安全·web安全·网络安全
Hello World . .9 分钟前
Linux驱动编程:内核同步的艺术-从互斥到底半部
linux·开发语言·数据库
江山与紫云9 分钟前
告别重复造轮子:Codex写脚本
开发语言·python
星轨zb9 分钟前
什么是Spring设计模式:单例、工厂与代理
java·spring·设计模式