requiredType) {
+ assertContextInjected();
+ return applicationContext.getBean(requiredType);
+ }
+
+ /**
+ * 清除SpringContextHolder中的ApplicationContext为Null.
+ */
+ public static void clearHolder() {
+ if (logger.isDebugEnabled()){
+ logger.debug("清除SpringContextHolder中的ApplicationContext:" + applicationContext);
+ }
+ applicationContext = null;
+ }
+
+
+ /**
+ * 实现ApplicationContextAware接口, 注入Context到静态变量中.
+ */
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext) {
+ SpringContextHolder.applicationContext = applicationContext;
+ }
+
+
+ /**
+ * 实现DisposableBean接口, 在Context关闭时清理静态变量.
+ */
+ @Override
+ public void destroy() throws Exception {
+ SpringContextHolder.clearHolder();
+ }
+
+ /**
+ * 检查ApplicationContext不为空.
+ */
+ private static void assertContextInjected() {
+ Validate.validState(applicationContext != null, "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");
+ }
+}
diff --git a/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/Base64Utils.java b/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/Base64Utils.java
new file mode 100644
index 00000000..a832c907
--- /dev/null
+++ b/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/Base64Utils.java
@@ -0,0 +1,148 @@
+package com.xhpc.pp.utils.security;
+
+import com.ruoyi.common.core.utils.sign.Base64;
+
+import java.io.*;
+
+
+/** */
+
+/**
+ *
+ * BASE64编码解码工具包
+ *
+ *
+ * 依赖javabase64-1.3.1.jar
+ *
+ *
+ * @author IceWee
+ * @version 1.0
+ * @date 2012-5-19
+ */
+public class Base64Utils {
+
+ /** */
+ /**
+ * 文件读取缓冲区大小
+ */
+ private static final int CACHE_SIZE = 1024;
+
+ /** */
+ /**
+ *
+ * BASE64字符串解码为二进制数据
+ *
+ *
+ * @param base64
+ * @return
+ * @throws Exception
+ */
+ public static byte[] decode(String base64) throws Exception {
+ return Base64.decode(base64);
+ }
+
+ /** */
+ /**
+ *
+ * 二进制数据编码为BASE64字符串
+ *
+ *
+ * @param bytes
+ * @return
+ * @throws Exception
+ */
+ public static String encode(byte[] bytes) throws Exception {
+ return new String(Base64.encode(bytes));
+ }
+
+ /** */
+ /**
+ *
+ * 将文件编码为BASE64字符串
+ *
+ *
+ * 大文件慎用,可能会导致内存溢出
+ *
+ *
+ * @param filePath 文件绝对路径
+ * @return
+ * @throws Exception
+ */
+ public static String encodeFile(String filePath) throws Exception {
+ byte[] bytes = fileToByte(filePath);
+ return encode(bytes);
+ }
+
+ /** */
+ /**
+ *
+ * BASE64字符串转回文件
+ *
+ *
+ * @param filePath 文件绝对路径
+ * @param base64 编码字符串
+ * @throws Exception
+ */
+ public static void decodeToFile(String filePath, String base64) throws Exception {
+ byte[] bytes = decode(base64);
+ byteArrayToFile(bytes, filePath);
+ }
+
+ /** */
+ /**
+ *
+ * 文件转换为二进制数组
+ *
+ *
+ * @param filePath 文件路径
+ * @return
+ * @throws Exception
+ */
+ public static byte[] fileToByte(String filePath) throws Exception {
+ byte[] data = new byte[0];
+ File file = new File(filePath);
+ if (file.exists()) {
+ FileInputStream in = new FileInputStream(file);
+ ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
+ byte[] cache = new byte[CACHE_SIZE];
+ int nRead = 0;
+ while ((nRead = in.read(cache)) != -1) {
+ out.write(cache, 0, nRead);
+ out.flush();
+ }
+ out.close();
+ in.close();
+ data = out.toByteArray();
+ }
+ return data;
+ }
+
+ /** */
+ /**
+ *
+ * 二进制数据写文件
+ *
+ *
+ * @param bytes 二进制数据
+ * @param filePath 文件生成目录
+ */
+ public static void byteArrayToFile(byte[] bytes, String filePath) throws Exception {
+ InputStream in = new ByteArrayInputStream(bytes);
+ File destFile = new File(filePath);
+ if (!destFile.getParentFile().exists()) {
+ destFile.getParentFile().mkdirs();
+ }
+ destFile.createNewFile();
+ OutputStream out = new FileOutputStream(destFile);
+ byte[] cache = new byte[CACHE_SIZE];
+ int nRead = 0;
+ while ((nRead = in.read(cache)) != -1) {
+ out.write(cache, 0, nRead);
+ out.flush();
+ }
+ out.close();
+ in.close();
+ }
+
+
+}
diff --git a/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/CRCCalculator.java b/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/CRCCalculator.java
new file mode 100644
index 00000000..e384c9f8
--- /dev/null
+++ b/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/CRCCalculator.java
@@ -0,0 +1,76 @@
+package com.xhpc.pp.utils.security;
+
+public class CRCCalculator {
+
+ public static String ModbusCRC(byte[] pData, int len) {
+ int crc = 0xFFFF;
+ for (int pos = 0; pos < len; pos++) {
+ crc ^= (int)pData[pos] & 0xFF; // XOR byte into least sig. byte of crc
+ for (int i = 8; i != 0; i--) { // Loop over each bit
+ if ((crc & 0x0001) != 0) { // If the LSB is set
+ crc >>= 1; // Shift right and XOR 0xA001
+ crc ^= 0xA001;
+ }
+ else // Else LSB is not set
+ crc >>= 1; // Just shift right
+ }
+ }
+ // Revert hi-lo
+ crc = ((crc & 0xFF00) >> 8) | ((crc & 0x00FF) << 8);
+ return String.format("%04X", crc);
+ }
+
+ public static int byteArrayToInt(byte[] b) {
+ return b[3] & 0xFF |
+ (b[2] & 0xFF) << 8 |
+ (b[1] & 0xFF) << 16 |
+ (b[0] & 0xFF) << 24;
+ }
+
+ public static byte[] intToByteArray(int a) {
+ return new byte[]{
+ (byte) ((a >> 24) & 0xFF),
+ (byte) ((a >> 16) & 0xFF),
+ (byte) ((a >> 8) & 0xFF),
+ (byte) (a & 0xFF)
+ };
+ }
+
+ private static byte[] hi = {
+ (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+ (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+ (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+ (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+ (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+ (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+ (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+ (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+ (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+ (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+ (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+ (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+ (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40,
+ (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+ (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41,
+ (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x01, (byte) 0xC0, (byte) 0x80, (byte) 0x41, (byte) 0x00, (byte) 0xC1, (byte) 0x81, (byte) 0x40
+ };
+
+ private static byte lo[] = {
+ (byte) 0x00, (byte) 0xC0, (byte) 0xC1, (byte) 0x01, (byte) 0xC3, (byte) 0x03, (byte) 0x02, (byte) 0xC2, (byte) 0xC6, (byte) 0x06, (byte) 0x07, (byte) 0xC7, (byte) 0x05, (byte) 0xC5, (byte) 0xC4, (byte) 0x04,
+ (byte) 0xCC, (byte) 0x0C, (byte) 0x0D, (byte) 0xCD, (byte) 0x0F, (byte) 0xCF, (byte) 0xCE, (byte) 0x0E, (byte) 0x0A, (byte) 0xCA, (byte) 0xCB, (byte) 0x0B, (byte) 0xC9, (byte) 0x09, (byte) 0x08, (byte) 0xC8,
+ (byte) 0xD8, (byte) 0x18, (byte) 0x19, (byte) 0xD9, (byte) 0x1B, (byte) 0xDB, (byte) 0xDA, (byte) 0x1A, (byte) 0x1E, (byte) 0xDE, (byte) 0xDF, (byte) 0x1F, (byte) 0xDD, (byte) 0x1D, (byte) 0x1C, (byte) 0xDC,
+ (byte) 0x14, (byte) 0xD4, (byte) 0xD5, (byte) 0x15, (byte) 0xD7, (byte) 0x17, (byte) 0x16, (byte) 0xD6, (byte) 0xD2, (byte) 0x12, (byte) 0x13, (byte) 0xD3, (byte) 0x11, (byte) 0xD1, (byte) 0xD0, (byte) 0x10,
+ (byte) 0xF0, (byte) 0x30, (byte) 0x31, (byte) 0xF1, (byte) 0x33, (byte) 0xF3, (byte) 0xF2, (byte) 0x32, (byte) 0x36, (byte) 0xF6, (byte) 0xF7, (byte) 0x37, (byte) 0xF5, (byte) 0x35, (byte) 0x34, (byte) 0xF4,
+ (byte) 0x3C, (byte) 0xFC, (byte) 0xFD, (byte) 0x3D, (byte) 0xFF, (byte) 0x3F, (byte) 0x3E, (byte) 0xFE, (byte) 0xFA, (byte) 0x3A, (byte) 0x3B, (byte) 0xFB, (byte) 0x39, (byte) 0xF9, (byte) 0xF8, (byte) 0x38,
+ (byte) 0x28, (byte) 0xE8, (byte) 0xE9, (byte) 0x29, (byte) 0xEB, (byte) 0x2B, (byte) 0x2A, (byte) 0xEA, (byte) 0xEE, (byte) 0x2E, (byte) 0x2F, (byte) 0xEF, (byte) 0x2D, (byte) 0xED, (byte) 0xEC, (byte) 0x2C,
+ (byte) 0xE4, (byte) 0x24, (byte) 0x25, (byte) 0xE5, (byte) 0x27, (byte) 0xE7, (byte) 0xE6, (byte) 0x26, (byte) 0x22, (byte) 0xE2, (byte) 0xE3, (byte) 0x23, (byte) 0xE1, (byte) 0x21, (byte) 0x20, (byte) 0xE0,
+ (byte) 0xA0, (byte) 0x60, (byte) 0x61, (byte) 0xA1, (byte) 0x63, (byte) 0xA3, (byte) 0xA2, (byte) 0x62, (byte) 0x66, (byte) 0xA6, (byte) 0xA7, (byte) 0x67, (byte) 0xA5, (byte) 0x65, (byte) 0x64, (byte) 0xA4,
+ (byte) 0x6C, (byte) 0xAC, (byte) 0xAD, (byte) 0x6D, (byte) 0xAF, (byte) 0x6F, (byte) 0x6E, (byte) 0xAE, (byte) 0xAA, (byte) 0x6A, (byte) 0x6B, (byte) 0xAB, (byte) 0x69, (byte) 0xA9, (byte) 0xA8, (byte) 0x68,
+ (byte) 0x78, (byte) 0xB8, (byte) 0xB9, (byte) 0x79, (byte) 0xBB, (byte) 0x7B, (byte) 0x7A, (byte) 0xBA, (byte) 0xBE, (byte) 0x7E, (byte) 0x7F, (byte) 0xBF, (byte) 0x7D, (byte) 0xBD, (byte) 0xBC, (byte) 0x7C,
+ (byte) 0xB4, (byte) 0x74, (byte) 0x75, (byte) 0xB5, (byte) 0x77, (byte) 0xB7, (byte) 0xB6, (byte) 0x76, (byte) 0x72, (byte) 0xB2, (byte) 0xB3, (byte) 0x73, (byte) 0xB1, (byte) 0x71, (byte) 0x70, (byte) 0xB0,
+ (byte) 0x50, (byte) 0x90, (byte) 0x91, (byte) 0x51, (byte) 0x93, (byte) 0x53, (byte) 0x52, (byte) 0x92, (byte) 0x96, (byte) 0x56, (byte) 0x57, (byte) 0x97, (byte) 0x55, (byte) 0x95, (byte) 0x94, (byte) 0x54,
+ (byte) 0x9C, (byte) 0x5C, (byte) 0x5D, (byte) 0x9D, (byte) 0x5F, (byte) 0x9F, (byte) 0x9E, (byte) 0x5E, (byte) 0x5A, (byte) 0x9A, (byte) 0x9B, (byte) 0x5B, (byte) 0x99, (byte) 0x59, (byte) 0x58, (byte) 0x98,
+ (byte) 0x88, (byte) 0x48, (byte) 0x49, (byte) 0x89, (byte) 0x4B, (byte) 0x8B, (byte) 0x8A, (byte) 0x4A, (byte) 0x4E, (byte) 0x8E, (byte) 0x8F, (byte) 0x4F, (byte) 0x8D, (byte) 0x4D, (byte) 0x4C, (byte) 0x8C,
+ (byte) 0x44, (byte) 0x84, (byte) 0x85, (byte) 0x45, (byte) 0x87, (byte) 0x47, (byte) 0x46, (byte) 0x86, (byte) 0x82, (byte) 0x42, (byte) 0x43, (byte) 0x83, (byte) 0x41, (byte) 0x81, (byte) 0x80, (byte) 0x40
+ };
+}
diff --git a/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/DES.java b/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/DES.java
new file mode 100644
index 00000000..aaa4382c
--- /dev/null
+++ b/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/DES.java
@@ -0,0 +1,5 @@
+package com.xhpc.pp.utils.security;
+
+public class DES {
+
+}
diff --git a/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/HexUtils.java b/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/HexUtils.java
new file mode 100644
index 00000000..4fd993f2
--- /dev/null
+++ b/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/HexUtils.java
@@ -0,0 +1,168 @@
+package com.xhpc.pp.utils.security;
+
+import org.apache.commons.lang3.ArrayUtils;
+
+public class HexUtils {
+
+ /**
+ * 字节数据转字符串专用集合
+ */
+ private static final char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
+ 'F'};
+
+ public static String toHex(byte[] data) {
+ StringBuilder stringBuilder = new StringBuilder();
+ for (int i = 0; i < data.length; i++) {
+ // 取出字节的高四位 作为索引得到相应的十六进制标识符 注意无符号右移
+ stringBuilder.append(HEX_CHAR[(data[i] & 0xf0) >>> 4]);
+ // 取出字节的低四位 作为索引得到相应的十六进制标识符
+ stringBuilder.append(HEX_CHAR[(data[i] & 0x0f)]);
+ }
+
+ return stringBuilder.toString();
+
+ }
+
+ public static String toHex(byte[] data, int start, int end) {
+ if (data == null || data.length < end)
+ return "";
+
+ return toHex(ArrayUtils.subarray(data, start, end));
+ }
+
+ public static String toString(byte[] data) {
+ return new String(data);
+ }
+
+ public static String toString(byte[] data, int start, int end) {
+ if (data == null || data.length < end)
+ return "";
+
+ return toString(ArrayUtils.subarray(data, start, end));
+ }
+
+ public static int toInteger(byte[] data, int start, int end) {
+ if (data == null || data.length < end)
+ return 0;
+
+ return Integer.decode("0x" + toHex(data, start, end));
+ }
+
+ public static byte[] toBytes(String hex) {
+ hex = hex.trim();
+ if (hex == null || hex.length() == 0 || hex.length() % 2 != 0)
+ return null;
+
+ byte[] b = new byte[hex.length() / 2];
+
+ for (int i = 0; i < hex.length(); i = i + 2) {
+ b[i / 2] = Integer.decode("0x" + hex.substring(i, i + 2)).byteValue();
+ }
+
+ return b;
+ }
+
+ public static byte[] stringToBytes(String str, int len) {
+ byte[] data = str.getBytes();
+ if (data.length > len)
+ return data;
+
+ for (int i = data.length; i < len; i++)
+ data = ArrayUtils.add(data, (byte) 0);
+
+ return data;
+ }
+
+
+ public static String toIntString(String hex) {
+ return toIntString(hex, 4);
+ }
+
+ public static String toIntString(String hex, int len) {
+ if (hex == null || hex.length() == 0 || hex.length() % len != 0)
+ return null;
+
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < hex.length(); i = i + len) {
+ sb.append(String.format("%0" + len + "d", byte2int(toBytes(hex.substring(i, i + len)))));
+ }
+
+ return sb.toString();
+ }
+
+ public static byte[] toIntBytes(String num, int len) {
+ if (num == null || num.length() == 0 || num.length() % len != 0)
+ return null;
+
+ byte[] result = new byte[0];
+
+ for (int i = 0; i < num.length(); i = i + len) {
+ int n = Integer.parseInt(num.substring(i, i + len));
+
+ result = ArrayUtils.addAll(result, toIntBytes(n, len / 2));
+ }
+
+ return result;
+ }
+
+ public static byte[] toIntBytes(int n, int len) {
+ byte[] b = new byte[len];
+
+ for (int i = 0; i < len; i++) {
+ b[i] = (byte) (n >> i * 8 & 0xff);
+ }
+ return b;
+
+ }
+
+ public static int byte2int(byte[] b) {
+ int res = 0;
+ int bLen = b.length;
+
+ if (bLen < 5) {// int 最大到4个字节
+ for (int i = 0; i < bLen; i++) {
+ res += (b[i] & 0xFF) << (8 * i);
+ }
+ }
+
+ return res;
+ }
+
+ public static byte[] toLongBytes(long n) {
+ byte[] b = new byte[4];
+
+ for (int i = 0; i < 4; i++) {
+ b[i] = (byte) ((n >> i * 8) & 0xff);
+ }
+ return b;
+
+ }
+
+ // 使用小端 字节index 0 对应 int 的最后一个字节
+ public static long byte2Long(byte[] b) {
+ long res = 0;
+ int bLen = b.length;
+// int 最大到4个字节
+ if (bLen < 9) {
+ for (int i = 0; i < bLen; i++) {
+ res += (b[i] & 0xFFL) << 8 * i;
+ }
+ }
+
+ return res;
+ }
+
+ public static void main(String[] args) {
+ System.out.println(toIntString("E80373000E02E903", 4));
+ System.out.println(toHex(toIntBytes("1000011505261001", 4)));
+ System.out.println(toIntBytes("0016537797330272", 4));
+// System.out.println(toIntString("32FFD505484B323441260443AAAAAAAA",8));
+ System.out.println(toHex(toLongBytes(1000000L)));
+ System.out.println(byte2Long(toBytes("20090080")));
+
+ System.out.println(0x80 & 0xff);
+ System.out.println(String.format("%032d", 123456));
+ }
+
+
+}
diff --git a/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/MD5.java b/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/MD5.java
new file mode 100644
index 00000000..da68c268
--- /dev/null
+++ b/xhpc-modules/xhpc-power-pole/src/main/java/com/xhpc/pp/utils/security/MD5.java
@@ -0,0 +1,118 @@
+package com.xhpc.pp.utils.security;
+
+import org.apache.commons.codec.digest.DigestUtils;
+
+import java.io.UnsupportedEncodingException;
+import java.security.SignatureException;
+import java.util.*;
+
+public class MD5 {
+
+ /**
+ * 签名字符串
+ *
+ * @param text 需要签名的字符串
+ * @param key 密钥
+ * @param input_charset 编码格式
+ * @return 签名结果
+ */
+ public static String sign(String text, String key, String input_charset) {
+ text = text + key;
+ return DigestUtils.md5Hex(getContentBytes(text, input_charset));
+ }
+
+ public static String sign(String text, String key) {
+ return sign(text, key, "utf-8").toUpperCase();
+ }
+
+ /**
+ * 签名字符串
+ *
+ * @param text 需要签名的字符串
+ * @param sign 签名结果
+ * @param key 密钥
+ * @return 签名结果
+ */
+ public static boolean verify(String text, String sign, String key) {
+ text = text + key;
+ String mysign = DigestUtils.md5Hex(getContentBytes(text, "UTF-8"));
+ if (mysign.equals(sign)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @param content
+ * @param charset
+ * @return
+ * @throws SignatureException
+ * @throws UnsupportedEncodingException
+ */
+ private static byte[] getContentBytes(String content, String charset) {
+ if (charset == null || "".equals(charset)) {
+ return content.getBytes();
+ }
+ try {
+ return content.getBytes(charset);
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("MD5签名过程中出现错误,指定的编码集不对,您目前指定的编码集是:" + charset);
+ }
+ }
+
+ /**
+ * 除去数组中的空值和签名参数
+ *
+ * @param sArray 签名参数组
+ * @return 去掉空值与签名参数后的新签名参数组
+ */
+ public static Map paraFilter(Map sArray) {
+
+ Map result = new HashMap();
+
+ if (sArray == null || sArray.size() <= 0) {
+ return result;
+ }
+
+ for (String key : sArray.keySet()) {
+ String value = sArray.get(key);
+ if (value == null || value.equals("") || key.equalsIgnoreCase("sign")
+ || key.equalsIgnoreCase("sign_type")) {
+ continue;
+ }
+ result.put(key, value);
+ }
+
+ return result;
+ }
+
+ /**
+ * 把数组所有元素排序,并按照“参数=参数值”的模式用“&”字符拼接成字符串
+ *
+ * @param params 需要排序并参与字符拼接的参数组
+ * @return 拼接后字符串
+ */
+ public static String createLinkString(Map params) {
+
+ List keys = new ArrayList(params.keySet());
+ Collections.sort(keys);
+
+ String prestr = "";
+
+ for (int i = 0; i < keys.size(); i++) {
+ String key = keys.get(i);
+ String value = params.get(key);
+
+ if (i == keys.size() - 1) {//拼接时,不包括最后一个&字符
+ prestr = prestr + key + "=" + value;
+ } else {
+ prestr = prestr + key + "=" + value + "&";
+ }
+ }
+
+ return prestr;
+ }
+
+
+}
diff --git a/xhpc-modules/xhpc-power-pole/src/main/resources/banner.txt b/xhpc-modules/xhpc-power-pole/src/main/resources/banner.txt
new file mode 100644
index 00000000..27cacb9c
--- /dev/null
+++ b/xhpc-modules/xhpc-power-pole/src/main/resources/banner.txt
@@ -0,0 +1,10 @@
+Spring Boot Version: ${spring-boot.version}
+Spring Application Name: ${spring.application.name}
+ _ __ _ _
+ (_) / _|(_)| |
+ _ __ _ _ ___ _ _ _ ______ | |_ _ | | ___
+| '__|| | | | / _ \ | | | || ||______|| _|| || | / _ \
+| | | |_| || (_) || |_| || | | | | || || __/
+|_| \__,_| \___/ \__, ||_| |_| |_||_| \___|
+ __/ |
+ |___/
\ No newline at end of file
diff --git a/xhpc-modules/xhpc-power-pole/src/main/resources/bootstrap.yml b/xhpc-modules/xhpc-power-pole/src/main/resources/bootstrap.yml
new file mode 100644
index 00000000..24c288c0
--- /dev/null
+++ b/xhpc-modules/xhpc-power-pole/src/main/resources/bootstrap.yml
@@ -0,0 +1,29 @@
+ppsvc:
+ server: 0.0.0.0
+ port: 8886
+
+# Tomcat
+server:
+ port: ${random.int(1300,1400)}
+
+# Spring
+spring:
+ application:
+ # 应用名称
+ name: xhpc-power-pole
+ profiles:
+ # 环境配置
+ active: dev
+ cloud:
+ nacos:
+ discovery:
+ # 服务注册地址
+ server-addr: 127.0.0.1:8848
+ config:
+ # 配置中心地址
+ server-addr: 127.0.0.1:8848
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
diff --git a/xhpc-modules/xhpc-power-pole/src/main/resources/logback.xml b/xhpc-modules/xhpc-power-pole/src/main/resources/logback.xml
new file mode 100644
index 00000000..7161a262
--- /dev/null
+++ b/xhpc-modules/xhpc-power-pole/src/main/resources/logback.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+ ${log.pattern}
+
+
+
+
+
+ ${log.path}/info.log
+
+
+
+ ${log.path}/info.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+ ${log.pattern}
+
+
+
+ INFO
+
+ ACCEPT
+
+ DENY
+
+
+
+
+ ${log.path}/error.log
+
+
+
+ ${log.path}/error.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+ ${log.pattern}
+
+
+
+ ERROR
+
+ ACCEPT
+
+ DENY
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xhpc-modules/xhpc-power-pole/src/main/resources/mapper/ServiceFieldMapper.xml b/xhpc-modules/xhpc-power-pole/src/main/resources/mapper/ServiceFieldMapper.xml
new file mode 100644
index 00000000..7f2859e0
--- /dev/null
+++ b/xhpc-modules/xhpc-power-pole/src/main/resources/mapper/ServiceFieldMapper.xml
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+ , service_name, version, name, code, len, seq, remark, data_type
+
+
+
+
+
+
+
+ delete
+ from service_field
+ where id = #{id,jdbcType=BIGINT}
+
+
+
+ insert into service_field (id, service_name, version,
+ name, code, len, seq,
+ remark)
+ values (#{id,jdbcType=BIGINT}, #{serviceName,jdbcType=VARCHAR}, #{version,jdbcType=VARCHAR},
+ #{name,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, #{len,jdbcType=INTEGER}, #{seq,jdbcType=INTEGER},
+ #{remark,jdbcType=VARCHAR})
+
+
+
+ update service_field
+
+
+ service_name = #{serviceName,jdbcType=VARCHAR},
+
+
+ version = #{version,jdbcType=VARCHAR},
+
+
+ name = #{name,jdbcType=VARCHAR},
+
+
+ code = #{code,jdbcType=VARCHAR},
+
+
+ len = #{len,jdbcType=INTEGER},
+
+
+ seq = #{seq,jdbcType=INTEGER},
+
+
+ remark = #{remark,jdbcType=VARCHAR},
+
+
+ where id = #{id,jdbcType=BIGINT}
+
+
+
+