package com.zhongzheng.controller.cmmon; import cn.hutool.core.lang.Validator; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.zhongzheng.common.core.controller.BaseController; import com.zhongzheng.common.core.domain.AjaxResult; import com.zhongzheng.common.core.page.TableDataInfo; import com.zhongzheng.common.core.redis.RedisCache; import com.zhongzheng.common.utils.ServletUtils; import com.zhongzheng.common.utils.ToolsUtils; import com.zhongzheng.framework.web.service.WxLoginService; import com.zhongzheng.modules.base.bo.ConfigQueryBo; import com.zhongzheng.modules.course.bo.CourseQueryBo; import com.zhongzheng.modules.course.bo.CourseTopicGoodsQueryBo; import com.zhongzheng.modules.course.service.ICourseService; import com.zhongzheng.modules.course.service.ICourseTopicService; import com.zhongzheng.modules.course.vo.CourseTopicGoodsVo; import com.zhongzheng.modules.course.vo.CourseTopicVo; import com.zhongzheng.modules.course.vo.CourseUserVo; import com.zhongzheng.modules.exam.bo.ExamActivityApplyBo; import com.zhongzheng.modules.exam.bo.ExamActivityApplyVo; import com.zhongzheng.modules.exam.service.IExamActivityService; import com.zhongzheng.modules.exam.vo.ExamActivityVo; import com.zhongzheng.modules.goods.service.IGoodsSpecTemplateService; import com.zhongzheng.modules.goods.vo.GoodsSpecTemplateVo; import com.zhongzheng.modules.goods.vo.GoodsUserVo; import com.zhongzheng.modules.goods.vo.GoodsVo; import com.zhongzheng.modules.order.domain.Printer; import com.zhongzheng.modules.system.bo.SysTenantQueryBo; import com.zhongzheng.modules.system.service.ISysConfigService; import com.zhongzheng.modules.system.service.ISysTenantService; import com.zhongzheng.modules.system.service.ISysWebService; import com.zhongzheng.modules.wx.bo.WxInfoBo; import com.zhongzheng.modules.wx.bo.WxInfoQuery; import com.zhongzheng.modules.wx.bo.WxServerBody; import com.zhongzheng.modules.wx.domain.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.text.ParseException; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 课程Controller * * @author hjl * @date 2021-10-09 */ @Api(value = "游客访问接口", tags = {"游客访问接口"}) @RequiredArgsConstructor(onConstructor_ = @Autowired) @RestController @RequestMapping("/app/common/") public class CommonController extends BaseController { private final ICourseService iCourseService; private final WxLoginService wxLoginService; private final ISysConfigService configService; @Autowired private RedisCache redisCache; private final ICourseTopicService iCourseTopicService; private final IGoodsSpecTemplateService iGoodsSpecTemplateService; private final ISysTenantService iSysTenantService; /** * 获取微信小程序信息(网页跳转小程序) */ @ApiOperation("获取微信小程序信息(网页跳转小程序)") @GetMapping("/get/wx/info") public AjaxResult getWxInfo(WxInfoQuery query) { return AjaxResult.success(wxLoginService.getWxInfo(query)); } /** * 获取小程序首页链接 */ @ApiOperation("获取小程序首页链接") @GetMapping("/get/small/link") public AjaxResult getWxSmallLink() { return AjaxResult.success(wxLoginService.getWxSmallLink()); } /** * 获取商品专题页指定商品信息 */ @ApiOperation("获取商品专题页指定商品信息") @GetMapping("/get/goodsInfo/{topicId}") public AjaxResult getGoodsInfo(@PathVariable("topicId") Integer topicId) { return AjaxResult.success(iCourseTopicService.getGoodsInfo(topicId)); } /** * 获取商品规格模板信息 */ @ApiOperation("获取商品规格模板信息") @GetMapping("/spec/{specTemplateId}") public AjaxResult getSpecTemplate(@PathVariable("specTemplateId")Long specTemplateId) { return AjaxResult.success(iGoodsSpecTemplateService.queryById(specTemplateId)); } /** * 获取规格属性值对应的商品信息 */ @ApiOperation("获取规格属性值对应的商品信息") @GetMapping("/attr/goods") public AjaxResult getSpecTemplate(@RequestParam("specTemplateId")Long specTemplateId,@RequestParam("specAttrIds")String specAttrIds) { GoodsVo vo = iGoodsSpecTemplateService.getSpecTemplate(specTemplateId,specAttrIds); return AjaxResult.success(vo); } /** * 获取专题页组合班级商品 */ @ApiOperation("获取专题页组合班级商品") @GetMapping("/get/goodsList") public AjaxResult> getGoodsList(CourseTopicGoodsQueryBo bo) { return AjaxResult.success(iCourseTopicService.getGoodsList(bo)); } /** * 查询课程列表 */ @ApiOperation("查询商品下的课程列表") @GetMapping("/courseList") public TableDataInfo courseList(CourseQueryBo bo) { startPage(); List list = iCourseService.courseList(bo); return getDataTable(list); } /** * 查询课程列表 */ @ApiOperation("查询用户拥有的商品") @GetMapping("/goodsList") public TableDataInfo goodsList(CourseQueryBo bo) { startPage(); List list = iCourseService.goodsList(bo); return getDataTable(list); } @ApiOperation("查询用户拥有的商品") @GetMapping("/test") public AjaxResult test(CourseQueryBo bo) throws InterruptedException, ParseException { return AjaxResult.success(Printer.num); } @ApiOperation("小程序配置") @GetMapping("/config") public AjaxResult> config(ConfigQueryBo bo) { Map map = new HashMap<>(); map.put("hide",false); if(Validator.isNotEmpty(bo.getVersion())){ String hideVersion = configService.selectConfigByKey("version.hide"); if(bo.getVersion().equals(hideVersion)){ map.put("hide",true); } } return AjaxResult.success(map); } @ApiOperation("登录双重验证") @GetMapping("/dual_auth") public AjaxResult dual_auth() { String dualAuth = configService.selectConfigByKey("login.dual.auth"); return AjaxResult.success("成功",dualAuth); } /** * 公众号服务接口 */ @ApiOperation("公众号服务接口") @GetMapping("/wxGzhServer") public String wxGzhServer(WxServerBody bo) { try { String token = "511A23101c826G90T1"; String EncodingAESKey = "ybzse4DNAMj9oGzZ9kQqOX0F7nKjebGZ3xNesVFInPP"; String echostr = bo.getEchostr(); if (ToolsUtils.checkGzhServerSignature(token,bo.getSignature(), bo.getTimestamp(), bo.getNonce())) { return echostr; } } catch (Exception e) { //验证公众号token失败 } return null; } @ApiOperation("公众号服务接口") @PostMapping("/wxGzhServer") public String wxGzhServer(@RequestBody String xmlData) { // 将xml格式的数据,转换为 AllMessage 对象 AllMessage allMessage = MessageUtil.xmlToAllMessage(xmlData); String TenantId = "867735392558919680"; ServletUtils.getRequestAttributes().getResponse().setHeader("TenantId", TenantId); // 是否是文本消息类型 if (allMessage.getMsgType().equals(MessageTypeEnum.MSG_TEXT.getMsgType())) { // 自动回复用户所发送的文本消息 // return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_PREFIX.getContent() + allMessage.getContent()); return ""; } // 是否是事件推送类型 else if (allMessage.getMsgType().equals(MessageTypeEnum.MSG_EVENT.getMsgType())) { // 是否为订阅事件,即公众号被关注时所触发的事件 if (EventType.EVENT_SUBSCRIBE.getEventType().equals(allMessage.getEvent())) { // System.out.println("关注"); String openId = allMessage.getFromUserName(); wxLoginService.subGzh(openId); // 自动回复欢迎语 return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_SUBSCRIBE.getContent()); } else if (EventType.EVENT_UNSUBSCRIBE.getEventType().equals(allMessage.getEvent())) { String openId = allMessage.getFromUserName(); wxLoginService.unsubGzh(openId); // System.out.println("取消关注"); } } else { // 暂不支持文本以外的消息回复 return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_NONSUPPORT.getContent()); } return MessageUtil.autoReply(allMessage, ContentEnum.CONTENT_NONSUPPORT.getContent()); } /** * 获取企业ID */ @ApiOperation("获取企业ID") @GetMapping("/findTenantId") public AjaxResult findTenantId(SysTenantQueryBo bo) { Long tenantId = iSysTenantService.findTenantId(bo); if(Validator.isNotEmpty(tenantId)){ return AjaxResult.success("成功",tenantId.toString()); }else{ if(Validator.isNotEmpty(bo.getHostH5())&&bo.getHostH5().equals("120.79.166.78:19012")){ return AjaxResult.success("成功","867735392558919680"); } if(Validator.isNotEmpty(bo.getHostLive())&&bo.getHostLive().equals("120.79.166.78:19012")){ return AjaxResult.success("成功","867735392558919680"); } if(Validator.isNotEmpty(bo.getHostPc())&&bo.getHostPc().equals("120.79.166.78:19012")){ return AjaxResult.success("成功","867735392558919680"); } return AjaxResult.error("失败",null); } } @ApiOperation("移动端配置参数") @GetMapping("/mobileConfig") public AjaxResult> mobileConfig(ConfigQueryBo bo) { Map map = new HashMap<>(); String json = configService.selectConfigByKey("home.mobile"); map.put("mobileConfig",json); return AjaxResult.success(map); } }