医保支付本地中转程序
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

  1. package com.cmyy.localtransfer;
  2. import org.slf4j.Logger;
  3. import org.slf4j.LoggerFactory;
  4. import org.springframework.boot.SpringApplication;
  5. import org.springframework.boot.autoconfigure.SpringBootApplication;
  6. import org.springframework.core.env.Environment;
  7. import java.io.*;
  8. @SpringBootApplication
  9. public class LocalTransferApplication {
  10. private static final Logger LOG = LoggerFactory.getLogger(LocalTransferApplication.class);
  11. public static void main(String[] args) {
  12. System.setProperty("jna.encoding", "GBK");
  13. loadNative("NationECCode");
  14. SpringApplication.run(LocalTransferApplication.class, args);
  15. System.out.println(
  16. " ____ _____ ___.__.___.__. \n" +
  17. " _/ ___\\ / < | < | | \n" +
  18. " \\ \\___| Y Y \\___ |\\___ | \n" +
  19. " \\___ >__|_| / ____|/ ____| \n" +
  20. " \\/ \\/\\/ \\/ \n" +
  21. "\n成美药业医保电子凭证解码中转台启动成功 \n官网:http://www.chengmeimedicine.com 提供技术支持゙ \n");
  22. }
  23. private synchronized static void loadNative(String nativeName) {
  24. String systemType = System.getProperty("os.name");
  25. String fileExt = (systemType.toLowerCase().indexOf("win") != -1) ? ".dll" : ".so";
  26. File path = new File(".");
  27. //将所有动态链接库dll/so文件都放在一个临时文件夹下,然后进行加载
  28. //这是应为项目为可执行jar文件的时候不能很方便的扫描里面文件
  29. //此目录放置在与项目同目录下的natives文件夹下
  30. String sysUserTempDir = path.getAbsoluteFile().getParent() + File.separator + "natives";
  31. //System.out.println("------>>native lib临时存放目录 : " + sysUserTempDir);
  32. String fileName = nativeName + fileExt;
  33. InputStream in = null;
  34. BufferedInputStream reader = null;
  35. FileOutputStream writer = null;
  36. File tempFile = new File(sysUserTempDir + File.separator + fileName);
  37. if(!tempFile.getParentFile().exists())
  38. tempFile.getParentFile().mkdirs() ;
  39. if (tempFile.exists()) {
  40. tempFile.delete();
  41. }
  42. try {
  43. //读取文件形成输入流
  44. in = LocalTransferApplication.class.getClassLoader().getResourceAsStream("/native/" + fileName);
  45. if (in == null)
  46. in = LocalTransferApplication.class.getClassLoader().getResourceAsStream("native/" + fileName);
  47. LocalTransferApplication.class.getClassLoader().getResource(fileName);
  48. reader = new BufferedInputStream(in);
  49. writer = new FileOutputStream(tempFile);
  50. byte[] buffer = new byte[1024];
  51. while (reader.read(buffer) > 0) {
  52. writer.write(buffer);
  53. buffer = new byte[1024];
  54. }
  55. } catch (IOException e) {
  56. e.printStackTrace();
  57. } finally {
  58. try {
  59. if (in != null)
  60. in.close();
  61. if (writer != null)
  62. writer.close();
  63. } catch (IOException e) {
  64. e.printStackTrace();
  65. }
  66. }
  67. System.load(tempFile.getPath());
  68. System.out.println("------>> 加载native文件 :" + tempFile + "成功!!");
  69. }
  70. }