From 094e86130d7170aa113d8c68079b8404535d3f45 Mon Sep 17 00:00:00 2001 From: weiyachao <13526234727@126.com> Date: Fri, 4 Aug 2023 18:00:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iot-modules/iot-box-user-api/.gitignore | 38 +++++++ iot-modules/iot-box-user-api/pom.xml | 101 ++++++++++++++++++ .../user/api/IotBoxUserApiApplication.java | 13 +++ .../user/api/controller/UserController.java | 64 +++++++++++ .../src/main/resources/bootstrap.yml | 53 +++++++++ iot-modules/pom.xml | 2 + 6 files changed, 271 insertions(+) create mode 100644 iot-modules/iot-box-user-api/.gitignore create mode 100644 iot-modules/iot-box-user-api/pom.xml create mode 100644 iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/IotBoxUserApiApplication.java create mode 100644 iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/controller/UserController.java create mode 100644 iot-modules/iot-box-user-api/src/main/resources/bootstrap.yml diff --git a/iot-modules/iot-box-user-api/.gitignore b/iot-modules/iot-box-user-api/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/iot-modules/iot-box-user-api/.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/iot-modules/iot-box-user-api/pom.xml b/iot-modules/iot-box-user-api/pom.xml new file mode 100644 index 0000000..13ef4c2 --- /dev/null +++ b/iot-modules/iot-box-user-api/pom.xml @@ -0,0 +1,101 @@ + + + 4.0.0 + + com.qiuguo.iot + iot-modules + 0.0.1-SNAPSHOT + + + iot-box-user-api + + + 8 + 8 + UTF-8 + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.hswebframework.web + hsweb-commons-crud + ${hsweb.framework.version} + + + org.hswebframework.web + hsweb-system-authorization-default + ${hsweb.framework.version} + + + + org.hswebframework + hsweb-easy-orm-rdb + ${hsweb.framework.version} + + + + org.hswebframework.web + hsweb-starter + ${hsweb.framework.version} + + + io.projectreactor + reactor-test + test + + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + + + \ No newline at end of file diff --git a/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/IotBoxUserApiApplication.java b/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/IotBoxUserApiApplication.java new file mode 100644 index 0000000..a7c993b --- /dev/null +++ b/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/IotBoxUserApiApplication.java @@ -0,0 +1,13 @@ +package com.qiuguo.iot.user.api; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class IotBoxUserApiApplication { + + public static void main(String[] args) { + SpringApplication.run(IotBoxUserApiApplication.class, args); + } + +} diff --git a/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/controller/UserController.java b/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/controller/UserController.java new file mode 100644 index 0000000..73a98a9 --- /dev/null +++ b/iot-modules/iot-box-user-api/src/main/java/com/qiuguo/iot/user/api/controller/UserController.java @@ -0,0 +1,64 @@ +package com.qiuguo.iot.user.api.controller; + +import com.alibaba.fastjson.JSONObject; +import java.util.Objects; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +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 org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE; + +/** + * XXX + * + * @author weiyachao + * @since 2023/8/3 17:29 + */ + +@RestController +@Slf4j +@RequestMapping("/user") +public class UserController { + private final WebClient webClient = WebClient.builder() + .defaultHeader(HttpHeaders.CONTENT_TYPE,APPLICATION_FORM_URLENCODED_VALUE) + // .defaultHeader("Api-Type","box") + .build(); + + @Value("${userUrl.baseUrl}") + private String baseUrl; + + @Value("${userUrl.pwdUrl}") + private String pwdUrl; + + @Value("${userUrl.smsUrl}") + private String smsUrl; + + @Value("${userUrl.sendSmsUrl}") + private String sendSmsUrl; + + @PostMapping("/login/pwd") + public Mono loginByPwd(@RequestBody JSONObject jsonObject) { + MultiValueMap object = new LinkedMultiValueMap<>(); + jsonObject.forEach((k,v)->{ + object.add(k, String.valueOf(v)); + }); + Mono jsonObjectMono = webClient.post().uri(baseUrl + pwdUrl).bodyValue(object).retrieve() + .bodyToMono(JSONObject.class) + .doOnNext(res -> { + if (!Objects.equals(res.getInteger("code"), 1)) { + throw new RuntimeException("参数错误"); + } + }); + return jsonObjectMono; + } + +} diff --git a/iot-modules/iot-box-user-api/src/main/resources/bootstrap.yml b/iot-modules/iot-box-user-api/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..1fb3f89 --- /dev/null +++ b/iot-modules/iot-box-user-api/src/main/resources/bootstrap.yml @@ -0,0 +1,53 @@ +server: + port: 9701 +spring: + profiles: + # 环境配置 + active: dev + application: + name: qiuguo-iot-box-user-api + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 172.24.218.235:8848/ + config: + # 配置中心地址 + server-addr: 172.24.218.235:8848/ + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + redis: + # cluster: + # nodes: + # - 127.0.0.1:7001 + # - 127.0.0.1:7002 + host: 192.168.8.101 + port: 6379 + password: 123456 + timeout: 5000 + r2dbc: + url: r2dbc:mysql://172.24.218.235:3306/qiuguo-reseller?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + username: root + password: '!pHuRvGKIsbiqcX1' +easyorm: + auto-ddl: true + default-schema: qiuguo_iot # 默认使用的schema. mysql时则为数据库名 + dialect: mysql # 方言: h2,mysql,postgresql +logging: + level: + org.hswebframework: debug + org.hswebframework.expands: error +hsweb: + webflux: + response-wrapper: + enabled: true # 将响应结果包装为{"status":200,"result":{}} + excludes: #不包装的类 + - org.springdoc +userUrl: + baseUrl: 'https://exper.qiuguojihua.com/data' + pwdUrl: '/api.login/in' + smsUrl: '/api.login/phone' + sendSmsUrl: '/api.login/sendsms' diff --git a/iot-modules/pom.xml b/iot-modules/pom.xml index c7ce7c3..d124597 100644 --- a/iot-modules/pom.xml +++ b/iot-modules/pom.xml @@ -12,6 +12,8 @@ iot-customer-http-api iot-admin-http-api + iot-box-websocket + iot-box-user-api UTF-8