前言
接上文步骤,通过小程序引流到企业微信中,需要追踪小程序的用户添加企业微信管理员以及加入企业微信群的情况,本文记录了如何去关联
一、企业微信事件接收服务器
通过配置企业微信事件接收服务,当客户有添加企业微信管理员的时候,企业微信会通知导服务器,从而知道小程序引流的用户的后续动作
1、配置企业微信事件接收服务器
登录企业微信官网,打开客户联系–>客户页面,点开api按钮
a、获取Secret
b、绑定对应的微信小程序
c、配置接收事件服务器
输入接收通知url地址,token以及EncodingAESKey保存的时候,通知服务器会接收到一条验证请求,需要返回解析好的参数才能通过验证,具体代码如下:
public class QywxController extends BaseController{
@Autowired
private QywxService qywxService;
@RequestMapping(value = "/change",method = {
RequestMethod.GET, RequestMethod.POST})
@ResponseBody
public String change(@RequestParam("msg_signature") String signature, @RequestParam("timestamp") String timestamp, @RequestParam("nonce") String nonce,@RequestParam(value = "echostr") String echostr) throws Exception {
return qywxService.verifyUrl(signature,timestamp,nonce,echostr);
}
}
public class QywxService {
@Value("${qywxCorpid}")
private String sCorpID;
@Value("${qywxMsgReplyToken}")
private String token;
@Value("${qywxEncodingAESKey}")
private String encodingAESKey;
public String verifyUrl(String signature, String timestamp, String nonce,String echostr) throws AesException {
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(token, encodingAESKey, sCorpID);
return wxcpt.VerifyURL(signature,t