• Java操作百度身份证API


    网址:http://apistore.baidu.com/

    点击功能进行复制代码,就拿百度的身份证API 举例子:

    http://apistore.baidu.com/apiworks/servicedetail/113.html

     

    Java 代码:

    String httpUrl = "http://apis.baidu.com/apistore/idservice/id";

    String httpArg = "id=420984198704207896";

    String jsonResult = request(httpUrl, httpArg);

    System.out.println(jsonResult);

     

    /**

    * @param urlAll

    * :请求接口

    * @param httpArg

    * :参数

    * @return 返回结果

    */

    public static String request(String httpUrl, String httpArg) {

    BufferedReader reader = null;

    String result = null;

    StringBuffer sbf = new StringBuffer();

    httpUrl = httpUrl + "?" + httpArg;

     

    try {

    URL url = new URL(httpUrl);

    HttpURLConnection connection = (HttpURLConnection) url

    .openConnection();

    connection.setRequestMethod("GET");

    // 填入apikeyHTTP header

    connection.setRequestProperty("apikey", "您自己的apikey");

    connection.connect();

    InputStream is = connection.getInputStream();

    reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));

    String strRead = null;

    while ((strRead = reader.readLine()) != null) {

    sbf.append(strRead);

    sbf.append(" ");

    }

    reader.close();

    result = sbf.toString();

    } catch (Exception e) {

    e.printStackTrace();

    }

    return result;

    }

    填入自己的apikey

     

    接下来就是切割字符串了

    1. 将Unicode转为汉字返回

    public static String convert(String utfString){

            StringBuilder sb = new StringBuilder();

            int i = -1;

            int pos = 0;

            

            while((i=utfString.indexOf("\u", pos)) != -1){

                sb.append(utfString.substring(pos, i));

                if(i+5 < utfString.length()){

                    pos = i+6;

                    sb.append((char)Integer.parseInt(utfString.substring(i+2, i+6), 16));

                }

            }

            

            return sb.toString();

        }

  • 相关阅读:
    http4j
    EmbeddedBrowser
    curl v www.linode.com查看请求及响应信息
    JRUN
    PAC Manager: Ubuntu 上强大的 SSH 帐号管理工具,可取代 SecureCRT
    centos下载地址
    Web应用调试:现在是Weinre和JSConsole,最终会是WebKit的远程调试协议
    用ClusterSSH管理多台Linux服务器(2)
    Ubuntu + IntelliJ + Maven + Jetty + JRebel
    Java的连接池程序
  • 原文地址:https://www.cnblogs.com/chengzhipcx/p/4629627.html
Copyright © 2020-2023  润新知