//package org.jeecg.modules.api.controller;
//
//import io.swagger.annotations.Api;
//import lombok.extern.slf4j.Slf4j;
//import org.jeecg.common.api.vo.Result;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.io.IOException;
//import java.security.NoSuchAlgorithmException;
//
//import org.apache.http.HttpEntity;
//import org.apache.http.HttpResponse;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.entity.StringEntity;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.impl.client.HttpClients;
//import org.apache.http.util.EntityUtils;
//
//import java.io.IOException;
//import java.security.MessageDigest;
//import java.security.NoSuchAlgorithmException;
//import java.nio.charset.StandardCharsets;
//import java.util.ArrayList;
//import java.util.Base64;
//
//
//@Api(tags="短信接口")
//@RestController
//@RequestMapping("/post")
//@Slf4j
//public class SmsController {
//
//
//    public Result<?> sendSms(String phone, String code) throws IOException, NoSuchAlgorithmException {
//
//        // 设置基本请求参数
//        String userName = "your_username";
//        String password = "your_password";
//        long timestamp = System.currentTimeMillis();
//        String sendTime = null; // 如果需要定时发送，请设置此值
//
//        // 计算sign
//        String sign = calculateSign(userName, timestamp, password);
//
//        // 构造messageList
//        ArrayList<Object> messageList = new ArrayList<>();
//        // 添加多个JSON对象到messageList，这里只添加一个作为示例
//        messageList.add(createMessageJson("12345678901", "Hello, this is a test message", null, null));
//
//        // 将messageList和其他参数转换为JSON字符串
//        String requestBody = createRequestBody(userName, messageList, timestamp, sign, sendTime);
//
//        // 发送POST请求
//        CloseableHttpClient httpClient = HttpClients.createDefault();
//        HttpPost httpPost = new HttpPost("http://agent.izjun.com:8001/sms/api/sendMessageOne");
//
//        // 设置请求头
//        httpPost.setHeader("Accept", "application/json");
//        httpPost.setHeader("Content-Type", "application/json;charset=utf-8");
//
//        // 设置请求体
//        StringEntity entity = new StringEntity(requestBody, StandardCharsets.UTF_8);
//        httpPost.setEntity(entity);
//
//        // 执行请求并处理响应
//        HttpResponse response = httpClient.execute(httpPost);
//        HttpEntity responseEntity = response.getEntity();
//        if (responseEntity != null) {
//            System.out.println(EntityUtils.toString(responseEntity));
//        }
//
//        // 关闭连接
//        httpClient.close();
//
//
//        return Result.OK();
//    }
//
//
//    private static String calculateSign(String userName, long timestamp, String password) throws NoSuchAlgorithmException {
//        MessageDigest md5 = MessageDigest.getInstance("MD5");
//        md5.update(password.getBytes(StandardCharsets.UTF_8));
//        byte[] passwordHash = md5.digest();
//
//        StringBuilder sb = new StringBuilder();
//        sb.append(userName).append(timestamp).append(new String(Base64.getEncoder().encode(passwordHash)));
//
//        md5.reset();
//        md5.update(sb.toString().getBytes(StandardCharsets.UTF_8));
//        byte[] digest = md5.digest();
//        StringBuilder hexString = new StringBuilder();
//        for (byte b : digest) {
//            String hex = Integer.toHexString(0xff & b);
//            if (hex.length() == 1) hexString.append('0');
//            hexString.append(hex);
//        }
//        return hexString.toString();
//    }
//
//    private static String createRequestBody(String userName, ArrayList<Object> messageList, long timestamp, String sign, String sendTime) {
//        // 这里省略了将Java对象转换为JSON字符串的过程，您可以使用像Jackson或Gson这样的库来完成
//        // 示例中仅返回JSON字符串的伪代码表示
//        return "";
//    }
//
//
//}
