123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- 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
- * <p/>
- * 参考一(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 QueryDemoScm_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://www.h11.site/gateway?api=credit.sec.data";//北京节点
- //private static final String URL = "http://jk.h11.site/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.68:8000/gateway?api=credit.sec.data_test";
- // 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 appKey = "DATA_TEST";
- // 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 {
- QueryDemoScm_Test demo = new QueryDemoScm_Test();
- demo.runMainService();
- }
- /**
- * 流转字符串
- *
- * @param is
- * @return
- */
- public static String convertStreamToString(InputStream is) {
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- StringBuilder builder = new StringBuilder();
- String line = null;
- try {
- while ((line = reader.readLine()) != null) {
- builder.append(line + "\n");
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- is.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return builder.toString();
- }
- /**
- * 调用主接口
- */
- 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_REENTRYNET_QUERY_V5");//CMCC_MOBILE_CHECK_V8//CMCC_3RD_V2//CMCC_3RD_DETAIL_V1//
- //paramJsonObj.put("api", "MSISDNMD5TOIMEI");//MOBILE_CHECK_V1//CMCC_3RD_VERIFY_V4//CTCC_CHECK_V1//CMCC_ONLINE_CHECK_V5
- 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("id_number","45032719990321321X");
- dataJson.put("name","刘伟");//"id_number":"131126199009280345","name":"王聪","mobile":"18322155936"
- dataJson.put("mobile","18929408405");*///15201563103,,,15201563013
- dataJson.put("mobile", "19530103205");//15201563103,,,15201563013
- dataJson.put("date", "20221126");//15201563103,,,15201563013
- /* dataJson.put("name","3febda274935a59ce9ff44e2bd0f690aa33fe8ec2c7df3ce384ee0868126decf");
- dataJson.put("id_number","bdbcb76a4c74b6f7770e469d647d30ae674b9d089e1cb01615cc46e258201255");
- dataJson.put("mobile","54f3746ad9998989ebcb7a3444b5edb694314472cbb74a2fd6458dd64b378b02");
- dataJson.put("encrypt","SHA256");*/
- //dataJson.put("bank_card_number","6253624025440494");
- /*dataJson.put("name",MD5Util.MD5("周凤云"));
- dataJson.put("id_number",MD5Util.MD5("370523197112090723"));
- dataJson.put("mobile",MD5Util.MD5("13490329255"));*/
- // dataJson.put("appkey","6222350107122010");
- /* dataJson.put("mobileCaller","13911084965");
- dataJson.put("mobileCalled","13691459653");*/
- /* List<String> list = new ArrayList<>();
- list.add("13752639577");
- dataJson.put("msisdnmd5list",list);*/
- 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<String> keys = paramObj.keys();
- int i = 0;
- while (keys.hasNext()) {
- String key = (String) keys.next();
- String value = paramObj.getString(key);
- param[i] = new NameValuePair(key, value);
- i++;
- }
- method.setRequestBody(param);
- client.executeMethod(method);
- str = convertStreamToString(method.getResponseBodyAsStream());
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (method != null) {
- method.releaseConnection();
- }
- }
- return str;
- }
- }
|