微信公众平台开发教程(四)_点击事件处理

在我们配置了微信公众号的基本配置之后

用户每次触发点击事件之后,腾讯都会回调到我们的这个URL,然后我们再处理对应逻辑,返回给腾讯。

下面以我暴露出来/wechat.do来进行举例:@RequestMapping(value="/wechat.do",method = RequestMethod.POST, produces = { "application/xml;charset=UTF-8" })

public @ResponseBody String processWxMessage(
            @RequestBody String requestBody,
            @RequestParam(value = "signature", required = false) String signature,
            @RequestParam(value = "timestamp", required = false) String timestamp,
            @RequestParam(value = "nonce", required = false) String nonce,
            @RequestParam(value = "encrypt_type", required = false) String encrypt_type,
            @RequestParam(value = "msg_signature", required = false) String msg_signature,
            HttpServletRequest request,HttpServletResponse response) throws Exception {
        String respMessage = null;
     //接收微信消息实体类 ReceiveMessage message
= new ReceiveMessage(); Map config=null; try{ if(StringUtils.isNotBlank(encrypt_type) && !"raw".equals(encrypt_type) && "aes".equals(encrypt_type)){ logger.info("消息经过加密处理!");
          //获取本地存储的公众号配置信息 String sysytemAppid
= (String) wxPropertiesBean.getProperties("system").get("system_appid"); config = this.wxMpService.queryWxAccountByCode(sysytemAppid); String encodingaeskey = (String) config.get("encoding_aes_key"); String token = (String) config.get("account_token"); String appid = (String) config.get("account_appid");
          //解密消息 WXBizMsgCrypt msgCryPt
= new WXBizMsgCrypt(token, encodingaeskey, appid); requestBody = msgCryPt.decryptMsg(msg_signature, timestamp, nonce, requestBody); }
message
= MessageUtil.parseXml(requestBody);
       //根据腾讯返回信息确认事件触发类型后进行处理,最后转换成xml格式的String返回给腾讯 respMessage
= this.wxService.analyzeMessage(message, config); }catch (Exception e){ logger.error(e.getMessage()); return null; } return respMessage; }

 

转载于:https://www.cnblogs.com/Onedayzk/p/7799547.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值