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

---
 libs/iailab-plat-sdk-1.0.0.jar                            |    0 
 libs/iailab-plat-sdk-1.0.0-jar-with-dependencies.jar      |    0 
 src/main/java/com/iailab/sdk/demo/HttpClientDemo.java     |   30 ++++++++++--------------------
 src/test/java/com/iailab/sdk/demo/HttpClientDemoTest.java |   10 +++-------
 src/main/resources/application.yaml                       |    5 ++---
 README.md                                                 |    6 +++---
 6 files changed, 18 insertions(+), 33 deletions(-)

diff --git a/README.md b/README.md
index 446a122..b2f1546 100644
--- a/README.md
+++ b/README.md
@@ -4,9 +4,9 @@
 * `iailab-plat-sdk-1.0.0.jar`包内不包含依赖包,使用的时候需要引用其依赖;`iailab-plat-sdk-1.0.0-jar-with-dependencies.jar`内已经包含依赖,二者用其一
 * 获取平台授权token后可以自行存储封装`accessToken`和`refreshToken`,在请求平台接口时,将`accessToken`和`tenantId`按照下图添加到请求headers中
 ![img_1.png](img_1.png)
-* 鉴权token `accessToken`和刷新token `refreshToken`有效期都是在平台配置配置的,当鉴权token过期后,使用`refreshToken`重新刷新accessToken并存储使用(IailabAuthClient.refreshToken());
- 当刷新`refreshToken`也过期后,需要重新请求授权接口授权(`IailabAuthClient.authenticate()`)
-* 租户id:`tenant-id`、租户OAuth2客户端id:`client-id`、租户OAuth2客户端密钥:`client-secret`、租户登录账号:`username`、租户登录密码:`password`都是在平台事先配置好的
+* 鉴权token `accessToken`和刷新token `refreshToken`有效期都是在平台配置配置的,当鉴权token过期后,使用`refreshToken`重新刷新accessToken并存储使用(IailabClient.refreshToken());
+ 当刷新`refreshToken`也过期后,需要重新请求授权接口授权(`IailabClient.authenticate()`)
+* 租户id:`tenant-id`、租户OAuth2客户端id:`client-id`、租户OAuth2客户端密钥:`client-secret`、租户登录账号:`username`是在平台事先配置好的
 * 此demo使用`HttpClientDemoTest`进行的测试
 ![img.png](img.png)
 
diff --git a/libs/iailab-plat-sdk-1.0.0-jar-with-dependencies.jar b/libs/iailab-plat-sdk-1.0.0-jar-with-dependencies.jar
index 0361cd1..29ede75 100644
--- a/libs/iailab-plat-sdk-1.0.0-jar-with-dependencies.jar
+++ b/libs/iailab-plat-sdk-1.0.0-jar-with-dependencies.jar
Binary files differ
diff --git a/libs/iailab-plat-sdk-1.0.0.jar b/libs/iailab-plat-sdk-1.0.0.jar
index 80a8d22..84917bc 100644
--- a/libs/iailab-plat-sdk-1.0.0.jar
+++ b/libs/iailab-plat-sdk-1.0.0.jar
Binary files differ
diff --git a/src/main/java/com/iailab/sdk/demo/HttpClientDemo.java b/src/main/java/com/iailab/sdk/demo/HttpClientDemo.java
index 3c8580b..1f386ef 100644
--- a/src/main/java/com/iailab/sdk/demo/HttpClientDemo.java
+++ b/src/main/java/com/iailab/sdk/demo/HttpClientDemo.java
@@ -1,6 +1,7 @@
 package com.iailab.sdk.demo;
 
-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 org.springframework.web.bind.annotation.RestController;
@@ -20,7 +21,7 @@
      * 获取平台授权token及refreshToken
      */
     public void authenticate() {
-        TokenDTO authenticate = IailabAuthClient.authenticate();
+        TokenDTO authenticate = IailabClient.authenticate();
         System.out.println(authenticate);
     }
 
@@ -29,27 +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 Map<String, Object> queryPointsRealValue() throws Exception {
+    public CommonResult<Map<String, Object>> queryPointsRealValue() throws Exception {
         List<String> pointNos = new ArrayList<>();
-        pointNos.add("111");
-        return IailabAuthClient.getInstance().queryPointsRealValue(pointNos);
-    }
-
-    public Map<String, Object> queryPlanChart() throws Exception {
-        ApiDataQueryDTO apiDataQueryDTO = new ApiDataQueryDTO();
-        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);
-        return IailabAuthClient.getInstance().queryPlanChart(apiDataQueryDTO);
+        pointNos.add("F0000120031");
+        return IailabClient.getInstance().queryPointsRealValue(pointNos);
     }
 
     /**
@@ -65,7 +55,7 @@
         params.put("granularity", null);
         itemNos.add("P0000100010");
         params.put("itemNos", itemNos);
-        String s = IailabAuthClient.doHttp("POST", "http://172.16.8.100/admin-api/data/api/query-plans/chart", params);
+        String s = IailabClient.doHttp("POST", "http://172.16.8.100/admin-api/data/api/query-plans/chart", params);
         System.out.println(s);
     }
 
@@ -76,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", "http://172.16.8.100/admin-api/data/api/device-value", params);
+        String s = IailabClient.doHttp("get", "http://172.16.8.100/admin-api/data/api/device-value", params);
         System.out.println(s);
     }
 }
diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml
index 435cf7a..62d4de5 100644
--- a/src/main/resources/application.yaml
+++ b/src/main/resources/application.yaml
@@ -14,8 +14,7 @@
     base-url: http://172.16.8.100/admin-api #平台接口url,使用时需修改成真实的ip和端口
     tenant-id: 172 #租户id
     client-id: shasteel #租户OAuth2客户端id
-    client-secret: shasteel111111111111111 #租户OAuth2客户端密钥
-    username: shasteel #租户登录账号
-    password: 123456 #租户登录密码
+    client-secret: S3mYv7LkF1xJtQqWp9rZ2cVb8N6hT0D #租户OAuth2客户端密钥
+    username: shasteel
 
 debug: true
diff --git a/src/test/java/com/iailab/sdk/demo/HttpClientDemoTest.java b/src/test/java/com/iailab/sdk/demo/HttpClientDemoTest.java
index 880f477..7a62ee0 100644
--- a/src/test/java/com/iailab/sdk/demo/HttpClientDemoTest.java
+++ b/src/test/java/com/iailab/sdk/demo/HttpClientDemoTest.java
@@ -1,5 +1,6 @@
 package com.iailab.sdk.demo;
 
+import com.iailab.sdk.auth.client.common.pojo.CommonResult;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,16 +28,11 @@
         httpClientDemo.refreshToken();
     }
 
-    @Test
-    public void testQueryPlanChart() throws Exception {
-        Map<String, Object> stringObjectMap = httpClientDemo.queryPlanChart();
-        System.out.println(stringObjectMap);
-    }
 
     @Test
     public void testQueryPointsRealValue() throws Exception {
-        Map<String, Object> stringObjectMap = httpClientDemo.queryPointsRealValue();
-        System.out.println(stringObjectMap);
+        CommonResult<Map<String, Object>> mapCommonResult = httpClientDemo.queryPointsRealValue();
+        System.out.println(mapCommonResult.getData());
     }
 
     @Test

--
Gitblit v1.9.3