From c09880d791eccb623be595aeb11d6ce0c4561a3f Mon Sep 17 00:00:00 2001 From: houzhongjian <houzhongyi@126.com> Date: 星期五, 14 三月 2025 15:50:46 +0800 Subject: [PATCH] sdk密码授权模式修改为客户端模式,只需要用户名和客户端id、secret --- src/main/java/com/iailab/sdk/demo/HttpClientDemo.java | 67 +++++++-------------------------- 1 files changed, 15 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/iailab/sdk/demo/HttpClientDemo.java b/src/main/java/com/iailab/sdk/demo/HttpClientDemo.java index e66e3b2..1f386ef 100644 --- a/src/main/java/com/iailab/sdk/demo/HttpClientDemo.java +++ b/src/main/java/com/iailab/sdk/demo/HttpClientDemo.java @@ -1,12 +1,9 @@ package com.iailab.sdk.demo; -import com.alibaba.fastjson.JSON; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.iailab.sdk.auth.client.IailabAuthClient; +import com.iailab.sdk.auth.client.IailabClient; +import com.iailab.sdk.auth.client.common.pojo.CommonResult; +import com.iailab.sdk.auth.client.dto.ApiDataQueryDTO; import com.iailab.sdk.auth.client.dto.TokenDTO; -import com.iailab.sdk.demo.dto.ApiDataQueryDTO; -import com.iailab.sdk.util.http.IailabHttpUtils; -import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RestController; import java.text.SimpleDateFormat; @@ -19,53 +16,12 @@ @RestController public class HttpClientDemo { - @Value("${iailab.token.base-url}") - private String baseUrl; - - @Value("${iailab.api.user-simple-list}") - private String userSimpleList; - - @Value("${iailab.api.query-plans-chart}") - private String queryPlansChart; - - @Value("${iailab.api.device-value}") - private String deviceValue; - - /** - * 无参get请求测试 - * @throws Exception - */ - public void HttpGet() throws Exception { - String s = IailabHttpUtils.doGet(baseUrl + userSimpleList, null, "utf-8"); - System.out.println(s); - } - - public void HttpPost() throws Exception { - ApiDataQueryDTO apiDataQueryDTO = new ApiDataQueryDTO(); - ObjectMapper objectMapper = new ObjectMapper(); - List<String> itemNos = new ArrayList<>(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - apiDataQueryDTO.setStart(sdf.parse("2024-06-11 07:24:00")); - apiDataQueryDTO.setEnd(sdf.parse("2024-06-13 00:00:00")); - itemNos.add("P0000100010"); - apiDataQueryDTO.setItemNos(itemNos); - String jsonString = objectMapper.writeValueAsString(apiDataQueryDTO); - String s = IailabHttpUtils.doPost(baseUrl + queryPlansChart, jsonString, "utf-8"); - System.out.println(s); - } - - public void HttpGetDeviceValue() throws Exception { - Map<String, Object> params = new HashMap<>(); - params.put("pointNos", "M0000101158,M0000101157,M0000101156,M0000101155,F0000120026"); - String s = IailabHttpUtils.doGet(baseUrl + deviceValue, params, "utf-8"); - System.out.println(s); - } /** * 获取平台授权token及refreshToken */ public void authenticate() { - TokenDTO authenticate = IailabAuthClient.authenticate(); + TokenDTO authenticate = IailabClient.authenticate(); System.out.println(authenticate); } @@ -74,9 +30,16 @@ * @throws Exception */ public void refreshToken() throws Exception { - IailabAuthClient.authenticate(); - TokenDTO authenticate = IailabAuthClient.refreshToken(); + IailabClient.authenticate(); + TokenDTO authenticate = IailabClient.refreshToken(); System.out.println(authenticate); + } + + + public CommonResult<Map<String, Object>> queryPointsRealValue() throws Exception { + List<String> pointNos = new ArrayList<>(); + pointNos.add("F0000120031"); + return IailabClient.getInstance().queryPointsRealValue(pointNos); } /** @@ -92,7 +55,7 @@ params.put("granularity", null); itemNos.add("P0000100010"); params.put("itemNos", itemNos); - String s = IailabAuthClient.doHttp("POST", baseUrl + queryPlansChart, params); + String s = IailabClient.doHttp("POST", "http://172.16.8.100/admin-api/data/api/query-plans/chart", params); System.out.println(s); } @@ -103,7 +66,7 @@ public void doHttpGet() throws Exception { Map<String, Object> params = new HashMap<>(); params.put("pointNos", "M0000101158,M0000101157,M0000101156,M0000101155,F0000120026"); - String s = IailabAuthClient.doHttp("get", baseUrl + deviceValue, params); + String s = IailabClient.doHttp("get", "http://172.16.8.100/admin-api/data/api/device-value", params); System.out.println(s); } } -- Gitblit v1.9.3