java implementation - strong intellectual educational system API documentation - time information

Time information to achieve

Because each has acquired access token, so I wrote a utility class

String getToken (String xh, String pwd) get token value

 

import net.sf.json.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.net.URISyntaxException;

public class Data {

    public String getToken(String xh,String pwd) throws URISyntaxException, IOException {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        URIBuilder uriBuilder = new URIBuilder("http://zswxyjw.minghuaetc.com/znlykjdxswxy/app.do");
        uriBuilder.setParameter("method","authUser").setParameter("xh",xh).setParameter("pwd",pwd);
        HttpGet httpGet = new HttpGet(uriBuilder.build());
        CloseableHttpResponse response = httpClient.execute(httpGet);
        String s = null;
        if(response.getStatusLine().getStatusCode()==200){
            HttpEntity entity = response.getEntity();
            s = EntityUtils.toString(entity, "utf-8");
        }
        JSONObject obj = new JSONObject();
        obj = obj.fromObject(s);
        Object token = obj.get("token");
        return  token.toString();
    }

}

  

Access to data

Strong intellectual API returns a JOSN file can be directly resolved by the Firefox browser

  • Code for
    1. Import jar package
    2. The code for

 

if(response.getStatusLine().getStatusCode()==200){
            HttpEntity entity = response.getEntity();
            s = EntityUtils.toString(entity, "utf-8");
        }
        JSONObject obj = new JSONObject();
        obj = obj.fromObject(s);
        Object token = obj.get("token");

  

I created a Maven project, so the jar package only needs to be added to the configuration information in the configuration file

 

        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <classifier>jdk15</classifier>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.7.0</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>net.sf.ezmorph</groupId>
            <artifactId>ezmorph</artifactId>
            <version>1.0.3</version>
        </dependency>

  

Specific implementation time information
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.net.URISyntaxException;

public class Test2 {
    public static void main(String[] args) throws URISyntaxException, IOException {
        String token = new Data().getToken("学号","密码");

        CloseableHttpClient httpClient = HttpClients.createDefault();
        URIBuilder uriBuilder = new URIBuilder("http://zswxyjw.minghuaetc.com/znlykjdxswxy/app.do");
        uriBuilder.setParameter("method","getCurrentTime").setParameter("currDate","2019-05-27");//YYYY-MM_DD  这里特别注意,MM DD一定要两位数,不足前面补零
        HttpGet httpGet = new HttpGet(uriBuilder.build());
        httpGet.setHeader("token",token);
        CloseableHttpResponse response = httpClient.execute(httpGet);
        String s = null;
        if(response.getStatusLine().getStatusCode()==200){
            HttpEntity entity = response.getEntity();
            s = EntityUtils.toString(entity, "utf-8");
            System.out.println(s);
        }
    }
}

  

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE1NTkwMzI3MDMsImF1ZCI6IjIwMTc3NTgzIn0.i0PW59S18U7WDk7wyKKZgEa3e2o3fQwi_XeIxipSM9U
GET
http://zswxyjw.minghuaetc.com/znlykjdxswxy/app.do?method=getCurrentTime&currDate=2019-05-27
HTTP/1.1
{“zc”:14,“e_time”:“2019-06-01”,“s_time”:“2019-05-26”,“xnxqh”:“2018-2019-2”}


Original: https: //blog.csdn.net/qq_40674583/article/details/90613863

 

Guess you like

Origin www.cnblogs.com/qbdj/p/10980993.html