package com.jkcredit.invoice.util; import net.sf.json.JSONObject; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Iterator; /** * Created by zhangqingxin Date : 16/11/6 Time : 10:41 *
* 参考一(HttpClient):http://mvnrepository.com/artifact/commons-httpclient/commons- * httpclient/3.1 * 参考一(json-lib):http://mvnrepository.com/artifact/net.sf.json-lib/json-lib/2.4 */ public class QueryDemo_Test { /** * 测试地址 */ // private static final String URL = "http://110.88.150.74:80/credit?api=credit.sec.data"; //private static final String URL = "http://110.88.150.74/credit?api=credit.sec.data"; // private static final String URL = "http://123.57.186.204/gateway?api=credit.sec.data"; //private static final String URL = "http://123.57.186.204/gateway?api=credit.sec.data"; //private static final String URL = "http://192.168.50.4:18080/gateway?api=credit.sec.data";//北京节点 private static final String URL = "https://credit.h11.site/gateway?api=credit.sec.data"; // private static final String URL = "http://127.0.0.1:18080/gateway?api=credit.sec.data"; // private static final String URL = "http://110.88.150.68:8000/gateway?api=credit.sec.data"; // private static final String URL = "http://110.88.150.72:8000/gateway?api=credit.sec.data_test"; // private static final String URL = "http://60.205.114.163:8000/gateway?api=credit.sec.data"; //private static final String URL = " http://45.126.120.88/gateway?api=credit.sec.data_test"; // private static final String URL = " http://45.126.120.88/gateway?api=credit.sec.data"; // private static final String URL = " http://119.18.195.163/gateway?api=credit.sec.data"; /** * 分配的appKey */ // private static final String APP_KEY = "jkxy"; // private static final String appKey = "junxin_test"; private static final String appKey = "DATA_TEST"; //private static final String appKey = "JIAO_KE"; //private static final String appKey = "HANGZHOU_JUNXIN_72"; /**290dec3f6a243889e5ed3210cf1ad499 * 方法入口 * * @param args */ public static void main(String args[]) throws Exception { QueryDemo_Test demo = new QueryDemo_Test(); demo.runMainService(); } /** * 调用主接口 */ public void runMainService() { try { /** * 实名demo */ JSONObject paramJsonObj = initParamJsonObj_Realname(); String ret = postClient(URL, paramJsonObj); System.out.println(ret); } catch (Exception e) { e.printStackTrace(); } } /** * 整合参数(实名认证) * * @return */ public JSONObject initParamJsonObj_Realname() { /** * 基本参数 */ JSONObject paramJsonObj = new JSONObject(); paramJsonObj.put("api", "CMCC_STATUS_CHECK_V7");//CMCC_3RD_DETAIL_V15//CMCC_2ND_V27G//CMCC_3RD_DETAIL_V32B//CMCC_ONLINE_CHECK_V8//CMCC_STATUS_CHECK_V7 paramJsonObj.put("appKey", appKey); paramJsonObj.put("appSecret", // "D78C393359BF128715C65D91C67051478A4DFC13"); "C41DF125F0C23FBBB83E461F5045A30ACB3FF55A"); /** * 业务参数 */ JSONObject dataJson = initMainServiceParamJsonObj_Realname(); paramJsonObj.put("data", dataJson); return paramJsonObj; } /* * 初始化业务参数(实名认证) * * 姓名,身份证,手机号 * * @return */ public JSONObject initMainServiceParamJsonObj_Realname() { /** * 具体业务参数放在data中 */ JSONObject dataJson = new JSONObject(); dataJson.put("name","陈春灵"); dataJson.put("mobile","19846930551"); dataJson.put("id_number","372926198502202847"); return dataJson; } /** * 实现http post请求 注意编码 UTF-8 * * @param url * @param paramObj * @return */ public String postClient(String url, JSONObject paramObj) { String str = ""; HttpClient client = null; PostMethod method = null; try { client = new HttpClient(); method = new PostMethod(url); method.setRequestHeader("Content-Type", "application/json;charset=utf-8"); NameValuePair[] param = new NameValuePair[paramObj.size()]; @SuppressWarnings("unchecked") Iterator