南海區行政審批管理系統接口規範v0.3(規劃)4.2.【queryExpireList】當天到期業務查詢
阿新 • • 發佈:2017-11-07
tostring mef under etime 賬號 true ken 對稱加密 ==
加密前:{"time":"1510053168455","username":"GH_DATA_EXCHANGE","password":"15E45RRM"} 加密後:eyJ0aW1lIjoiMTUxMDA1MzE2ODQ1NSIsInVzZXJuYW1lIjoiR0hfREFUQV9FWENIQU5HRSIsInBh c3N3b3JkIjoiMTVFNDVSUk0ifQ== %7B%22r_code%22%3A%22200%22%2C%22r_msg%22%3A%22%E7%99%BB%E5%BD%95%E6%88%90%E5%8A%9F%22%2C%22count%22%3A0%2C%22data%22%3A%220ef9e732-008d-4875-a8d2-60abde59ba60%22%7D {"r_code":"200","r_msg":"登錄成功","count":0,"data":"0ef9e732-008d-4875-a8d2-60abde59ba60"} 轉碼前:%7B%22r_code%22%3A%22200%22%2C%22r_msg%22%3A%22%E7%99%BB%E5%BD%95%E6%88%90%E5%8A%9F%22%2C%22count%22%3A0%2C%22data%22%3A%220ef9e732-008d-4875-a8d2-60abde59ba60%22%7D 轉碼後:{"r_code":"200","r_msg":"登錄成功","count":0,"data":"0ef9e732-008d-4875-a8d2-60abde59ba60"} data<--->0ef9e732-008d-4875-a8d2-60abde59ba60 %7B%22r_code%22%3A%22200%22%2C%22r_msg%22%3A%22%E6%93%8D%E4%BD%9C%E6%88%90%E5%8A%9F%22%2C%22count%22%3A0%2C%22data%22%3A%5B%5D%7D {"r_code":"200","r_msg":"操作成功","count":0,"data":[]} 轉碼前:%7B%22r_code%22%3A%22200%22%2C%22r_msg%22%3A%22%E6%93%8D%E4%BD%9C%E6%88%90%E5%8A%9F%22%2C%22count%22%3A0%2C%22data%22%3A%5B%5D%7D 轉碼後:{"r_code":"200","r_msg":"操作成功","count":0,"data":[]} {"r_code":"200","r_msg":"操作成功","count":0,"data":[]}
package queryExpireList; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; //import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import com.rl.client1.TestLogin2Action; import net.sf.json.JSONException; import net.sf.json.JSONObject; //import org.json.JSONException; //import org.json.JSONObject; import test.BASE64; public class QueryExpireList { public static String query(String username,String password){ //定義WebService的URL //URL url = new URL("http://10.168.20.12:8888/fsWebServiceWebHall/business/login.action"); //URL url = new URL("http://10.168.13.108/fsWebServiceWebHall/business/login2.action"); //URL url = new URL("http://10.168.13.108/fsWebServiceWebHall/business/login.action"); URL url; PrintWriter ptout = null; InputStream in = null; StringBuffer sb = null; String apptoken = null; try { //url = new URL("http://10.168.20.12:8888/fsWebServiceWebHall/business/login2.action"); //url = new URL("http://10.168.41.107:8080/fsWebServiceWebHall/business/login2.action"); url = new URL("http://10.168.20.12:8888/fsWebServiceWebHall/business/queryExpireList.action"); //打開連接獲得URLConnection HttpURLConnection uc = (HttpURLConnection)url.openConnection(); //打開輸入輸出的開關 uc.setDoInput(true); uc.setDoOutput(true);//開啟輸入輸出 //設置Connection uc.setRequestProperty("connection", "Keep-Alive"); //設置Accept uc.setRequestProperty("accept", "*/*"); uc.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); //組裝消息體 apptoken = TestLogin2Action.getLogin(username, password); //根據HttpURLConnection獲得輸出流 OutputStream out = uc.getOutputStream(); // 獲取URLConnection對象對應的輸出流 ptout = new PrintWriter(out); // 發送請求參數 //ptout.print("appkey="+appkey); ptout.print("apptoken="+apptoken); // flush輸出流的緩沖 ptout.flush(); //out.write(encodeappkey.getBytes()); //int httpCode = httpuc.getResponseCode(); //System.out.println(httpCode); //如果請求成功 //if(httpuc.getResponseCode()==200){ //獲得輸入流 in = uc.getInputStream();//通過輸入流把消息接收完 //使用輸入緩沖區 BufferedReader br = new BufferedReader(new InputStreamReader(in,"utf-8")); //寫Socket的那種輸入流的方式來讀它 String line = null; //讀取響應的消息 sb = new StringBuffer(); while((line = br.readLine())!=null ){ sb.append(line); } }catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //使用finally塊來關閉輸出流、輸入流 finally{ try{ if(ptout!=null){ ptout.close(); } if(in!=null){ in.close(); } } catch(IOException ex){ ex.printStackTrace(); } } String decodesb = ""; System.out.println(sb.toString()); try { decodesb = java.net.URLDecoder.decode(sb.toString(),"UTF-8"); System.out.println(decodesb); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("轉碼前:"+sb); System.out.println("轉碼後:" + decodesb); /*// 創建JSON解析對象(兩條規則的體現:大括號用JSONObject,註意傳入數據對象) JSONObject obj; String data = null; try { //obj = new JSONObject(decodesb); obj = JSONObject.fromObject(decodesb); //obj.後面有各種數據類型,根據對象來選擇使用的數據類型 data = obj.getString("data"); // 同理如上,這裏的age為Int類型,我們就用對應的類型進行解析 //int age = obj.getInt("age"); // 最後輸出到控制臺 System.out.println("data"+"<--->"+data); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } */ return decodesb; } public static void main(String[] args){ //String queryExpireList = QueryExpireList.query("0216", "1234"); //String apptoken = TestLogin2Action.getLogin("GH_DATA_EXCHANGE","15E45RRM"); String queryExpireList = QueryExpireList.query("GH_DATA_EXCHANGE", "15E45RRM"); System.out.println(queryExpireList); } public static void main1(String[] args){ //定義WebService的URL //URL url = new URL("http://10.168.20.12:8888/fsWebServiceWebHall/business/login.action"); //URL url = new URL("http://10.168.13.108/fsWebServiceWebHall/business/login2.action"); //URL url = new URL("http://10.168.13.108/fsWebServiceWebHall/business/login.action"); URL url; PrintWriter ptout = null; InputStream in = null; StringBuffer sb = null; try { //url = new URL("http://10.168.20.12:8888/fsWebServiceWebHall/business/login2.action"); url = new URL("http://10.168.20.12:8888/fsWebServiceWebHall/business/queryExpireList.action"); //打開連接獲得URLConnection URLConnection uc = url.openConnection(); //強轉成HttpURLConnection //HttpURLConnection httpuc = (HttpURLConnection) uc; //打開輸入輸出的開關 uc.setDoInput(true); uc.setDoOutput(true);//開啟輸入輸出 //設置請求方式 //uc.setRequestMethod("POST"); //設置Connection uc.setRequestProperty("connection", "Keep-Alive"); //設置Charset //httpuc.setRequestProperty("Charset", "UTF-8"); //設置Accept //httpuc.setRequestProperty("Accept", "application/json"); uc.setRequestProperty("accept", "*/*"); //設置content-type //httpuc.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); //httpuc.setRequestProperty("Content-Type", "text/html"); uc.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); //組裝消息體 //String data = "c1f2e41650919327d85367194f75d4cf6a5f39dcef42ae6a3c33015ca92935009d6c6c4ed59a67637d54f29f7e77b9e2af95afddd4dc77b28a3d1d5056a52fe11ea6f735f35d8b62b3c2ebd9d43e533d"; /* Date date = new Date(); DateFormat dateTimeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //DateFormat dateTimeformat = new SimpleDateFormat("yyyyMMddHHmmss"); String strBeginDate = dateTimeformat.format(date); System.out.println(date); System.out.println(strBeginDate); String appkey = "02161234"+date; appkey = "02241234"+strBeginDate; String data = java.net.URLEncoder.encode(appkey, "utf-8"); System.out.println("編碼後:" + data);//加密後 */ String username = "GH_DATA_EXCHANGE"; // 用戶賬號 String password = "15E45RRM"; // 密碼 long time = System.currentTimeMillis(); // 當前時間,毫秒 //String str="{\"username\":"+ username +",\"password\":"+ password +",\"time\": "+ time +"}"; // 原數據 //String str="{\"username\":"+ username +",\"password\":"+ password +",\"time\":"+ time +"}"; // 原數據 //String str="{\"time\":"+ time +",\"username\":"+ username +",\"password\":"+ password +"}"; // 原數據 String str = "{\"time\":\""+time+"\",\"username\":\""+username+"\",\"password\":\""+password+"\"}"; // 原數據 //String str = username+password+time; //String appkey = AES.method1(str); System.out.println("加密前:"+str); //SymmetricEncoder se=new SymmetricEncoder(); //String appkey = se.AESEncode("使用AES對稱加密", str); //System.out.println("根據輸入的規則"+"使用AES對稱加密"+"加密後的密文是:"+se.AESEncode("使用AES對稱加密", str)); //System.out.println("根據輸入的規則"+"使用AES對稱解密"+"解密後的明文是:"+se.AESDncode("使用AES對稱解密",se.AESEncode("使用AES對稱加密", str))); //System.out.println("根據輸入的規則"+"使用AES對稱解密"+"解密後的明文是:"+se.AESDncode("使用AES對稱解密",appkey)); //System.out.println("加密後:" + appkey); // 加密後 //appkey = "fB75+Z+CXIuVwqDNJYbKzZmHuVGORfL9TxqEx5AXE5w="; // String encode = java.net.URLEncoder.encode(str,"utf-8"); // System.out.println("編碼後:" + encode); String appkey = BASE64.encryptBASE64(str.toString().getBytes()); //String appkey = new sun.misc.BASE64Encoder().encode(str.toString().getBytes()); // String appkey = BASE64.encryptBASE64(encode.getBytes()); //appkey = "eyJ1c2VybmFtZSI6Imd6OTkiLCJwYXNzd29yZCI6IjEyMzQiLCJ0aW1lIjogMTQ0ODQzMjY3NTE5NH0="; //appkey = "c1f2e41650919327d85367194f75d4cf6a5f39dcef42ae6a3c33015ca92935009d6c6c4ed59a67637d54f29f7e77b9e2af95afddd4dc77b28a3d1d5056a52fe11ea6f735f35d8b62b3c2ebd9d43e533d"; System.out.println("加密後:"+appkey); //String data = "eyJ1c2VybmFtZSI6Imd6OTkiLCJwYXNzd29yZCI6IjEyMzQiLCJ0aW1lIjogMTQ0ODQzMjY3NTE5NH0="; /* Date date = new Date(); String appkey = "02241234"+date; String data = java.net.URLEncoder.encode(appkey, "utf-8"); System.out.println("編碼後:" + data);//加密後 */ //根據HttpURLConnection獲得輸出流 OutputStream out = uc.getOutputStream(); //用輸出流把消息發送到服務端 //out.write(data.getBytes());//已經把消息給寫過去了. //System.out.println(appkey.getBytes()); //String encodeappkey = java.net.URLEncoder.encode(appkey,"utf-8"); //out.write(appkey.getBytes());//已經把消息給寫過去了. // 獲取URLConnection對象對應的輸出流 ptout = new PrintWriter(out); // 發送請求參數 ptout.print("appkey="+appkey); // flush輸出流的緩沖 ptout.flush(); //out.write(encodeappkey.getBytes()); //int httpCode = httpuc.getResponseCode(); //System.out.println(httpCode); //如果請求成功 //if(httpuc.getResponseCode()==200){ //獲得輸入流 in = uc.getInputStream();//通過輸入流把消息接收完 //使用輸入緩沖區 BufferedReader br = new BufferedReader(new InputStreamReader(in,"utf-8")); //寫Socket的那種輸入流的方式來讀它 String line = null; //讀取響應的消息 sb = new StringBuffer(); while((line = br.readLine())!=null ){ sb.append(line); } }catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //使用finally塊來關閉輸出流、輸入流 finally{ try{ if(ptout!=null){ ptout.close(); } if(in!=null){ in.close(); } } catch(IOException ex){ ex.printStackTrace(); } } String decodesb = null; try { decodesb = java.net.URLDecoder.decode(sb.toString(),"UTF-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("轉碼前:"+sb); System.out.println("轉碼後:" + decodesb); // 創建JSON解析對象(兩條規則的體現:大括號用JSONObject,註意傳入數據對象) JSONObject obj; try { //obj = new JSONObject(decodesb); obj = JSONObject.fromObject(decodesb); //obj.後面有各種數據類型,根據對象來選擇使用的數據類型 String data = obj.getString("data"); // 同理如上,這裏的age為Int類型,我們就用對應的類型進行解析 //int age = obj.getInt("age"); // 最後輸出到控制臺 System.out.println("data"+"<--->"+data); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } //StringBuffer是一個可變字符串,我們要把它變成一個文檔來解析 //java代碼裏面解析XML //解析消息,定義讀取器對象SAXReader /*SAXReader reader = new SAXReader(); //獲得文檔對象 Document doc = reader.read(new StringReader(sb.toString()));//它的返回值是一個文檔對象Document //使用XPath的方式獲得到return這個元素的集合 List<Element> eList = doc.selectNodes("//return"); //遍歷元素集合 for (Element element : eList) { System.out.println(element.getText()); }*/ } } //}
南海區行政審批管理系統接口規範v0.3(規劃)4.2.【queryExpireList】當天到期業務查詢