瀏覽代碼

修改包结构

赵冬冬 4 年之前
父節點
當前提交
5d75638bbb

+ 0 - 41
UtilsDemo-WX/src/main/java/com/example/config/WxMaConfiguration.java

@@ -1,41 +0,0 @@
-package com.example.config;
-
-import cn.binarywang.wx.miniapp.api.WxMaService;
-import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
-import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Configuration
-@ConditionalOnClass(WxMaService.class)
-public class WxMaConfiguration {
-
-    /**
-     * 设置微信小程序的appid
-     */
-    @Value("${wx.ma.appId}")
-    private String appId;
-
-    /**
-     * 设置微信小程序的app secret
-     */
-    @Value("${wx.ma.secret}")
-
-    private String secret;
-
-
-    @Bean
-    @ConditionalOnMissingBean
-    public WxMaService wxMaService() {
-        WxMaInMemoryConfig config = new WxMaInMemoryConfig();
-        config.setAppid(appId);
-        config.setSecret(secret);
-        WxMaService wxMaService = new WxMaServiceImpl();
-        wxMaService.setWxMaConfig(config);
-        return wxMaService;
-    }
-
-}

+ 0 - 24
UtilsDemo-WX/src/main/java/com/example/config/WxMaProperties.java

@@ -1,24 +0,0 @@
-package com.example.config;
-
-
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-
-/**
- * @author xiezt
- */
-@Data
-@ConfigurationProperties(prefix = "wx.ma")
-public class WxMaProperties {
-    /**
-     * 设置微信公众号的appid
-     */
-    private String appId;
-
-    /**
-     * 设置微信公众号的app secret
-     */
-    private String secret;
-
-}

+ 0 - 42
UtilsDemo-WX/src/main/java/com/example/config/WxMpConfiguration.java

@@ -1,42 +0,0 @@
-package com.example.config;
-
-
-import lombok.extern.slf4j.Slf4j;
-import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
-import me.chanjar.weixin.mp.api.WxMpService;
-import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-@Slf4j
-@Configuration
-@ConditionalOnClass(WxMpService.class)
-@EnableConfigurationProperties(WxMpProperties.class)
-public class WxMpConfiguration {
-
-    private WxMpProperties properties;
-
-    @Autowired
-    public WxMpConfiguration(WxMpProperties properties) {
-        this.properties = properties;
-    }
-
-    @Bean
-    @ConditionalOnMissingBean
-    public WxMpService wxMpService() {
-        WxMpInMemoryConfigStorage configStorage = new WxMpInMemoryConfigStorage();
-        configStorage.setAppId(StringUtils.trimToNull(this.properties.getAppId()));
-        configStorage.setSecret(StringUtils.trimToNull(this.properties.getSecret()));
-        configStorage.setToken(StringUtils.trimToNull(this.properties.getToken()));
-        configStorage.setAesKey(StringUtils.trimToNull(this.properties.getAesKey()));
-        WxMpService wxMpService = new WxMpServiceImpl();
-        wxMpService.setWxMpConfigStorage(configStorage);
-        return wxMpService;
-    }
-}
-

+ 0 - 34
UtilsDemo-WX/src/main/java/com/example/config/WxMpProperties.java

@@ -1,34 +0,0 @@
-package com.example.config;
-
-
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-
-/**
- * @author xiezt
- */
-@Data
-@ConfigurationProperties(prefix = "wx.mp")
-public class WxMpProperties {
-    /**
-     * 设置微信公众号的appid
-     */
-    private String appId;
-
-    /**
-     * 设置微信公众号的app secret
-     */
-    private String secret;
-
-    /**
-     * 设置微信公众号的token
-     */
-    private String token;
-
-    /**
-     * 设置微信公众号的EncodingAESKey
-     */
-    private String aesKey;
-
-}

+ 0 - 49
UtilsDemo-WX/src/main/java/com/example/config/WxPayConfiguration.java

@@ -1,49 +0,0 @@
-package com.example.config;
-
-import com.github.binarywang.wxpay.config.WxPayConfig;
-import com.github.binarywang.wxpay.service.WxPayService;
-import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @author Binary Wang
- */
-@Configuration
-@ConditionalOnClass(WxPayService.class)
-@EnableConfigurationProperties(WxPayProperties.class)
-public class WxPayConfiguration {
-
-  private WxPayProperties properties;
-
-  @Autowired
-  public WxPayConfiguration(WxPayProperties properties) {
-    this.properties = properties;
-  }
-
-  @Bean
-  @ConditionalOnMissingBean
-  public WxPayService wxService() {
-    WxPayConfig payConfig = new WxPayConfig();
-    payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId()));
-    payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId()));
-    payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey()));
-    payConfig.setSubAppId(StringUtils.trimToNull(this.properties.getSubAppId()));
-    payConfig.setSubMchId(StringUtils.trimToNull(this.properties.getSubMchId()));
-    payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
-
-
-    // 可以指定是否使用沙箱环境
-    payConfig.setUseSandboxEnv(false);
-
-    WxPayService wxPayService = new WxPayServiceImpl();
-    wxPayService.setConfig(payConfig);
-    return wxPayService;
-  }
-
-}

+ 0 - 97
UtilsDemo-WX/src/main/java/com/example/config/WxPayProperties.java

@@ -1,97 +0,0 @@
-package com.example.config;
-
-import org.apache.commons.lang3.builder.ToStringBuilder;
-import org.apache.commons.lang3.builder.ToStringStyle;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * wxpay pay properties
- *
- * @author Binary Wang
- */
-@ConfigurationProperties(prefix = "wx.pay")
-public class WxPayProperties {
-  /**
-   * 设置微信公众号或者小程序等的appid
-   */
-  private String appId;
-
-  /**
-   * 微信支付商户号
-   */
-  private String mchId;
-
-  /**
-   * 微信支付商户密钥
-   */
-  private String mchKey;
-
-  /**
-   * 服务商模式下的子商户公众账号ID,普通模式请不要配置,请在配置文件中将对应项删除
-   */
-  private String subAppId;
-
-  /**
-   * 服务商模式下的子商户号,普通模式请不要配置,最好是请在配置文件中将对应项删除
-   */
-  private String subMchId;
-
-  /**
-   * apiclient_cert.p12文件的绝对路径,或者如果放在项目中,请以classpath:开头指定
-   */
-  private String keyPath;
-
-  public String getAppId() {
-    return this.appId;
-  }
-
-  public void setAppId(String appId) {
-    this.appId = appId;
-  }
-
-  public String getMchId() {
-    return mchId;
-  }
-
-  public void setMchId(String mchId) {
-    this.mchId = mchId;
-  }
-
-  public String getMchKey() {
-    return mchKey;
-  }
-
-  public void setMchKey(String mchKey) {
-    this.mchKey = mchKey;
-  }
-
-  public String getSubAppId() {
-    return subAppId;
-  }
-
-  public void setSubAppId(String subAppId) {
-    this.subAppId = subAppId;
-  }
-
-  public String getSubMchId() {
-    return subMchId;
-  }
-
-  public void setSubMchId(String subMchId) {
-    this.subMchId = subMchId;
-  }
-
-  public String getKeyPath() {
-    return this.keyPath;
-  }
-
-  public void setKeyPath(String keyPath) {
-    this.keyPath = keyPath;
-  }
-
-  @Override
-  public String toString() {
-    return ToStringBuilder.reflectionToString(this,
-        ToStringStyle.MULTI_LINE_STYLE);
-  }
-}

+ 69 - 109
UtilsDemo-WX/src/main/java/com/example/util/UUID.java

@@ -1,8 +1,6 @@
 package com.example.util;
 
 
-import com.sun.xml.internal.ws.util.UtilException;
-
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.security.SecureRandom;
@@ -14,41 +12,47 @@ import java.util.concurrent.ThreadLocalRandom;
  *
  * @author ruoyi
  */
-public final class UUID implements java.io.Serializable, Comparable<UUID>
-{
+public final class UUID implements java.io.Serializable, Comparable<UUID> {
     private static final long serialVersionUID = -1185015143654744140L;
 
     /**
      * SecureRandom 的单例
-     *
      */
-    private static class Holder
-    {
-        static final SecureRandom numberGenerator = getSecureRandom();
+    private static class Holder {
+        static SecureRandom numberGenerator = null;
+
+        static {
+            try {
+                numberGenerator = getSecureRandom();
+            } catch (NoSuchAlgorithmException e) {
+                e.printStackTrace();
+            }
+        }
     }
 
-    /** 此UUID的最高64有效位 */
+    /**
+     * 此UUID的最高64有效位
+     */
     private final long mostSigBits;
 
-    /** 此UUID的最低64有效位 */
+    /**
+     * 此UUID的最低64有效位
+     */
     private final long leastSigBits;
 
     /**
      * 私有构造
-     * 
+     *
      * @param data 数据
      */
-    private UUID(byte[] data)
-    {
+    private UUID(byte[] data) {
         long msb = 0;
         long lsb = 0;
         assert data.length == 16 : "data must be 16 bytes in length";
-        for (int i = 0; i < 8; i++)
-        {
+        for (int i = 0; i < 8; i++) {
             msb = (msb << 8) | (data[i] & 0xff);
         }
-        for (int i = 8; i < 16; i++)
-        {
+        for (int i = 8; i < 16; i++) {
             lsb = (lsb << 8) | (data[i] & 0xff);
         }
         this.mostSigBits = msb;
@@ -58,43 +62,39 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
     /**
      * 使用指定的数据构造新的 UUID。
      *
-     * @param mostSigBits 用于 {@code UUID} 的最高有效 64 位
+     * @param mostSigBits  用于 {@code UUID} 的最高有效 64 位
      * @param leastSigBits 用于 {@code UUID} 的最低有效 64 位
      */
-    public UUID(long mostSigBits, long leastSigBits)
-    {
+    public UUID(long mostSigBits, long leastSigBits) {
         this.mostSigBits = mostSigBits;
         this.leastSigBits = leastSigBits;
     }
 
     /**
      * 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的本地线程伪随机数生成器生成该 UUID。
-     * 
+     *
      * @return 随机生成的 {@code UUID}
      */
-    public static UUID fastUUID()
-    {
+    public static UUID fastUUID() {
         return randomUUID(false);
     }
 
     /**
      * 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的强伪随机数生成器生成该 UUID。
-     * 
+     *
      * @return 随机生成的 {@code UUID}
      */
-    public static UUID randomUUID()
-    {
+    public static UUID randomUUID() {
         return randomUUID(true);
     }
 
     /**
      * 获取类型 4(伪随机生成的)UUID 的静态工厂。 使用加密的强伪随机数生成器生成该 UUID。
-     * 
+     *
      * @param isSecure 是否使用{@link SecureRandom}如果是可以获得更安全的随机码,否则可以得到更好的性能
      * @return 随机生成的 {@code UUID}
      */
-    public static UUID randomUUID(boolean isSecure)
-    {
+    public static UUID randomUUID(boolean isSecure) {
         final Random ng = isSecure ? Holder.numberGenerator : getRandom();
 
         byte[] randomBytes = new byte[16];
@@ -110,18 +110,13 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      * 根据指定的字节数组获取类型 3(基于名称的)UUID 的静态工厂。
      *
      * @param name 用于构造 UUID 的字节数组。
-     *
      * @return 根据指定数组生成的 {@code UUID}
      */
-    public static UUID nameUUIDFromBytes(byte[] name)
-    {
+    public static UUID nameUUIDFromBytes(byte[] name) {
         MessageDigest md;
-        try
-        {
+        try {
             md = MessageDigest.getInstance("MD5");
-        }
-        catch (NoSuchAlgorithmException nsae)
-        {
+        } catch (NoSuchAlgorithmException nsae) {
             throw new InternalError("MD5 not supported");
         }
         byte[] md5Bytes = md.digest(name);
@@ -138,17 +133,13 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      * @param name 指定 {@code UUID} 字符串
      * @return 具有指定值的 {@code UUID}
      * @throws IllegalArgumentException 如果 name 与 {@link #toString} 中描述的字符串表示形式不符抛出此异常
-     *
      */
-    public static UUID fromString(String name)
-    {
+    public static UUID fromString(String name) {
         String[] components = name.split("-");
-        if (components.length != 5)
-        {
+        if (components.length != 5) {
             throw new IllegalArgumentException("Invalid UUID string: " + name);
         }
-        for (int i = 0; i < 5; i++)
-        {
+        for (int i = 0; i < 5; i++) {
             components[i] = "0x" + components[i];
         }
 
@@ -170,8 +161,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      *
      * @return 此 UUID 的 128 位值中的最低有效 64 位。
      */
-    public long getLeastSignificantBits()
-    {
+    public long getLeastSignificantBits() {
         return leastSigBits;
     }
 
@@ -180,8 +170,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      *
      * @return 此 UUID 的 128 位值中最高有效 64 位。
      */
-    public long getMostSignificantBits()
-    {
+    public long getMostSignificantBits() {
         return mostSigBits;
     }
 
@@ -198,8 +187,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      *
      * @return 此 {@code UUID} 的版本号
      */
-    public int version()
-    {
+    public int version() {
         // Version is bits masked by 0x000000000000F000 in MS long
         return (int) ((mostSigBits >> 12) & 0x0f);
     }
@@ -217,8 +205,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      *
      * @return 此 {@code UUID} 相关联的变体号
      */
-    public int variant()
-    {
+    public int variant() {
         // This field is composed of a varying number of bits.
         // 0 - - Reserved for NCS backward compatibility
         // 1 0 - The IETF aka Leach-Salz variant (used by this class)
@@ -240,8 +227,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      *
      * @throws UnsupportedOperationException 如果此 {@code UUID} 不是 version 为 1 的 UUID。
      */
-    public long timestamp() throws UnsupportedOperationException
-    {
+    public long timestamp() throws UnsupportedOperationException {
         checkTimeBase();
         return (mostSigBits & 0x0FFFL) << 48//
                 | ((mostSigBits >> 16) & 0x0FFFFL) << 32//
@@ -258,11 +244,9 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      * UnsupportedOperationException。
      *
      * @return 此 {@code UUID} 的时钟序列
-     *
      * @throws UnsupportedOperationException 如果此 UUID 的 version 不为 1
      */
-    public int clockSequence() throws UnsupportedOperationException
-    {
+    public int clockSequence() throws UnsupportedOperationException {
         checkTimeBase();
         return (int) ((leastSigBits & 0x3FFF000000000000L) >>> 48);
     }
@@ -277,11 +261,9 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      * 如果此 UUID 不是基于时间的 UUID,则此方法抛出 UnsupportedOperationException。
      *
      * @return 此 {@code UUID} 的节点值
-     *
      * @throws UnsupportedOperationException 如果此 UUID 的 version 不为 1
      */
-    public long node() throws UnsupportedOperationException
-    {
+    public long node() throws UnsupportedOperationException {
         checkTimeBase();
         return leastSigBits & 0x0000FFFFFFFFFFFFL;
     }
@@ -291,7 +273,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      *
      * <p>
      * UUID 的字符串表示形式由此 BNF 描述:
-     * 
+     *
      * <pre>
      * {@code
      * UUID                   = <time_low>-<time_mid>-<time_high_and_version>-<variant_and_sequence>-<node>
@@ -304,15 +286,14 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      * hexDigit               = [0-9a-fA-F]
      * }
      * </pre>
-     * 
+     *
      * </blockquote>
      *
      * @return 此{@code UUID} 的字符串表现形式
      * @see #toString(boolean)
      */
     @Override
-    public String toString()
-    {
+    public String toString() {
         return toString(false);
     }
 
@@ -321,7 +302,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      *
      * <p>
      * UUID 的字符串表示形式由此 BNF 描述:
-     * 
+     *
      * <pre>
      * {@code
      * UUID                   = <time_low>-<time_mid>-<time_high_and_version>-<variant_and_sequence>-<node>
@@ -334,37 +315,32 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      * hexDigit               = [0-9a-fA-F]
      * }
      * </pre>
-     * 
+     *
      * </blockquote>
      *
      * @param isSimple 是否简单模式,简单模式为不带'-'的UUID字符串
      * @return 此{@code UUID} 的字符串表现形式
      */
-    public String toString(boolean isSimple)
-    {
+    public String toString(boolean isSimple) {
         final StringBuilder builder = new StringBuilder(isSimple ? 32 : 36);
         // time_low
         builder.append(digits(mostSigBits >> 32, 8));
-        if (false == isSimple)
-        {
+        if (false == isSimple) {
             builder.append('-');
         }
         // time_mid
         builder.append(digits(mostSigBits >> 16, 4));
-        if (false == isSimple)
-        {
+        if (false == isSimple) {
             builder.append('-');
         }
         // time_high_and_version
         builder.append(digits(mostSigBits, 4));
-        if (false == isSimple)
-        {
+        if (false == isSimple) {
             builder.append('-');
         }
         // variant_and_sequence
         builder.append(digits(leastSigBits >> 48, 4));
-        if (false == isSimple)
-        {
+        if (false == isSimple) {
             builder.append('-');
         }
         // node
@@ -379,8 +355,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      * @return UUID 的哈希码值。
      */
     @Override
-    public int hashCode()
-    {
+    public int hashCode() {
         long hilo = mostSigBits ^ leastSigBits;
         return ((int) (hilo >> 32)) ^ (int) hilo;
     }
@@ -391,14 +366,11 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      * 当且仅当参数不为 {@code null}、而是一个 UUID 对象、具有与此 UUID 相同的 varriant、包含相同的值(每一位均相同)时,结果才为 {@code true}。
      *
      * @param obj 要与之比较的对象
-     *
      * @return 如果对象相同,则返回 {@code true};否则返回 {@code false}
      */
     @Override
-    public boolean equals(Object obj)
-    {
-        if ((null == obj) || (obj.getClass() != UUID.class))
-        {
+    public boolean equals(Object obj) {
+        if ((null == obj) || (obj.getClass() != UUID.class)) {
             return false;
         }
         UUID id = (UUID) obj;
@@ -414,13 +386,10 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
      * 如果两个 UUID 不同,且第一个 UUID 的最高有效字段大于第二个 UUID 的对应字段,则第一个 UUID 大于第二个 UUID。
      *
      * @param val 与此 UUID 比较的 UUID
-     *
      * @return 在此 UUID 小于、等于或大于 val 时,分别返回 -1、0 或 1。
-     *
      */
     @Override
-    public int compareTo(UUID val)
-    {
+    public int compareTo(UUID val) {
         // The ordering is intentionally set up so that the UUIDs
         // can simply be numerically compared as two numbers
         return (this.mostSigBits < val.mostSigBits ? -1 : //
@@ -432,15 +401,15 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
 
     // -------------------------------------------------------------------------------------------------------------------
     // Private method start
+
     /**
      * 返回指定数字对应的hex值
-     * 
-     * @param val 值
+     *
+     * @param val    
      * @param digits 位
      * @return 值
      */
-    private static String digits(long val, int digits)
-    {
+    private static String digits(long val, int digits) {
         long hi = 1L << (digits * 4);
         return Long.toHexString(hi | (val & (hi - 1))).substring(1);
     }
@@ -448,39 +417,30 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
     /**
      * 检查是否为time-based版本UUID
      */
-    private void checkTimeBase()
-    {
-        if (version() != 1)
-        {
+    private void checkTimeBase() {
+        if (version() != 1) {
             throw new UnsupportedOperationException("Not a time-based UUID");
         }
     }
 
     /**
      * 获取{@link SecureRandom},类提供加密的强随机数生成器 (RNG)
-     * 
+     *
      * @return {@link SecureRandom}
      */
-    public static SecureRandom getSecureRandom()
-    {
-        try
-        {
-            return SecureRandom.getInstance("SHA1PRNG");
-        }
-        catch (NoSuchAlgorithmException e)
-        {
-            throw new UtilException(e);
-        }
+    public static SecureRandom getSecureRandom() throws NoSuchAlgorithmException {
+
+        return SecureRandom.getInstance("SHA1PRNG");
+
     }
 
     /**
      * 获取随机数生成器对象<br>
      * ThreadLocalRandom是JDK 7之后提供并发产生随机数,能够解决多个线程发生的竞争争夺。
-     * 
+     *
      * @return {@link ThreadLocalRandom}
      */
-    public static ThreadLocalRandom getRandom()
-    {
+    public static ThreadLocalRandom getRandom() {
         return ThreadLocalRandom.current();
     }
 }

+ 4 - 5
pom.xml

@@ -52,11 +52,10 @@
 
     <pluginManagement>
       <plugins>
-        <plugin>
-          <groupId>org.apache.maven.plugins</groupId>
-          <artifactId>maven-jar-plugin</artifactId>
-          <version>3.0.2</version>
-        </plugin>
+<!--        <plugin>-->
+<!--          <groupId>org.apache.maven.plugins</groupId>-->
+<!--          <artifactId>maven-jar-plugin</artifactId>-->
+<!--        </plugin>-->
         <plugin>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-maven-plugin</artifactId>