QueryDemoScm_Test.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package com.jkcredit.invoice.util;
  2. import net.sf.json.JSONObject;
  3. import org.apache.commons.httpclient.HttpClient;
  4. import org.apache.commons.httpclient.NameValuePair;
  5. import org.apache.commons.httpclient.methods.PostMethod;
  6. import java.io.BufferedReader;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.io.InputStreamReader;
  10. import java.util.Iterator;
  11. /**
  12. * Created by zhangqingxin Date : 16/11/6 Time : 10:41
  13. * <p/>
  14. * 参考一(HttpClient):http://mvnrepository.com/artifact/commons-httpclient/commons-
  15. * httpclient/3.1
  16. * 参考一(json-lib):http://mvnrepository.com/artifact/net.sf.json-lib/json-lib/2.4
  17. */
  18. public class QueryDemoScm_Test {
  19. /**
  20. * 测试地址
  21. */
  22. // private static final String URL = "http://110.88.150.74:80/credit?api=credit.sec.data";
  23. //private static final String URL = "http://110.88.150.74/credit?api=credit.sec.data";
  24. // private static final String URL = "http://123.57.186.204/gateway?api=credit.sec.data";
  25. //private static final String URL = "http://123.57.186.204/gateway?api=credit.sec.data";
  26. // private static final String URL = "http://www.h11.site/gateway?api=credit.sec.data";//北京节点
  27. //private static final String URL = "http://jk.h11.site/gateway?api=credit.sec.data";
  28. private static final String URL = "http://110.88.150.68:8000/gateway?api=credit.sec.data";
  29. // private static final String URL = "http://110.88.150.68:8000/gateway?api=credit.sec.data_test";
  30. // private static final String URL = "http://110.88.150.72:8000/gateway?api=credit.sec.data_test";
  31. // private static final String URL = "http://60.205.114.163:8000/gateway?api=credit.sec.data";
  32. //private static final String URL = " http://45.126.120.88/gateway?api=credit.sec.data_test";
  33. // private static final String URL = " http://45.126.120.88/gateway?api=credit.sec.data";
  34. // private static final String URL = " http://119.18.195.163/gateway?api=credit.sec.data";
  35. /**
  36. * 分配的appKey
  37. */
  38. private static final String appKey = "DATA_TEST";
  39. // private static final String appKey = "junxin_test";
  40. // private static final String appKey = "DATA_TEST";
  41. //private static final String appKey = "JIAO_KE";
  42. //private static final String appKey = "HANGZHOU_JUNXIN_72";
  43. /**
  44. * 290dec3f6a243889e5ed3210cf1ad499
  45. * 方法入口
  46. *
  47. * @param args
  48. */
  49. public static void main(String args[]) throws Exception {
  50. QueryDemoScm_Test demo = new QueryDemoScm_Test();
  51. demo.runMainService();
  52. }
  53. /**
  54. * 流转字符串
  55. *
  56. * @param is
  57. * @return
  58. */
  59. public static String convertStreamToString(InputStream is) {
  60. BufferedReader reader = new BufferedReader(new InputStreamReader(is));
  61. StringBuilder builder = new StringBuilder();
  62. String line = null;
  63. try {
  64. while ((line = reader.readLine()) != null) {
  65. builder.append(line + "\n");
  66. }
  67. } catch (IOException e) {
  68. e.printStackTrace();
  69. } finally {
  70. try {
  71. is.close();
  72. } catch (IOException e) {
  73. e.printStackTrace();
  74. }
  75. }
  76. return builder.toString();
  77. }
  78. /**
  79. * 调用主接口
  80. */
  81. public void runMainService() {
  82. try {
  83. /**
  84. * 实名demo
  85. */
  86. JSONObject paramJsonObj = initParamJsonObj_Realname();
  87. String ret = postClient(URL, paramJsonObj);
  88. System.out.println(ret);
  89. } catch (Exception e) {
  90. e.printStackTrace();
  91. }
  92. }
  93. /**
  94. * 整合参数(实名认证)
  95. *
  96. * @return
  97. */
  98. public JSONObject initParamJsonObj_Realname() {
  99. /**
  100. * 基本参数
  101. */
  102. JSONObject paramJsonObj = new JSONObject();
  103. paramJsonObj.put("api", "CMCC_REENTRYNET_QUERY_V5");//CMCC_MOBILE_CHECK_V8//CMCC_3RD_V2//CMCC_3RD_DETAIL_V1//
  104. //paramJsonObj.put("api", "MSISDNMD5TOIMEI");//MOBILE_CHECK_V1//CMCC_3RD_VERIFY_V4//CTCC_CHECK_V1//CMCC_ONLINE_CHECK_V5
  105. paramJsonObj.put("appKey", appKey);
  106. paramJsonObj.put("appSecret",
  107. // "D78C393359BF128715C65D91C67051478A4DFC13");
  108. "C41DF125F0C23FBBB83E461F5045A30ACB3FF55A");
  109. /**
  110. * 业务参数
  111. */
  112. JSONObject dataJson = initMainServiceParamJsonObj_Realname();
  113. paramJsonObj.put("data", dataJson);
  114. return paramJsonObj;
  115. }
  116. /*
  117. * 初始化业务参数(实名认证)
  118. *
  119. * 姓名,身份证,手机号
  120. *
  121. * @return
  122. */
  123. public JSONObject initMainServiceParamJsonObj_Realname() {
  124. /**
  125. * 具体业务参数放在data中
  126. */
  127. JSONObject dataJson = new JSONObject();
  128. /* dataJson.put("id_number","45032719990321321X");
  129. dataJson.put("name","刘伟");//"id_number":"131126199009280345","name":"王聪","mobile":"18322155936"
  130. dataJson.put("mobile","18929408405");*///15201563103,,,15201563013
  131. dataJson.put("mobile", "19530103205");//15201563103,,,15201563013
  132. dataJson.put("date", "20221126");//15201563103,,,15201563013
  133. /* dataJson.put("name","3febda274935a59ce9ff44e2bd0f690aa33fe8ec2c7df3ce384ee0868126decf");
  134. dataJson.put("id_number","bdbcb76a4c74b6f7770e469d647d30ae674b9d089e1cb01615cc46e258201255");
  135. dataJson.put("mobile","54f3746ad9998989ebcb7a3444b5edb694314472cbb74a2fd6458dd64b378b02");
  136. dataJson.put("encrypt","SHA256");*/
  137. //dataJson.put("bank_card_number","6253624025440494");
  138. /*dataJson.put("name",MD5Util.MD5("周凤云"));
  139. dataJson.put("id_number",MD5Util.MD5("370523197112090723"));
  140. dataJson.put("mobile",MD5Util.MD5("13490329255"));*/
  141. // dataJson.put("appkey","6222350107122010");
  142. /* dataJson.put("mobileCaller","13911084965");
  143. dataJson.put("mobileCalled","13691459653");*/
  144. /* List<String> list = new ArrayList<>();
  145. list.add("13752639577");
  146. dataJson.put("msisdnmd5list",list);*/
  147. return dataJson;
  148. }
  149. /**
  150. * 实现http post请求 注意编码 UTF-8
  151. *
  152. * @param url
  153. * @param paramObj
  154. * @return
  155. */
  156. public String postClient(String url, JSONObject paramObj) {
  157. String str = "";
  158. HttpClient client = null;
  159. PostMethod method = null;
  160. try {
  161. client = new HttpClient();
  162. method = new PostMethod(url);
  163. method.setRequestHeader("Content-Type", "application/json;charset=utf-8");
  164. NameValuePair[] param = new NameValuePair[paramObj.size()];
  165. @SuppressWarnings("unchecked")
  166. Iterator<String> keys = paramObj.keys();
  167. int i = 0;
  168. while (keys.hasNext()) {
  169. String key = (String) keys.next();
  170. String value = paramObj.getString(key);
  171. param[i] = new NameValuePair(key, value);
  172. i++;
  173. }
  174. method.setRequestBody(param);
  175. client.executeMethod(method);
  176. str = convertStreamToString(method.getResponseBodyAsStream());
  177. } catch (Exception e) {
  178. e.printStackTrace();
  179. } finally {
  180. if (method != null) {
  181. method.releaseConnection();
  182. }
  183. }
  184. return str;
  185. }
  186. }