From 4817bf9d3ec31010f154fdcc149d3e59bf4cff7f Mon Sep 17 00:00:00 2001 From: zhizhi wu <2377881365@qq.com> Date: Thu, 21 Oct 2021 17:12:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E5=AE=A2=E6=9C=8D=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 +++ .../ccsens/carbasics/api/MiniController.java | 55 +++++++++++++++++++ src/main/resources/application-common.yml | 4 ++ 3 files changed, 66 insertions(+) create mode 100644 src/main/java/com/ccsens/carbasics/api/MiniController.java diff --git a/pom.xml b/pom.xml index 4b805ae..370885d 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,13 @@ 1.0-SNAPSHOT compile + + + com.ccsens + wechatutil + 1.0-SNAPSHOT + compile + diff --git a/src/main/java/com/ccsens/carbasics/api/MiniController.java b/src/main/java/com/ccsens/carbasics/api/MiniController.java new file mode 100644 index 0000000..cfc1b81 --- /dev/null +++ b/src/main/java/com/ccsens/carbasics/api/MiniController.java @@ -0,0 +1,55 @@ +package com.ccsens.carbasics.api; + +import com.alibaba.fastjson.JSONObject; +import com.ccsens.wechatutil.bean.dto.wxmini.NoticeDto; +import com.ccsens.wechatutil.bean.vo.wxmini.Custom; +import com.ccsens.wechatutil.wxcommon.WxCommonUtil; +import com.ccsens.wechatutil.wxmini.MiniCustomSendUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import java.security.NoSuchAlgorithmException; + +/** + * @description: + * @author: whj + * @time: 2021/10/21 14:46 + */ +@Api(tags = "微信小程序相关" , description = "") +@RestController +@RequestMapping("/mini") +@Slf4j +public class MiniController { + + @Value("wx.mini.token") + private String token; + @Value("wx.mini.appId") + private String appId; + @Value("wx.mini.secret") + private String secret; + + @ApiOperation(value = "接收微信小程序消息通知", notes = "") + @RequestMapping(value = "/notice", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"}) + public String noticeGet(@Validated NoticeDto.ValidMsg validMsg) throws NoSuchAlgorithmException { + log.info("接收微信小程序token:{}",validMsg); + return validMsg.check(token) ? validMsg.getEchostr() : null; + } + + @ApiOperation(value = "接收微信小程序消息通知", notes = "") + @RequestMapping(value = "/notice", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public String notice(@Validated NoticeDto.Notice notice) { + log.info("接收微信小程序消息通知:{}", notice); + Custom.Text text = new Custom.Text(); + text.setContent("客服人员正在赶来的路上..."); + MiniCustomSendUtil.send(notice.getFromUserName(), Custom.Type.TEXT, text); + + return "success"; + } +} diff --git a/src/main/resources/application-common.yml b/src/main/resources/application-common.yml index b870f11..07d725e 100644 --- a/src/main/resources/application-common.yml +++ b/src/main/resources/application-common.yml @@ -27,4 +27,8 @@ spring: snowflake: datacenterId: 2 workerId: 2 +mini: + token: ccsensTyphoneye + appId: wx3190e3f68dd4d068 + secret: 71d797c1f81f9f0caadab3289ee7367c