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();
    }
相关推荐
第二只羽毛17 分钟前
重载和继承的实践
java·开发语言
AndrewHZ21 分钟前
【图像处理基石】GIS图像处理入门:4个核心算法与Python实现(附完整代码)
图像处理·python·算法·计算机视觉·gis·cv·地理信息系统
王嘉俊92522 分钟前
设计模式--适配器模式:优雅解决接口不兼容问题
java·设计模式·适配器模式
王嘉俊92524 分钟前
设计模式--组合模式:统一处理树形结构的优雅设计
java·设计模式·组合模式
道199331 分钟前
50 台小型无人车与50套穿戴终端 5 公里范围内通信组网方案深度研究
java·后端·struts
迎風吹頭髮37 分钟前
UNIX下C语言编程与实践35-UNIX 守护进程编写:后台执行、脱离终端、清除掩码与信号处理
java·c语言·unix
光军oi1 小时前
全栈开发杂谈————JAVA微服务全套技术栈详解
java·开发语言·微服务
帮帮志1 小时前
目录【系列文章目录】-(关于帮帮志,关于作者)
java·开发语言·python·链表·交互
聪明的笨猪猪1 小时前
Java Spring “MVC ”面试清单(含超通俗生活案例与深度理解)
java·经验分享·笔记·面试
qiuiuiu4131 小时前
正点原子RK3568学习日记-GIT
linux·c语言·开发语言·单片机