Skip to content

Commit d7f983f

Browse files
committed
提交demo
1 parent 24d9dae commit d7f983f

25 files changed

+769
-0
lines changed

.classpath

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15+
<attributes>
16+
<attribute name="optional" value="true"/>
17+
<attribute name="maven.pomderived" value="true"/>
18+
<attribute name="test" value="true"/>
19+
</attributes>
20+
</classpathentry>
21+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
22+
<attributes>
23+
<attribute name="maven.pomderived" value="true"/>
24+
</attributes>
25+
</classpathentry>
26+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
27+
<attributes>
28+
<attribute name="maven.pomderived" value="true"/>
29+
</attributes>
30+
</classpathentry>
31+
<classpathentry kind="src" path="target/generated-sources/annotations">
32+
<attributes>
33+
<attribute name="optional" value="true"/>
34+
<attribute name="maven.pomderived" value="true"/>
35+
<attribute name="ignore_optional_problems" value="true"/>
36+
<attribute name="m2e-apt" value="true"/>
37+
</attributes>
38+
</classpathentry>
39+
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
40+
<attributes>
41+
<attribute name="optional" value="true"/>
42+
<attribute name="maven.pomderived" value="true"/>
43+
<attribute name="ignore_optional_problems" value="true"/>
44+
<attribute name="m2e-apt" value="true"/>
45+
<attribute name="test" value="true"/>
46+
</attributes>
47+
</classpathentry>
48+
<classpathentry kind="output" path="target/classes"/>
49+
</classpath>

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.project

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>IotSharpDemo</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
<filteredResources>
24+
<filter>
25+
<id>1624020427937</id>
26+
<name></name>
27+
<type>30</type>
28+
<matcher>
29+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
30+
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
31+
</matcher>
32+
</filter>
33+
</filteredResources>
34+
</projectDescription>
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.apt.aptEnabled=false

.settings/org.eclipse.jdt.core.prefs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
3+
org.eclipse.jdt.core.compiler.compliance=11
4+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7+
org.eclipse.jdt.core.compiler.processAnnotations=disabled
8+
org.eclipse.jdt.core.compiler.release=disabled
9+
org.eclipse.jdt.core.compiler.source=11

.settings/org.eclipse.m2e.core.prefs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.configuration.updateBuildConfiguration": "interactive"
3+
}

pom.xml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>IotSharpDemo</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>11</maven.compiler.source>
13+
<maven.compiler.target>11</maven.compiler.target>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>org.apache.httpcomponents</groupId>
19+
<artifactId>httpclient</artifactId>
20+
<version>4.5.6</version>
21+
</dependency>
22+
23+
<dependency>
24+
<groupId>org.springframework</groupId>
25+
<artifactId>spring-web</artifactId>
26+
<version>5.3.6</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot</artifactId>
31+
<version>2.2.2.RELEASE</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-test</artifactId>
36+
<version>2.2.2.RELEASE</version>
37+
</dependency>
38+
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
39+
<dependency>
40+
<groupId>com.fasterxml.jackson.core</groupId>
41+
<artifactId>jackson-databind</artifactId>
42+
<version>2.12.3</version>
43+
</dependency>
44+
45+
46+
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
47+
<dependency>
48+
<groupId>com.fasterxml.jackson.core</groupId>
49+
<artifactId>jackson-core</artifactId>
50+
<version>2.12.3</version>
51+
</dependency>
52+
53+
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
54+
<dependency>
55+
<groupId>com.fasterxml.jackson.core</groupId>
56+
<artifactId>jackson-annotations</artifactId>
57+
<version>2.12.3</version>
58+
</dependency>
59+
</dependencies>
60+
</project>
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package iotsharp;
2+
3+
public abstract class CommonResult {
4+
String code;
5+
boolean succeeded;
6+
String msg;
7+
8+
public String getMsg() {
9+
return msg;
10+
}
11+
12+
public void setMsg(String msg) {
13+
this.msg = msg;
14+
}
15+
16+
public String getCode() {
17+
return code;
18+
}
19+
20+
public void setCode(String code) {
21+
this.code = code;
22+
}
23+
24+
public boolean isSucceeded() {
25+
return succeeded;
26+
}
27+
28+
public void setSucceeded(boolean succeeded) {
29+
this.succeeded = succeeded;
30+
}
31+
32+
33+
public static final String SUCCESSED="10000";
34+
35+
36+
37+
}

src/main/java/iotsharp/Main.java

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package iotsharp;
2+
3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.node.ObjectNode;
5+
import com.fasterxml.jackson.databind.util.JSONPObject;
6+
import iotsharp.models.DeviceIdentity;
7+
import iotsharp.models.UserInfo;
8+
import iotsharp.models.UserInfoResult;
9+
import iotsharp.models.UserResult;
10+
import org.springframework.boot.test.web.client.TestRestTemplate;
11+
import org.springframework.http.HttpEntity;
12+
import org.springframework.http.HttpHeaders;
13+
import org.springframework.http.HttpMethod;
14+
import org.springframework.http.MediaType;
15+
import org.springframework.web.client.RestTemplate;
16+
17+
import java.util.ArrayList;
18+
import java.util.Arrays;
19+
import java.util.List;
20+
import java.util.stream.Collectors;
21+
22+
public class Main {
23+
24+
private static final ObjectMapper objectMapper = new ObjectMapper();
25+
private static final String BASE_URL="http://localhost:2927";
26+
public static void main(String[] args) {
27+
System.out.println("this is Demo");
28+
//SignIn 登录
29+
RestTemplate testRestTemplate = new RestTemplate();
30+
var headers = new HttpHeaders();
31+
headers.setContentType(MediaType.APPLICATION_JSON);
32+
ObjectNode SignInObject = objectMapper.createObjectNode();
33+
SignInObject.put("password","Wq*1234/wq");
34+
SignInObject.put("userName","wq1234wq@163.com");
35+
HttpEntity<String> formEntity = new HttpEntity<String>(SignInObject.toString(), headers);
36+
var result= testRestTemplate.postForObject(BASE_URL+"/api/Account/Login",formEntity, UserResult.class);
37+
if(CommonResult.SUCCESSED.equals(result.getCode())){
38+
//获取用户详情
39+
String token=result.getToken().getAccess_token();
40+
headers=new HttpHeaders();
41+
headers.setContentType(MediaType.APPLICATION_JSON);
42+
headers.add("Authorization","Bearer "+token);
43+
HttpEntity<Object> entity = new HttpEntity<Object>(null, headers);
44+
var UserInfo = testRestTemplate.exchange(BASE_URL+"/api/Account/MyInfo", HttpMethod.GET,entity, UserInfoResult.class);
45+
//获取设备列表
46+
var devices = testRestTemplate.exchange(BASE_URL+"/api/Devices/Customers/"+ UserInfo.getBody().getData().getCustomer().getId(), HttpMethod.GET,entity, String.class);
47+
//获取设备Token
48+
String DeviceId="febb19a8-265c-4064-bb23-9062a1044e41";
49+
// DeviceId= Arrays.stream(devices).map((x)->x.getData().getId()).filter((x)->x.equals("The DeviceId you want")).findFirst();
50+
var deviceIdentity = testRestTemplate.exchange(BASE_URL+"/api/Devices/"+DeviceId+"/Identity", HttpMethod.GET,entity, DeviceIdentity.class);
51+
//上传遥测数据
52+
var deviceTelemetryheaders = new HttpHeaders();
53+
deviceTelemetryheaders.setContentType(MediaType.APPLICATION_JSON);
54+
deviceTelemetryheaders.add("Authorization","Bearer "+token);
55+
ObjectNode deviceTelemetryObject = objectMapper.createObjectNode();
56+
deviceTelemetryObject.put("additionalPropx","string");
57+
deviceTelemetryObject.put("additionalPropy","string");
58+
deviceTelemetryObject.put("additionalPropz","string");
59+
HttpEntity<String> deviceTelemetryEntity = new HttpEntity<String>(SignInObject.toString(), headers);
60+
var resultdeviceTelemetryEntity= testRestTemplate.postForObject(BASE_URL+"/api/Devices/"+deviceIdentity.getBody().getIdentityId()+"/Telemetry",deviceTelemetryEntity, String.class);
61+
System.out.println(resultdeviceTelemetryEntity.toString());
62+
63+
} else{
64+
65+
}
66+
67+
68+
69+
70+
}
71+
}

0 commit comments

Comments
 (0)