Parcourir la source

测试类提交

mashengyi il y a 1 an
Parent
commit
105c49849c

+ 4 - 8
src/main/java/com/jkcredit/invoice/util/QueryDemoTest.java

@@ -6,7 +6,6 @@ import org.apache.commons.httpclient.NameValuePair;
 import org.apache.commons.httpclient.methods.PostMethod;
 
 import java.io.BufferedReader;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -20,17 +19,17 @@ public class QueryDemoTest {
     /**
      * 测试地址
      */
-    private static final String URL = "http://127.0.0.1:18081/api/rest";
+    private static final String URL = "http://etc.jkcredit.com:9999/api/rest";
 
     /**
      * 分配的appKey
      */
-    private static final String APP_KEY = "data_test";
+    private static final String APP_KEY = "jkxy";
 
     /**
      * 分配的appSecret
      */
-    private static final String APP_SECRET = "6MD50FA127P1ACNP9C64272X13C1FA1BEA20H406";
+    private static final String APP_SECRET = "7697CE9BB9D5A856CFDDE738320AD34EA53E483C";
 
 
     /**
@@ -96,7 +95,7 @@ public class QueryDemoTest {
          */
         JSONObject paramJsonObj = new JSONObject();
         //CMCC_MOBILE_CHECK_V8//CMCC_3RD_V2//CMCC_3RD_DETAIL_V1//
-        paramJsonObj.put("api", "WAY_BILL_HISTORY_END");
+        paramJsonObj.put("api", "WAY_BILL_HISTORY_START");
         paramJsonObj.put("appKey", APP_KEY);
         paramJsonObj.put("appSecret", APP_SECRET);
 
@@ -124,9 +123,6 @@ public class QueryDemoTest {
         dataJson.put("fee", 10000);
         dataJson.put("titleType", 1);
         dataJson.put("taxplayerCode", "91330106MA28LMW9XQ");
-        dataJson.put("waybillFileName", "承运人合同.pdf");
-        dataJson.put("base64Str", Base64Utils.fileToBase64Str(new File("/Users/mashengyi/Downloads/协议/123.pdf")));
-        dataJson.put("contractType",1);
         return dataJson;
     }
 

+ 14 - 24
src/main/java/com/jkcredit/invoice/util/QueryDemo_3rd1.java

@@ -5,14 +5,7 @@ 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.io.*;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.regex.Matcher;
@@ -29,10 +22,10 @@ public class QueryDemo_3rd1 {
     /**
      * 分配的appKey
      */
-    private static final String appKey = "yunyitong";
+    private static final String appKey = "yqxd";
 
-    static String filename = "/Users/mashengyi/Downloads/";
-    static String logname = "无车运单查询列表_202386 (1).txt";
+    static String filename = "/Users/mumuxigua/Downloads/";
+    static String logname = "测试.txt";
 
     /**
      * 方法入口
@@ -67,10 +60,9 @@ public class QueryDemo_3rd1 {
                     if (str == null)
                         break;
 
-                    String num = getsrt("num:\"", "\"endTime:", str);
-                    String realDestAddr = getsrt1("realDestAddr:", str);
-                    String endTime = getsrt("endTime:","realDestAddr:",  str);
-                    demo.runMainService(num,realDestAddr,endTime);
+                    String num = str;
+
+                    demo.runMainService(num);
 
 
                 } catch (Exception e) {
@@ -131,13 +123,13 @@ public class QueryDemo_3rd1 {
     /**
      * 调用主接口
      */
-    public void runMainService(String name,String idcard,String mobile) {
+    public void runMainService(String name) {
         try {
             /**
              * 实名demo
              */
 
-                JSONObject paramJsonObj = initParamJsonObj_Realname(name,idcard,mobile);
+                JSONObject paramJsonObj = initParamJsonObj_Realname(name);
                  String ret = postClient(URL, paramJsonObj);
                 System.out.println(ret);
 
@@ -152,21 +144,21 @@ public class QueryDemo_3rd1 {
      *
      * @return
      */
-    public JSONObject initParamJsonObj_Realname(String name,String idcard,String mobile) {
+    public JSONObject initParamJsonObj_Realname(String name) {
         /**
          * 基本参数
          */
         JSONObject paramJsonObj = new JSONObject();
-        paramJsonObj.put("api", "WAY_BILL_HISTORY_END");
+        paramJsonObj.put("api", "WAY_BILL_NUM_FIND_OWNER_INVOICE");
         paramJsonObj.put("appKey", appKey);
         paramJsonObj.put("appSecret",
-                "4ED8C0AB82F1FA4511FAE5FAFC76B6FF95D5237D");
+                "01C01EF10B715233D90AC3B5FB2363FD37C6CF5D");
 
 
         /**
          * 业务参数
          */
-        JSONObject dataJson = initMainServiceParamJsonObj_Realname(name,idcard,mobile);
+        JSONObject dataJson = initMainServiceParamJsonObj_Realname(name);
         paramJsonObj.put("data", dataJson);
         return paramJsonObj;
     }
@@ -178,14 +170,12 @@ public class QueryDemo_3rd1 {
      *
      * @return
      */
-    public JSONObject initMainServiceParamJsonObj_Realname(String name,String idcard,String mobile) {
+    public JSONObject initMainServiceParamJsonObj_Realname(String name) {
         /**
          * 具体业务参数放在data中
          */
         JSONObject dataJson = new JSONObject();
         dataJson.put("num", name);
-        dataJson.put("realDestAddr", idcard);
-        dataJson.put("endTime", DateUtil.formatTime(mobile));
         return dataJson;
     }
 

+ 247 - 0
src/main/java/com/jkcredit/invoice/util/QueryDemo_3rd2.java

@@ -0,0 +1,247 @@
+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.*;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class QueryDemo_3rd2 {
+
+    /**
+     * 测试地址
+     */
+   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/mumuxigua/Downloads/";
+    static String logname = "编辑1.txt";
+
+    /**
+     * 方法入口
+     *
+     * @param args
+     */
+
+    public static void main(String args[]) throws Exception {
+
+        QueryDemo_3rd2 demo = new QueryDemo_3rd2();
+
+
+
+        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 = getsrt("appKey:", ":::appSecret:::", str).trim();
+                    String appSecret = getsrt(":::appSecret:::", ":::num:::", str).trim();
+                    String num = getsrt(":::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();
+    }
+
+}