医保支付本地中转程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
3.3 KiB

package com.cmyy.localtransfer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;
import java.io.*;
@SpringBootApplication
public class LocalTransferApplication {
private static final Logger LOG = LoggerFactory.getLogger(LocalTransferApplication.class);
public static void main(String[] args) {
System.setProperty("jna.encoding", "GBK");
loadNative("NationECCode");
SpringApplication.run(LocalTransferApplication.class, args);
System.out.println(
" ____ _____ ___.__.___.__. \n" +
" _/ ___\\ / < | < | | \n" +
" \\ \\___| Y Y \\___ |\\___ | \n" +
" \\___ >__|_| / ____|/ ____| \n" +
" \\/ \\/\\/ \\/ \n" +
"\n成美药业医保电子凭证解码中转台启动成功 \n官网:http://www.chengmeimedicine.com 提供技术支持゙ \n");
}
private synchronized static void loadNative(String nativeName) {
String systemType = System.getProperty("os.name");
String fileExt = (systemType.toLowerCase().indexOf("win") != -1) ? ".dll" : ".so";
File path = new File(".");
//将所有动态链接库dll/so文件都放在一个临时文件夹下,然后进行加载
//这是应为项目为可执行jar文件的时候不能很方便的扫描里面文件
//此目录放置在与项目同目录下的natives文件夹下
String sysUserTempDir = path.getAbsoluteFile().getParent() + File.separator + "natives";
//System.out.println("------>>native lib临时存放目录 : " + sysUserTempDir);
String fileName = nativeName + fileExt;
InputStream in = null;
BufferedInputStream reader = null;
FileOutputStream writer = null;
File tempFile = new File(sysUserTempDir + File.separator + fileName);
if(!tempFile.getParentFile().exists())
tempFile.getParentFile().mkdirs() ;
if (tempFile.exists()) {
tempFile.delete();
}
try {
//读取文件形成输入流
in = LocalTransferApplication.class.getClassLoader().getResourceAsStream("/native/" + fileName);
if (in == null)
in = LocalTransferApplication.class.getClassLoader().getResourceAsStream("native/" + fileName);
LocalTransferApplication.class.getClassLoader().getResource(fileName);
reader = new BufferedInputStream(in);
writer = new FileOutputStream(tempFile);
byte[] buffer = new byte[1024];
while (reader.read(buffer) > 0) {
writer.write(buffer);
buffer = new byte[1024];
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (in != null)
in.close();
if (writer != null)
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.load(tempFile.getPath());
System.out.println("------>> 加载native文件 :" + tempFile + "成功!!");
}
}