wjli
2024-04-08 fc96e4d7fc20dbec5d2d96c6e8c557c1cc3212d3
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
package cn.exrick.xboot.your.util;
 
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
 
@Component
public class ApplicationRunnerImpl implements ApplicationRunner {
 
    @Autowired
    private HaiKangPost haiKangPost;
    @Autowired
    private MQTT mqtt;
 
    @Override
    public void run(ApplicationArguments args) throws Exception {
        String topicInfo = haiKangPost.getTopicInfo();
        System.out.println("订阅信息:"+topicInfo);
        JSONObject jsonObject = JSONUtil.parseObj(topicInfo);
        if(jsonObject.get("data")!=null){
            String data = jsonObject.get("data").toString();
            JSONObject jsonObject2 = JSONUtil.parseObj(data);
            String clientId = jsonObject2.get("clientId").toString();
            String userName = jsonObject2.get("userName").toString();
            String password = jsonObject2.get("password").toString();
            mqtt.event(clientId,userName,password);
        }
 
    }
}