1.配置小程序
小程序-开发管理-开发设置-消息推送,设置如下:
2.java程序
@RestController
public class MsgController {
private org.slf4j.Logger logger = LoggerFactory.getLogger(getClass());
@GetMapping("/msg")
public String msg(String signature, String timestamp, String nonce, String echostr) {
logger.info("signature:{}", signature);
logger.info("timestamp:{}", timestamp);
logger.info("nonce:{}", nonce);
logger.info("echostr:{}", echostr);
return echostr;
}
@PostMapping("/msg")
// public void msg(@RequestParam String FromUserName,String ToUserName,String
// Content,String CreateTime,String MsgId,String MsgType) {
public void msg(HttpServletRequest request) {
String s = "";
try {
final int BUF_COUNT=1024;
byte[] buf = new byte[BUF_COUNT];
ServletInputStream sis = request.getInputStream();
int count = sis.read(buf, 0, BUF_COUNT);
s += new String(buf, 0, count);
logger.info(s);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// logger.info("request:{}",);
}
}
3.微信小程序
<button open-type="contact" bindcontact="handleContact" session-from="sessionFrom">客服</button>