CommonController.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. package com.zhongzheng.controller.cmmon;
  2. import cn.hutool.core.lang.Validator;
  3. import com.baomidou.mybatisplus.core.toolkit.StringUtils;
  4. import com.zhongzheng.common.core.controller.BaseController;
  5. import com.zhongzheng.common.core.domain.AjaxResult;
  6. import com.zhongzheng.common.core.page.TableDataInfo;
  7. import com.zhongzheng.common.core.redis.RedisCache;
  8. import com.zhongzheng.common.utils.ServletUtils;
  9. import com.zhongzheng.common.utils.ToolsUtils;
  10. import com.zhongzheng.framework.web.service.WxLoginService;
  11. import com.zhongzheng.modules.base.bo.ConfigQueryBo;
  12. import com.zhongzheng.modules.course.bo.CourseQueryBo;
  13. import com.zhongzheng.modules.course.bo.CourseTopicGoodsQueryBo;
  14. import com.zhongzheng.modules.course.service.ICourseService;
  15. import com.zhongzheng.modules.course.service.ICourseTopicService;
  16. import com.zhongzheng.modules.course.vo.CourseTopicGoodsVo;
  17. import com.zhongzheng.modules.course.vo.CourseTopicVo;
  18. import com.zhongzheng.modules.course.vo.CourseUserVo;
  19. import com.zhongzheng.modules.exam.bo.ExamActivityApplyBo;
  20. import com.zhongzheng.modules.exam.bo.ExamActivityApplyVo;
  21. import com.zhongzheng.modules.exam.service.IExamActivityService;
  22. import com.zhongzheng.modules.exam.vo.ExamActivityVo;
  23. import com.zhongzheng.modules.goods.service.IGoodsSpecTemplateService;
  24. import com.zhongzheng.modules.goods.vo.GoodsSpecTemplateVo;
  25. import com.zhongzheng.modules.goods.vo.GoodsUserVo;
  26. import com.zhongzheng.modules.goods.vo.GoodsVo;
  27. import com.zhongzheng.modules.order.domain.Printer;
  28. import com.zhongzheng.modules.system.service.ISysConfigService;
  29. import com.zhongzheng.modules.wx.bo.WxServerBody;
  30. import com.zhongzheng.modules.wx.domain.*;
  31. import io.swagger.annotations.Api;
  32. import io.swagger.annotations.ApiOperation;
  33. import lombok.RequiredArgsConstructor;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.web.bind.annotation.*;
  36. import java.text.ParseException;
  37. import java.util.HashMap;
  38. import java.util.List;
  39. import java.util.Map;
  40. /**
  41. * 课程Controller
  42. *
  43. * @author hjl
  44. * @date 2021-10-09
  45. */
  46. @Api(value = "游客访问接口", tags = {"游客访问接口"})
  47. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  48. @RestController
  49. @RequestMapping("/app/common/")
  50. public class CommonController extends BaseController {
  51. private final ICourseService iCourseService;
  52. private final WxLoginService wxLoginService;
  53. @Autowired
  54. private RedisCache redisCache;
  55. private final ICourseTopicService iCourseTopicService;
  56. private final IGoodsSpecTemplateService iGoodsSpecTemplateService;
  57. /**
  58. * 获取商品专题页指定商品信息
  59. */
  60. @ApiOperation("获取商品专题页指定商品信息")
  61. @GetMapping("/get/goodsInfo/{topicId}")
  62. public AjaxResult<CourseTopicVo> getGoodsInfo(@PathVariable("topicId") Integer topicId) {
  63. return AjaxResult.success(iCourseTopicService.getGoodsInfo(topicId));
  64. }
  65. /**
  66. * 获取商品规格模板信息
  67. */
  68. @ApiOperation("获取商品规格模板信息")
  69. @GetMapping("/spec/{specTemplateId}")
  70. public AjaxResult<GoodsSpecTemplateVo> getSpecTemplate(@PathVariable("specTemplateId")Long specTemplateId) {
  71. return AjaxResult.success(iGoodsSpecTemplateService.queryById(specTemplateId));
  72. }
  73. /**
  74. * 获取规格属性值对应的商品信息
  75. */
  76. @ApiOperation("获取规格属性值对应的商品信息")
  77. @GetMapping("/attr/goods")
  78. public AjaxResult<GoodsVo> getSpecTemplate(@RequestParam("specTemplateId")Long specTemplateId,@RequestParam("specAttrIds")String specAttrIds) {
  79. GoodsVo vo = iGoodsSpecTemplateService.getSpecTemplate(specTemplateId,specAttrIds);
  80. return AjaxResult.success(vo);
  81. }
  82. /**
  83. * 获取专题页组合班级商品
  84. */
  85. @ApiOperation("获取专题页组合班级商品")
  86. @GetMapping("/get/goodsList")
  87. public AjaxResult<List<CourseTopicGoodsVo>> getGoodsList(CourseTopicGoodsQueryBo bo) {
  88. return AjaxResult.success(iCourseTopicService.getGoodsList(bo));
  89. }
  90. private final ISysConfigService configService;
  91. /**
  92. * 查询课程列表
  93. */
  94. @ApiOperation("查询商品下的课程列表")
  95. @GetMapping("/courseList")
  96. public TableDataInfo<CourseUserVo> courseList(CourseQueryBo bo) {
  97. startPage();
  98. List<CourseUserVo> list = iCourseService.courseList(bo);
  99. return getDataTable(list);
  100. }
  101. /**
  102. * 查询课程列表
  103. */
  104. @ApiOperation("查询用户拥有的商品")
  105. @GetMapping("/goodsList")
  106. public TableDataInfo<GoodsUserVo> goodsList(CourseQueryBo bo) {
  107. startPage();
  108. List<GoodsUserVo> list = iCourseService.goodsList(bo);
  109. return getDataTable(list);
  110. }
  111. @ApiOperation("查询用户拥有的商品")
  112. @GetMapping("/test")
  113. public AjaxResult<Integer> test(CourseQueryBo bo) throws InterruptedException, ParseException {
  114. return AjaxResult.success(Printer.num);
  115. }
  116. @ApiOperation("小程序配置")
  117. @GetMapping("/config")
  118. public AjaxResult<Map<String,Object>> config(ConfigQueryBo bo) {
  119. Map<String,Object> map = new HashMap<>();
  120. map.put("hide",false);
  121. if(Validator.isNotEmpty(bo.getVersion())){
  122. String hideVersion = configService.selectConfigByKey("version.hide");
  123. if(bo.getVersion().equals(hideVersion)){
  124. map.put("hide",true);
  125. }
  126. }
  127. return AjaxResult.success(map);
  128. }
  129. /**
  130. * 公众号服务接口
  131. */
  132. @ApiOperation("公众号服务接口")
  133. @GetMapping("/wxGzhServer")
  134. public String wxGzhServer(WxServerBody bo) {
  135. try {
  136. String token = "511A23101c826G90T1";
  137. String EncodingAESKey = "ybzse4DNAMj9oGzZ9kQqOX0F7nKjebGZ3xNesVFInPP";
  138. String echostr = bo.getEchostr();
  139. if (ToolsUtils.checkGzhServerSignature(token,bo.getSignature(), bo.getTimestamp(), bo.getNonce())) {
  140. return echostr;
  141. }
  142. } catch (Exception e) {
  143. //验证公众号token失败
  144. }
  145. return null;
  146. }
  147. @ApiOperation("公众号服务接口")
  148. @PostMapping("/wxGzhServer")
  149. public String wxGzhServer(@RequestBody String xmlData) {
  150. // 将xml格式的数据,转换为 AllMessage 对象
  151. AllMessage allMessage = MessageUtil.xmlToAllMessage(xmlData);
  152. String TenantId = "867735392558919680";
  153. ServletUtils.getRequestAttributes().getResponse().setHeader("TenantId", TenantId);
  154. // 是否是文本消息类型
  155. if (allMessage.getMsgType().equals(MessageTypeEnum.MSG_TEXT.getMsgType())) {
  156. // 自动回复用户所发送的文本消息
  157. // return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_PREFIX.getContent() + allMessage.getContent());
  158. return "";
  159. }
  160. // 是否是事件推送类型
  161. else if (allMessage.getMsgType().equals(MessageTypeEnum.MSG_EVENT.getMsgType())) {
  162. // 是否为订阅事件,即公众号被关注时所触发的事件
  163. if (EventType.EVENT_SUBSCRIBE.getEventType().equals(allMessage.getEvent())) {
  164. // System.out.println("关注");
  165. String openId = allMessage.getFromUserName();
  166. wxLoginService.subGzh(openId);
  167. // 自动回复欢迎语
  168. return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_SUBSCRIBE.getContent());
  169. }
  170. else if (EventType.EVENT_UNSUBSCRIBE.getEventType().equals(allMessage.getEvent())) {
  171. String openId = allMessage.getFromUserName();
  172. wxLoginService.unsubGzh(openId);
  173. // System.out.println("取消关注");
  174. }
  175. } else {
  176. // 暂不支持文本以外的消息回复
  177. return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_NONSUPPORT.getContent());
  178. }
  179. return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_NONSUPPORT.getContent());
  180. }
  181. }