WexinController.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package com.diagbot.web;
  2. import com.diagbot.dto.RespDTO;
  3. import com.diagbot.facade.WeixinFacade;
  4. import com.diagbot.vo.WeixinVO;
  5. import io.swagger.annotations.Api;
  6. import io.swagger.annotations.ApiOperation;
  7. import io.swagger.annotations.ApiParam;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.PostMapping;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import javax.servlet.http.HttpServletRequest;
  17. import java.util.Enumeration;
  18. import java.util.LinkedHashMap;
  19. import java.util.Map;
  20. /**
  21. * @Description:
  22. * @Author:zhoutg
  23. * @time: 2020/2/6 10:48
  24. */
  25. @RestController
  26. @Api(value = "微信", tags = { "微信API" })
  27. @SuppressWarnings("unchecked")
  28. @RequestMapping("/weixin")
  29. @Slf4j
  30. public class WexinController {
  31. @Autowired
  32. WeixinFacade weixinFacade;
  33. @RequestMapping("/getConfig")
  34. public RespDTO<Map> getConfig(@RequestBody WeixinVO weixinVO) {
  35. Map<String, String> map = weixinFacade.getConfig(weixinVO);
  36. return RespDTO.onSuc(map);
  37. }
  38. @RequestMapping(value = "/test", method = RequestMethod.GET, produces = { "application/json;charset=utf-8" })
  39. @ApiOperation(value = "测试微信公众号的接口配置信息", notes = "接口配置信息", httpMethod = "GET")
  40. public String getWxUserInfo(HttpServletRequest request,
  41. @ApiParam(value = "微信求的 echostr") String echostr
  42. ) {
  43. try {
  44. Map<String, String> map = new LinkedHashMap<>();
  45. //只需要把微信请求的 echostr, 返回给微信就可以了
  46. log.info("测试来过===================" + echostr);
  47. Enumeration pNames = request.getParameterNames();
  48. while (pNames.hasMoreElements()) {
  49. String name = (String) pNames.nextElement();
  50. String value = request.getParameter(name);
  51. map.put(name, value);
  52. }
  53. log.info(map.toString());
  54. return echostr;
  55. } catch (Exception e) {
  56. log.info("测试微信公众号的接口配置信息发生异常:", e);
  57. return null;
  58. }
  59. }
  60. }