fuliqi
2024-08-28 9f5b9db2c8cdbcf74bd2eecefc3557d4048b8d4c
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
package com.ycl.api.HK;
 
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
 
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;
import java.net.URI;
 
@Slf4j
public class HKApi {
    public static void getOsdByIP(String ip) {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        String hostUrl = "http://" + ip;
        // 获取焦距
        String url = hostUrl + "/ISAPI/System/Video/inputs/channels/1/overlays";
        URI serverURI = null;
        try {
            serverURI = new URI(url);
            HttpGet httpGet = new HttpGet(url);
            String username = "admin";
            String password = "zg@2024dx";
            Credentials creds = new UsernamePasswordCredentials(username,
                    password);
            httpclient.getCredentialsProvider().
 
                    setCredentials(
                            new AuthScope(serverURI.getHost(), serverURI.
 
                                    getPort()), (Credentials) creds);
 
            HttpResponse response = httpclient.execute(httpGet);
 
            String resultString = EntityUtils.toString(response.getEntity(), "utf-8");
            log.info(resultString);
            //解析xml
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document document = builder.parse(new InputSource(new StringReader(resultString)));
            document.getDocumentElement().normalize();
            NodeList nodeList = document.getElementsByTagName("TextOverlay");
            for (int i = 0; i < nodeList.getLength(); i++) {
                Node node = nodeList.item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE) {
                    Element element = (Element) node;
                    log.info("TEXT : " + element.getElementsByTagName("displayText").item(0).getTextContent());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}