|
@@ -0,0 +1,253 @@
|
|
|
+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.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.InputStreamReader;
|
|
|
+import java.io.LineNumberReader;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+public class QueryDemo_3rd4 {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试地址
|
|
|
+ */
|
|
|
+ private static final String URL = "http://etc.jkcredit.com:9999/api/rest";
|
|
|
+ // private static final String URL = "http://127.0.0.1:18081/api/rest";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分配的appKey
|
|
|
+ */
|
|
|
+ // private static final String appKey = "yqxd";
|
|
|
+
|
|
|
+ static String filename = "/Users/mashengyi/Downloads/";
|
|
|
+ static String logname = "cc.txt";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 方法入口
|
|
|
+ *
|
|
|
+ * @param args
|
|
|
+ */
|
|
|
+
|
|
|
+ public static void main(String args[]) throws Exception {
|
|
|
+
|
|
|
+ QueryDemo_3rd4 demo = new QueryDemo_3rd4();
|
|
|
+
|
|
|
+
|
|
|
+ int count = 0;
|
|
|
+ int total = 0;
|
|
|
+
|
|
|
+ HashMap hashMap = new HashMap();
|
|
|
+
|
|
|
+ try {
|
|
|
+ File file = new File(filename + logname);
|
|
|
+ FileInputStream fis = new FileInputStream(file);
|
|
|
+ InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
|
|
|
+ LineNumberReader lr = new LineNumberReader(isr, 512);
|
|
|
+ String laststr = "";
|
|
|
+ int count_d = 0;
|
|
|
+ int total_d = 0;
|
|
|
+ while (true) {
|
|
|
+
|
|
|
+ String str = lr.readLine();
|
|
|
+
|
|
|
+ try {
|
|
|
+ if (str == null)
|
|
|
+ break;
|
|
|
+
|
|
|
+ String appKey = "yqxd";
|
|
|
+ String appSecret = "01C01EF10B715233D90AC3B5FB2363FD37C6CF5D";
|
|
|
+ String num = str.trim();
|
|
|
+
|
|
|
+ demo.runMainService(appKey, appSecret, num);
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ System.out.println("无法解析:" + str);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ lr.close();
|
|
|
+
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ System.out.println("FILENAME:" + filename);
|
|
|
+ System.out.println("File not found");
|
|
|
+ } catch (IOException e) {
|
|
|
+ System.out.println("IO error");
|
|
|
+ }
|
|
|
+
|
|
|
+ Iterator it = hashMap.keySet().iterator();
|
|
|
+
|
|
|
+ while (it.hasNext()) {
|
|
|
+
|
|
|
+ String key = (String) it.next();
|
|
|
+ Integer ttttttt = (Integer) hashMap.get(key);
|
|
|
+
|
|
|
+ System.out.println(key + "====" + ttttttt);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getsrt(String startkeystr, String endstr, String str) {
|
|
|
+ int customerindex = str.indexOf(startkeystr);
|
|
|
+ String temp = str.substring(customerindex + startkeystr.length());
|
|
|
+ int endindex = temp.indexOf(endstr);
|
|
|
+ String sss = temp.substring(0, endindex);
|
|
|
+ return sss;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getsrt1(String startkeystr, String str) {
|
|
|
+ int customerindex = str.indexOf(startkeystr);
|
|
|
+ String temp = str.substring(customerindex + startkeystr.length());
|
|
|
+ return temp;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 利用正则表达式判断字符串是否是数字
|
|
|
+ *
|
|
|
+ * @param str
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean isNumeric(String str) {
|
|
|
+ Pattern pattern = Pattern.compile("[0-9]*");
|
|
|
+ Matcher isNum = pattern.matcher(str);
|
|
|
+ if (!isNum.matches()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 调用主接口
|
|
|
+ */
|
|
|
+ public void runMainService(String appKey, String appSecret, String num) {
|
|
|
+ try {
|
|
|
+ /**
|
|
|
+ * 实名demo
|
|
|
+ */
|
|
|
+
|
|
|
+ JSONObject paramJsonObj = initParamJsonObj_Realname(appKey, appSecret, num);
|
|
|
+ String ret = postClient(URL, paramJsonObj);
|
|
|
+ System.out.println(ret);
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 整合参数(实名认证)
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject initParamJsonObj_Realname(String appKey, String appSecret, String num) {
|
|
|
+ /**
|
|
|
+ * 基本参数
|
|
|
+ */
|
|
|
+ JSONObject paramJsonObj = new JSONObject();
|
|
|
+ paramJsonObj.put("api", "WAY_BILL_NUM_FIND_OWNER_INVOICE");
|
|
|
+ paramJsonObj.put("appKey", appKey);
|
|
|
+ paramJsonObj.put("appSecret",
|
|
|
+ appSecret);
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 业务参数
|
|
|
+ */
|
|
|
+ JSONObject dataJson = initMainServiceParamJsonObj_Realname(num);
|
|
|
+ paramJsonObj.put("data", dataJson);
|
|
|
+ return paramJsonObj;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 初始化业务参数(实名认证)
|
|
|
+ *
|
|
|
+ * 姓名,身份证,手机号
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject initMainServiceParamJsonObj_Realname(String num) {
|
|
|
+ /**
|
|
|
+ * 具体业务参数放在data中
|
|
|
+ */
|
|
|
+ JSONObject dataJson = new JSONObject();
|
|
|
+ dataJson.put("num", num);
|
|
|
+ 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/x-www-form-urlencoded;charset=utf-8");
|
|
|
+ NameValuePair[] param = new NameValuePair[paramObj.size()];
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 流转字符串
|
|
|
+ *
|
|
|
+ * @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();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|