12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package com.cybertogether.wx.notice.web;
- import com.cybertogether.wx.notice.infrastructure.Downstream;
- import com.cybertogether.wx.notice.infrastructure.HttpClientUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- /**
- * 接收微信推送通知
- * 授权流程文档
- * https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1453779503&token=&lang=
- */
- @RestController
- @RequestMapping("/wx/pushReception")
- public class WxPushReceptionController {
- private static final Logger LOGGER = LoggerFactory.getLogger(WxPushReceptionController.class);
- @Autowired
- Downstream downstream;
- /**
- * 接收微信的授权事件通知
- * 开发配置-开发资料-授权事件接收配置
- * localhost:8080/pandora/wx/pushReception/authorization?timestamp=34353535&nonce=4342344&msg_signature=ee661ba5dbbf82d488aaf18883808411d9c73b31
- * todo 应该在此处进行解密并验签,然后将解密后的数据体进行广播转发
- */
- @PostMapping("/authorization")
- public String receptionAuthorizationEvent(@RequestParam("timestamp") String timestamp,
- @RequestParam("nonce") String nonce,
- @RequestParam("msg_signature") String msgSignature,
- @RequestBody String encryptedXmlBodyText) {
- LOGGER.info("微信通知转发服务-收到微信授权通知");
- String urlParams = String.format("?timestamp=%s&nonce=%s&msg_signature=%s", timestamp, nonce, msgSignature);
- for (String url : downstream.getUrls()) {
- try {
- HttpClientUtils.postData(url + urlParams, encryptedXmlBodyText);
- }catch (Exception e) {
- // ignore
- }
- }
- return "success";
- }
- /**
- * 接收微信消息与事件通知
- * 开发配置-开发资料-消息与事件接收配置
- */
- @PostMapping("/msgEvent/{appId}")
- public String receptionMsgEvent(@RequestBody String requestBody, @PathVariable String appId) {
- LOGGER.info("微信通知转发服务-收到微信消息与事件通知-{}", requestBody);
- return "success";
- }
- }
|