This commit is contained in:
雷欧(林平凡)
2025-08-15 11:32:43 +08:00
parent 75ffa2ad54
commit 72c51de7f8
2 changed files with 55 additions and 3 deletions

View File

@@ -0,0 +1,41 @@
package com.ruoyi.web.controller.jarvis;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.http.HttpUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
/**
* @author Leo
* @version 1.0
* @create 2025/8/15 10:53
* @description京东指令类
*/
@RestController
@RequestMapping("/jarvis/jdorder")
public class JDOrderController {
private final static String skey = "2192057370ef8140c201079969c956a3";
private final static String requestUrl = "http://192.168.8.88:6666/jd/";
@RequestMapping("/generatePromotionContent")
public String generatePromotionContent(String promotionContent) {
System.out.println(promotionContent);
String result = "";
try {
String url = requestUrl+ "generatePromotionContent";
JSONObject param = new JSONObject();
param.put("skey", skey);
param.put("promotionContent", promotionContent);
result = HttpUtils.sendJsonPost(url, param.toJSONString());
System.out.println(result);
} catch (Exception e) {
System.out.println(e.getMessage());
}
return result;
}
}

View File

@@ -25,7 +25,7 @@ import org.springframework.http.MediaType;
/** /**
* 通用http发送方法 * 通用http发送方法
* *
* @author ruoyi * @author ruoyi
*/ */
public class HttpUtils public class HttpUtils
@@ -129,10 +129,21 @@ public class HttpUtils
{ {
return sendPost(url, param, MediaType.APPLICATION_FORM_URLENCODED_VALUE); return sendPost(url, param, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
} }
/**
* 向指定 URL 发送POST方法的请求请求体为JSON格式
*
* @param url 发送请求的 URL
* @param json JSON格式的请求体
* @return 所代表远程资源的响应结果
*/
public static String sendJsonPost(String url, String json)
{
return sendPost(url, json, MediaType.APPLICATION_JSON_VALUE);
}
/** /**
* 向指定 URL 发送POST方法的请求 * 向指定 URL 发送POST方法的请求
* *
* @param url 发送请求的 URL * @param url 发送请求的 URL
* @param param 请求参数 * @param param 请求参数
* @param contentType 内容类型 * @param contentType 内容类型
@@ -290,4 +301,4 @@ public class HttpUtils
return true; return true;
} }
} }
} }