Bladeren bron

feat:封装http下发请求携带token

韩帛霖 1 jaar geleden
bovenliggende
commit
cef05ec91a
1 gewijzigde bestanden met toevoegingen van 11 en 6 verwijderingen
  1. 11 6
      ruoyi-common/src/main/java/com/ruoyi/common/utils/http/sending.java

+ 11 - 6
ruoyi-common/src/main/java/com/ruoyi/common/utils/http/sending.java

@@ -16,14 +16,10 @@ public class sending<T> {
     @Autowired
     private BpmProperties bpmProperties;
 
-
     // 创建RestTemplate实例
     RestTemplate restTemplate = new RestTemplate();
 
-    /**
-     * 执行流程排产
-     */
-    public HttpStatus sendCommonUpdate(T param) {
+    public HttpStatus sendCommonPOST(String url, T param) {
         // 得到当前用户的token  下发流程请求需要携带
         String token = SecurityUtils.getLoginUser().getToken();
         // 设置请求头
@@ -34,7 +30,7 @@ public class sending<T> {
         // 将请求体和请求头添加到HttpEntity
         HttpEntity<Map<String, Object>> requestEntity = (HttpEntity<Map<String, Object>>) new HttpEntity<>(param, headers);
         // 发送POST请求
-        ResponseEntity<String> response = restTemplate.exchange(bpmProperties.formCommonUpdateIp, HttpMethod.PUT, requestEntity, String.class);
+        ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
         // 处理响应
         if (response.getStatusCode().is2xxSuccessful()) {
             String responseBody = response.getBody();
@@ -44,4 +40,13 @@ public class sending<T> {
             return response.getStatusCode();
         }
     }
+
+
+    /**
+     * 执行流程排产
+     */
+    public HttpStatus sendCommonUpdate(T param) {
+        return this.sendCommonPOST(bpmProperties.formCommonUpdateIp, param);
+    }
+
 }