Pu Zhibing
2025-04-01 a8ab05221c6e8e376eb6bb72bf3e222d7ef2ee80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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;
    }
 
 
 
}