package com.sqx.common.utils; import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; 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 org.springframework.util.DigestUtils; import java.nio.charset.StandardCharsets; @Slf4j public class SignUtil { //获取快跑者平台签名 public static String getSign(String body, String dev_key, String team_token, String ticket, Long timestamp, Integer version) { String message = "body=" + body + "&dev_key=" + dev_key + "&team_token=" + team_token + "&ticket=" + ticket + "×tamp=" + timestamp + "&version=" + version + "WNEL248ZY8381W91EB66ZTULHBU176M9"; String sign = encryptToMD5(message); log.info("sign = " + sign); return sign; } public static String encryptToMD5(String str) { return DigestUtils.md5DigestAsHex(str.getBytes()); } public static void main(String[] args) { String sign = getSign("{ \"shop_id\": 147, \"shop_name\": \"创海测试店铺\", \"shop_tel\": \"15079248859\", \"shop_address\": \"江西省南昌市新建区黄家湖东路111号\", \"shop_tag\": \"115.827705,28.707832\", \"customer_name\": \"刘大人\", \"customer_tel\": \"15779631234\", \"customer_address\": \"新建区南昌交通学院(黄家湖校区)\", \"customer_tag\": \"115.827614,28.70773\", \"order_no\": \"202508150910421538\", \"pay_status\": 1 }", "31RRHA4O165VFN9W2DAPDYDH8N83BT12", "Q444DMV4LT8WSGRW", "05ffa0fe-2cb9-4350-86be-c2e625f43d3c", 1755504603L, 1); System.out.println("sign = " + sign); // JSONObject jsonObject = new JSONObject(); // jsonObject.put("name","三三"); // jsonObject.put("name2","三三2"); // String s = jsonObject.toString(); // System.out.println("s = " + s); // long currentTimeMillis = System.currentTimeMillis(); // long currentTimeSeconds = currentTimeMillis / 1000; // System.out.println("当前时间的秒级时间戳: " + currentTimeSeconds); } public void http() { try (CloseableHttpClient client = HttpClients.createDefault()) { HttpPost httpPost = new HttpPost("http://example.com/api"); String params = "key1=value1&key2=value2"; // 注意:这里不需要手动编码,HttpClient会处理它。 StringEntity entity = new StringEntity(params, StandardCharsets.UTF_8); entity.setContentType("application/x-www-form-urlencoded"); // 设置Content-Type为application/x-www-form-urlencoded,但不是必须的,HttpClient会自动设置。 httpPost.setEntity(entity); String responseBody = EntityUtils.toString(client.execute(httpPost).getEntity()); // 处理响应... System.out.println(responseBody); } catch (Exception e) { e.printStackTrace(); } } }