diff --git a/boot-service/src/main/java/com/xwbing/demo/CalendarDemo.java b/boot-service/src/main/java/com/xwbing/demo/CalendarDemo.java index f673804..dcc2443 100644 --- a/boot-service/src/main/java/com/xwbing/demo/CalendarDemo.java +++ b/boot-service/src/main/java/com/xwbing/demo/CalendarDemo.java @@ -21,18 +21,18 @@ public class CalendarDemo { */ calendar.set(Calendar.YEAR, 2008);// 年 calendar.set(Calendar.MONTH, 7);// 月从0开始,0表示1月 - /* - * 设置日 对应的时间分量常用的: DATE:月中天 DAY_OF-MONTH:月中的天,与DATE一致 - * DAY_OF_WEEK:周中的天,星期几 DAY_OF_YEAR:年中的天 - */ + /* + * 设置日 对应的时间分量常用的: DATE:月中天 DAY_OF-MONTH:月中的天,与DATE一致 + * DAY_OF_WEEK:周中的天,星期几 DAY_OF_YEAR:年中的天 + */ calendar.set(Calendar.DAY_OF_MONTH, 8);// 日 calendar.set(Calendar.HOUR_OF_DAY, 8);// 时 calendar.set(Calendar.MINUTE, 8);// 分 calendar.set(Calendar.SECOND, 8);// 秒 System.out.println(calendar.getTime()); - /* - * int get(int field) 获取对应的分量的值 - */ + /* + * int get(int field) 获取对应的分量的值 + */ Calendar now = Calendar.getInstance(); int year = now.get(Calendar.YEAR);// 获取年 int month = now.get(Calendar.MONTH) + 1;// 获取月+1 @@ -59,25 +59,25 @@ public class CalendarDemo { now.set(Calendar.MONTH, 1); System.out.println(now.getActualMaximum(Calendar.DAY_OF_MONTH)); - - - - /* - * 查看3年2个月零8天以后的日期? - */ + + + + /* + * 查看3年2个月零8天以后的日期? + */ Calendar nowTime = Calendar.getInstance(); System.out.println(nowTime.getTime()); nowTime.add(Calendar.YEAR, 3); nowTime.add(Calendar.MONTH, 2); nowTime.add(Calendar.DAY_OF_YEAR, 8);// 用DAY_OF_YEAR System.out.println(nowTime.getTime()); - /* - * 当遇到类似开发需求: 要求用户输入一个日期,然后对该日期进行一系列的运算 再将计算后的日期显示给用户时。 流程如下: - * 1:获取用户输入的日期字符串 - * 2:使用SimpleDateFormat将其转换为Date - * 3:创建一个Calendar。使其表示Date表示的日期 - * 4:使用Calendar根据需求计算时间 - * 5:将Calendar转换为一个Date 6:使用SimpleDateFormal将Date转换为字符串后显示给用户 - */ + /* + * 当遇到类似开发需求: 要求用户输入一个日期,然后对该日期进行一系列的运算 再将计算后的日期显示给用户时。 流程如下: + * 1:获取用户输入的日期字符串 + * 2:使用SimpleDateFormat将其转换为Date + * 3:创建一个Calendar。使其表示Date表示的日期 + * 4:使用Calendar根据需求计算时间 + * 5:将Calendar转换为一个Date 6:使用SimpleDateFormal将Date转换为字符串后显示给用户 + */ } } diff --git a/boot-service/src/main/java/com/xwbing/demo/FileDemo.java b/boot-service/src/main/java/com/xwbing/demo/FileDemo.java index 70ce940..bea47ae 100644 --- a/boot-service/src/main/java/com/xwbing/demo/FileDemo.java +++ b/boot-service/src/main/java/com/xwbing/demo/FileDemo.java @@ -16,7 +16,7 @@ import java.io.InputStream; public class FileDemo { public static void main(String[] args) throws IOException { /* - * + * * 文件 * 尽量使用相对路径 * 在eclipse中,"."当前目录,指的是 @@ -24,35 +24,35 @@ public class FileDemo { */ //创建文件对象 File file = new File("." + File.separator + "demo.txt");//创建文件对象,并不创建文件 - if(!file.exists()){ + if (!file.exists()) { file.createNewFile(); //创建文件 } - if(file.exists()){ + if (file.exists()) { file.delete();//删除文件 } String name = file.getName();//获取文件名 long length = file.length();//获取文件大小 long time = file.lastModified();//获取文件最后修改时间 //查看文件是否具有可运行,可读,可写的权限 - boolean b=file.canExecute(); - boolean b1=file.canRead(); - boolean b2=file.canWrite(); + boolean b = file.canExecute(); + boolean b1 = file.canRead(); + boolean b2 = file.canWrite(); boolean isDir = file.isDirectory();//是否为一个目录 boolean isFile = file.isFile();//是否为一个文件 - boolean isHidden=file.isHidden();//是否为一个隐藏文件 - + boolean isHidden = file.isHidden();//是否为一个隐藏文件 + /** * 目录 */ - File dir=new File("demo"); - File[] subs=dir.listFiles();//获取目录下的所有子项 - if(!dir.exists()){ + File dir = new File("demo"); + File[] subs = dir.listFiles();//获取目录下的所有子项 + if (!dir.exists()) { dir.mkdir(); - }else { + } else { dir.delete();//空目录才能删除 } - File dirs =new File("a"+File.separator+"b"+File.separator+"c"); - if(!dirs.exists()){ + File dirs = new File("a" + File.separator + "b" + File.separator + "c"); + if (!dirs.exists()) { /* * 在创建当前目录的同时将不存在的父目录一并创建出来 */ diff --git a/boot-service/src/main/java/com/xwbing/demo/FileUploadDemo.java b/boot-service/src/main/java/com/xwbing/demo/FileUploadDemo.java index 5ac864d..f38ca6a 100644 --- a/boot-service/src/main/java/com/xwbing/demo/FileUploadDemo.java +++ b/boot-service/src/main/java/com/xwbing/demo/FileUploadDemo.java @@ -22,6 +22,7 @@ import java.util.List; public class FileUploadDemo { /** * 获取文件数据 + * * @param multipartFiles * @return */ @@ -30,11 +31,11 @@ public class FileUploadDemo { JSONObject materialInfo; for (MultipartFile multipartFile : multipartFiles) { if (!multipartFile.isEmpty()) { - materialInfo=new JSONObject(); + materialInfo = new JSONObject(); String originName = multipartFile.getOriginalFilename();//原始名字 - materialInfo.put("name",originName); + materialInfo.put("name", originName); String fileType = originName.substring(originName.lastIndexOf(".") + 1);//获取文件后缀名 - materialInfo.put("type",fileType); + materialInfo.put("type", fileType); byte[] data; try { InputStream is = multipartFile.getInputStream();//文件输入流 @@ -45,7 +46,7 @@ public class FileUploadDemo { throw new UtilException("读取数据错误"); } String base64 = Base64.getEncoder().encodeToString(data);//对数据字节进行base64编码 - materialInfo.put("data",base64); + materialInfo.put("data", base64); list.add(materialInfo); } } @@ -54,30 +55,31 @@ public class FileUploadDemo { /** * 采用file.Transto 来保存上传的文件 + * * @param multipartFile */ public void fileUpload(CommonsMultipartFile multipartFile) { - if (!multipartFile.isEmpty()) { - String name = multipartFile.getOriginalFilename();//原始名字 - ClassPathResource file = new ClassPathResource("pic"); - try { - String path = file.getFile().getAbsolutePath(); - File targetFile = new File(path+ File.separator+name); - if (!targetFile.exists()) { - targetFile.createNewFile(); - } - multipartFile.transferTo(targetFile); - } catch (IOException e) { - throw new UtilException("读取数据错误"); + if (!multipartFile.isEmpty()) { + String name = multipartFile.getOriginalFilename();//原始名字 + ClassPathResource file = new ClassPathResource("pic"); + try { + String path = file.getFile().getAbsolutePath(); + File targetFile = new File(path + File.separator + name); + if (!targetFile.exists()) { + targetFile.createNewFile(); } + multipartFile.transferTo(targetFile); + } catch (IOException e) { + throw new UtilException("读取数据错误"); } + } } - public static void main(String[] args) throws Exception{ + public static void main(String[] args) throws Exception { ClassPathResource file = new ClassPathResource("pic"); String path = file.getFile().getAbsolutePath(); - File targetFile = new File(path+ File.separator+"test.txt"); - if(!targetFile.exists()){ + File targetFile = new File(path + File.separator + "test.txt"); + if (!targetFile.exists()) { targetFile.createNewFile(); //创建文件 } System.out.println(""); diff --git a/boot-service/src/main/java/com/xwbing/demo/ForEachMap.java b/boot-service/src/main/java/com/xwbing/demo/ForEachMap.java index a68c7aa..d115211 100644 --- a/boot-service/src/main/java/com/xwbing/demo/ForEachMap.java +++ b/boot-service/src/main/java/com/xwbing/demo/ForEachMap.java @@ -35,24 +35,24 @@ public class ForEachMap { }; /* * 遍历所有的key - * set keySet() - * 该方法会将当前map中所有的key存入一个set集合后返回 - * 那么遍历该集合就等于遍历类所有的key - */ + * set keySet() + * 该方法会将当前map中所有的key存入一个set集合后返回 + * 那么遍历该集合就等于遍历类所有的key + */ Set keySet = map.keySet(); for (String key : keySet) { System.out.println(key); } /* * 遍历每一组键值对(推荐) - * map中每一组键值对都是由map的内部类: - * java.util.map.entry的一个实例类表示的 - * entry有两个方法:getkey getvalue 可以分别获取这一组键值对中的key和value - * - * Set entrySet - * 该方法会将map中的每一组键对(entry实例) - * 存入一个set集合后返回 - */ + * map中每一组键值对都是由map的内部类: + * java.util.map.entry的一个实例类表示的 + * entry有两个方法:getkey getvalue 可以分别获取这一组键值对中的key和value + * + * Set entrySet + * 该方法会将map中的每一组键对(entry实例) + * 存入一个set集合后返回 + */ Set> entrySet = map.entrySet(); for (Entry e : entrySet) { String key = e.getKey(); @@ -61,9 +61,9 @@ public class ForEachMap { } /* * 遍历所有的value - * Collection values() - * 该方法会将当前map中所有的value存入一个集合后返回 - */ + * Collection values() + * 该方法会将当前map中所有的value存入一个集合后返回 + */ Collection values = map.values(); for (Integer value : values) { System.out.println(value); diff --git a/boot-service/src/main/java/com/xwbing/demo/IODemo.java b/boot-service/src/main/java/com/xwbing/demo/IODemo.java index f818f9c..b438e6c 100644 --- a/boot-service/src/main/java/com/xwbing/demo/IODemo.java +++ b/boot-service/src/main/java/com/xwbing/demo/IODemo.java @@ -55,7 +55,7 @@ public class IODemo { } bis1.close(); bos1.close(); - + /* * 字符流 * 读写单位是字符 diff --git a/boot-service/src/main/java/com/xwbing/demo/Java8DateDemo.java b/boot-service/src/main/java/com/xwbing/demo/Java8DateDemo.java index d39e022..7355f92 100644 --- a/boot-service/src/main/java/com/xwbing/demo/Java8DateDemo.java +++ b/boot-service/src/main/java/com/xwbing/demo/Java8DateDemo.java @@ -52,15 +52,15 @@ public class Java8DateDemo { LocalTime specificSecondTime = LocalTime.ofSecondOfDay(1);// 00:00:01 LocalDateTime dateTime = date.atTime(time);// Create LocalDateTime from - // LocalDate + // LocalDate LocalDateTime today = LocalDateTime.now();// Current Date today = LocalDateTime.of(LocalDate.now(), LocalTime.now()); LocalDateTime specificDate = LocalDateTime.of(2014, Month.JANUARY, 1, 10, 10, 30);// 2014-01-01T10:10:30 LocalDateTime todayKolkata1 = LocalDateTime.now(ZoneId .of("Asia/Kolkata")); - int second=today.getSecond();//获取时间中的秒 - int week=today.getDayOfWeek().getValue();//获取周几 + int second = today.getSecond();//获取时间中的秒 + int week = today.getDayOfWeek().getValue();//获取周几 /* * 时钟 @@ -73,8 +73,8 @@ public class Java8DateDemo { /* *新旧日期转换 */ - Instant instant = new Date().toInstant(); - Date dateee = Date.from(instant); + Instant instant = new Date().toInstant(); + Date dateee = Date.from(instant); /* * 时间相差 diff --git a/boot-service/src/main/java/com/xwbing/demo/RecursiveFIle.java b/boot-service/src/main/java/com/xwbing/demo/RecursiveFIle.java index 2a275d3..15d97ae 100644 --- a/boot-service/src/main/java/com/xwbing/demo/RecursiveFIle.java +++ b/boot-service/src/main/java/com/xwbing/demo/RecursiveFIle.java @@ -4,26 +4,26 @@ import java.io.File; /** * 删除一个含有子项的目录 - * - * @author xiangwb * + * @author xiangwb */ public class RecursiveFIle { - public static void main(String[] args) { - File dir = new File("C:\\Users\\admin\\Desktop\\123"); - deleteFile(dir); - } - /* - * 将给定的file表示的文件或目录删除 - */ - public static void deleteFile(File f) { - if(f.isDirectory()){ - //将该目录下的所有子项删除 - File[] subs=f.listFiles(); - for(File sub:subs){ - deleteFile(sub); - } - } - f.delete(); - } + public static void main(String[] args) { + File dir = new File("C:\\Users\\admin\\Desktop\\123"); + deleteFile(dir); + } + + /* + * 将给定的file表示的文件或目录删除 + */ + public static void deleteFile(File f) { + if (f.isDirectory()) { + //将该目录下的所有子项删除 + File[] subs = f.listFiles(); + for (File sub : subs) { + deleteFile(sub); + } + } + f.delete(); + } } diff --git a/boot-service/src/main/java/com/xwbing/demo/ThreadSyncDemo.java b/boot-service/src/main/java/com/xwbing/demo/ThreadSyncDemo.java index ade639d..73a1b72 100644 --- a/boot-service/src/main/java/com/xwbing/demo/ThreadSyncDemo.java +++ b/boot-service/src/main/java/com/xwbing/demo/ThreadSyncDemo.java @@ -29,8 +29,8 @@ public class ThreadSyncDemo { Thread t2 = new Thread(s::buy); t1.start(); t2.start(); - - + + /* * 静态方法锁 */ @@ -38,7 +38,7 @@ public class ThreadSyncDemo { Thread tt2 = new Thread(ThreadSyncDemo::doSome); tt1.start(); tt2.start(); - + /* * 互斥 */ diff --git a/boot-service/src/main/java/com/xwbing/demo/XmlDemo.java b/boot-service/src/main/java/com/xwbing/demo/XmlDemo.java index e7cb613..479127f 100644 --- a/boot-service/src/main/java/com/xwbing/demo/XmlDemo.java +++ b/boot-service/src/main/java/com/xwbing/demo/XmlDemo.java @@ -3,6 +3,7 @@ package com.xwbing.demo; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.List; + import org.dom4j.Attribute; import org.dom4j.Document; import org.dom4j.DocumentHelper; @@ -18,80 +19,78 @@ import org.dom4j.io.XMLWriter; public class XmlDemo { - /** - * - * 功能描述:将doc对象(xml)写到文件中 - * 作 者:xwb - * 创建时间:2017年2月16日 下午2:59:26 - * - * @param doc - * @param xml - * @throws Exception - */ - private static void write2xml(Document doc, String fos) throws Exception { - FileOutputStream out = new FileOutputStream(fos); - // dom4j 提供类格式工具,可以输出时候对doc进行化妆,搞漂亮一些 - OutputFormat fmt = OutputFormat.createPrettyPrint(); - XMLWriter writer = new XMLWriter(out, fmt);// 格式 - writer.write(doc); - writer.close(); - } + /** + * 功能描述:将doc对象(xml)写到文件中 + * 作 者:xwb + * 创建时间:2017年2月16日 下午2:59:26 + * + * @param doc + * @param xml + * @throws Exception + */ + private static void write2xml(Document doc, String fos) throws Exception { + FileOutputStream out = new FileOutputStream(fos); + // dom4j 提供类格式工具,可以输出时候对doc进行化妆,搞漂亮一些 + OutputFormat fmt = OutputFormat.createPrettyPrint(); + XMLWriter writer = new XMLWriter(out, fmt);// 格式 + writer.write(doc); + writer.close(); + } - /** - * - * 功能描述: 读取XML文件到doc对象 - * 作 者:xwb - * 创建时间:2017年2月16日 下午3:01:33 - * - * @return - * @throws Exception - */ - private static Document readXml(String fis) throws Exception { - SAXReader reader = new SAXReader(); - FileInputStream in = new FileInputStream(fis); - Document doc = reader.read(in); - return doc; - } + /** + * 功能描述: 读取XML文件到doc对象 + * 作 者:xwb + * 创建时间:2017年2月16日 下午3:01:33 + * + * @return + * @throws Exception + */ + private static Document readXml(String fis) throws Exception { + SAXReader reader = new SAXReader(); + FileInputStream in = new FileInputStream(fis); + Document doc = reader.read(in); + return doc; + } - public static void main(String[] args) throws Exception { - Document doc = readXml("xmlDemo.xml"); - System.out.println(doc.asXML() + "..............."); + public static void main(String[] args) throws Exception { + Document doc = readXml("xmlDemo.xml"); + System.out.println(doc.asXML() + "..............."); - // doc 是全部的XML文件的内容 - // doc 引用的是内存中的对象。 - Element root = doc.getRootElement();// 获取xml的根元素,访问xml中数据的唯一入口 - // 获取根元素下所有子元素,并遍历 - List list = root.elements(); - for (Element e2 : list) { - System.out.println(e2.getName());// 获取元素名字 - System.out.println(e2.getText());// 获取元素内文本内容 - } + // doc 是全部的XML文件的内容 + // doc 引用的是内存中的对象。 + Element root = doc.getRootElement();// 获取xml的根元素,访问xml中数据的唯一入口 + // 获取根元素下所有子元素,并遍历 + List list = root.elements(); + for (Element e2 : list) { + System.out.println(e2.getName());// 获取元素名字 + System.out.println(e2.getText());// 获取元素内文本内容 + } - Element book = root.element("book");// 获取满足第一个条件的子元素 - Element name = book.element("name"); - name.setText("轶名名");// 修改元素内容 - Attribute id = book.attribute("id");// 获取属性 - System.out.println(id.getValue()); - id.setValue("b3");// 修改属性 + Element book = root.element("book");// 获取满足第一个条件的子元素 + Element name = book.element("name"); + name.setText("轶名名");// 修改元素内容 + Attribute id = book.attribute("id");// 获取属性 + System.out.println(id.getValue()); + id.setValue("b3");// 修改属性 - // 如果修改了doc 就能实现修改xml并写文件 - // 为根元素添加子元素 - Element newOne = root.addElement("book8"); - newOne.addElement("name").setText("18岁给我一姑娘"); - newOne.addAttribute("id", "b5"); - newOne.addAttribute("lang", "中文"); + // 如果修改了doc 就能实现修改xml并写文件 + // 为根元素添加子元素 + Element newOne = root.addElement("book8"); + newOne.addElement("name").setText("18岁给我一姑娘"); + newOne.addAttribute("id", "b5"); + newOne.addAttribute("lang", "中文"); - // 找到元素并且删除这个子元素 - Element book1 = root.element("book8"); - root.remove(book1); - write2xml(doc, "demo.xml"); + // 找到元素并且删除这个子元素 + Element book1 = root.element("book8"); + root.remove(book1); + write2xml(doc, "demo.xml"); - // 创建新的xml document对象 - Document newDoc = DocumentHelper.createDocument(); - // 为doc添加根元素 - Element newRoot = newDoc.addElement("students"); - newRoot.addElement("stu1"); - newRoot.addElement("stu2"); - write2xml(newDoc, "xmlDemoStu.xml"); - } + // 创建新的xml document对象 + Document newDoc = DocumentHelper.createDocument(); + // 为doc添加根元素 + Element newRoot = newDoc.addElement("students"); + newRoot.addElement("stu1"); + newRoot.addElement("stu2"); + write2xml(newDoc, "xmlDemoStu.xml"); + } } diff --git a/boot-service/src/main/java/com/xwbing/demo/chat/Client.java b/boot-service/src/main/java/com/xwbing/demo/chat/Client.java index 9cc6857..99c873f 100644 --- a/boot-service/src/main/java/com/xwbing/demo/chat/Client.java +++ b/boot-service/src/main/java/com/xwbing/demo/chat/Client.java @@ -27,10 +27,10 @@ public class Client { try { /* * 初始化socket需要传入两个参数: 1:远程计算机的ip地址 2:服务端应用程序在服务器上申请的端口 - * 我们是通过ip地址找到服务器的计算机,在通过端口找到该机器上的服务端应用 程序,这个端口不是客户端决定的,而是服务端决定的 - * - * 实例化socket的过程就是连接的过程 若服务端没有响应,这里会抛出异常 - */ + * 我们是通过ip地址找到服务器的计算机,在通过端口找到该机器上的服务端应用 程序,这个端口不是客户端决定的,而是服务端决定的 + * + * 实例化socket的过程就是连接的过程 若服务端没有响应,这里会抛出异常 + */ socket = new Socket("localhost", 7851); } catch (Exception e) { throw e; @@ -44,8 +44,8 @@ public class Client { Thread t = new Thread(handler); t.start(); /* - * outputstream getoutputstream() 通过socket获取输出流,用来将数据发送至服务端 - */ + * outputstream getoutputstream() 通过socket获取输出流,用来将数据发送至服务端 + */ Scanner sc = new Scanner(System.in); OutputStream out = socket.getOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(out, "utf-8"); diff --git a/boot-service/src/main/java/com/xwbing/demo/chat/Server.java b/boot-service/src/main/java/com/xwbing/demo/chat/Server.java index 434d004..b059123 100644 --- a/boot-service/src/main/java/com/xwbing/demo/chat/Server.java +++ b/boot-service/src/main/java/com/xwbing/demo/chat/Server.java @@ -35,9 +35,9 @@ public class Server { public Server() throws Exception { try { /* - * 初始化serversocket并指定服务端口 - * 该端口不能与其他应用程序冲突,否则会抛出异常 - */ + * 初始化serversocket并指定服务端口 + * 该端口不能与其他应用程序冲突,否则会抛出异常 + */ server = new ServerSocket(7851); allOut = new ArrayList<>(); } catch (Exception e) { @@ -79,12 +79,12 @@ public class Server { */ public void start() { try { - /* - * scoket accept() - * serversocket提供了accept方法,该方法用于监听申请的服务端口,直到一个客户端连接 - * 然后返回一个socket实例用于与该客户端通讯 - * 这个方法是一个阻塞方法,直到客户端连接返回继续向下执行 - */ + /* + * scoket accept() + * serversocket提供了accept方法,该方法用于监听申请的服务端口,直到一个客户端连接 + * 然后返回一个socket实例用于与该客户端通讯 + * 这个方法是一个阻塞方法,直到客户端连接返回继续向下执行 + */ while (true) { System.out.println("等待客户端连接"); Socket socket = server.accept(); @@ -122,10 +122,10 @@ public class Server { ClientHandler(Socket socket) { this.socket = socket; - /* - * 通过socket可以获取远程计算机地址信息 - * 对于服务端这边而言,远程计算机即客户端 - */ + /* + * 通过socket可以获取远程计算机地址信息 + * 对于服务端这边而言,远程计算机即客户端 + */ InetAddress address = socket.getInetAddress(); // 获取ip地址的字符串形式 host = address.getHostAddress(); @@ -137,31 +137,31 @@ public class Server { try { //通知所有客户该客户端上线了 sendMessage("[" + host + "]" + "上线了!"); - /* - * 通过Socket获取输出流,用于将消息发送 - * 给客户端 - */ + /* + * 通过Socket获取输出流,用于将消息发送 + * 给客户端 + */ OutputStream out = socket.getOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(out, "utf-8"); pw = new PrintWriter(osw, true); //将该客户端的输出流存入共享集合 addOut(pw); - /* - * inputstream getinputstream() - * socket提供的该方法用来获取一个输入流 - * 通过该输入流可以读取远端计算机发送过来的数据 - */ + /* + * inputstream getinputstream() + * socket提供的该方法用来获取一个输入流 + * 通过该输入流可以读取远端计算机发送过来的数据 + */ InputStream in = socket.getInputStream(); InputStreamReader isr = new InputStreamReader(in, "utf-8"); BufferedReader br = new BufferedReader(isr); //读取客户端发送过来的消息 String message; - /* - * 服务端接受客户端发送过来的消息时,由于客户端操作系统不同, - * 那么当客户端断开连接时的效果也不相同, - * 当windows的客户端断开连接后,br.readline方法会抛出异常 - * 当linux的客户端断开连接后,br.readline会返回null - */ + /* + * 服务端接受客户端发送过来的消息时,由于客户端操作系统不同, + * 那么当客户端断开连接时的效果也不相同, + * 当windows的客户端断开连接后,br.readline方法会抛出异常 + * 当linux的客户端断开连接后,br.readline会返回null + */ while ((message = br.readLine()) != null) { // System.out.println(host+"说:"+message); // pw.println(host+"说:"+message); @@ -169,17 +169,17 @@ public class Server { } } catch (Exception e) { } finally { - /* - * 客户端与服务端断开后 - */ + /* + * 客户端与服务端断开后 + */ try { //将该客户端的输出流从共享集合中删除 removeOut(pw); //下线 sendMessage("[" + host + "]" + "下线了!"); - /* - * 通讯完毕后,应当socekt关闭,以释放底层资源 - */ + /* + * 通讯完毕后,应当socekt关闭,以释放底层资源 + */ socket.close(); } catch (Exception e) { e.printStackTrace(); diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/model/EmailModel.java b/boot-service/src/main/java/com/xwbing/domain/entity/model/EmailModel.java index 2eb8b3a..09e38ff 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/model/EmailModel.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/model/EmailModel.java @@ -11,53 +11,54 @@ import java.util.Date; * 作者: xiangwb */ @Data -public class EmailModel { - public EmailModel(){ - //默认值 - } - /** - * 发送邮件协议名称,默认smtp - */ - private String protocol; - /** - * 发送邮箱地址 - */ - private String fromEmail; - /** - * 邮箱密码 - */ - private String password; - /** - * 接收邮箱 - */ - private String toEmail; - /** - * 设置发送时间,默认是即时发送 - */ - private Date sendTime; - /** - * 发送邮件服务器主机 - */ - private String serverHost; - /** - * 发送邮件服务器端口 - */ - private Integer serverPort; - /** - * 是否需要身份验证 - */ - private boolean auth; +public class EmailModel { + public EmailModel() { + //默认值 + } - /** - * 邮件主题 - */ - private String subject; - /** - * 邮件内容 - */ - private String centent; - /** - * 邮件附件的文件名 - */ - private String[] attachFileNames; + /** + * 发送邮件协议名称,默认smtp + */ + private String protocol; + /** + * 发送邮箱地址 + */ + private String fromEmail; + /** + * 邮箱密码 + */ + private String password; + /** + * 接收邮箱 + */ + private String toEmail; + /** + * 设置发送时间,默认是即时发送 + */ + private Date sendTime; + /** + * 发送邮件服务器主机 + */ + private String serverHost; + /** + * 发送邮件服务器端口 + */ + private Integer serverPort; + /** + * 是否需要身份验证 + */ + private boolean auth; + + /** + * 邮件主题 + */ + private String subject; + /** + * 邮件内容 + */ + private String centent; + /** + * 邮件附件的文件名 + */ + private String[] attachFileNames; } diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/pay/alipay/AliPayQueryResult.java b/boot-service/src/main/java/com/xwbing/domain/entity/pay/alipay/AliPayQueryResult.java index 652776f..bb8be25 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/pay/alipay/AliPayQueryResult.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/pay/alipay/AliPayQueryResult.java @@ -15,7 +15,7 @@ public class AliPayQueryResult extends AliPayBaseResult { /** * 交易支付状态 */ - private String tradeStatus; + private String tradeStatus; public AliPayQueryResult(boolean success) { this.setSuccess(success); diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/pay/wxpay/WxQueryResult.java b/boot-service/src/main/java/com/xwbing/domain/entity/pay/wxpay/WxQueryResult.java index 0d1afd0..05f062b 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/pay/wxpay/WxQueryResult.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/pay/wxpay/WxQueryResult.java @@ -20,6 +20,7 @@ public class WxQueryResult extends WxBaseResult { * 退款状态 */ private String refundStatus; + public WxQueryResult(boolean success) { this.setSuccess(success); } diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/pay/wxpay/WxRefundParam.java b/boot-service/src/main/java/com/xwbing/domain/entity/pay/wxpay/WxRefundParam.java index 7d97833..e469495 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/pay/wxpay/WxRefundParam.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/pay/wxpay/WxRefundParam.java @@ -42,6 +42,7 @@ public class WxRefundParam { this.refundFee = refundFee; this.opUserId = opUserId; } + public WxRefundParam(String transactionId, String outRefundNo, String opUserId, int totalFee, int refundFee) { this.transactionId = transactionId; this.outRefundNo = outRefundNo; diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/sys/BaseEntity.java b/boot-service/src/main/java/com/xwbing/domain/entity/sys/BaseEntity.java index f3fcc92..d31c714 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/sys/BaseEntity.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/sys/BaseEntity.java @@ -4,9 +4,6 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; -import javax.persistence.Column; -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; import java.io.Serializable; import java.util.Date; @@ -22,12 +19,12 @@ public class BaseEntity implements Serializable { private static final long serialVersionUID = 8901948362657956187L; @ApiModelProperty(value = "主键") private String id; - @ApiModelProperty(value = "创建者",hidden = true) + @ApiModelProperty(value = "创建者", hidden = true) private String creator; - @ApiModelProperty(value = "修改者",hidden = true) + @ApiModelProperty(value = "修改者", hidden = true) private String modifier; - @ApiModelProperty(value = "创建时间",hidden = true) + @ApiModelProperty(value = "创建时间", hidden = true) private Date createTime; - @ApiModelProperty(value = "修改时间",hidden = true) + @ApiModelProperty(value = "修改时间", hidden = true) private Date modifiedTime; } diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysAuthority.java b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysAuthority.java index 9db3841..7c1e36a 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysAuthority.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysAuthority.java @@ -4,9 +4,6 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; -import javax.persistence.Column; -import javax.persistence.Entity; - /** * 说明: 权限 * 项目名称: boot-module-demo diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysConfig.java b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysConfig.java index 4c1ce14..1ace902 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysConfig.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysConfig.java @@ -20,18 +20,18 @@ import javax.validation.constraints.Pattern; @Entity(name = "system_config") public class SysConfig extends BaseEntity { private static final long serialVersionUID = -7587016038432881980L; - @ApiModelProperty(value = "配置项的code",example = "email_config",required = true) + @ApiModelProperty(value = "配置项的code", example = "email_config", required = true) @NotBlank(message = "配置项的code不能为空") @Length(min = 1, max = 50, message = "code长度为1-50") private String code; - @ApiModelProperty(value = "配置项的值",example = "{}",required = true) + @ApiModelProperty(value = "配置项的值", example = "{}", required = true) @NotBlank(message = "配置项的value不能为空") private String value; - @ApiModelProperty(value = "配置项的描述(名称)",example = "邮箱配置",required = true) + @ApiModelProperty(value = "配置项的描述(名称)", example = "邮箱配置", required = true) @NotBlank(message = "配置项的name不能为空") @Length(min = 1, max = 20, message = "value长度为1-20") private String name; - @ApiModelProperty(value = "是否启用",example = "Y",required = true) + @ApiModelProperty(value = "是否启用", example = "Y", required = true) @NotBlank(message = "是否启用不能为空") @Pattern(regexp = "[Y|N]", message = "是否启用格式为Y|N") private String enable; diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysRole.java b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysRole.java index 54d3563..ec84f1e 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysRole.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysRole.java @@ -4,8 +4,6 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; -import javax.persistence.Entity; - /** * 说明: 角色 * 项目名称: boot-module-demo diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysRoleAuthority.java b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysRoleAuthority.java index 8688d2a..1763f99 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysRoleAuthority.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysRoleAuthority.java @@ -3,9 +3,6 @@ package com.xwbing.domain.entity.sys; import lombok.Data; import lombok.EqualsAndHashCode; -import javax.persistence.Column; -import javax.persistence.Entity; - /** * 说明: 角色权限关系 * 项目名称: boot-module-demo diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysUserLoginInOut.java b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysUserLoginInOut.java index 9aff812..5ee860f 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysUserLoginInOut.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysUserLoginInOut.java @@ -3,9 +3,6 @@ package com.xwbing.domain.entity.sys; import lombok.Data; import lombok.EqualsAndHashCode; -import javax.persistence.Column; -import javax.persistence.Entity; - /** * 项目名称: boot-module-demo * 创建时间: 2017/11/7 9:46 diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysUserRole.java b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysUserRole.java index 17fed82..729b4a8 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysUserRole.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/sys/SysUserRole.java @@ -3,9 +3,6 @@ package com.xwbing.domain.entity.sys; import lombok.Data; import lombok.EqualsAndHashCode; -import javax.persistence.Column; -import javax.persistence.Entity; - /** * 说明: 用户角色关系 * 项目名称: boot-module-demo @@ -16,13 +13,13 @@ import javax.persistence.Entity; @Data public class SysUserRole extends BaseEntity { private static final long serialVersionUID = 7340808603856635810L; - public static String table="sys_user_role"; + public static String table = "sys_user_role"; /** * 用户主键 */ - private String userId; + private String userId; /** * 角色主键 */ - private String roleId; + private String roleId; } diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/vo/ListDataDictionaryVo.java b/boot-service/src/main/java/com/xwbing/domain/entity/vo/ListDataDictionaryVo.java index d240b6a..2815b39 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/vo/ListDataDictionaryVo.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/vo/ListDataDictionaryVo.java @@ -15,7 +15,7 @@ import java.util.List; */ @Data @ApiModel -public class ListDataDictionaryVo extends RestMessageVo{ +public class ListDataDictionaryVo extends RestMessageVo { @ApiModelProperty(value = "返回数据") private List data; } diff --git a/boot-service/src/main/java/com/xwbing/domain/entity/vo/SysAuthVo.java b/boot-service/src/main/java/com/xwbing/domain/entity/vo/SysAuthVo.java index 37cfc72..4c99110 100644 --- a/boot-service/src/main/java/com/xwbing/domain/entity/vo/SysAuthVo.java +++ b/boot-service/src/main/java/com/xwbing/domain/entity/vo/SysAuthVo.java @@ -26,5 +26,6 @@ public class SysAuthVo extends SysAuthority { e.printStackTrace(); } } + private List children; } diff --git a/boot-service/src/main/java/com/xwbing/domain/repository/DataDictionaryRepository.java b/boot-service/src/main/java/com/xwbing/domain/repository/DataDictionaryRepository.java index 934ecf6..5b94c60 100644 --- a/boot-service/src/main/java/com/xwbing/domain/repository/DataDictionaryRepository.java +++ b/boot-service/src/main/java/com/xwbing/domain/repository/DataDictionaryRepository.java @@ -14,7 +14,7 @@ import java.util.List; public interface DataDictionaryRepository extends JpaRepository { DataDictionary getByCode(String code); - DataDictionary getByCodeAndEnable(String code,String enable); + DataDictionary getByCodeAndEnable(String code, String enable); List getByParentIdAndEnable(String parentId, String enable); diff --git a/boot-service/src/main/java/com/xwbing/exception/BusinessException.java b/boot-service/src/main/java/com/xwbing/exception/BusinessException.java index af1fefc..ae3f8fd 100644 --- a/boot-service/src/main/java/com/xwbing/exception/BusinessException.java +++ b/boot-service/src/main/java/com/xwbing/exception/BusinessException.java @@ -7,18 +7,18 @@ package com.xwbing.exception; * 作者: xiangwb */ public class BusinessException extends RuntimeException { - private static final long serialVersionUID = 7493711492820795133L; + private static final long serialVersionUID = 7493711492820795133L; - public BusinessException(Throwable cause) { - super(cause); - } + public BusinessException(Throwable cause) { + super(cause); + } - public BusinessException(String message) { - super(message); - } + public BusinessException(String message) { + super(message); + } - public BusinessException(String message, Throwable cause) { - super(message, cause); - } + public BusinessException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/boot-service/src/main/java/com/xwbing/redis/RedisService.java b/boot-service/src/main/java/com/xwbing/redis/RedisService.java index a576fcf..1d4aeb3 100644 --- a/boot-service/src/main/java/com/xwbing/redis/RedisService.java +++ b/boot-service/src/main/java/com/xwbing/redis/RedisService.java @@ -13,6 +13,7 @@ import javax.annotation.Resource; import java.util.List; import java.util.Map; import java.util.Set; + /** * 说明: 封装redis 缓存服务器服务接口 * 项目名称: boot-module-demo @@ -26,7 +27,8 @@ public class RedisService { private JedisPool jedisPool; @Value("${redisCode}") private String redisCode; - private final Logger logger= LoggerFactory.getLogger(RedisService.class); + private final Logger logger = LoggerFactory.getLogger(RedisService.class); + private RedisService() { } @@ -39,7 +41,7 @@ public class RedisService { private Jedis getJedis() { try { return jedisPool.getResource(); - }catch (Exception ex){ + } catch (Exception ex) { logger.error("redis连接失败=================================="); throw new BusinessException("redis连接失败"); } @@ -384,9 +386,9 @@ public class RedisService { String ping = jedis.ping(); logger.info("redis连接成功"); return ping; - } catch (BusinessException ex){//获取jedis客户端失败 + } catch (BusinessException ex) {//获取jedis客户端失败 return ""; - } catch (Exception ex){//ping失败 + } catch (Exception ex) {//ping失败 logger.error("redis连接失败================================="); return ""; } finally { diff --git a/boot-service/src/main/java/com/xwbing/redis/RedisStartupInit.java b/boot-service/src/main/java/com/xwbing/redis/RedisStartupInit.java index 515af59..ca6350d 100644 --- a/boot-service/src/main/java/com/xwbing/redis/RedisStartupInit.java +++ b/boot-service/src/main/java/com/xwbing/redis/RedisStartupInit.java @@ -33,15 +33,15 @@ public class RedisStartupInit implements InitializingBean { public void afterPropertiesSet() { logger.info("redis启动===执行方法===刷新缓存=========================="); String ping = redisService.ping(); - if(StringUtils.isNotEmpty(ping)){ + if (StringUtils.isNotEmpty(ping)) { redisService.set("test", "成功"); - logger.info("redis获取测试数据:{}",redisService.get("test")); + logger.info("redis获取测试数据:{}", redisService.get("test")); redisService.del("xwb"); boolean exists = redisService.exists("xwb"); - logger.info("redis删除测试数据:{}",!exists); + logger.info("redis删除测试数据:{}", !exists); Set set = redisService.keys(redisCode + "*"); set.forEach(keyStr -> { - logger.info("删除缓存名称:{}",keyStr); + logger.info("删除缓存名称:{}", keyStr); redisService.delInit(keyStr); }); logger.info("redis初始化成功================================="); diff --git a/boot-service/src/main/java/com/xwbing/service/rest/ExpressDeliveryService.java b/boot-service/src/main/java/com/xwbing/service/rest/ExpressDeliveryService.java index e1f94bc..e31ff97 100644 --- a/boot-service/src/main/java/com/xwbing/service/rest/ExpressDeliveryService.java +++ b/boot-service/src/main/java/com/xwbing/service/rest/ExpressDeliveryService.java @@ -87,8 +87,8 @@ public class ExpressDeliveryService { if (infoVo != null) { boolean success = infoVo.isSuccess(); logger.info("查询快递信息:{}", success); - if(success){ - String status= StringUtils.isNotEmpty(infoVo.getState()) ? infoVo.getState() : "0"; + if (success) { + String status = StringUtils.isNotEmpty(infoVo.getState()) ? infoVo.getState() : "0"; int statusValue = Integer.valueOf(status); Optional statusEnum = Arrays.stream(CommonEnum.ExpressStatusEnum.values()).filter(obj -> obj.getValue() == statusValue).findFirst(); statusEnum.ifPresent(expressStatusEnum -> infoVo.setDescribe(expressStatusEnum.getName())); diff --git a/boot-service/src/main/java/com/xwbing/service/sys/SysRoleAuthorityService.java b/boot-service/src/main/java/com/xwbing/service/sys/SysRoleAuthorityService.java index 535b393..1510aac 100644 --- a/boot-service/src/main/java/com/xwbing/service/sys/SysRoleAuthorityService.java +++ b/boot-service/src/main/java/com/xwbing/service/sys/SysRoleAuthorityService.java @@ -79,7 +79,7 @@ public class SysRoleAuthorityService { if (deleteByIds != 0) { result.setSuccess(true); result.setMessage("批量删除成功"); - }else { + } else { result.setMessage("批量删除失败"); } return result; diff --git a/boot-service/src/main/java/com/xwbing/service/sys/SysUserRoleService.java b/boot-service/src/main/java/com/xwbing/service/sys/SysUserRoleService.java index c052722..932985e 100644 --- a/boot-service/src/main/java/com/xwbing/service/sys/SysUserRoleService.java +++ b/boot-service/src/main/java/com/xwbing/service/sys/SysUserRoleService.java @@ -78,7 +78,7 @@ public class SysUserRoleService { if (deleteByIds != 0) { result.setSuccess(true); result.setMessage("批量删除成功"); - }else { + } else { result.setMessage("批量删除失败"); } return result; diff --git a/boot-service/src/main/java/com/xwbing/util/EmailUtil.java b/boot-service/src/main/java/com/xwbing/util/EmailUtil.java index b700866..5bd51da 100644 --- a/boot-service/src/main/java/com/xwbing/util/EmailUtil.java +++ b/boot-service/src/main/java/com/xwbing/util/EmailUtil.java @@ -34,8 +34,8 @@ public class EmailUtil { throw new UtilException("发送邮件主机不能为空"); } String protocol = emailModel.getProtocol(); - if(protocol==null || "".equals(protocol.trim())){ - protocol="smtp"; + if (protocol == null || "".equals(protocol.trim())) { + protocol = "smtp"; } props.setProperty("mail.transport.protocol", protocol);// 使用的协议(JavaMail规范要求) props.setProperty("mail.smtp.host", serverHost); // 发件人的邮箱的 @@ -63,12 +63,12 @@ public class EmailUtil { message.setRecipients(Message.RecipientType.TO, toEmailList); /* * message.addRecipient(MimeMessage.RecipientType.TO,new - * InternetAddress("xx@xx.com")); // To: 增加收件人(单个)(可选) - * message.setRecipient(MimeMessage.RecipientType.CC,new - * InternetAddress("xx@xx.com")); // Cc: 抄送(可选) - * message.setRecipient(MimeMessage.RecipientType.BCC,new - * InternetAddress("xx@xx.com"));// Bcc: 密送(可选) - */ + * InternetAddress("xx@xx.com")); // To: 增加收件人(单个)(可选) + * message.setRecipient(MimeMessage.RecipientType.CC,new + * InternetAddress("xx@xx.com")); // Cc: 抄送(可选) + * message.setRecipient(MimeMessage.RecipientType.BCC,new + * InternetAddress("xx@xx.com"));// Bcc: 密送(可选) + */ // Subject: 邮件主题 if (StringUtils.isEmpty(emailModel.getSubject())) { throw new UtilException("邮件主题不能为空"); @@ -83,8 +83,8 @@ public class EmailUtil { multipart.addBodyPart(html); message.setContent(multipart); Date sendTime = emailModel.getSendTime(); - if(sendTime==null){ - sendTime=new Date(); + if (sendTime == null) { + sendTime = new Date(); } message.setSentDate(sendTime);// 设置显示的发件时间 message.saveChanges();// 保存邮件 diff --git a/boot-service/src/main/java/com/xwbing/util/JsonResult.java b/boot-service/src/main/java/com/xwbing/util/JsonResult.java index eb7a18e..3b0af02 100644 --- a/boot-service/src/main/java/com/xwbing/util/JsonResult.java +++ b/boot-service/src/main/java/com/xwbing/util/JsonResult.java @@ -31,7 +31,8 @@ public class JsonResult { /** * 查询返回值为Object - * @param o Object/List + * + * @param o Object/List * @param message * @return */ @@ -47,6 +48,7 @@ public class JsonResult { /** * 增删改返回值为RestMessage + * * @param rest * @return */ @@ -61,6 +63,7 @@ public class JsonResult { /** * 直接返回错误提示 + * * @param error * @return */ diff --git a/boot-service/src/main/java/com/xwbing/util/QRCodeUtil.java b/boot-service/src/main/java/com/xwbing/util/QRCodeUtil.java index ab63724..a55252c 100644 --- a/boot-service/src/main/java/com/xwbing/util/QRCodeUtil.java +++ b/boot-service/src/main/java/com/xwbing/util/QRCodeUtil.java @@ -62,35 +62,37 @@ public class QRCodeUtil { /** * 生成默认尺寸带logo的二维码 + * * @param output 图片文件 - * @param text 二维码内容 + * @param text 二维码内容 * @param logoImg logo图片 - * @param title 二维码图片描述 + * @param title 二维码图片描述 */ - public static void createCodeLogo(File output,String text, InputStream logoImg, String title) { - createCodeLogo(output,text, logoImg, title, 200, 200,14); + public static void createCodeLogo(File output, String text, InputStream logoImg, String title) { + createCodeLogo(output, text, logoImg, title, 200, 200, 14); } /** * 生成自定义尺寸带logo的二维码 - * @param output 图片文件 - * @param width 宽 - * @param height 高 + * + * @param output 图片文件 + * @param width 宽 + * @param height 高 * @param logoImg logo图片 - * @param text 二维码内容 - * @param title 二维码图片描述 - * @param size 字体大小 + * @param text 二维码内容 + * @param title 二维码图片描述 + * @param size 字体大小 */ - public static void createCodeLogo(File output,String text,InputStream logoImg, String title, int width, int height,int size) { + public static void createCodeLogo(File output, String text, InputStream logoImg, String title, int width, int height, int size) { try { internal._codeHeight = height; internal._codeWidth = width; internal._logoImg = logoImg; internal._text = title; internal._fontSize = size; - internal._output=output; - BitMatrix bitMatrix = internal.createCode(text); - internal.addMaterial(bitMatrix); + internal._output = output; + BitMatrix bitMatrix = internal.createCode(text); + internal.addMaterial(bitMatrix); } catch (WriterException e) { LOGGER.error(e.getMessage()); throw new UtilException("生成自定义尺寸带logo的二维码失败"); @@ -151,6 +153,7 @@ public class QRCodeUtil { /** * 根据内容生成二维码矩阵 + * * @param text * @return * @throws WriterException @@ -208,6 +211,7 @@ public class QRCodeUtil { /** * 定位文字 + * * @param image * @return */ @@ -227,6 +231,7 @@ public class QRCodeUtil { /** * 定位logo + * * @param image * @return * @throws IOException @@ -288,6 +293,7 @@ public class QRCodeUtil { /** * 二维码图片转化为输入流 + * * @param image * @return * @throws IOException @@ -299,13 +305,13 @@ public class QRCodeUtil { } } - public static void main(String[] args) throws Exception{ + public static void main(String[] args) throws Exception { ClassPathResource file = new ClassPathResource("pic"); String path = file.getFile().getAbsolutePath(); - File image = new File(path+File.separator+"logo.png"); - FileInputStream logo=new FileInputStream(image); - File out = new File(path+File.separator+"QRCode.png"); - createCodeLogo(out,"java生成的二維碼",logo,"logo"); + File image = new File(path + File.separator + "logo.png"); + FileInputStream logo = new FileInputStream(image); + File out = new File(path + File.separator + "QRCode.png"); + createCodeLogo(out, "java生成的二維碼", logo, "logo"); } } diff --git a/boot-service/src/main/java/com/xwbing/util/captcha/CaptchaUtil.java b/boot-service/src/main/java/com/xwbing/util/captcha/CaptchaUtil.java index 0dae529..840f355 100644 --- a/boot-service/src/main/java/com/xwbing/util/captcha/CaptchaUtil.java +++ b/boot-service/src/main/java/com/xwbing/util/captcha/CaptchaUtil.java @@ -13,103 +13,103 @@ import java.util.Random; */ public class CaptchaUtil { - // 随机产生的字符串 - private static final String RANDOM_STRS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - private static final String FONT_NAME = "Fixedsys"; - private Random random = new Random(); - private static final int FONT_SIZE = 18;// 字体大小 - private static final int WIDTH = 80;// 图片宽 - private static final int HEIGHT = 25;// 图片高 - private static final int LINE_NUM = 50;// 干扰线数量 - private static final int STR_NUM = 4;// 随机产生字符数量 - + // 随机产生的字符串 + private static final String RANDOM_STRS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + private static final String FONT_NAME = "Fixedsys"; + private Random random = new Random(); + private static final int FONT_SIZE = 18;// 字体大小 + private static final int WIDTH = 80;// 图片宽 + private static final int HEIGHT = 25;// 图片高 + private static final int LINE_NUM = 50;// 干扰线数量 + private static final int STR_NUM = 4;// 随机产生字符数量 - /** - * 生成随机图片 - */ - public BufferedImage genRandomCodeImage(StringBuffer randomCode) { - // BufferedImage类是具有缓冲区的Image类 - BufferedImage image = new BufferedImage(WIDTH, HEIGHT, - BufferedImage.TYPE_INT_BGR); - // 获取Graphics对象,便于对图像进行各种绘制操作 - Graphics g = image.getGraphics(); - // 设置背景色 - g.setColor(getRandColor(200, 250)); - // 填充矩形面积 - g.fillRect(0, 0, WIDTH, HEIGHT); - // 设置干扰线的颜色 - g.setColor(getRandColor(110, 120)); - // 绘制干扰线 - for (int i = 0; i <= LINE_NUM; i++) { - drowLine(g); - } - // 绘制随机字符 - g.setFont(new Font(FONT_NAME, Font.PLAIN, FONT_SIZE)); - for (int i = 1; i <= STR_NUM; i++) { - randomCode.append(drowString(g, i)); - } - g.dispose(); - return image; - } - /** - * 给定范围获得随机颜色 - */ - private Color getRandColor(int fc, int bc) { - if (fc > 255) { - fc = 255; - } - if (bc > 255) { - bc = 255; - } - int r = fc + random.nextInt(bc - fc); - int g = fc + random.nextInt(bc - fc); - int b = fc + random.nextInt(bc - fc); - return new Color(r, g, b); - } + /** + * 生成随机图片 + */ + public BufferedImage genRandomCodeImage(StringBuffer randomCode) { + // BufferedImage类是具有缓冲区的Image类 + BufferedImage image = new BufferedImage(WIDTH, HEIGHT, + BufferedImage.TYPE_INT_BGR); + // 获取Graphics对象,便于对图像进行各种绘制操作 + Graphics g = image.getGraphics(); + // 设置背景色 + g.setColor(getRandColor(200, 250)); + // 填充矩形面积 + g.fillRect(0, 0, WIDTH, HEIGHT); + // 设置干扰线的颜色 + g.setColor(getRandColor(110, 120)); + // 绘制干扰线 + for (int i = 0; i <= LINE_NUM; i++) { + drowLine(g); + } + // 绘制随机字符 + g.setFont(new Font(FONT_NAME, Font.PLAIN, FONT_SIZE)); + for (int i = 1; i <= STR_NUM; i++) { + randomCode.append(drowString(g, i)); + } + g.dispose(); + return image; + } - /** - * 绘制字符串 - */ - private String drowString(Graphics g, int i) { - g.setColor(new Color(random.nextInt(101), random.nextInt(111), random - .nextInt(121))); - String rand = String.valueOf(getRandomString(random.nextInt(RANDOM_STRS - .length()))); - g.translate(random.nextInt(3), random.nextInt(3)); - g.drawString(rand, 13 * i, 16); - return rand; - } + /** + * 给定范围获得随机颜色 + */ + private Color getRandColor(int fc, int bc) { + if (fc > 255) { + fc = 255; + } + if (bc > 255) { + bc = 255; + } + int r = fc + random.nextInt(bc - fc); + int g = fc + random.nextInt(bc - fc); + int b = fc + random.nextInt(bc - fc); + return new Color(r, g, b); + } - /** - * 绘制干扰线 - */ - private void drowLine(Graphics g) { - int x = random.nextInt(WIDTH); - int y = random.nextInt(HEIGHT); - int x0 = random.nextInt(16); - int y0 = random.nextInt(16); - g.drawLine(x, y, x + x0, y + y0); - } + /** + * 绘制字符串 + */ + private String drowString(Graphics g, int i) { + g.setColor(new Color(random.nextInt(101), random.nextInt(111), random + .nextInt(121))); + String rand = String.valueOf(getRandomString(random.nextInt(RANDOM_STRS + .length()))); + g.translate(random.nextInt(3), random.nextInt(3)); + g.drawString(rand, 13 * i, 16); + return rand; + } - /** - * 获取随机的字符 - */ - private String getRandomString(int num) { - return String.valueOf(RANDOM_STRS.charAt(num)); - } + /** + * 绘制干扰线 + */ + private void drowLine(Graphics g) { + int x = random.nextInt(WIDTH); + int y = random.nextInt(HEIGHT); + int x0 = random.nextInt(16); + int y0 = random.nextInt(16); + g.drawLine(x, y, x + x0, y + y0); + } - public static void main(String[] args) { - CaptchaUtil tool = new CaptchaUtil(); - StringBuffer code = new StringBuffer(); - BufferedImage image = tool.genRandomCodeImage(code); - System.out.println("random code : " + code); - try { - // 将内存中的图片通过流动形式输出到客户端 - ImageIO.write(image, "JPEG", new FileOutputStream(new File( - "random-code.jpg"))); - } catch (Exception e) { - e.printStackTrace(); - } - } + /** + * 获取随机的字符 + */ + private String getRandomString(int num) { + return String.valueOf(RANDOM_STRS.charAt(num)); + } + + public static void main(String[] args) { + CaptchaUtil tool = new CaptchaUtil(); + StringBuffer code = new StringBuffer(); + BufferedImage image = tool.genRandomCodeImage(code); + System.out.println("random code : " + code); + try { + // 将内存中的图片通过流动形式输出到客户端 + ImageIO.write(image, "JPEG", new FileOutputStream(new File( + "random-code.jpg"))); + } catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/boot-service/src/main/java/com/xwbing/util/wxpay/MD5Signature.java b/boot-service/src/main/java/com/xwbing/util/wxpay/MD5Signature.java index fd06fe7..5d67f6c 100644 --- a/boot-service/src/main/java/com/xwbing/util/wxpay/MD5Signature.java +++ b/boot-service/src/main/java/com/xwbing/util/wxpay/MD5Signature.java @@ -1,5 +1,5 @@ /** - * + * */ package com.xwbing.util.wxpay; @@ -12,67 +12,67 @@ import java.security.SignatureException; public class MD5Signature { - public static String sign(String content, String key) throws Exception { + public static String sign(String content, String key) throws Exception { - String tosign = (content == null ? "" : content) + key; + String tosign = (content == null ? "" : content) + key; - System.out.println("signdata:" + tosign); - try { - return DigestUtils.md5Hex(getContentBytes(tosign, "utf-8")); - } catch (UnsupportedEncodingException e) { - throw new SignatureException("MD5签名[content = " + content + "; charset = utf-8" + "]发生异常!", e); - } + System.out.println("signdata:" + tosign); + try { + return DigestUtils.md5Hex(getContentBytes(tosign, "utf-8")); + } catch (UnsupportedEncodingException e) { + throw new SignatureException("MD5签名[content = " + content + "; charset = utf-8" + "]发生异常!", e); + } - } + } - public static boolean verify(String content, String sign, String key) throws Exception { - String tosign = (content == null ? "" : content) + key; + public static boolean verify(String content, String sign, String key) throws Exception { + String tosign = (content == null ? "" : content) + key; - try { - String mySign = DigestUtils.md5Hex(getContentBytes(tosign, "utf-8")); + try { + String mySign = DigestUtils.md5Hex(getContentBytes(tosign, "utf-8")); - return StringUtils.equals(mySign, sign) ? true : false; - } catch (UnsupportedEncodingException e) { - throw new SignatureException("MD5验证签名[content = " + content + "; charset =utf-8 " + "; signature = " + sign + "]发生异常!", e); - } - } + return StringUtils.equals(mySign, sign) ? true : false; + } catch (UnsupportedEncodingException e) { + throw new SignatureException("MD5验证签名[content = " + content + "; charset =utf-8 " + "; signature = " + sign + "]发生异常!", e); + } + } - public static boolean verify(String content, String sign, String key, String charset) throws Exception { - String tosign = (content == null ? "" : content) + key; - try { - String mySign = DigestUtils.md5Hex(getContentBytes(tosign, charset)); + public static boolean verify(String content, String sign, String key, String charset) throws Exception { + String tosign = (content == null ? "" : content) + key; + try { + String mySign = DigestUtils.md5Hex(getContentBytes(tosign, charset)); - return StringUtils.equals(mySign, sign) ? true : false; - } catch (UnsupportedEncodingException e) { - throw new SignatureException("MD5验证签名[content = " + content + "; charset =" + charset + "; signature = " + sign + "]发生异常!", e); - } - } + return StringUtils.equals(mySign, sign) ? true : false; + } catch (UnsupportedEncodingException e) { + throw new SignatureException("MD5验证签名[content = " + content + "; charset =" + charset + "; signature = " + sign + "]发生异常!", e); + } + } - /** - * @param content - * @param charset - * @return - * @throws SignatureException - * @throws UnsupportedEncodingException - */ - protected static byte[] getContentBytes(String content, String charset) throws UnsupportedEncodingException { - if (StringUtils.isEmpty(charset)) { - return content.getBytes(); - } + /** + * @param content + * @param charset + * @return + * @throws SignatureException + * @throws UnsupportedEncodingException + */ + protected static byte[] getContentBytes(String content, String charset) throws UnsupportedEncodingException { + if (StringUtils.isEmpty(charset)) { + return content.getBytes(); + } - return content.getBytes(charset); - } + return content.getBytes(charset); + } - public static void main(String[] args) { - try { - String str = MD5Signature.sign("123455", "666666666666666"); - System.out.println("qqq:" + str); - System.out.println(MD5Signature.verify("123455", "6edd55a3421c6324db29690dbc334666", "666666666666666")); + public static void main(String[] args) { + try { + String str = MD5Signature.sign("123455", "666666666666666"); + System.out.println("qqq:" + str); + System.out.println(MD5Signature.verify("123455", "6edd55a3421c6324db29690dbc334666", "666666666666666")); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/boot-service/src/main/java/com/xwbing/util/wxpay/Md5Encrypt.java b/boot-service/src/main/java/com/xwbing/util/wxpay/Md5Encrypt.java index 767ffc2..96271fc 100644 --- a/boot-service/src/main/java/com/xwbing/util/wxpay/Md5Encrypt.java +++ b/boot-service/src/main/java/com/xwbing/util/wxpay/Md5Encrypt.java @@ -8,62 +8,60 @@ import java.security.NoSuchAlgorithmException; * 功能:支付宝MD5加密处理核心文件,不需要修改 版本:3.1 修改日期:2010-11-01 说明: * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。 * 该代码仅供学习和研究支付宝接口使用,只是提供一个 - * */ + */ public class Md5Encrypt { - /** - * Used building output as Hex - */ - private static final char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + /** + * Used building output as Hex + */ + private static final char[] DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; - /** - * 对字符串进行MD5加密 - * - * @param text - * 明文 - * - * @return 密文 - */ - public static String md5(String text) { - MessageDigest msgDigest = null; + /** + * 对字符串进行MD5加密 + * + * @param text 明文 + * @return 密文 + */ + public static String md5(String text) { + MessageDigest msgDigest = null; - try { - msgDigest = MessageDigest.getInstance("MD5"); - } catch (NoSuchAlgorithmException e) { - throw new IllegalStateException("System doesn't support MD5 algorithm."); - } + try { + msgDigest = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + throw new IllegalStateException("System doesn't support MD5 algorithm."); + } - try { - msgDigest.update(text.getBytes("utf-8")); // 注意改接口是按照指定编码形式签名 + try { + msgDigest.update(text.getBytes("utf-8")); // 注意改接口是按照指定编码形式签名 - } catch (UnsupportedEncodingException e) { + } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("System doesn't support your EncodingException."); + throw new IllegalStateException("System doesn't support your EncodingException."); - } + } - byte[] bytes = msgDigest.digest(); + byte[] bytes = msgDigest.digest(); - String md5Str = new String(encodeHex(bytes)); + String md5Str = new String(encodeHex(bytes)); - return md5Str; - } + return md5Str; + } - public static char[] encodeHex(byte[] data) { + public static char[] encodeHex(byte[] data) { - int l = data.length; + int l = data.length; - char[] out = new char[l << 1]; + char[] out = new char[l << 1]; - // two characters form the hex value. - for (int i = 0, j = 0; i < l; i++) { - out[j++] = DIGITS[(0xF0 & data[i]) >>> 4]; - out[j++] = DIGITS[0x0F & data[i]]; - } + // two characters form the hex value. + for (int i = 0, j = 0; i < l; i++) { + out[j++] = DIGITS[(0xF0 & data[i]) >>> 4]; + out[j++] = DIGITS[0x0F & data[i]]; + } - return out; - } + return out; + } } \ No newline at end of file diff --git a/boot-service/src/main/java/com/xwbing/util/wxpay/RandomKit.java b/boot-service/src/main/java/com/xwbing/util/wxpay/RandomKit.java index 31fdd46..9cf49bd 100644 --- a/boot-service/src/main/java/com/xwbing/util/wxpay/RandomKit.java +++ b/boot-service/src/main/java/com/xwbing/util/wxpay/RandomKit.java @@ -6,23 +6,24 @@ import java.util.Random; * Created by drore-wzm on 2015/11/23. */ public class RandomKit { - static String[] la_arrs={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","S","X","Y","Z","0","1","2","3","4","5","6","7","8","9"}; + static String[] la_arrs = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "S", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; /**** * 生成len个长度的随机字符 * @param len * @return */ - public static synchronized String buildRandom(int len){ - if (len<=0) { + public static synchronized String buildRandom(int len) { + if (len <= 0) { throw new RuntimeException("参数异常!!!"); } - StringBuffer random=new StringBuffer(); + StringBuffer random = new StringBuffer(); for (int i = 0; i < len; i++) { random.append(la_arrs[new Random().nextInt(la_arrs.length)]); } return random.toString(); } + public static void main(String[] args) { System.out.println(buildRandom(32)); } diff --git a/boot-service/src/main/java/com/xwbing/util/wxpay/SHA1.java b/boot-service/src/main/java/com/xwbing/util/wxpay/SHA1.java index 2ee55d4..5c482c9 100644 --- a/boot-service/src/main/java/com/xwbing/util/wxpay/SHA1.java +++ b/boot-service/src/main/java/com/xwbing/util/wxpay/SHA1.java @@ -3,210 +3,225 @@ package com.xwbing.util.wxpay; import java.security.MessageDigest; public class SHA1 { - private final int[] abcde = { - 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 - }; + private final int[] abcde = { + 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 + }; // 摘要数据存储数组 - private int[] digestInt = new int[5]; + private int[] digestInt = new int[5]; // 计算过程中的临时数据存储数组 - private int[] tmpData = new int[80]; + private int[] tmpData = new int[80]; + // 计算sha-1摘要 - private int process_input_bytes(byte[] bytedata) { + private int process_input_bytes(byte[] bytedata) { // 初试化常量 - System.arraycopy(abcde, 0, digestInt, 0, abcde.length); + System.arraycopy(abcde, 0, digestInt, 0, abcde.length); // 格式化输入字节数组,补10及长度数据 - byte[] newbyte = byteArrayFormatData(bytedata); + byte[] newbyte = byteArrayFormatData(bytedata); // 获取数据摘要计算的数据单元个数 - int MCount = newbyte.length / 64; + int MCount = newbyte.length / 64; // 循环对每个数据单元进行摘要计算 - for (int pos = 0; pos < MCount; pos++) { + for (int pos = 0; pos < MCount; pos++) { // 将每个单元的数据转换成16个整型数据,并保存到tmpData的前16个数组元素中 - for (int j = 0; j < 16; j++) { - tmpData[j] = byteArrayToInt(newbyte, (pos * 64) + (j * 4)); - } + for (int j = 0; j < 16; j++) { + tmpData[j] = byteArrayToInt(newbyte, (pos * 64) + (j * 4)); + } // 摘要计算函数 - encrypt(); - } - return 20; - } + encrypt(); + } + return 20; + } + // 格式化输入字节数组格式 - private byte[] byteArrayFormatData(byte[] bytedata) { + private byte[] byteArrayFormatData(byte[] bytedata) { // 补0数量 - int zeros = 0; + int zeros = 0; // 补位后总位数 - int size = 0; + int size = 0; // 原始数据长度 - int n = bytedata.length; + int n = bytedata.length; // 模64后的剩余位数 - int m = n % 64; + int m = n % 64; // 计算添加0的个数以及添加10后的总长度 - if (m < 56) { - zeros = 55 - m; - size = n - m + 64; - } else if (m == 56) { - zeros = 63; - size = n + 8 + 64; - } else { - zeros = 63 - m + 56; - size = (n + 64) - m + 64; - } + if (m < 56) { + zeros = 55 - m; + size = n - m + 64; + } else if (m == 56) { + zeros = 63; + size = n + 8 + 64; + } else { + zeros = 63 - m + 56; + size = (n + 64) - m + 64; + } // 补位后生成的新数组内容 - byte[] newbyte = new byte[size]; + byte[] newbyte = new byte[size]; // 复制数组的前面部分 - System.arraycopy(bytedata, 0, newbyte, 0, n); + System.arraycopy(bytedata, 0, newbyte, 0, n); // 获得数组Append数据元素的位置 - int l = n; + int l = n; // 补1操作 - newbyte[l++] = (byte) 0x80; + newbyte[l++] = (byte) 0x80; // 补0操作 - for (int i = 0; i < zeros; i++) { - newbyte[l++] = (byte) 0x00; - } + for (int i = 0; i < zeros; i++) { + newbyte[l++] = (byte) 0x00; + } // 计算数据长度,补数据长度位共8字节,长整型 - long N = (long) n * 8; - byte h8 = (byte) (N & 0xFF); - byte h7 = (byte) ((N >> 8) & 0xFF); - byte h6 = (byte) ((N >> 16) & 0xFF); - byte h5 = (byte) ((N >> 24) & 0xFF); - byte h4 = (byte) ((N >> 32) & 0xFF); - byte h3 = (byte) ((N >> 40) & 0xFF); - byte h2 = (byte) ((N >> 48) & 0xFF); - byte h1 = (byte) (N >> 56); - newbyte[l++] = h1; - newbyte[l++] = h2; - newbyte[l++] = h3; - newbyte[l++] = h4; - newbyte[l++] = h5; - newbyte[l++] = h6; - newbyte[l++] = h7; - newbyte[l++] = h8; - return newbyte; - } - private int f1(int x, int y, int z) { - return (x & y) | (~x & z); - } - private int f2(int x, int y, int z) { - return x ^ y ^ z; - } - private int f3(int x, int y, int z) { - return (x & y) | (x & z) | (y & z); - } - private int f4(int x, int y) { - return (x << y) | x >>> (32 - y); - } + long N = (long) n * 8; + byte h8 = (byte) (N & 0xFF); + byte h7 = (byte) ((N >> 8) & 0xFF); + byte h6 = (byte) ((N >> 16) & 0xFF); + byte h5 = (byte) ((N >> 24) & 0xFF); + byte h4 = (byte) ((N >> 32) & 0xFF); + byte h3 = (byte) ((N >> 40) & 0xFF); + byte h2 = (byte) ((N >> 48) & 0xFF); + byte h1 = (byte) (N >> 56); + newbyte[l++] = h1; + newbyte[l++] = h2; + newbyte[l++] = h3; + newbyte[l++] = h4; + newbyte[l++] = h5; + newbyte[l++] = h6; + newbyte[l++] = h7; + newbyte[l++] = h8; + return newbyte; + } + + private int f1(int x, int y, int z) { + return (x & y) | (~x & z); + } + + private int f2(int x, int y, int z) { + return x ^ y ^ z; + } + + private int f3(int x, int y, int z) { + return (x & y) | (x & z) | (y & z); + } + + private int f4(int x, int y) { + return (x << y) | x >>> (32 - y); + } + // 单元摘要计算函数 - private void encrypt() { - for (int i = 16; i <= 79; i++) { - tmpData[i] = f4(tmpData[i - 3] ^ tmpData[i - 8] ^ tmpData[i - 14] ^ - tmpData[i - 16], 1); - } - int[] tmpabcde = new int[5]; - for (int i1 = 0; i1 < tmpabcde.length; i1++) { - tmpabcde[i1] = digestInt[i1]; - } - for (int j = 0; j <= 19; j++) { - int tmp = f4(tmpabcde[0], 5) + - f1(tmpabcde[1], tmpabcde[2], tmpabcde[3]) + tmpabcde[4] + - tmpData[j] + 0x5a827999; - tmpabcde[4] = tmpabcde[3]; - tmpabcde[3] = tmpabcde[2]; - tmpabcde[2] = f4(tmpabcde[1], 30); - tmpabcde[1] = tmpabcde[0]; - tmpabcde[0] = tmp; - } - for (int k = 20; k <= 39; k++) { - int tmp = f4(tmpabcde[0], 5) + - f2(tmpabcde[1], tmpabcde[2], tmpabcde[3]) + tmpabcde[4] + - tmpData[k] + 0x6ed9eba1; - tmpabcde[4] = tmpabcde[3]; - tmpabcde[3] = tmpabcde[2]; - tmpabcde[2] = f4(tmpabcde[1], 30); - tmpabcde[1] = tmpabcde[0]; - tmpabcde[0] = tmp; - } - for (int l = 40; l <= 59; l++) { - int tmp = f4(tmpabcde[0], 5) + - f3(tmpabcde[1], tmpabcde[2], tmpabcde[3]) + tmpabcde[4] + - tmpData[l] + 0x8f1bbcdc; - tmpabcde[4] = tmpabcde[3]; - tmpabcde[3] = tmpabcde[2]; - tmpabcde[2] = f4(tmpabcde[1], 30); - tmpabcde[1] = tmpabcde[0]; - tmpabcde[0] = tmp; - } - for (int m = 60; m <= 79; m++) { - int tmp = f4(tmpabcde[0], 5) + - f2(tmpabcde[1], tmpabcde[2], tmpabcde[3]) + tmpabcde[4] + - tmpData[m] + 0xca62c1d6; - tmpabcde[4] = tmpabcde[3]; - tmpabcde[3] = tmpabcde[2]; - tmpabcde[2] = f4(tmpabcde[1], 30); - tmpabcde[1] = tmpabcde[0]; - tmpabcde[0] = tmp; - } - for (int i2 = 0; i2 < tmpabcde.length; i2++) { - digestInt[i2] = digestInt[i2] + tmpabcde[i2]; - } - for (int n = 0; n < tmpData.length; n++) { - tmpData[n] = 0; - } - } + private void encrypt() { + for (int i = 16; i <= 79; i++) { + tmpData[i] = f4(tmpData[i - 3] ^ tmpData[i - 8] ^ tmpData[i - 14] ^ + tmpData[i - 16], 1); + } + int[] tmpabcde = new int[5]; + for (int i1 = 0; i1 < tmpabcde.length; i1++) { + tmpabcde[i1] = digestInt[i1]; + } + for (int j = 0; j <= 19; j++) { + int tmp = f4(tmpabcde[0], 5) + + f1(tmpabcde[1], tmpabcde[2], tmpabcde[3]) + tmpabcde[4] + + tmpData[j] + 0x5a827999; + tmpabcde[4] = tmpabcde[3]; + tmpabcde[3] = tmpabcde[2]; + tmpabcde[2] = f4(tmpabcde[1], 30); + tmpabcde[1] = tmpabcde[0]; + tmpabcde[0] = tmp; + } + for (int k = 20; k <= 39; k++) { + int tmp = f4(tmpabcde[0], 5) + + f2(tmpabcde[1], tmpabcde[2], tmpabcde[3]) + tmpabcde[4] + + tmpData[k] + 0x6ed9eba1; + tmpabcde[4] = tmpabcde[3]; + tmpabcde[3] = tmpabcde[2]; + tmpabcde[2] = f4(tmpabcde[1], 30); + tmpabcde[1] = tmpabcde[0]; + tmpabcde[0] = tmp; + } + for (int l = 40; l <= 59; l++) { + int tmp = f4(tmpabcde[0], 5) + + f3(tmpabcde[1], tmpabcde[2], tmpabcde[3]) + tmpabcde[4] + + tmpData[l] + 0x8f1bbcdc; + tmpabcde[4] = tmpabcde[3]; + tmpabcde[3] = tmpabcde[2]; + tmpabcde[2] = f4(tmpabcde[1], 30); + tmpabcde[1] = tmpabcde[0]; + tmpabcde[0] = tmp; + } + for (int m = 60; m <= 79; m++) { + int tmp = f4(tmpabcde[0], 5) + + f2(tmpabcde[1], tmpabcde[2], tmpabcde[3]) + tmpabcde[4] + + tmpData[m] + 0xca62c1d6; + tmpabcde[4] = tmpabcde[3]; + tmpabcde[3] = tmpabcde[2]; + tmpabcde[2] = f4(tmpabcde[1], 30); + tmpabcde[1] = tmpabcde[0]; + tmpabcde[0] = tmp; + } + for (int i2 = 0; i2 < tmpabcde.length; i2++) { + digestInt[i2] = digestInt[i2] + tmpabcde[i2]; + } + for (int n = 0; n < tmpData.length; n++) { + tmpData[n] = 0; + } + } + // 4字节数组转换为整数 - private int byteArrayToInt(byte[] bytedata, int i) { - return ((bytedata[i] & 0xff) << 24) | ((bytedata[i + 1] & 0xff) << 16) | - ((bytedata[i + 2] & 0xff) << 8) | (bytedata[i + 3] & 0xff); - } + private int byteArrayToInt(byte[] bytedata, int i) { + return ((bytedata[i] & 0xff) << 24) | ((bytedata[i + 1] & 0xff) << 16) | + ((bytedata[i + 2] & 0xff) << 8) | (bytedata[i + 3] & 0xff); + } + // 整数转换为4字节数组 - private void intToByteArray(int intValue, byte[] byteData, int i) { - byteData[i] = (byte) (intValue >>> 24); - byteData[i + 1] = (byte) (intValue >>> 16); - byteData[i + 2] = (byte) (intValue >>> 8); - byteData[i + 3] = (byte) intValue; - } + private void intToByteArray(int intValue, byte[] byteData, int i) { + byteData[i] = (byte) (intValue >>> 24); + byteData[i + 1] = (byte) (intValue >>> 16); + byteData[i + 2] = (byte) (intValue >>> 8); + byteData[i + 3] = (byte) intValue; + } + // 将字节转换为十六进制字符串 - private static String byteToHexString(byte ib) { - char[] Digit = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', - 'D', 'E', 'F' - }; - char[] ob = new char[2]; - ob[0] = Digit[(ib >>> 4) & 0X0F]; - ob[1] = Digit[ib & 0X0F]; - String s = new String(ob); - return s; - } + private static String byteToHexString(byte ib) { + char[] Digit = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', + 'D', 'E', 'F' + }; + char[] ob = new char[2]; + ob[0] = Digit[(ib >>> 4) & 0X0F]; + ob[1] = Digit[ib & 0X0F]; + String s = new String(ob); + return s; + } + // 将字节数组转换为十六进制字符串 - private static String byteArrayToHexString(byte[] bytearray) { - String strDigest = ""; - for (int i = 0; i < bytearray.length; i++) { - strDigest += byteToHexString(bytearray[i]); - } - return strDigest; - } + private static String byteArrayToHexString(byte[] bytearray) { + String strDigest = ""; + for (int i = 0; i < bytearray.length; i++) { + strDigest += byteToHexString(bytearray[i]); + } + return strDigest; + } + // 计算sha-1摘要,返回相应的字节数组 - public byte[] getDigestOfBytes(byte[] byteData) { - process_input_bytes(byteData); - byte[] digest = new byte[20]; - for (int i = 0; i < digestInt.length; i++) { - intToByteArray(digestInt[i], digest, i * 4); - } - return digest; - } + public byte[] getDigestOfBytes(byte[] byteData) { + process_input_bytes(byteData); + byte[] digest = new byte[20]; + for (int i = 0; i < digestInt.length; i++) { + intToByteArray(digestInt[i], digest, i * 4); + } + return digest; + } + // 计算sha-1摘要,返回相应的十六进制字符串 - public String getDigestOfString(byte[] byteData) { - return byteArrayToHexString(getDigestOfBytes(byteData)); - } - public static void main(String[] args) { - String data = "123456"; - System.out.println(data); + public String getDigestOfString(byte[] byteData) { + return byteArrayToHexString(getDigestOfBytes(byteData)); + } + + public static void main(String[] args) { + String data = "123456"; + System.out.println(data); String digest = new SHA1().getDigestOfString(data.getBytes()); System.out.println(digest); - - // System.out.println( ToMD5.convertSHA1(data).toUpperCase()); + + // System.out.println( ToMD5.convertSHA1(data).toUpperCase()); } private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + private static String getFormattedText(byte[] bytes) { int len = bytes.length; StringBuilder buf = new StringBuilder(len * 2); @@ -217,6 +232,7 @@ public class SHA1 { } return buf.toString(); } + public static String encode(String str) { if (str == null) { return null; diff --git a/boot-service/src/main/java/com/xwbing/util/wxpay/WxSignKit.java b/boot-service/src/main/java/com/xwbing/util/wxpay/WxSignKit.java index 9a7b740..dc4e93c 100644 --- a/boot-service/src/main/java/com/xwbing/util/wxpay/WxSignKit.java +++ b/boot-service/src/main/java/com/xwbing/util/wxpay/WxSignKit.java @@ -15,11 +15,11 @@ public class WxSignKit { * @param params * @return */ - public static String buildJsApiSign(Map params){ + public static String buildJsApiSign(Map params) { StringBuffer sb = new StringBuffer(); Map result = paramsFilter(params); String prestr = createLinkString(result); // 把数组所有元素,按照“参数参数值”的模式拼接成字符串 - String encodeKey= SHA1.encode(prestr); + String encodeKey = SHA1.encode(prestr); return encodeKey; } @@ -36,9 +36,9 @@ public class WxSignKit { public static String buildSign(Map params, String key) { Map result = paramsFilter(params); String prestr = createLinkString(result); // 把数组所有元素,按照“参数参数值”的模式拼接成字符串 - System.out.println(prestr+"==========="); - prestr = prestr +"&key="+ key; // 把接口密钥+拼接后的字符串直接连接起来 - System.out.println("==========="+prestr+"==========="); + System.out.println(prestr + "==========="); + prestr = prestr + "&key=" + key; // 把接口密钥+拼接后的字符串直接连接起来 + System.out.println("===========" + prestr + "==========="); String mysign = Md5Encrypt.md5(prestr); if (mysign != null) { mysign = mysign.toUpperCase(); @@ -71,21 +71,20 @@ public class WxSignKit { /** * 把数组所有元素排序,并按照“参数参数值”的模式拼接成字符串 * - * @param params - * 需要排序并参与字符拼接的参数组 + * @param params 需要排序并参与字符拼接的参数组 * @return 拼接后字符串 */ private static String createLinkString(Map params) { List keys = new ArrayList(params.keySet()); Collections.sort(keys); String prestr = ""; - StringBuffer sb=new StringBuffer(); + StringBuffer sb = new StringBuffer(); for (int i = 0; i < keys.size(); i++) { String key = keys.get(i); String value = params.get(key); sb.append(key).append("=").append(value); - prestr = prestr + key +"="+ value+"&"; - if (i - - E:\apache-maven-3.3.9\repo - - - - - - - - - + E:\apache-maven-3.3.9\repo - - - - - - - - - - - - nexus-drore-team-3rd - admin - admin123 - - - - - - - - nexus - aliyun nexus - http://maven.aliyun.com/nexus/content/groups/public - * - - + + + + - - - - - - jdk1.8 - - true - 1.8 - - - 1.8 - 1.8 - 1.8 - - - - + + + - - - target-env - dev - - + + + - - /path/to/tomcat/instance - - + + + + nexus-drore-team-3rd + admin + admin123 + + + + + + + + + nexus + aliyun nexus + http://maven.aliyun.com/nexus/content/groups/public + * + + + + + + + + + jdk1.8 + + true + 1.8 + + + 1.8 + 1.8 + 1.8 + + + + + + + - - - diff --git a/boot-web/src/main/resources/static/js/baseValue.js b/boot-web/src/main/resources/static/js/baseValue.js index d38ef1a..e27e04f 100644 --- a/boot-web/src/main/resources/static/js/baseValue.js +++ b/boot-web/src/main/resources/static/js/baseValue.js @@ -1 +1 @@ -var basePath="http://127.0.0.1:8080/"; \ No newline at end of file +var basePath = "http://127.0.0.1:8080/"; \ No newline at end of file diff --git a/boot-web/src/main/resources/static/login.html b/boot-web/src/main/resources/static/login.html index e3cfd15..6efe593 100644 --- a/boot-web/src/main/resources/static/login.html +++ b/boot-web/src/main/resources/static/login.html @@ -1,8 +1,8 @@ - - Welcome to the world + + Welcome to the world

Hello World!