CommonController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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.bo.SysTenantQueryBo;
  29. import com.zhongzheng.modules.system.service.ISysConfigService;
  30. import com.zhongzheng.modules.system.service.ISysTenantService;
  31. import com.zhongzheng.modules.system.service.ISysWebService;
  32. import com.zhongzheng.modules.wx.bo.WxInfoBo;
  33. import com.zhongzheng.modules.wx.bo.WxInfoQuery;
  34. import com.zhongzheng.modules.wx.bo.WxServerBody;
  35. import com.zhongzheng.modules.wx.domain.*;
  36. import io.swagger.annotations.Api;
  37. import io.swagger.annotations.ApiOperation;
  38. import lombok.RequiredArgsConstructor;
  39. import org.springframework.beans.factory.annotation.Autowired;
  40. import org.springframework.web.bind.annotation.*;
  41. import java.text.ParseException;
  42. import java.util.HashMap;
  43. import java.util.List;
  44. import java.util.Map;
  45. /**
  46. * 课程Controller
  47. *
  48. * @author hjl
  49. * @date 2021-10-09
  50. */
  51. @Api(value = "游客访问接口", tags = {"游客访问接口"})
  52. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  53. @RestController
  54. @RequestMapping("/app/common/")
  55. public class CommonController extends BaseController {
  56. private final ICourseService iCourseService;
  57. private final WxLoginService wxLoginService;
  58. private final ISysConfigService configService;
  59. @Autowired
  60. private RedisCache redisCache;
  61. private final ICourseTopicService iCourseTopicService;
  62. private final IGoodsSpecTemplateService iGoodsSpecTemplateService;
  63. private final ISysTenantService iSysTenantService;
  64. /**
  65. * 获取微信小程序信息(网页跳转小程序)
  66. */
  67. @ApiOperation("获取微信小程序信息(网页跳转小程序)")
  68. @GetMapping("/get/wx/info")
  69. public AjaxResult<WxInfoBo> getWxInfo(WxInfoQuery query) {
  70. return AjaxResult.success(wxLoginService.getWxInfo(query));
  71. }
  72. /**
  73. * 获取小程序首页链接
  74. */
  75. @ApiOperation("获取小程序首页链接")
  76. @GetMapping("/get/small/link")
  77. public AjaxResult<Void> getWxSmallLink() {
  78. return AjaxResult.success(wxLoginService.getWxSmallLink());
  79. }
  80. /**
  81. * 获取商品专题页指定商品信息
  82. */
  83. @ApiOperation("获取商品专题页指定商品信息")
  84. @GetMapping("/get/goodsInfo/{topicId}")
  85. public AjaxResult<CourseTopicVo> getGoodsInfo(@PathVariable("topicId") Integer topicId) {
  86. return AjaxResult.success(iCourseTopicService.getGoodsInfo(topicId));
  87. }
  88. /**
  89. * 获取商品规格模板信息
  90. */
  91. @ApiOperation("获取商品规格模板信息")
  92. @GetMapping("/spec/{specTemplateId}")
  93. public AjaxResult<GoodsSpecTemplateVo> getSpecTemplate(@PathVariable("specTemplateId")Long specTemplateId) {
  94. return AjaxResult.success(iGoodsSpecTemplateService.queryById(specTemplateId));
  95. }
  96. /**
  97. * 获取规格属性值对应的商品信息
  98. */
  99. @ApiOperation("获取规格属性值对应的商品信息")
  100. @GetMapping("/attr/goods")
  101. public AjaxResult<GoodsVo> getSpecTemplate(@RequestParam("specTemplateId")Long specTemplateId,@RequestParam("specAttrIds")String specAttrIds) {
  102. GoodsVo vo = iGoodsSpecTemplateService.getSpecTemplate(specTemplateId,specAttrIds);
  103. return AjaxResult.success(vo);
  104. }
  105. /**
  106. * 获取专题页组合班级商品
  107. */
  108. @ApiOperation("获取专题页组合班级商品")
  109. @GetMapping("/get/goodsList")
  110. public AjaxResult<List<CourseTopicGoodsVo>> getGoodsList(CourseTopicGoodsQueryBo bo) {
  111. return AjaxResult.success(iCourseTopicService.getGoodsList(bo));
  112. }
  113. /**
  114. * 查询课程列表
  115. */
  116. @ApiOperation("查询商品下的课程列表")
  117. @GetMapping("/courseList")
  118. public TableDataInfo<CourseUserVo> courseList(CourseQueryBo bo) {
  119. startPage();
  120. List<CourseUserVo> list = iCourseService.courseList(bo);
  121. return getDataTable(list);
  122. }
  123. /**
  124. * 查询课程列表
  125. */
  126. @ApiOperation("查询用户拥有的商品")
  127. @GetMapping("/goodsList")
  128. public TableDataInfo<GoodsUserVo> goodsList(CourseQueryBo bo) {
  129. startPage();
  130. List<GoodsUserVo> list = iCourseService.goodsList(bo);
  131. return getDataTable(list);
  132. }
  133. @ApiOperation("查询用户拥有的商品")
  134. @GetMapping("/test")
  135. public AjaxResult<Integer> test(CourseQueryBo bo) throws InterruptedException, ParseException {
  136. return AjaxResult.success(Printer.num);
  137. }
  138. @ApiOperation("小程序配置")
  139. @GetMapping("/config")
  140. public AjaxResult<Map<String,Object>> config(ConfigQueryBo bo) {
  141. Map<String,Object> map = new HashMap<>();
  142. map.put("hide",false);
  143. if(Validator.isNotEmpty(bo.getVersion())){
  144. String hideVersion = configService.selectConfigByKey("version.hide");
  145. if(bo.getVersion().equals(hideVersion)){
  146. map.put("hide",true);
  147. }
  148. }
  149. return AjaxResult.success(map);
  150. }
  151. @ApiOperation("登录双重验证")
  152. @GetMapping("/dual_auth")
  153. public AjaxResult<String> dual_auth() {
  154. String dualAuth = configService.selectConfigByKey("login.dual.auth");
  155. return AjaxResult.success("成功",dualAuth);
  156. }
  157. /**
  158. * 公众号服务接口
  159. */
  160. @ApiOperation("公众号服务接口")
  161. @GetMapping("/wxGzhServer")
  162. public String wxGzhServer(WxServerBody bo) {
  163. try {
  164. String token = "511A23101c826G90T1";
  165. String EncodingAESKey = "ybzse4DNAMj9oGzZ9kQqOX0F7nKjebGZ3xNesVFInPP";
  166. String echostr = bo.getEchostr();
  167. if (ToolsUtils.checkGzhServerSignature(token,bo.getSignature(), bo.getTimestamp(), bo.getNonce())) {
  168. return echostr;
  169. }
  170. } catch (Exception e) {
  171. //验证公众号token失败
  172. }
  173. return null;
  174. }
  175. @ApiOperation("公众号服务接口")
  176. @PostMapping("/wxGzhServer")
  177. public String wxGzhServer(@RequestBody String xmlData) {
  178. // 将xml格式的数据,转换为 AllMessage 对象
  179. AllMessage allMessage = MessageUtil.xmlToAllMessage(xmlData);
  180. String TenantId = "867735392558919680";
  181. ServletUtils.getRequestAttributes().getResponse().setHeader("TenantId", TenantId);
  182. // 是否是文本消息类型
  183. if (allMessage.getMsgType().equals(MessageTypeEnum.MSG_TEXT.getMsgType())) {
  184. // 自动回复用户所发送的文本消息
  185. // return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_PREFIX.getContent() + allMessage.getContent());
  186. return "";
  187. }
  188. // 是否是事件推送类型
  189. else if (allMessage.getMsgType().equals(MessageTypeEnum.MSG_EVENT.getMsgType())) {
  190. // 是否为订阅事件,即公众号被关注时所触发的事件
  191. if (EventType.EVENT_SUBSCRIBE.getEventType().equals(allMessage.getEvent())) {
  192. // System.out.println("关注");
  193. String openId = allMessage.getFromUserName();
  194. wxLoginService.subGzh(openId);
  195. // 自动回复欢迎语
  196. return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_SUBSCRIBE.getContent());
  197. }
  198. else if (EventType.EVENT_UNSUBSCRIBE.getEventType().equals(allMessage.getEvent())) {
  199. String openId = allMessage.getFromUserName();
  200. wxLoginService.unsubGzh(openId);
  201. // System.out.println("取消关注");
  202. }
  203. } else {
  204. // 暂不支持文本以外的消息回复
  205. return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_NONSUPPORT.getContent());
  206. }
  207. return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_NONSUPPORT.getContent());
  208. }
  209. /**
  210. * 获取企业ID
  211. */
  212. @ApiOperation("获取企业ID")
  213. @GetMapping("/findTenantId")
  214. public AjaxResult<String> findTenantId(SysTenantQueryBo bo) {
  215. Long tenantId = iSysTenantService.findTenantId(bo);
  216. if(Validator.isNotEmpty(tenantId)){
  217. return AjaxResult.success("成功",tenantId.toString());
  218. }else{
  219. if(Validator.isNotEmpty(bo.getHostH5())&&bo.getHostH5().equals("120.79.166.78:19012")){
  220. return AjaxResult.success("成功","867735392558919680");
  221. }
  222. if(Validator.isNotEmpty(bo.getHostLive())&&bo.getHostLive().equals("120.79.166.78:19012")){
  223. return AjaxResult.success("成功","867735392558919680");
  224. }
  225. if(Validator.isNotEmpty(bo.getHostPc())&&bo.getHostPc().equals("120.79.166.78:19012")){
  226. return AjaxResult.success("成功","867735392558919680");
  227. }
  228. return AjaxResult.error("失败",null);
  229. }
  230. }
  231. @ApiOperation("移动端配置参数")
  232. @GetMapping("/mobileConfig")
  233. public AjaxResult<Map<String,Object>> mobileConfig(ConfigQueryBo bo) {
  234. Map<String,Object> map = new HashMap<>();
  235. String json = configService.selectConfigByKey("home.mobile");
  236. map.put("mobileConfig",json);
  237. return AjaxResult.success(map);
  238. }
  239. }