道路环境监测node后端和java后台代码
wangrong
2021-11-24 ac1a5f4542431c28b5865acbeb81985cefdbc2a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.example.demo.utils;
 
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
public class GetPlatformData {
 
    @Autowired
    private RestTemplate restTemplate;
 
//    public static String url= "http://faceopenapi.ymiot.net/api";
    /**
     * 平台分配的应用Id,用于标识用户,用户将APPID 放入访问请求,以便智能设备平台识别访问者的身份
     */
    public static String appid = "pm9776621402d9a9f1";
    /**
     * 用于加密签名字符串和服务器端验证签名字符串的密钥
     */
    public static String appsecret = "21a8667dc55140739bfa42d87928e8a1";
 
    /**
     * 获取平台社区的设备列表
     * @return
     */
    public String getDeviceList(){
        String url = "http://faceopenapi.ymiot.net/api/Device/GetDeviceList";
 
        //设备编号
//        String deviceno = "0A20050820860";
        //社区编号
        String communityno = "2005130013492251";
        String data = "{ \"pageindex\": \"1\",\"pagesize\": \"50\"}";
 
        String timestemp = (new SimpleDateFormat("yyyyMMddHHmmssSSS")).format(new Date());
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        Map<String, String> params = new HashMap<String, String>();
        params.put("appid", appid);
//        params.put("communityno",communityno);
        params.put("communityno", communityno);
        params.put("timestemp", timestemp);
        params.put("data", data);
        String sign = MD5.md5("&key=" + appsecret);
        params.put("sign", sign);
        JSONObject json = (JSONObject) JSONObject.toJSON(params);
//        String json = params.toString();
//        HttpEntity<Map<String, Object>> request = new HttpEntity<Map<String, Object>>(Collections.unmodifiableMap(params),headers);
//        JSONObject post = JSONObject.fromObject(request);
 
        ResponseEntity<String> entity = restTemplate.postForEntity(url, json, String.class);
 
        String body = entity.getBody();
        System.out.println(body);
        return null;
    }
 
    public String getCityList(){
        String url = "http://faceopenapi.ymiot.net/api/DataItem/GetCommunityByCity";
 
        //设备编号
//        String deviceno = "0A20050820860";
        //社区编号
//        String    communityno = "2005130013492251";
        String data = "{ \"community_cityno\": \"532502000000\"}";
//        String community_cityno = "532502000000";
 
        String timestemp = (new SimpleDateFormat("yyyyMMddHHmmssSSS")).format(new Date());
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        Map<String, String> params = new HashMap<String, String>();
        params.put("appid", appid);
//        params.put("communityno",communityno);
//        params.put("communityno", communityno);
        params.put("timestemp", timestemp);
 
//        params.put("data", data);
        String sign = MD5.md5("&key=" + appsecret);
        params.put("sign", sign);
        JSONObject json = (JSONObject) JSONObject.toJSON(params);
//        String json = params.toString();
//        HttpEntity<Map<String, Object>> request = new HttpEntity<Map<String, Object>>(Collections.unmodifiableMap(params),headers);
//        JSONObject post = JSONObject.fromObject(request);
 
        ResponseEntity<String> entity = restTemplate.postForEntity(url, json, String.class);
 
        String body = entity.getBody();
        System.out.println(body);
        return null;
    }
 
    public String getProvideList(){
        String url = "\thttp://faceopenapi.ymiot.net/api/DataItem/GetProvince";
        String timestemp = (new SimpleDateFormat("yyyyMMddHHmmssSSS")).format(new Date());
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        Map<String, String> params = new HashMap<String, String>();
        params.put("appid", appid);
//        params.put("communityno",communityno);
//        params.put("communityno", communityno);
        params.put("timestemp", timestemp);
 
//        params.put("data", data);
        String sign = MD5.md5("&key=" + appsecret);
        params.put("sign", sign);
        JSONObject json = (JSONObject) JSONObject.toJSON(params);
//        String json = params.toString();
//        HttpEntity<Map<String, Object>> request = new HttpEntity<Map<String, Object>>(Collections.unmodifiableMap(params),headers);
//        JSONObject post = JSONObject.fromObject(request);
 
        ResponseEntity<String> entity = restTemplate.postForEntity(url, json, String.class);
 
        String body = entity.getBody();
        System.out.println(body);
        return null;
    }
}