From fac98a7c4c8321566f7ec2867c9c5b3003064379 Mon Sep 17 00:00:00 2001 From: 3y Date: Fri, 9 Dec 2022 19:06:21 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81docker-compose=E5=90=AF=E5=8A=A8austi?= =?UTF-8?q?n=202=E3=80=81=E5=BE=AE=E4=BF=A1=E6=9C=8D=E5=8A=A1=E5=8F=B7?= =?UTF-8?q?=E7=99=BB=E5=BD=95=20=E6=8E=A5=E5=85=A5=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 +- .../web/controller/HealthController.java | 24 ++++++++ .../controller/OfficialAccountController.java | 56 ++++++++++++++++++- .../main/resources/application-dev.properties | 3 +- .../resources/application-docker.properties | 9 ++- .../src/main/resources/application.properties | 3 +- docker-compose.yml | 6 +- 7 files changed, 90 insertions(+), 14 deletions(-) create mode 100644 austin-web/src/main/java/com/java3y/austin/web/controller/HealthController.java diff --git a/Dockerfile b/Dockerfile index f01f029..fe7ea75 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,9 @@ ENV PARAMS="--spring.profiles.active=docker" # 设置工作目录 WORKDIR /build + # 将jar包复制到容器中 ADD ./austin-web/target/austin-web-0.0.1-SNAPSHOT.jar ./austin.jar -# 暴露8080端口 -EXPOSE 8080 # 运行jar包 ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS austin.jar $PARAMS"] diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/HealthController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/HealthController.java new file mode 100644 index 0000000..8f582cc --- /dev/null +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/HealthController.java @@ -0,0 +1,24 @@ +package com.java3y.austin.web.controller; + + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 健康检测 + * + * @author 3y + */ +@Slf4j +@RestController +@Api("健康检测") +public class HealthController { + @GetMapping("/") + @ApiOperation("/健康检测") + public String health() { + return "success"; + } +} diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java index ea200d0..9d68b55 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/OfficialAccountController.java @@ -1,6 +1,9 @@ package com.java3y.austin.web.controller; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; import com.google.common.base.Throwables; import com.java3y.austin.common.enums.RespStatusEnum; import com.java3y.austin.common.vo.BasicResultVO; @@ -11,12 +14,17 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.mp.api.WxMpService; +import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import me.chanjar.weixin.mp.bean.template.WxMpTemplate; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.List; +import java.util.Map; /** * 微信服务号 @@ -79,4 +87,50 @@ public class OfficialAccountController { } + /** + * 接收微信的事件消息 + * https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html + * 临时给微信服务号登录使用,正常消息推送平台不会有此接口 + * + * @return + */ + @GetMapping("/receipt") + @ApiOperation("/接收微信的事件消息") + public String receiptMessage(String signature, String timestamp, String nonce, String echostr) { + log.info("get weixin signature:{},:{},nonce:{},echostr:{}", signature, timestamp, nonce, echostr); + if (StrUtil.isNotBlank(echostr)) { + return echostr; + } + return null; + } + + /** + * 临时给微信服务号登录使用(生成二维码),正常消息推送平台不会有此接口 + * + * @param accountId 消息推送平台体系内的Id + * @return + */ + @GetMapping("/qrCode") + @ApiOperation("/生成 服务号 二维码") + public BasicResultVO getQrCode(Long accountId) { + if (accountId == null) { + return BasicResultVO.fail(RespStatusEnum.CLIENT_BAD_PARAMETERS); + } + try { + // 生成随机值,获取服务号二维码 且 用于校验登录 + String id = IdUtil.getSnowflake().nextIdStr(); + WxMpService wxMpService = wxServiceUtils.getOfficialAccountServiceMap().get(accountId); + WxMpQrCodeTicket ticket = wxMpService.getQrcodeService().qrCodeCreateTmpTicket(id, 2592000); + + + String url = wxMpService.getQrcodeService().qrCodePictureUrl(ticket.getTicket()); + Map result = MapUtil.of(new String[][]{{"url", url}, {"id", id}}); + return BasicResultVO.success(result); + } catch (Exception e) { + log.error("OfficialAccountController#getQrCode fail:{}", Throwables.getStackTraceAsString(e)); + return BasicResultVO.fail(RespStatusEnum.SERVICE_ERROR); + } + } + + } diff --git a/austin-web/src/main/resources/application-dev.properties b/austin-web/src/main/resources/application-dev.properties index 81c188d..2f3de48 100644 --- a/austin-web/src/main/resources/application-dev.properties +++ b/austin-web/src/main/resources/application-dev.properties @@ -1,6 +1,7 @@ # TODO please replace 【must】 config value # TODO please replace 【must】 config value # TODO please replace 【must】 config value +server.port=8080 # todo [database] ip/port/username/password 【must】 austin.database.ip=austin.mysql @@ -83,8 +84,6 @@ austin.rocketmq.recall.consumer.group=unique-recall-consumer-group ########################################## RabbitMq start ########################################## spring.rabbitmq.host=${austin.rabbitmq.ip} spring.rabbitmq.port=${austin.rabbitmq.port} -server.port=8080 -spring.application.name=cl spring.rabbitmq.username=root spring.rabbitmq.password=123456 spring.rabbitmq.publisher-confirm-type=correlated diff --git a/austin-web/src/main/resources/application-docker.properties b/austin-web/src/main/resources/application-docker.properties index 57db57b..434fff9 100644 --- a/austin-web/src/main/resources/application-docker.properties +++ b/austin-web/src/main/resources/application-docker.properties @@ -1,15 +1,16 @@ # TODO please replace 【must】 config value # TODO please replace 【must】 config value # TODO please replace 【must】 config value +server.port=8080 # todo [database] ip/port/username/password 【must】 -austin.database.ip=mysql +austin.database.ip=austin-mysql austin.database.port=3306 austin.database.username=root austin.database.password=root123_A # todo [redis] ip/port/password【must】 -austin.redis.ip=redis +austin.redis.ip=austin-redis austin.redis.port=6379 austin.redis.password=austin @@ -45,7 +46,7 @@ austin.business.upload.crowd.path=/Users/3y/temp ########################################## database start ########################################## # notice:mysql version 5.7x !!! -spring.datasource.url=jdbc:mysql://${austin.database.ip}:${austin.database.port}/austin?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull +spring.datasource.url=jdbc:mysql://${austin.database.ip}:${austin.database.port}/austin?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull spring.datasource.username=${austin.database.username} spring.datasource.password=${austin.database.password} spring.datasource.driver-class-name=com.mysql.jdbc.Driver @@ -83,8 +84,6 @@ austin.rocketmq.recall.consumer.group=unique-recall-consumer-group ########################################## RabbitMq start ########################################## spring.rabbitmq.host=${austin.rabbitmq.ip} spring.rabbitmq.port=${austin.rabbitmq.port} -server.port=8080 -spring.application.name=cl spring.rabbitmq.username=root spring.rabbitmq.password=123456 spring.rabbitmq.publisher-confirm-type=correlated diff --git a/austin-web/src/main/resources/application.properties b/austin-web/src/main/resources/application.properties index 257b306..ea39e51 100644 --- a/austin-web/src/main/resources/application.properties +++ b/austin-web/src/main/resources/application.properties @@ -1 +1,2 @@ -spring.profiles.active=dev \ No newline at end of file +spring.profiles.active=dev +spring.application.name=austin \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index eefef6a..90e28af 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ version: '3' services: - mysql: + austin-mysql: environment: TZ: Asia/Shanghai MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' @@ -17,12 +17,12 @@ services: - 23306:3306 networks: - app - redis: + austin-redis: image: redis:3.2 ports: - 16379:6379 restart: always - container_name: redis + container_name: austin-redis networks: - app austin: