package com.ruoyi.system.controller.conslole;
|
|
import com.ruoyi.common.core.utils.StringUtils;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.log4j.Log4j2;
|
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
|
import org.apache.commons.io.IOUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
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 javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
|
/**
|
* @ClassName QYWXCallBackController
|
* @Description TODO
|
* @Author jqs
|
* @Date 2023/8/16 16:56
|
* @Version 1.0
|
*/
|
@Api(value = "企业微信通知控制", tags = "企业微信通知控制", description = "企业微信通知控制")
|
@RestController
|
@RequestMapping("/qywx")
|
@Log4j2
|
public class QYWXCallBackController {
|
|
@Autowired
|
private WxCryptUtil wxCryptUtil;
|
|
@ApiOperation(value = "消息与事件接收配置")
|
@RequestMapping(value = "/qywxNotify", method = {RequestMethod.GET,RequestMethod.POST})
|
public String wechatPlatformEvent(@RequestBody(required = false) String body,
|
HttpServletRequest request,
|
HttpServletResponse response
|
) throws Exception {
|
String nonce = request.getParameter("nonce");
|
String timestamp = request.getParameter("timestamp");
|
String signature = request.getParameter("signature");
|
String msgSignature = request.getParameter("msg_signature");
|
String echostr = request.getParameter("echostr");
|
String encType = request.getParameter("encrypt_type");
|
String xml = IOUtils.toString(request.getReader());
|
log.info("企业微信回调参数nonce"+nonce);
|
log.info("企业微信回调参数timestamp"+timestamp);
|
log.info("企业微信回调参数signature"+signature);
|
log.info("企业微信回调参数msgSignature"+msgSignature);
|
log.info("企业微信回调参数encType"+encType);
|
log.info("企业微信回调参数xml"+xml);
|
log.info("企业微信回调参数echostr"+echostr);
|
if(StringUtils.isNotBlank(msgSignature)&&StringUtils.isNotBlank(timestamp)&&StringUtils.isNotBlank(nonce)&&StringUtils.isNotBlank(xml)){
|
String reponseStr = wxCryptUtil.decryptXml(msgSignature,timestamp,nonce,xml);
|
log.info("企业微信回调参数xml解析"+reponseStr);
|
}
|
if(StringUtils.isNotBlank(msgSignature)&&StringUtils.isNotBlank(timestamp)&&StringUtils.isNotBlank(nonce)&&StringUtils.isNotBlank(echostr)){
|
String reponseStr = wxCryptUtil.decryptContent(msgSignature,timestamp,nonce,echostr);
|
log.info("企业微信回调参数xml解析"+reponseStr);
|
return reponseStr;
|
}
|
return echostr;
|
}
|
|
|
|
}
|