From 2f103856c8c85a79510aa9297e192148cb050170 Mon Sep 17 00:00:00 2001 From: cheney Date: Sat, 2 Apr 2022 17:31:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 27 +- public.script/index.js | 68 +- src/main/java/racal/sunyard/main/.gitignore | 1 + .../java/racal/sunyard/main/SydApiSDF4j.java | 762 +++++++++--------- .../sunyard/main/TestDecryptDataWithFile.java | 40 - .../com/sunyard/sydapi/test}/TestClass.java | 6 +- .../sydapi/test/TestDecryptDataWithFile.java | 36 +- .../com/sunyard/sydapi/test}/TestInf.java | 2 +- 8 files changed, 471 insertions(+), 471 deletions(-) delete mode 100644 src/main/java/racal/sunyard/main/TestDecryptDataWithFile.java rename src/{main/java/racal/sunyard/main => test/java/com/sunyard/sydapi/test}/TestClass.java (79%) rename src/{main/java/racal/sunyard/main => test/java/com/sunyard/sydapi/test}/TestInf.java (61%) diff --git a/pom.xml b/pom.xml index 6bdfa06..b347781 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.sunyard sydapi4j - 1.0.202201101633 + 1.0.20220402 jar sydapi4j @@ -19,6 +19,13 @@ + + junit + junit + 4.12 + test + + org.apache.commons @@ -48,13 +55,6 @@ 1.6.1 - - - org.codehaus.groovy - groovy-all - 2.3.2 - - com.alibaba @@ -76,16 +76,11 @@ com.sunyard - dproto - 1.0-20220107 + proto + 1.0-20220402 - - junit - junit - 4.12 - test - + diff --git a/public.script/index.js b/public.script/index.js index 1258b33..558df14 100644 --- a/public.script/index.js +++ b/public.script/index.js @@ -1,9 +1,55 @@ const l = require("./log") +const os = require("os"); const fs = require('fs'); const path = require('path'); const util = require('util'); -const cmd = require('node-cmd'); -const cmdget = util.promisify(cmd.get); +const { exec } = require('child_process') + + +function sync( cmds , options = {}){ + + if ( options.detached ) { + throw "sync 不支持 detached" + } + + options = Object.assign({ + cwd : os.tmpdir(), + encoding: 'buffer' + }, options) + + // 支持多命令 + let cmd = cmds + + // win 乱码问题 + let encode = "win32" === os.platform() ? 'cp936' : "utf-8" + + + + return new Promise(function (resolve, reject) { + let process = exec( cmd , options , function (e, stdout, stderr) { + // console.log( e, + // iconv.decode( stdout, 'cp936'), + // iconv.decode( stderr, 'cp936') + // ) + + if ( e ) { + reject( e ) + } else { + + resolve({ + pid : process.pid, + exitCode : process.exitCode, + stdout : stdout, + stderr : stderr + }) + } + }) + console.log( "process", process.pid ) + + }) +} + + var version = "" const project_path = path.join(__dirname, "../") @@ -19,7 +65,7 @@ function prepareDir(){ l.i("存在旧文件,清空旧文件") } - cmdget("rd /s/q .\\public").catch(function (reason) { + sync("rd /s/q .\\public").catch(function (reason) { // pass @@ -45,7 +91,7 @@ function prepareDir(){ function mvn(){ l.i("调用 maven 打包,可能需要好几分钟。") return new Promise(function (cbok, cberr) { - cmdget('mvn package -DskipTests').then(function (value, error) { + sync('mvn package -DskipTests').then(function (value, error) { l.d( value ) if ( value.indexOf("BUILD SUCCESS") < 0 ){ @@ -67,7 +113,7 @@ function mvn(){ } function doc(){ - return cmdget('mvn javadoc:javadoc').then(function (value, error) { + return sync('mvn javadoc:javadoc').then(function (value, error) { l.d( value ) // if ( value.indexOf("BUILD SUCCESS") < 0 ){ @@ -81,7 +127,7 @@ function doc(){ } function zipjar(){ - return cmdget("7z a .\\public\\sydapi-"+ version +".zip .\\public\\jar\\").then(function (value, error) { + return sync("7z a .\\public\\sydapi-"+ version +".zip .\\public\\jar\\").then(function (value, error) { l.d( value ) if ( value.indexOf("Everything is Ok") < 0 ){ @@ -92,7 +138,7 @@ function zipjar(){ } function zipdoc(){ - return cmdget("7z a .\\public\\sydapi-doc-"+ version +".zip .\\public\\doc\\ .\\public\\html\\ .\\src\\test\\java\\com\\sunyard\\sydapi\\sample .\\release.txt").then(function (value, error) { + return sync("7z a .\\public\\sydapi-doc-"+ version +".zip .\\public\\doc\\ .\\public\\html\\ .\\src\\test\\java\\com\\sunyard\\sydapi\\sample .\\release.txt").then(function (value, error) { l.d( value ) if ( value.indexOf("Everything is Ok") < 0 ){ @@ -104,7 +150,7 @@ function zipdoc(){ function dependencies(){ - return cmdget('mvn dependency:copy-dependencies -DoutputDirectory=./public/jar/dependences').then(function (value, error) { + return sync('mvn dependency:copy-dependencies -DoutputDirectory=./public/jar/dependences').then(function (value, error) { l.d( value ) if ( value.indexOf("BUILD SUCCESS") < 0 ){ @@ -119,7 +165,7 @@ async function main() { l.i("项目目录 : " + project_path ) - cmdget('git status').then(function (value, error) { + sync('git status').then(function (value, error) { l.d( value ) @@ -141,7 +187,7 @@ async function main() { l.i( r.groups.version ) version = r.groups.version - return cmdget('git log -1') + return sync('git log -1') }).then(function (value) { @@ -193,7 +239,7 @@ async function main() { }).then(function () { l.i("打包完成!") - cmdget('start .\\public') + sync('start .\\public') }).catch(function (reason) { diff --git a/src/main/java/racal/sunyard/main/.gitignore b/src/main/java/racal/sunyard/main/.gitignore index f51faad..ac8020d 100644 --- a/src/main/java/racal/sunyard/main/.gitignore +++ b/src/main/java/racal/sunyard/main/.gitignore @@ -1,2 +1,3 @@ /proto/ /script/ +/dto/ diff --git a/src/main/java/racal/sunyard/main/SydApiSDF4j.java b/src/main/java/racal/sunyard/main/SydApiSDF4j.java index 509e24f..825702b 100644 --- a/src/main/java/racal/sunyard/main/SydApiSDF4j.java +++ b/src/main/java/racal/sunyard/main/SydApiSDF4j.java @@ -1,381 +1,381 @@ -package racal.sunyard.main; - -import com.sunyard.SydApiException; -import com.sunyard.SydApiSDF; -import com.sunyard.entity.DeviceInfo; -import com.sunyard.proto.Packet; -import com.sunyard.proto.PacketSection; -import com.sunyard.proto.Util; -import com.sunyard.trans.PacketSN; -import racal.sunyard.main.proto.Proto0100; -import racal.sunyard.main.proto.Proto0101; -import racal.sunyard.main.proto.ProtoSK; - -import java.io.IOException; -import java.io.InputStream; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketAddress; -import java.net.SocketTimeoutException; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -public class SydApiSDF4j implements SydApiSDF { - - private static boolean debug = false; - - private static long sTime = System.currentTimeMillis(); - - private static String ip1; - private static String ip2; - private static int port; - private static int timeout; - - private Socket socket; - - //初始化变量 - static { - - String d = System.getProperty("com.sunyard.sydapi4j.debug"); - if ("true".equals(d)) { - debug = true; - } - } - - private static void println(Object i) { - if (debug) { - System.out.println(i); - } - - } - - private static void print(Object i) { - if (debug) { - System.out.print(i); - } - - } - - //gc回收 - @Override - protected void finalize() throws Throwable { - super.finalize(); - if (null != this.socket) { - this.socket.close(); - } - } - - /** - * 确认链接可用 - * 确认读缓存为空 - */ - private void testSocket() { - - // 就是简单对象模式,链接长短完全由用户自己控制 - if (null == socket) { - - // 全局热备模式(old shool) - if (null != ip2) { - - Socket s1 = new Socket(); - SocketAddress address = new InetSocketAddress(ip1, port); - - try { - s1.connect(address, timeout); - socket = s1; - socket.setSoTimeout(timeout); - } catch (Exception e) { - Socket s2 = new Socket(); - SocketAddress add2 = new InetSocketAddress(ip2, port); - try { - s2.connect(add2, timeout); - socket = s2; - socket.setSoTimeout(timeout); - } catch (Exception e2) { - throw new SydApiException(-2); - } - } - - } - } - - clear(); - - } - - protected byte[] syncSend(ByteBuffer bb) { - - - byte[] buff; - if (bb.position() == bb.limit()) { - buff = bb.array(); - } else { - buff = new byte[bb.position()]; - System.arraycopy(bb.array(), 0, buff, 0, buff.length); - } - - - println("\n\n发送数据"); - print("HEX数据: \t"); - println(Util.bytes2HexString(buff)); - - testSocket(); - - try { - socket.getOutputStream().write(buff); - } catch (IOException e) { - e.printStackTrace(); - } - - return buff; - } - - private void clear() { - try { - InputStream is = socket.getInputStream(); - while (is.available() > 0) { - is.read(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - - private ByteBuffer read(Socket socket) throws IOException { - InputStream is = socket.getInputStream(); - int d; - int high = is.read(); - int low = is.read(); - int len = (high << 8) + low; - - len += 2; - - print("H\t"); - println(Integer.toHexString(high)); - print("L\t"); - println(Integer.toHexString(low)); - print("Len\t"); - println(len); - - - ByteBuffer bb = ByteBuffer.allocate(len); - bb.put((byte) (high & 0xFF)); - bb.put((byte) (low & 0xFF)); - - while (true) { - d = is.read(); - if (-1 == d) { - break; - } - - bb.put((byte) (d & 0xFF)); - - if (bb.position() == len) { - break; - } - } - - print("HEX数据: \t"); - println(Util.bytes2HexString(bb.array())); - return bb; - } - - /** - * 阻塞读取 - * 前两个字节是长度 - * - * @return - * @buffer 如果出错,需要补发的数据。 - */ - protected ByteBuffer syncRead(byte[] buffer) { - println("\n\n接收数据"); - try { - // 正常接收 - ByteBuffer bb = read(socket); - return bb; - - } catch (SocketTimeoutException e) { - throw new SydApiException("接收数据超时", -2); - } catch (Exception e) { - e.printStackTrace(); - } - - throw new SydApiException("通信数据错误", -3); - } - - @Override - synchronized public SydApiSDF connect(String ip, int port, String pwd, int timeout) { - - if (null != ip2) { - throw new SydApiException("双机热备模式不用调用此方法", -1); - } - Socket socket = new Socket(); - SocketAddress address = new InetSocketAddress(ip, port); - - try { - if (timeout > 0) { - socket.connect(address, timeout); - } else { - socket.connect(address); - } - socket.setSoTimeout(timeout); - } catch (Exception e) { - throw new SydApiException(-2); - } - - this.socket = socket; - return this; - } - - @Override - synchronized public SydApiSDF connect(String ip, int port, String pwd, int connectTimeout, int readTimeout) { - - if (null != ip2) { - throw new SydApiException("双机热备模式不用调用此方法", -1); - } - Socket socket = new Socket(); - SocketAddress address = new InetSocketAddress(ip, port); - - try { - socket.connect(address, connectTimeout); - socket.setSoTimeout(readTimeout); - } catch (Exception e) { - throw new SydApiException(-2); - } - - this.socket = socket; - return this; - } - - @Override - synchronized public int disconnect() { - - if (null != socket) { - try { - socket.getInputStream().close(); - } catch (Exception e1) { - } - - - try { - socket.getOutputStream().close(); - } catch (Exception e2) { - } - - try { - socket.close(); - } catch (Exception e) { - } - - } - - return 0; - } - - @Override - public DeviceInfo getStatus() { - - Proto0100 proto = new Proto0100(); - - HashMap packet = new HashMap(); - HashMap data = new HashMap(); - PacketSN sn = PacketSN.gen(); - packet.put("header", sn.getSn().array()); - packet.put("data", data); - - // 渲染发送 - ByteBuffer bb = proto.rend(packet); - - synchronized (this) { - // 响应解析 - bb = syncRead(syncSend(bb)); - } - - Packet p = proto.parse(bb); - Map ret = p.toMap(); - - if ( - !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) - ) { - throw new SydApiException("包序号不匹配", -4); - } - - ret = (Map) ret.get("data"); - PacketSection error = (PacketSection) ret.get("error"); - byte[] be = error.getBytes(); - if ((0 != (be[0] ^ be[1]))) { - throw new SydApiException(error.getInfo(), error.autoInt()); - } - - byte[] deviceinfo = ((PacketSection) ret.get("deviceinfo")).getBytes(); - - return new DeviceInfo(deviceinfo); - } - - @Override - public byte[] directBytes(byte[] data) { - //初始化一个和byte长度一样的bb - ByteBuffer bb = ByteBuffer.allocate(data.length); - // 数组放到bb中 - bb.put(data); - - //发送数据,解析 - synchronized (this) { - bb = syncRead(syncSend(bb)); - } - //重置 limit 和postion 值 - bb.flip(); - //获取bb中有效大小 - int len = bb.limit() - bb.position(); - - byte[] bytes = new byte[len]; - for (int i = 0; i < bytes.length; i++) { - bytes[i] = bb.get(); - } - return bytes; - } - - /** - * 获取随机数 - * @param randLen 随机数长度 - * @return - */ - public byte[] genRandom(int randLen) { - //获取协议 - Proto0101 proto = new Proto0101(); - - //填充数据 - PacketSN sn = PacketSN.gen(); - HashMap packet = new HashMap(); - packet.put("header", sn.getSn().array()); - HashMap data = new HashMap(); - data.put("randLen", randLen); - packet.put("data", data); - - //渲染发送 - ByteBuffer bb = proto.rend(packet); - - synchronized (this) { - //解析响应 - bb = syncRead(syncSend(bb)); - } - Packet p = proto.parse(bb, packet); - Map ret = p.toMap(); - if ( - !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) - ) { - throw new SydApiException("包序号不匹配", -4); - } - ret = (Map) ret.get("data"); - PacketSection error = (PacketSection) ret.get("error"); - byte[] be = error.getBytes(); - if ((0 != (be[0] ^ be[1]))) { - throw new SydApiException(error.getInfo(), error.autoInt()); - } - - return ((PacketSection) ret.get("randData")).getBytes(); - } -} +//package racal.sunyard.main; +// +//import com.sunyard.SydApiException; +//import com.sunyard.SydApiSDF; +//import com.sunyard.entity.DeviceInfo; +//import com.sunyard.proto.Packet; +//import com.sunyard.proto.PacketSection; +//import com.sunyard.proto.Util; +//import com.sunyard.trans.PacketSN; +//import racal.sunyard.main.proto.Proto0100; +//import racal.sunyard.main.proto.Proto0101; +//import racal.sunyard.main.proto.ProtoSK; +// +//import java.io.IOException; +//import java.io.InputStream; +//import java.net.InetSocketAddress; +//import java.net.Socket; +//import java.net.SocketAddress; +//import java.net.SocketTimeoutException; +//import java.nio.ByteBuffer; +//import java.util.Arrays; +//import java.util.HashMap; +//import java.util.Map; +// +//public class SydApiSDF4j implements SydApiSDF { +// +// private static boolean debug = false; +// +// private static long sTime = System.currentTimeMillis(); +// +// private static String ip1; +// private static String ip2; +// private static int port; +// private static int timeout; +// +// private Socket socket; +// +// //初始化变量 +// static { +// +// String d = System.getProperty("com.sunyard.sydapi4j.debug"); +// if ("true".equals(d)) { +// debug = true; +// } +// } +// +// private static void println(Object i) { +// if (debug) { +// System.out.println(i); +// } +// +// } +// +// private static void print(Object i) { +// if (debug) { +// System.out.print(i); +// } +// +// } +// +// //gc回收 +// @Override +// protected void finalize() throws Throwable { +// super.finalize(); +// if (null != this.socket) { +// this.socket.close(); +// } +// } +// +// /** +// * 确认链接可用 +// * 确认读缓存为空 +// */ +// private void testSocket() { +// +// // 就是简单对象模式,链接长短完全由用户自己控制 +// if (null == socket) { +// +// // 全局热备模式(old shool) +// if (null != ip2) { +// +// Socket s1 = new Socket(); +// SocketAddress address = new InetSocketAddress(ip1, port); +// +// try { +// s1.connect(address, timeout); +// socket = s1; +// socket.setSoTimeout(timeout); +// } catch (Exception e) { +// Socket s2 = new Socket(); +// SocketAddress add2 = new InetSocketAddress(ip2, port); +// try { +// s2.connect(add2, timeout); +// socket = s2; +// socket.setSoTimeout(timeout); +// } catch (Exception e2) { +// throw new SydApiException(-2); +// } +// } +// +// } +// } +// +// clear(); +// +// } +// +// protected byte[] syncSend(ByteBuffer bb) { +// +// +// byte[] buff; +// if (bb.position() == bb.limit()) { +// buff = bb.array(); +// } else { +// buff = new byte[bb.position()]; +// System.arraycopy(bb.array(), 0, buff, 0, buff.length); +// } +// +// +// println("\n\n发送数据"); +// print("HEX数据: \t"); +// println(Util.bytes2HexString(buff)); +// +// testSocket(); +// +// try { +// socket.getOutputStream().write(buff); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// +// return buff; +// } +// +// private void clear() { +// try { +// InputStream is = socket.getInputStream(); +// while (is.available() > 0) { +// is.read(); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// +// +// private ByteBuffer read(Socket socket) throws IOException { +// InputStream is = socket.getInputStream(); +// int d; +// int high = is.read(); +// int low = is.read(); +// int len = (high << 8) + low; +// +// len += 2; +// +// print("H\t"); +// println(Integer.toHexString(high)); +// print("L\t"); +// println(Integer.toHexString(low)); +// print("Len\t"); +// println(len); +// +// +// ByteBuffer bb = ByteBuffer.allocate(len); +// bb.put((byte) (high & 0xFF)); +// bb.put((byte) (low & 0xFF)); +// +// while (true) { +// d = is.read(); +// if (-1 == d) { +// break; +// } +// +// bb.put((byte) (d & 0xFF)); +// +// if (bb.position() == len) { +// break; +// } +// } +// +// print("HEX数据: \t"); +// println(Util.bytes2HexString(bb.array())); +// return bb; +// } +// +// /** +// * 阻塞读取 +// * 前两个字节是长度 +// * +// * @return +// * @buffer 如果出错,需要补发的数据。 +// */ +// protected ByteBuffer syncRead(byte[] buffer) { +// println("\n\n接收数据"); +// try { +// // 正常接收 +// ByteBuffer bb = read(socket); +// return bb; +// +// } catch (SocketTimeoutException e) { +// throw new SydApiException("接收数据超时", -2); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// +// throw new SydApiException("通信数据错误", -3); +// } +// +// @Override +// synchronized public SydApiSDF connect(String ip, int port, String pwd, int timeout) { +// +// if (null != ip2) { +// throw new SydApiException("双机热备模式不用调用此方法", -1); +// } +// Socket socket = new Socket(); +// SocketAddress address = new InetSocketAddress(ip, port); +// +// try { +// if (timeout > 0) { +// socket.connect(address, timeout); +// } else { +// socket.connect(address); +// } +// socket.setSoTimeout(timeout); +// } catch (Exception e) { +// throw new SydApiException(-2); +// } +// +// this.socket = socket; +// return this; +// } +// +// @Override +// synchronized public SydApiSDF connect(String ip, int port, String pwd, int connectTimeout, int readTimeout) { +// +// if (null != ip2) { +// throw new SydApiException("双机热备模式不用调用此方法", -1); +// } +// Socket socket = new Socket(); +// SocketAddress address = new InetSocketAddress(ip, port); +// +// try { +// socket.connect(address, connectTimeout); +// socket.setSoTimeout(readTimeout); +// } catch (Exception e) { +// throw new SydApiException(-2); +// } +// +// this.socket = socket; +// return this; +// } +// +// @Override +// synchronized public int disconnect() { +// +// if (null != socket) { +// try { +// socket.getInputStream().close(); +// } catch (Exception e1) { +// } +// +// +// try { +// socket.getOutputStream().close(); +// } catch (Exception e2) { +// } +// +// try { +// socket.close(); +// } catch (Exception e) { +// } +// +// } +// +// return 0; +// } +// +// @Override +// public DeviceInfo getStatus() { +// +// Proto0100 proto = new Proto0100(); +// +// HashMap packet = new HashMap(); +// HashMap data = new HashMap(); +// PacketSN sn = PacketSN.gen(); +// packet.put("header", sn.getSn().array()); +// packet.put("data", data); +// +// // 渲染发送 +// ByteBuffer bb = proto.rend(packet); +// +// synchronized (this) { +// // 响应解析 +// bb = syncRead(syncSend(bb)); +// } +// +// Packet p = proto.parse(bb); +// Map ret = p.toMap(); +// +// if ( +// !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) +// ) { +// throw new SydApiException("包序号不匹配", -4); +// } +// +// ret = (Map) ret.get("data"); +// PacketSection error = (PacketSection) ret.get("error"); +// byte[] be = error.getBytes(); +// if ((0 != (be[0] ^ be[1]))) { +// throw new SydApiException(error.getInfo(), error.autoInt()); +// } +// +// byte[] deviceinfo = ((PacketSection) ret.get("deviceinfo")).getBytes(); +// +// return new DeviceInfo(deviceinfo); +// } +// +// @Override +// public byte[] directBytes(byte[] data) { +// //初始化一个和byte长度一样的bb +// ByteBuffer bb = ByteBuffer.allocate(data.length); +// // 数组放到bb中 +// bb.put(data); +// +// //发送数据,解析 +// synchronized (this) { +// bb = syncRead(syncSend(bb)); +// } +// //重置 limit 和postion 值 +// bb.flip(); +// //获取bb中有效大小 +// int len = bb.limit() - bb.position(); +// +// byte[] bytes = new byte[len]; +// for (int i = 0; i < bytes.length; i++) { +// bytes[i] = bb.get(); +// } +// return bytes; +// } +// +// /** +// * 获取随机数 +// * @param randLen 随机数长度 +// * @return +// */ +// public byte[] genRandom(int randLen) { +// //获取协议 +// Proto0101 proto = new Proto0101(); +// +// //填充数据 +// PacketSN sn = PacketSN.gen(); +// HashMap packet = new HashMap(); +// packet.put("header", sn.getSn().array()); +// HashMap data = new HashMap(); +// data.put("randLen", randLen); +// packet.put("data", data); +// +// //渲染发送 +// ByteBuffer bb = proto.rend(packet); +// +// synchronized (this) { +// //解析响应 +// bb = syncRead(syncSend(bb)); +// } +// Packet p = proto.parse(bb, packet); +// Map ret = p.toMap(); +// if ( +// !Arrays.equals(sn.getSn().array(), ((PacketSection) ret.get("header")).getBytes()) +// ) { +// throw new SydApiException("包序号不匹配", -4); +// } +// ret = (Map) ret.get("data"); +// PacketSection error = (PacketSection) ret.get("error"); +// byte[] be = error.getBytes(); +// if ((0 != (be[0] ^ be[1]))) { +// throw new SydApiException(error.getInfo(), error.autoInt()); +// } +// +// return ((PacketSection) ret.get("randData")).getBytes(); +// } +//} diff --git a/src/main/java/racal/sunyard/main/TestDecryptDataWithFile.java b/src/main/java/racal/sunyard/main/TestDecryptDataWithFile.java deleted file mode 100644 index 568a111..0000000 --- a/src/main/java/racal/sunyard/main/TestDecryptDataWithFile.java +++ /dev/null @@ -1,40 +0,0 @@ -package racal.sunyard.main; - -import com.sunyard.SydApi; - -import java.util.Scanner; - -import java.io.UnsupportedEncodingException; - - -public class TestDecryptDataWithFile -{ - - public static void main(String[] args) throws Exception { - - System.out.println("SydApi 测试程序启动"); - SydApi key = new SydApi4j().connect("192.168.0.71",8889,null,10000); - System.out.println("连接成功"); - - String seesionKey = "X246F7CEC2EF09A7A8F0475C6B1CE4B05"; - String inputPath = "c:\\Users\\KJ-Z285\\Desktop\\dataEncrypt.txt"; - String outputPath = "c:\\Users\\KJ-Z285\\Desktop\\dataDncrypt.txt"; - - System.out.println("[Tips]:" + "正在解密,请稍候...\n" ); - - if (!key.SYMDecryptDataWithFile(0x01, seesionKey, inputPath, outputPath)) - { - System.out.println("[Error]:" + "解密失败!\n" ); - } - - System.out.println("[Tips]:" + "解密完成!\n" ); - - - System.out.println("执行结束\n\n" ); - key.disconnect(); -// -// Scanner scanner = new Scanner(System.in); -// String in = scanner.nextLine(); - - } -} diff --git a/src/main/java/racal/sunyard/main/TestClass.java b/src/test/java/com/sunyard/sydapi/test/TestClass.java similarity index 79% rename from src/main/java/racal/sunyard/main/TestClass.java rename to src/test/java/com/sunyard/sydapi/test/TestClass.java index 1851b08..a92b859 100644 --- a/src/main/java/racal/sunyard/main/TestClass.java +++ b/src/test/java/com/sunyard/sydapi/test/TestClass.java @@ -1,9 +1,13 @@ -package racal.sunyard.main; +package com.sunyard.sydapi.test; + +import com.sunyard.util.SYMUtil; public class TestClass implements TestInf{ @Override public void run() { + + System.out.println( "class=" + TestClass.class.getName() ); System.out.println( "classloader" + TestClass.class.getClassLoader().getClass().getName() ); } diff --git a/src/test/java/com/sunyard/sydapi/test/TestDecryptDataWithFile.java b/src/test/java/com/sunyard/sydapi/test/TestDecryptDataWithFile.java index fd18a11..daa20b7 100644 --- a/src/test/java/com/sunyard/sydapi/test/TestDecryptDataWithFile.java +++ b/src/test/java/com/sunyard/sydapi/test/TestDecryptDataWithFile.java @@ -1,11 +1,10 @@ package com.sunyard.sydapi.test; - import com.sunyard.SydApi; -import com.sunyard.proto.Util; -import racal.sunyard.main.SydApi4j; -import java.io.*; +import java.util.Scanner; + +import java.io.UnsupportedEncodingException; public class TestDecryptDataWithFile @@ -14,33 +13,28 @@ public class TestDecryptDataWithFile public static void main(String[] args) throws Exception { System.out.println("SydApi 测试程序启动"); - SydApi key = new SydApi4j().connect("172.16.18.74",8889,null,10000); + SydApi key = new SydApi4j().connect("192.168.0.71",8889,null,10000); System.out.println("连接成功"); - long startTime = System.currentTimeMillis(); //获取开始时间 + String seesionKey = "X246F7CEC2EF09A7A8F0475C6B1CE4B05"; + String inputPath = "c:\\Users\\KJ-Z285\\Desktop\\dataEncrypt.txt"; + String outputPath = "c:\\Users\\KJ-Z285\\Desktop\\dataDncrypt.txt"; - byte[] bytes = Util.hexString2Bytes("CBB5DF1ECDB7564EFDA62076632F459BD8F618DC060A5AC368848C5A1D78A85CAFA26F8228F446E2ABA5AEA8F32CF91B606CFD2125766DD3A4E47F4DD22D3A198C2000E9C6F1B73FA33BFE13A00D3612DC9D7C2811A7C1ABAEDBAEEBE8E18D9A2CD670A2526E98C50C4F9205FDE32162E7C8583154D5DDEF2D1B71C6C1636F684BCF865A8EC852C389DEB381728806AC5659E7980651528C0B6F86A47881A66F2C21317D778253786765D60EAA73BC7C6C4CE658BB5231A4FE7282646B0DC774E0B56E38DA29FBA654DB6973661BC65227751E98AB2DD1EBB8076E32D1DB8712"); + System.out.println("[Tips]:" + "正在解密,请稍候...\n" ); - - String inputPath = "c:\\Users\\MrYang\\Desktop\\dataEncrypt.txt"; - String outputPath = "c:\\Users\\MrYang\\Desktop\\dataDncrypt.txt"; - try { - FileOutputStream fileWriter =new FileOutputStream(inputPath); - fileWriter.write(bytes); - fileWriter.flush(); - fileWriter.close(); - }catch (IOException e){ - e.printStackTrace(); + if (!key.SYMDecryptDataWithFile(0x01, seesionKey, inputPath, outputPath)) + { + System.out.println("[Error]:" + "解密失败!\n" ); } + System.out.println("[Tips]:" + "解密完成!\n" ); - key.SYMDecryptDataWithFile(1, "X246F7CEC2EF09A7A8F0475C6B1CE4B05", inputPath, outputPath); - - long endTime=System.currentTimeMillis(); //获取结束时间 - System.out.println("程序运行时间: "+(endTime-startTime)+"ms"); System.out.println("执行结束\n\n" ); key.disconnect(); +// +// Scanner scanner = new Scanner(System.in); +// String in = scanner.nextLine(); } } diff --git a/src/main/java/racal/sunyard/main/TestInf.java b/src/test/java/com/sunyard/sydapi/test/TestInf.java similarity index 61% rename from src/main/java/racal/sunyard/main/TestInf.java rename to src/test/java/com/sunyard/sydapi/test/TestInf.java index afe48aa..b7ccbb9 100644 --- a/src/main/java/racal/sunyard/main/TestInf.java +++ b/src/test/java/com/sunyard/sydapi/test/TestInf.java @@ -1,4 +1,4 @@ -package racal.sunyard.main; +package com.sunyard.sydapi.test; public interface TestInf { public void run();