commit 74535cfb45b4f302fa4fd3564aecfdfc7b38f67b Author: chenda Date: Tue Jun 14 23:05:06 2022 +0800 文件提交 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84adb3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# ---> Java +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..16f64e8 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..c70fb90 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..6560a98 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..8ff2146 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..8686156 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/design-mode/pom.xml b/design-mode/pom.xml new file mode 100644 index 0000000..727a2b9 --- /dev/null +++ b/design-mode/pom.xml @@ -0,0 +1,19 @@ + + + + java-study-demo + com.giao + 1.0-SNAPSHOT + + 4.0.0 + + design-mode + + + 8 + 8 + + + \ No newline at end of file diff --git a/design-mode/src/main/java/singletonPattern/SingletonE.java b/design-mode/src/main/java/singletonPattern/SingletonE.java new file mode 100644 index 0000000..caa1cfb --- /dev/null +++ b/design-mode/src/main/java/singletonPattern/SingletonE.java @@ -0,0 +1,18 @@ +package singletonPattern; + +/** + * 饿汉式单例模式 + * @author chenda + */ +public class SingletonE { + + private static SingletonE singleton = new SingletonE(); + + private SingletonE() { + + } + + public static SingletonE getInstance() { + return singleton; + } +} diff --git a/design-mode/src/main/java/singletonPattern/SingletonL.java b/design-mode/src/main/java/singletonPattern/SingletonL.java new file mode 100644 index 0000000..5340b38 --- /dev/null +++ b/design-mode/src/main/java/singletonPattern/SingletonL.java @@ -0,0 +1,40 @@ +package singletonPattern; + +/** + * 懒汉式 + * @author chenda + */ +public class SingletonL { + + private volatile static SingletonL singleton; + + private SingletonL() { + + } + + /** + * 加锁保证只会被实例化一次 + * @return singleton + */ + public synchronized static SingletonL getInstance() { + if (singleton == null) { + singleton = new SingletonL(); + } + return singleton; + } + + /** + * 双重锁 减少同步范围 + * @return + */ + public static SingletonL getInstanceDoubleLock() { + if (singleton == null) { + synchronized (SingletonL.class) { + if (singleton == null) { + singleton = new SingletonL(); + } + } + } + return singleton; + } +} diff --git a/design-mode/src/main/java/singletonPattern/SingletonPattern.java b/design-mode/src/main/java/singletonPattern/SingletonPattern.java new file mode 100644 index 0000000..6cb2630 --- /dev/null +++ b/design-mode/src/main/java/singletonPattern/SingletonPattern.java @@ -0,0 +1,10 @@ +package singletonPattern; + +/** + * 单例模式 + * @author chenda + */ +public class SingletonPattern { + + +} diff --git a/juc/pom.xml b/juc/pom.xml new file mode 100644 index 0000000..3096d55 --- /dev/null +++ b/juc/pom.xml @@ -0,0 +1,20 @@ + + + + java-study-demo + com.giao + 1.0-SNAPSHOT + + 4.0.0 + + com.example + juc + + + 8 + 8 + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..16a85ea --- /dev/null +++ b/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.7.0 + + + + com.giao + java-study-demo + pom + 1.0-SNAPSHOT + + design-mode + juc + + + + + org.apache.commons + commons-lang3 + 3.12.0 + + + cn.hutool + hutool-all + 5.8.1 + + + com.alibaba + fastjson + 2.0.1 + + + + + 8 + 8 + + + \ No newline at end of file diff --git a/weixin-test/.gitignore b/weixin-test/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/weixin-test/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/weixin-test/pom.xml b/weixin-test/pom.xml new file mode 100644 index 0000000..d03452a --- /dev/null +++ b/weixin-test/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + + java-study-demo + com.giao + 1.0-SNAPSHOT + + com.wx + weixin-test + 0.0.1-SNAPSHOT + weixin-test + weixin-test + + 1.8 + + + + org.springframework.boot + spring-boot-starter-web + + + + mysql + mysql-connector-java + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/weixin-test/src/main/java/com/wx/WeixinTestApplication.java b/weixin-test/src/main/java/com/wx/WeixinTestApplication.java new file mode 100644 index 0000000..86ccc64 --- /dev/null +++ b/weixin-test/src/main/java/com/wx/WeixinTestApplication.java @@ -0,0 +1,13 @@ +package com.wx; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WeixinTestApplication { + + public static void main(String[] args) { + SpringApplication.run(WeixinTestApplication.class, args); + } + +} diff --git a/weixin-test/src/main/java/com/wx/WxAccessEntity.java b/weixin-test/src/main/java/com/wx/WxAccessEntity.java new file mode 100644 index 0000000..29f302a --- /dev/null +++ b/weixin-test/src/main/java/com/wx/WxAccessEntity.java @@ -0,0 +1,15 @@ +package com.wx; + +import lombok.Data; +import lombok.ToString; +import lombok.experimental.Accessors; + +@Data +@Accessors(chain = true) +@ToString +public class WxAccessEntity { + + private String accessToken; + + private Integer expiresIn; +} diff --git a/weixin-test/src/main/java/com/wx/one/WxTestOneController.java b/weixin-test/src/main/java/com/wx/one/WxTestOneController.java new file mode 100644 index 0000000..f4d24ac --- /dev/null +++ b/weixin-test/src/main/java/com/wx/one/WxTestOneController.java @@ -0,0 +1,68 @@ +package com.wx.one; + +import cn.hutool.crypto.digest.DigestUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.wx.WxAccessEntity; +import org.apache.commons.lang3.StringUtils; +import org.springframework.util.Assert; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +@RestController +@RequestMapping +public class WxTestOneController { + + public static String TOKEN = "hahaha"; + + @RequestMapping("/test") + public String fun01(@RequestParam("signature") String signature, + @RequestParam("timestamp") String timestamp, + @RequestParam("nonce") String nonce, + @RequestParam("echostr") String echostr) { + List list = Arrays.asList(TOKEN, timestamp, nonce); + Collections.sort(list); + String joinStr = StringUtils.join(list, ""); + String s1 = DigestUtil.sha1Hex(joinStr); + if (s1.equals(signature)) { + return echostr; + } + return null; + } + + @PostMapping("/test") + public String fun02() { + return "rr"; + } + + private static String appId = "wx26376bb80b8541c2"; + + private static String appsecret = "a34f2006fcf0ce1ce1bb9b2ca5d26591"; + + public static void main(String[] args) { + WxAccessEntity wxAccessEntity = getWxAccessToken(appId, appsecret); + // 存入redis + System.out.println(wxAccessEntity); + } + + public static WxAccessEntity getWxAccessToken(String appId, String appsecret) { + Assert.hasText(appId, "appId不允许为空"); + Assert.hasText(appsecret, "appsecret不允许为空"); + String url = String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", appId, appsecret); + String response = HttpUtil.get(url); + JSONObject jsonObject = JSON.parseObject(response); + return new WxAccessEntity() + .setAccessToken(String.valueOf(jsonObject.get("access_token"))) + .setExpiresIn((Integer) jsonObject.get("expires_in")); + } + +} diff --git a/weixin-test/src/main/resources/application.properties b/weixin-test/src/main/resources/application.properties new file mode 100644 index 0000000..7274e65 --- /dev/null +++ b/weixin-test/src/main/resources/application.properties @@ -0,0 +1 @@ +server.port=18231 diff --git a/weixin-test/src/test/java/com/wx/WeixinTestApplicationTests.java b/weixin-test/src/test/java/com/wx/WeixinTestApplicationTests.java new file mode 100644 index 0000000..a5fc0d6 --- /dev/null +++ b/weixin-test/src/test/java/com/wx/WeixinTestApplicationTests.java @@ -0,0 +1,13 @@ +package com.wx; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class WeixinTestApplicationTests { + + @Test + void contextLoads() { + } + +}