//package cn.van.business.erp.request;
//
///**
// * @author Leo
// * @version 1.0
// * @create 2025/4/9 21:30
// * @description：
// */
//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
//import java.io.OutputStream;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.nio.charset.StandardCharsets;
//import java.security.MessageDigest;
//import java.security.NoSuchAlgorithmException;
//
//public class HttpTest {
//    private static long apiKey = 203413189371893L; // 开放平台提供的应用KEY
//    private static String apiKeySecret = "o9wl81dncmvby3ijpq7eur456zhgtaxs"; // 开放平台提供的应用密钥
//    private static String domain = "https://open.goofish.pro"; // 域名
//
//    public static void main(String[] args) {
//        // 获取当前时间戳
//        long timestamp = System.currentTimeMillis() / 1000L;
//
//        // 请求体JSON字符串
//        String productId = "220656347074629";
//        String jsonBody = "{\"product_id\":" + productId + "}";
//
//        // 生成签名
//        String sign = genSign(timestamp, jsonBody);
//
//        // 拼接请求地址
//        String apiUrl = domain + "/api/open/product/detail?appid=" + apiKey + "&timestamp=" + timestamp + "&sign="
//                + sign;
//
//        try {
//            // 创建URL对象
//            URL url = new URL(apiUrl);
//
//            // 打开连接
//            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//
//            // 设置请求方法为POST
//            connection.setRequestMethod("POST");
//
//            // 设置请求头部
//            connection.setRequestProperty("Content-Type", "application/json");
//            connection.setRequestProperty("Accept", "application/json");
//
//            // 启用输出流
//            connection.setDoOutput(true);
//
//            // 获取输出流并写入请求体
//            OutputStream outputStream = connection.getOutputStream();
//            outputStream.write(jsonBody.getBytes(StandardCharsets.UTF_8));
//            outputStream.close();
//
//            // 获取响应状态码
//            int responseCode = connection.getResponseCode();
//            System.out.println("API Response Code: " + responseCode);
//
//            // 读取响应内容
//            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
//            String line;
//            StringBuilder response = new StringBuilder();
//            while ((line = bufferedReader.readLine()) != null) {
//                response.append(line);
//            }
//            bufferedReader.close();
//
//            // 关闭连接
//            connection.disconnect();
//
//            System.out.println("API Response: " + response.toString());
//
//        } catch (IOException e) {
//            // 在此处处理异常
//            e.printStackTrace();
//        }
//    }
//
//    // md5加密
//    private static String genMd5(String str) {
//        StringBuilder result = new StringBuilder();
//        try {
//            MessageDigest md = MessageDigest.getInstance("MD5");
//            byte[] digest = md.digest(str.getBytes(StandardCharsets.UTF_8));
//            for (byte b : digest) {
//                result.append(String.format("%02x", b & 0xff));
//            }
//        } catch (NoSuchAlgorithmException e) {
//            throw new RuntimeException(e);
//        }
//        return result.toString();
//    }
//
//    // 生成签名
//    private static String genSign(long timestamp, String jsonStr) {
//        // 拼接字符串
//        String data = apiKey + "," + genMd5(jsonStr) + "," + timestamp + "," + apiKeySecret;
//
//        // 商务对接模式 拼接字符串
//        // String data = apiKey + "," + genMd5(jsonStr) + "," + timestamp + "," + seller_id + "," + apiKeySecret;
//
//        // 生成签名
//        return genMd5(data);
//    }
//}
