public class SBDemo { ????public static void main(String[] args) throws Exception {
????????String code = null; ????????String funcode = null; ????????File file = new File("C:/Users/Administrator/Desktop/11.txt"); ????????File fileLog = new File("C:/Users/Administrator/Desktop/check.txt"); ????????FileReader fis = new FileReader(file); ????????BufferedReader br = new BufferedReader(fis); ????????String line = null; ????????while ((line = br.readLine()) != null) { ????????????String[] split = line.split("###########");
????????????code = split[1]; ????????????funcode = split[0];
????????????boolean equals = find(code, funcode).subSequence(30, 36).toString().equals("未查询到数据"); ????????????System.out.println(code + " ???======= ??"+ funcode + " ????"+ equals);
????????????if (equals) { ????????????????System.out.println(funcode + " ??" + code + "=====不存在"); ????????????????FileOutputStream fos = new FileOutputStream(fileLog, true); ????????????????fos.write((funcode + " ??" + code + "=====不存在 \r\n").getBytes()); ????????????????fos.flush();
????????????????String send = send(code, funcode); ????????????????fos.write((funcode + " ??" + code+" ???sen====== " + send+" \r\n").getBytes()); ????????????????fos.flush(); ????????????????fos.close(); ????????????} else { ????????????????FileOutputStream fos = new FileOutputStream(fileLog, true); ????????????????fos.write((funcode + " ??" + code + "=====存在 \r\n").getBytes()); ????????????????System.out.println(funcode + " ??" + code + "=====存在"); ????????????????fos.flush(); ????????????????fos.close(); ????????????} ????????} ????}
????private static String find(String code, String funcode) throws MalformedURLException, IOException, ProtocolException { ????????String s = "http://182.207.129.68:9081/cqms/view/cqms/CQMS0021.do"; ????????final URL url = new URL(s); ????????HttpURLConnection connection = (HttpURLConnection) url.openConnection(); ????????connection.setDoInput(true); ????????connection.setDoOutput(true); ????????connection.setRequestMethod("POST"); ????????connection.setUseCaches(false); ????????connection.setRequestProperty("Charsert", "UTF-8"); ????????connection.setRequestProperty("Accept", "application/json, text/javascript, */*; q=0.01"); ????????connection.setRequestProperty("Accept-Encoding", "gzip, deflate"); ????????connection.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.9"); ????????connection.setRequestProperty("Connection", "Keep-Alive"); ????????connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); ????????connection.setRequestProperty("Cookie", "JSESSIONID=0000vKlZyCbOjVZnpaf-ZxqvsDJ:-1"); ????????connection.setRequestProperty("Host", "182.207.129.68:9081"); ????????connection.setRequestProperty("Origin", "http://182.207.129.68:9081"); ????????connection.setRequestProperty("Referer", "http://182.207.129.68:9081/cqms/view/cqms/ewp_check.html"); ????????connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3679.0 Safari/537.36"); ????????connection.setRequestProperty("X-Requested-With", "XMLHttpRequest"); ????????connection.setConnectTimeout(10000); ????????StringBuilder sb = new StringBuilder(); ????????sb.append("SYS=BMOS"); ????????sb.append("&SUN_SYS="); ????????sb.append("&FUNC_CODE=" + funcode); ????????sb.append("&TRAN_CODE=" + code); ????????sb.append("&PLUG_CODE=");
????????DataOutputStream out = new DataOutputStream(connection.getOutputStream()); ????????out.write(sb.toString().getBytes("utf-8"));
????????out.flush(); ????????out.close();
????????final StringBuffer responseBuffer = new StringBuffer(); ????????if (connection.getResponseCode() == 200) { ????????????BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); ????????????String line = in.readLine(); ????????????while (line != null) { ????????????????responseBuffer.append(line); ????????????????line = in.readLine(); ????????????} ????????} ????????System.out.println(responseBuffer.toString()); ????????return responseBuffer.toString(); ????}
????public static String send(String code, String funCode) throws MalformedURLException, IOException, ????????????ProtocolException, UnsupportedEncodingException { ????????final URL url = new URL("http://182.207.129.68:9081/cqms/view/cqms/CQMS0022.do"); ????????HttpURLConnection connection = (HttpURLConnection) url.openConnection();
????????connection.setDoInput(true); ????????connection.setDoOutput(true); ????????connection.setRequestMethod("POST"); ????????connection.setUseCaches(false); ????????connection.setRequestProperty("Charsert", "UTF-8"); ????????connection.setRequestProperty("Connection", "Keep-Alive"); ????????connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); ????????connection.setRequestProperty("Cookie", "JSESSIONID=0000vKlZyCbOjVZnpaf-ZxqvsDJ:-1"); ????????connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3679.0 Safari/537.36"); ????????connection.setConnectTimeout(10000);
????????StringBuilder sb = new StringBuilder(); ????????sb.append("SYS=BMOS"); ????????sb.append("&SUB_SYS=BMOS"); ????????sb.append("&TRAN_CODE=" + code); ????????sb.append("&PLUG_CODE="); ????????sb.append("&FUNC_CODE=" + funCode); ????????sb.append("&UP_DATOR=" + URLEncoder.encode("王尧", "UTF-8")); ????????sb.append("&PAGE_CODE="); ????????sb.append("&PAGE_NAME="); ????????sb.append("&NOTE=");
????????String string = sb.toString(); ????????OutputStream out = connection.getOutputStream(); ????????out.write(string.getBytes("UTF-8"));
????????out.flush(); ????????out.close();
????????final StringBuffer responseBuffer = new StringBuffer(); ????????if (connection.getResponseCode() == 200) { ????????????BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); ????????????String line = in.readLine(); ????????????while (line != null) { ????????????????responseBuffer.append(line); ????????????????line = in.readLine(); ????????????} ????????}
????????System.out.println(responseBuffer); ????????return responseBuffer.toString(); ????} } ============================= public static String sendPostHttpRequest( String requestUrl, String requestData ,String requestMethod ,String token) throws Exception{
????//token使用base64编码后上送 ????byte[] decodeBuffer =token.getBytes("UTF-8"); ????BASE64Encoder encoder = new BASE64Encoder(); ????String token_base64 ?= encoder.encode(decodeBuffer);
????OutputStream out = null; ????BufferedReader in = null; ????HttpURLConnection connection = null; ????try { ????????// 发送数据 ????????DefaultHttpClient client = new DefaultHttpClient(); ????????HttpPost post = new HttpPost(requestUrl); ????????StringEntity stringEntity = new StringEntity(requestData); ????????post.setEntity(stringEntity); ????????post.setHeader("Content-Type" ,"application/json"); ????????//post.setHeader("guwp-token","3590cd3585ee7efc5a5743ee8eee3dde"); ????????post.setHeader("muop-token",token_base64); ????????HttpResponse execute = client.execute(post); ????????String string = EntityUtils.toString(execute.getEntity()); ????????System.out.println("返回数据是="+string); ????????return string; ????} catch (IOException e) { ????????throw new RuntimeException("获取连接失败! ", e); ????} finally { ????????try { ????????????if (out != null) { ????????????????out.close(); ????????????} ????????} catch (IOException e) { ????????} ????????try { ????????????if (in != null) { ????????????????in.close(); ????????????} ????????} catch (Exception e2) { ????????} ????????try { ????????????if (connection != null) { ????????????????connection.disconnect(); ????????????} ????????} catch (Exception e2) { ????????} ????}
} |