Browse Source

给客服发送消息

master
zhizhi wu 4 years ago
parent
commit
4817bf9d3e
  1. 7
      pom.xml
  2. 55
      src/main/java/com/ccsens/carbasics/api/MiniController.java
  3. 4
      src/main/resources/application-common.yml

7
pom.xml

@ -41,6 +41,13 @@
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!--wechatutil 工具类-->
<dependency>
<groupId>com.ccsens</groupId>
<artifactId>wechatutil</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

55
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";
}
}

4
src/main/resources/application-common.yml

@ -27,4 +27,8 @@ spring:
snowflake:
datacenterId: 2
workerId: 2
mini:
token: ccsensTyphoneye
appId: wx3190e3f68dd4d068
secret: 71d797c1f81f9f0caadab3289ee7367c

Loading…
Cancel
Save