From b08bc30ba8b39e4075456c4d3bc65f9e3d6b7f37 Mon Sep 17 00:00:00 2001
From: WeiRan <2392355487@qq.com>
Date: Sun, 8 Sep 2024 21:13:33 +0800
Subject: [PATCH] =?UTF-8?q?=E8=81=9A=E5=90=88=E5=B9=B3=E5=8F=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 38 +++++
Dockerfile | 23 +++
cloud-juhe-client/.gitignore | 38 +++++
cloud-juhe-client/pom.xml | 21 +++
cloud-juhe-server/.gitignore | 38 +++++
cloud-juhe-server/pom.xml | 157 ++++++++++++++++++
.../data/mart/DataMartJuHeApplication.java | 19 +++
.../controller/RealNameJuHeController.java | 40 +++++
.../service/impl/RealNameServiceImpl.java | 128 ++++++++++++++
.../src/main/resources/bootstrap.yml | 54 ++++++
.../src/main/resources/logback/dev.xml | 74 +++++++++
.../src/main/resources/logback/prod.xml | 81 +++++++++
.../src/main/resources/logback/test.xml | 81 +++++++++
pom.xml | 28 ++++
14 files changed, 820 insertions(+)
create mode 100644 .gitignore
create mode 100644 Dockerfile
create mode 100644 cloud-juhe-client/.gitignore
create mode 100644 cloud-juhe-client/pom.xml
create mode 100644 cloud-juhe-server/.gitignore
create mode 100644 cloud-juhe-server/pom.xml
create mode 100644 cloud-juhe-server/src/main/java/com/muyu/data/mart/DataMartJuHeApplication.java
create mode 100644 cloud-juhe-server/src/main/java/com/muyu/data/mart/controller/RealNameJuHeController.java
create mode 100644 cloud-juhe-server/src/main/java/com/muyu/data/mart/service/impl/RealNameServiceImpl.java
create mode 100644 cloud-juhe-server/src/main/resources/bootstrap.yml
create mode 100644 cloud-juhe-server/src/main/resources/logback/dev.xml
create mode 100644 cloud-juhe-server/src/main/resources/logback/prod.xml
create mode 100644 cloud-juhe-server/src/main/resources/logback/test.xml
create mode 100644 pom.xml
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..a0cc4d9
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,23 @@
+#执行一些必备的条件
+# |-home
+# |- app.jar -启动jar包
+# |- logs -日志文件
+# |- uploadPath -上传路径
+
+#指定构建镜像的起始镜像
+FROM anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/dragonwell:17.0.4.0.4.8-standard-ga-8.6
+
+#定义时区参数
+# 设置环境变量TZ
+ENV TZ=Asia/Shanghai
+RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
+
+#挂载工作目录
+VOLUME ["/home/logs/cloud-juhe"]
+
+#拷贝执行jar包文件
+COPY ./cloud-juhe-server/target/cloud-juhe.jar /home/app.jar
+
+#构建启动命令
+ENTRYPOINT ["java","-Dfile.encoding=utf-8","-jar"]
+CMD ["/home/app.jar"]
diff --git a/cloud-juhe-client/.gitignore b/cloud-juhe-client/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/cloud-juhe-client/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/cloud-juhe-client/pom.xml b/cloud-juhe-client/pom.xml
new file mode 100644
index 0000000..99d2615
--- /dev/null
+++ b/cloud-juhe-client/pom.xml
@@ -0,0 +1,21 @@
+
+
+ 4.0.0
+
+ com.muyu
+ cloud-juhe
+ 1.0.0
+
+
+ cloud-juhe-client
+ 1.0.0
+
+
+ 17
+ 17
+ UTF-8
+
+
+
diff --git a/cloud-juhe-server/.gitignore b/cloud-juhe-server/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/cloud-juhe-server/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/cloud-juhe-server/pom.xml b/cloud-juhe-server/pom.xml
new file mode 100644
index 0000000..fa00141
--- /dev/null
+++ b/cloud-juhe-server/pom.xml
@@ -0,0 +1,157 @@
+
+
+ 4.0.0
+
+ com.muyu
+ cloud-juhe
+ 1.0.0
+
+
+ cloud-juhe-server
+ 1.0.0
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+
+
+
+ org.springframework.boot
+ spring-boot-starter
+
+
+
+ com.muyu
+ cloud-background-common
+ 1.0.0
+
+
+
+ com.mysql
+ mysql-connector-j
+
+
+
+
+ com.muyu
+ cloud-common-datasource
+
+
+
+
+
+ com.muyu
+ cloud-common-datascope
+
+
+
+
+ com.alibaba.fastjson2
+ fastjson2
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-sentinel
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+
+ com.mysql
+ mysql-connector-j
+
+
+
+
+ com.muyu
+ cloud-common-datasource
+
+
+
+
+ com.muyu
+ cloud-common-datascope
+
+
+
+
+ com.muyu
+ cloud-common-log
+
+
+
+
+ com.muyu
+ cloud-common-api-doc
+
+
+
+
+ com.muyu
+ cloud-common-xxl
+
+
+
+
+ cloud-juhe
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.13.0
+
+
+ -parameters
+
+
+
+
+
+
diff --git a/cloud-juhe-server/src/main/java/com/muyu/data/mart/DataMartJuHeApplication.java b/cloud-juhe-server/src/main/java/com/muyu/data/mart/DataMartJuHeApplication.java
new file mode 100644
index 0000000..520639f
--- /dev/null
+++ b/cloud-juhe-server/src/main/java/com/muyu/data/mart/DataMartJuHeApplication.java
@@ -0,0 +1,19 @@
+package com.muyu.data.mart;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+
+/**
+ * @Author:weiran
+ * @Package:com.muyu.data.mart
+ * @Project:cloud-background
+ * @name:DataMartJuHeApplication
+ * @Date:2024/9/5 16:07
+ */
+@SpringBootApplication
+public class DataMartJuHeApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(DataMartJuHeApplication.class, args);
+ }
+}
diff --git a/cloud-juhe-server/src/main/java/com/muyu/data/mart/controller/RealNameJuHeController.java b/cloud-juhe-server/src/main/java/com/muyu/data/mart/controller/RealNameJuHeController.java
new file mode 100644
index 0000000..9ff23fd
--- /dev/null
+++ b/cloud-juhe-server/src/main/java/com/muyu/data/mart/controller/RealNameJuHeController.java
@@ -0,0 +1,40 @@
+package com.muyu.data.mart.controller;
+
+
+import com.muyu.cloud.background.common.BasicApi;
+import com.muyu.cloud.background.domin.realname.RealNameReq;
+import com.muyu.cloud.background.domin.realname.RealNameResp;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+
+/**
+ * @Author:weiran
+ * @Package:com.muyu.data.mart.controller
+ * @Project:cloud-background
+ * @name:RealNameJuHeController
+ * @Date:2024/9/5 21:16
+ */
+@RestController
+@RequestMapping("/juhe")
+public class RealNameJuHeController {
+
+
+ @Resource(name = "juhe-real-name")
+ private BasicApi realNameService;
+
+ @PostMapping("/real/name")
+ public RealNameResp realName(@RequestBody RealNameReq realNameReq) {
+ RealNameResp realNameResp = null;
+ try {
+ realNameResp = realNameService.send(realNameReq);
+ return realNameResp;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/cloud-juhe-server/src/main/java/com/muyu/data/mart/service/impl/RealNameServiceImpl.java b/cloud-juhe-server/src/main/java/com/muyu/data/mart/service/impl/RealNameServiceImpl.java
new file mode 100644
index 0000000..b074b2a
--- /dev/null
+++ b/cloud-juhe-server/src/main/java/com/muyu/data/mart/service/impl/RealNameServiceImpl.java
@@ -0,0 +1,128 @@
+package com.muyu.data.mart.service.impl;
+
+
+import com.alibaba.fastjson2.JSONObject;
+import com.muyu.cloud.background.common.BasicApi;
+import com.muyu.cloud.background.domin.juhe.JuHeResult;
+import com.muyu.cloud.background.domin.realname.RealNameReq;
+import com.muyu.cloud.background.domin.realname.RealNameResp;
+import com.muyu.cloud.background.domin.realname.juhe.RealNameJuHeReq;
+import com.muyu.cloud.background.domin.realname.juhe.RealNameJuHeResp;
+import org.springframework.stereotype.Service;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+
+
+/**
+ * @Author:weiran
+ * @Package:com.muyu.data.mart.service.impl
+ * @Project:cloud-background
+ * @name:RealNameService
+ * @Date:2024/9/5 19:27
+ */
+@Service("juhe-real-name")
+public class RealNameServiceImpl implements BasicApi{
+ @Override
+ public RealNameResp send(RealNameReq realNameResp) {
+
+ RealNameJuHeReq realNameJuHeReq = RealNameJuHeReq.realNameJuHeReqBuild(realNameResp);
+ JuHeResult realNameJuHeRespJuHeResult = null;
+ try {
+ realNameJuHeRespJuHeResult = sendApi(realNameJuHeReq);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return RealNameResp.builder()
+ .code(String.valueOf(realNameJuHeRespJuHeResult.getErrorCode()))
+ .msg(realNameJuHeRespJuHeResult.getReason())
+ .build();
+ }
+
+ public JuHeResult sendApi(RealNameJuHeReq realNameJuHeReq) throws Exception{
+
+ //调用第三方的方法
+ String apiKey = "1a398917d330f5ec01ce1110c459ec45";
+ //c00bc093c4d5aee149a8d2efb2f2c51c谢欣悦(次数已用完)
+ //1a398917d330f5ec01ce1110c459ec45 张腾
+ //1abdb559b392ff72c789840e943e1d5f 彭思睿
+ //586eae3d5ee4cbf46cb1430fdb3f8428 杨闪闪
+ String apiUrl = "http://op.juhe.cn/idcard/query";
+
+ HashMap map = new HashMap<>();
+ map.put("key", apiKey);
+ map.put("idcard", realNameJuHeReq.getIdCard());
+ map.put("realname", realNameJuHeReq.getRealName());
+ map.put("orderid", "");
+
+ String queryString = params(map);
+ URL url = new URL(apiUrl + "?" + queryString);
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+
+ BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ String inputLine;
+ StringBuffer response = new StringBuffer();
+ while ((inputLine = in.readLine()) != null) {
+ response.append(inputLine);
+ }
+ in.close();
+ System.out.println(response);
+ //{"reason":"参数错误:身份证不合法","result":null,"error_code":210304} 或
+ //{"reason":"成功","result":{"realname":"魏然","idcard":"321183200303152916","res":1},"error_code":0}
+ StringBuffer stringBuffer = new StringBuffer(response);
+ JSONObject jsonObject = JSONObject.parseObject(stringBuffer.toString());
+ String reason = jsonObject.getString("reason");
+ JSONObject resultObj = jsonObject.getJSONObject("result");
+ String realname = resultObj.getString("realname");
+ String idcard = resultObj.getString("idcard");
+ int res = resultObj.getIntValue("res");
+ int errorCode = jsonObject.getIntValue("error_code");
+ return new JuHeResult(){{
+ setErrorCode(errorCode);
+ setReason(reason);
+ setResult(
+ RealNameJuHeResp.builder()
+ .realName(realname)
+ .idCard(idcard)
+ .res(res)
+ .build()
+ );
+ }};
+
+// return new JuHeResult(){{
+// setErrorCode(0);
+// setReason("成功");
+// setResult(
+// RealNameJuHeResp.builder()
+// .realName(realNameJuHeReq.getRealName())
+// .idCard(realNameJuHeReq.getIdCard())
+// .res(0)
+// .build()
+// );
+// }};
+
+ }
+
+
+ public static String params(Map map) {
+ return map.entrySet().stream()
+ .map(entry -> {
+ try {
+ return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
+ } catch (Exception e) {
+ e.printStackTrace();
+ return entry.getKey() + "=" + entry.getValue();
+ }
+ })
+ .collect(Collectors.joining("&"));
+ }
+}
diff --git a/cloud-juhe-server/src/main/resources/bootstrap.yml b/cloud-juhe-server/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..284eda8
--- /dev/null
+++ b/cloud-juhe-server/src/main/resources/bootstrap.yml
@@ -0,0 +1,54 @@
+# Tomcat
+server:
+ port: 9777
+
+# nacos线上地址
+nacos:
+ addr: 21.12.0.8:8848
+ user-name: nacos
+ password: nacos
+ namespace: ec66ecf1-f28e-43bc-aa86-625f1bc53bf8
+
+# Spring
+spring:
+ main:
+ allow-bean-definition-overriding: true
+ application:
+ # 应用名称
+ name: cloud-juhe
+ profiles:
+ # 环境配置
+ active: dev
+ cloud:
+ nacos:
+ discovery:
+ # 服务注册地址
+ server-addr: ${nacos.addr}
+ # nacos用户名
+ username: ${nacos.user-name}
+ # nacos密码
+ password: ${nacos.password}
+ # 命名空间
+ namespace: ${nacos.namespace}
+ config:
+ # 服务注册地址
+ server-addr: ${nacos.addr}
+ # nacos用户名
+ username: ${nacos.user-name}
+ # nacos密码
+ password: ${nacos.password}
+ # 命名空间
+ namespace: ${nacos.namespace}
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ # 系统共享配置
+ - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+ # 系统环境Config共享配置
+ - application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+ # xxl-job 配置文件
+ - application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+ # rabbit 配置文件
+ - application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
+
diff --git a/cloud-juhe-server/src/main/resources/logback/dev.xml b/cloud-juhe-server/src/main/resources/logback/dev.xml
new file mode 100644
index 0000000..3b900f9
--- /dev/null
+++ b/cloud-juhe-server/src/main/resources/logback/dev.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/cloud-juhe-server/src/main/resources/logback/prod.xml b/cloud-juhe-server/src/main/resources/logback/prod.xml
new file mode 100644
index 0000000..44e117e
--- /dev/null
+++ b/cloud-juhe-server/src/main/resources/logback/prod.xml
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+
+
+ ${log.sky.pattern}
+
+
+
+
+
+ ${log.path}/info.log
+
+
+
+ ${log.path}/info.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+
+
+ INFO
+
+ ACCEPT
+
+ DENY
+
+
+
+
+ ${log.path}/error.log
+
+
+
+ ${log.path}/error.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+
+
+ ERROR
+
+ ACCEPT
+
+ DENY
+
+
+
+
+
+
+
+ ${log.sky.pattern}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/cloud-juhe-server/src/main/resources/logback/test.xml b/cloud-juhe-server/src/main/resources/logback/test.xml
new file mode 100644
index 0000000..44e117e
--- /dev/null
+++ b/cloud-juhe-server/src/main/resources/logback/test.xml
@@ -0,0 +1,81 @@
+
+
+
+
+
+
+
+
+
+
+
+ ${log.sky.pattern}
+
+
+
+
+
+ ${log.path}/info.log
+
+
+
+ ${log.path}/info.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+
+
+ INFO
+
+ ACCEPT
+
+ DENY
+
+
+
+
+ ${log.path}/error.log
+
+
+
+ ${log.path}/error.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+
+
+ ERROR
+
+ ACCEPT
+
+ DENY
+
+
+
+
+
+
+
+ ${log.sky.pattern}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..a997028
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,28 @@
+
+
+ 4.0.0
+
+
+ com.muyu
+ cloud-server-parent
+ 3.6.4
+
+
+ cloud-juhe
+ 1.0.0
+ pom
+
+ cloud-juhe-client
+ cloud-juhe-server
+
+
+
+ 17
+ 17
+ UTF-8
+
+
+
+