互億無線 · 文檔中心

企業(yè)工商四要素 - 代碼示例


Java對接企業(yè)工商信息核驗(yàn)接口DEMO示例
本文為您提供了Java語言版本的企業(yè)工商四要素核驗(yàn)對接DEMO示例

企業(yè)工商信息四要素接口文檔 點(diǎn)擊下載

企業(yè)工商部信息四要素接入指南 點(diǎn)擊訪問


import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

public class Main {

    private static final String iUrl = "https://api.ihuyi.com/idcard/Submit.json";

    public static void main(String[] args) {
        System.out.println("開始請求!");
        int mobile_code = (int)((Math.random()*9+1)*100000);
        String account = "xxxxxxxxx";
        String password = "xxxxxxxxxxxxxxxx";
		String name = '張三'
		String id_card_no = '123456789012345678'
		String ent_name = '上海xx公司'
		String ent_code = '987876xxxx'
        String currentTime = "" + (System.currentTimeMillis() / 1000L);
        String password_raw = account + password + app + name + id_card_no + ent_name + ent_code + currentTime;
        String passwordMd5 = MD5Encode(password_raw);
        String param = "account="+account+"&password="+passwordMd5+"&app="+app+"&name="+name+"&id_card_no="+id_card_no+"&ent_name="+ent_name+"&ent_code="+ent_code+"&time="+currentTime;
        String res = sendPost(iUrl, param);
        System.out.println(res);
    }

    /**
     * 向指定 URL 發(fā)送POST方法的請求
     *
     * @param url 發(fā)送請求的 URL
     * @param param 請求參數(shù),請求參數(shù)應(yīng)該是 name1=value1&name2=value2 的形式。
     * @return 所代表遠(yuǎn)程資源的響應(yīng)結(jié)果
     */
    public static String sendPost(String url, String param)
    {
        PrintWriter out = null;
        BufferedReader in = null;
        StringBuilder result = new StringBuilder();
        try{
            URL realUrl = new URL(iUrl);
            URLConnection conn = realUrl.openConnection();
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            conn.setRequestProperty("Accept-Charset", "utf-8");
            conn.setRequestProperty("contentType", "utf-8");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            out = new PrintWriter(conn.getOutputStream());
            out.print(param);
            out.flush();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
            String line;
            while ((line = in.readLine()) != null){
                result.append(line);
            }
            System.out.println("result:" + result);
        }catch (ConnectException e){
            System.out.println("調(diào)用sendPost ConnectException, url=" + url + ",param=" + param + e);
        }catch (SocketTimeoutException e){
            System.out.println("調(diào)用sendPost SocketTimeoutException, url=" + url + ",param=" + param + e);
        }catch (IOException e){
            System.out.println("調(diào)用sendPost IOException, url=" + url + ",param=" + param + e);
        }catch (Exception e){
            System.out.println("調(diào)用sendPost Exception, url=" + url + ",param=" + param + e);
        }finally{
            try{
                if (out != null){
                    out.close();
                }
                if (in != null){
                    in.close();
                }
            }catch (IOException ex){
                System.out.println("調(diào)用in.close Exception, url=" + url + ",param=" + param + ex);
            }
        }
        return result.toString();
    }

    //md5加密
    private final static String[] hexDigits = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
    private static String byteToHexString(byte b) {
        int n = b;
        if (n < 0)
            n = 256 + n;
        int d1 = n / 16;
        int d2 = n % 16;
        return hexDigits[d1] + hexDigits[d2];
    }
    public static String byteArrayToHexString(byte[] b) {
        StringBuffer resultSb = new StringBuffer();
        for (int i = 0; i < b.length; i++) {
            resultSb.append(byteToHexString(b[i]));
        }
        return resultSb.toString();
    }
    public static String MD5Encode(String origin) {
        String resultString = null;
        try {
            resultString = new String(origin);
            MessageDigest md = MessageDigest.getInstance("MD5");
            resultString = byteArrayToHexString(md.digest(resultString
                    .getBytes()));
        } catch (Exception ex) {
        }
        return resultString;
    }

}

現(xiàn)在注冊,即享新用戶禮包!

在線咨詢
電話咨詢

服務(wù)熱線:

4008 808 898

服務(wù)熱線(工作時間):

4008 808 898

業(yè)務(wù)咨詢(非工作時間):

售后咨詢(非工作時間):

驗(yàn)證碼已發(fā)送到您的手機(jī),請查收!

輸入驗(yàn)證碼后,點(diǎn)擊“開通體驗(yàn)賬戶”按鈕可立即開通體驗(yàn)賬戶。

收不到短信驗(yàn)證碼?
互億無線不提供接碼服務(wù),接碼用戶請勿點(diǎn)擊開通按鈕。
×