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;
- public class QueryDemoScm_Test {
-
-
-
-
-
-
- private static final String URL = "http://110.88.150.68:8000/gateway?api=credit.sec.data";
-
-
-
-
-
-
-
- private static final String appKey = "DATA_TEST";
-
-
-
-
-
- public static void main(String args[]) throws Exception {
- QueryDemoScm_Test demo = new QueryDemoScm_Test();
- demo.runMainService();
- }
-
- 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 {
-
- JSONObject paramJsonObj = initParamJsonObj_Realname();
- String ret = postClient(URL, paramJsonObj);
- System.out.println(ret);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public JSONObject initParamJsonObj_Realname() {
-
- JSONObject paramJsonObj = new JSONObject();
- paramJsonObj.put("api", "CMCC_REENTRYNET_QUERY_V5");
-
- paramJsonObj.put("appKey", appKey);
- paramJsonObj.put("appSecret",
-
- "C41DF125F0C23FBBB83E461F5045A30ACB3FF55A");
-
- JSONObject dataJson = initMainServiceParamJsonObj_Realname();
- paramJsonObj.put("data", dataJson);
- return paramJsonObj;
- }
-
- public JSONObject initMainServiceParamJsonObj_Realname() {
-
- JSONObject dataJson = new JSONObject();
-
- dataJson.put("mobile", "19530103205");
- dataJson.put("date", "20221126");
-
-
-
-
-
-
- return dataJson;
- }
-
- 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;
- }
- }
|