CommonController.java 11 KB

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