| | |
| | | package com.ruoyi.goods.utils; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.date.DatePattern; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.utils.DateUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.goods.domain.dto.XiaoeCourseQueryDto; |
| | |
| | | import com.ruoyi.goods.domain.vo.XiaoeCourseChapterVO; |
| | | import com.ruoyi.goods.domain.vo.XiaoeCourseGroupVO; |
| | | import com.ruoyi.goods.domain.vo.XiaoeCourseVO; |
| | | import com.ruoyi.goods.domain.vo.XiaoeLiveDetailVOV2; |
| | | import com.ruoyi.goods.domain.vo.XiaoeLiveVo; |
| | | import com.ruoyi.goods.domain.vo.XiaoeLiveVoV2; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 小鹅通工具类 |
| | |
| | | //固定填写client_credential |
| | | private String grant_type = "client_credential"; |
| | | //获取直播列表 |
| | | private static final String LIVE_PAGE_LIST = "https://api.xiaoe-tech.com/xe.alive.list.get/2.0.0"; |
| | | private static final String LIVE_PAGE_LIST = "https://api.xiaoe-tech.com/xe.alive.list.get/1.0.0"; |
| | | private static final String LIVE_PAGE_LIST_V2 = "https://api.xiaoe-tech.com/xe.alive.list.get/2.0.0"; |
| | | //获取直播详情 |
| | | private static final String LIVE_DETAIL = "https://api.xiaoe-tech.com/xe.alive.detail.get/1.0.0"; |
| | | private static final String LIVE_DETAIL_V2 = "https://api.xiaoe-tech.com/xe.alive.detail.get/2.0.0"; |
| | | //创建直播 |
| | | private static final String LIVE_ADD = "https://api.xiaoe-tech.com/xe.alive.live.create/1.0.0"; |
| | | //编辑直播 |
| | |
| | | private static final String COURSE_CHAPTER = "https://api.xiaoe-tech.com/xe.course.course.chapter.get/1.0.0"; |
| | | //获取店铺商品分组列表 |
| | | private static final String COURSE_GROUP_LIST = "https://api.xiaoe-tech.com/xe.resource_tags.list/1.0.0"; |
| | | |
| | | |
| | | /** |
| | | * 获取小鹅通access_token |
| | |
| | | } |
| | | JSONObject jsonObject = JSONObject.parseObject(result); |
| | | Map data = (Map) jsonObject.get("data"); |
| | | accessToken = (String) data.get("access_token"); |
| | | accessToken = (String)data.get("access_token"); |
| | | Integer expiresIn = (int) data.get("expires_in"); |
| | | redisService.setCacheObject("xiaoe:access_token", accessToken,Long.parseLong(expiresIn.toString()), TimeUnit.SECONDS); |
| | | } |
| | | return accessToken; |
| | | } |
| | |
| | | String post = HttpUtil.post(LIVE_PAGE_LIST, JSONObject.toJSONString(postParams)); |
| | | Page<XiaoeLiveVo> xiaoeLiveVOPage = new Page<>(); |
| | | if (StringUtils.isNotBlank(post)) { |
| | | log.info("获取直播列表返回结果:{}", post); |
| | | JSONObject jsonObject = JSONObject.parseObject(post); |
| | | if (jsonObject.get("code").equals(0)) { |
| | | if (jsonObject.get("code").equals(0) ) { |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | JSONArray list = data.getJSONArray("list"); |
| | | List<XiaoeLiveVo> xiaoeLiveVos = JSONArray.parseArray(list.toJSONString(), XiaoeLiveVo.class); |
| | | xiaoeLiveVOPage.setRecords(xiaoeLiveVos); |
| | | xiaoeLiveVOPage.setCurrent(data.getLong("page")); |
| | | xiaoeLiveVOPage.setTotal(data.getLong("total")); |
| | | xiaoeLiveVOPage.setPages(data.getLong("page_count")); |
| | | if (CollectionUtil.isNotEmpty(list)) { |
| | | List<XiaoeLiveVo> xiaoeLiveVos = JSONArray.parseArray(list.toJSONString(), XiaoeLiveVo.class); |
| | | xiaoeLiveVOPage.setRecords(xiaoeLiveVos); |
| | | xiaoeLiveVOPage.setCurrent(dto.getPage()); |
| | | xiaoeLiveVOPage.setPages(data.getLong("page_count")); |
| | | } |
| | | } |
| | | } |
| | | return xiaoeLiveVOPage; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取直播列表2.0 |
| | | * @param dto |
| | | * @return |
| | | */ |
| | | public Page<XiaoeLiveVoV2> getLivePageListV2(XiaoeLiveQueryDto dto) { |
| | | Map<String,Object> postParams = new HashMap<>(); |
| | | postParams.put("search_content", dto.getSearchContent()); |
| | | postParams.put("create_mode", dto.getCreateMode()); |
| | | postParams.put("state", 0); |
| | | postParams.put("search_alive_type", dto.getSearchAliveType()); |
| | | postParams.put("alive_play_state", dto.getAlivePlayState()); |
| | | postParams.put("page", dto.getPage()); |
| | | postParams.put("page_size", dto.getPageSize()); |
| | | postParams.put("access_token", getAccessToken()); |
| | | postParams.put("zb_start_at_min", DateUtil.format(DateUtils.getTodayStartTime(), DatePattern.NORM_DATETIME_PATTERN)); |
| | | String post = HttpUtil.post(LIVE_PAGE_LIST_V2, JSONObject.toJSONString(postParams)); |
| | | Page<XiaoeLiveVoV2> xiaoeLiveVOPage = new Page<>(); |
| | | if (StringUtils.isNotBlank(post)) { |
| | | log.info("获取直播详情2.0返回结果:{}", post); |
| | | JSONObject jsonObject = JSONObject.parseObject(post); |
| | | if (jsonObject.get("code").equals(0)) { |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | JSONArray list = data.getJSONArray("live_list"); |
| | | if (!list.isEmpty()){ |
| | | List<XiaoeLiveVoV2> xiaoeLiveVos = JSONArray.parseArray(list.toJSONString(), XiaoeLiveVoV2.class); |
| | | xiaoeLiveVOPage.setRecords(xiaoeLiveVos); |
| | | xiaoeLiveVOPage.setCurrent(dto.getPage()); |
| | | xiaoeLiveVOPage.setTotal(data.getLong("total_count")); |
| | | } |
| | | } |
| | | } |
| | | return xiaoeLiveVOPage; |
| | | } |
| | | |
| | | /** |
| | | *获取直播详情 |
| | | * @param id 直播ID |
| | | * @return |
| | | */ |
| | | public XiaoeLiveDetailVOV2 getLiveDetailV2(String id) { |
| | | Map<String, Object> postParams = new HashMap<>(); |
| | | postParams.put("id", id); |
| | | postParams.put("access_token", getAccessToken()); |
| | | String post = HttpUtil.post(LIVE_DETAIL_V2, JSONObject.toJSONString(postParams)); |
| | | XiaoeLiveDetailVOV2 vo = null; |
| | | if (StringUtils.isNotBlank(post)) { |
| | | JSONObject jsonObject = JSONObject.parseObject(post); |
| | | if (jsonObject.get("code").equals(0)) { |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | vo = JSONObject.parseObject(data.toJSONString(), XiaoeLiveDetailVOV2.class); |
| | | } |
| | | } |
| | | return vo; |
| | | } |
| | | /** |
| | | * 创建直播 |
| | | * @param dto |
| | | * @return |
| | |
| | | moudleInfoMap.put("alive_mode", dto.getAliveMode()); |
| | | requestParams.put("module_info", moudleInfoMap); |
| | | //讲师信息 |
| | | List<Map<String, Object>> roleList = new ArrayList<>(); |
| | | Map<String, Object> roleInfoMap = new HashMap<>(); |
| | | roleInfoMap.put("role_name", "讲师"); |
| | | roleInfoMap.put("user_id", dto.getUserId()); |
| | | requestParams.put("role_info", roleInfoMap); |
| | | roleList.add(roleInfoMap); |
| | | requestParams.put("role_info", roleList); |
| | | //商品信息 |
| | | Map<String, Object> goodsInfoMap = new HashMap<>(); |
| | | goodsInfoMap.put("sale_type", 2);//售卖类型:1-单独售卖、2-关联售卖 |
| | | goodsInfoMap.put("sale_type", 1);//售卖类型:1-单独售卖、2-关联售卖 |
| | | goodsInfoMap.put("payment_type", dto.getPaymentType()); |
| | | if (dto.getPaymentType().equals(3)) { |
| | | goodsInfoMap.put("resource_password", dto.getResourcePassword()); |
| | | } |
| | | requestParams.put("goods_info", goodsInfoMap); |
| | | requestParams.put("access_token", getAccessToken()); |
| | | log.info("创建直播参数:{}" ,JSONObject.toJSONString(requestParams)); |
| | | String post = HttpUtil.post(LIVE_ADD, JSONObject.toJSONString(requestParams)); |
| | | if (StringUtils.isNotBlank(post)) { |
| | | JSONObject jsonObject = JSONObject.parseObject(post); |
| | |
| | | return null; |
| | | } |
| | | /** |
| | | * 创建直播 |
| | | * 编辑直播 |
| | | * @param dto |
| | | * @return |
| | | */ |
| | |
| | | moudleInfoMap.put("alive_mode", dto.getAliveMode()); |
| | | requestParams.put("module_info", moudleInfoMap); |
| | | //讲师信息 |
| | | List<Map<String, Object>> roleList = new ArrayList<>(); |
| | | Map<String, Object> roleInfoMap = new HashMap<>(); |
| | | roleInfoMap.put("role_name", "讲师"); |
| | | roleInfoMap.put("user_id", dto.getUserId()); |
| | | requestParams.put("role_info", roleInfoMap); |
| | | roleList.add(roleInfoMap); |
| | | requestParams.put("role_info", roleList); |
| | | //商品信息 |
| | | Map<String, Object> goodsInfoMap = new HashMap<>(); |
| | | goodsInfoMap.put("sale_type", 2);//售卖类型:1-单独售卖、2-关联售卖 |
| | | goodsInfoMap.put("sale_type", 1);//售卖类型:1-单独售卖、2-关联售卖 |
| | | goodsInfoMap.put("payment_type", dto.getPaymentType()); |
| | | if (dto.getPaymentType().equals(3)) { |
| | | goodsInfoMap.put("resource_password", dto.getResourcePassword()); |
| | | } |
| | | requestParams.put("goods_info", goodsInfoMap); |
| | | requestParams.put("access_token", getAccessToken()); |
| | | log.info("编辑直播参数:{}" ,JSONObject.toJSONString(requestParams)); |
| | | String post = HttpUtil.post(LIVE_EDIT, JSONObject.toJSONString(requestParams)); |
| | | if (StringUtils.isNotBlank(post)) { |
| | | JSONObject jsonObject = JSONObject.parseObject(post); |
| | |
| | | * @return |
| | | */ |
| | | public Page<XiaoeCourseVO> getCoursePageList(XiaoeCourseQueryDto dto) { |
| | | JSONObject requestParams = JSONObject.parseObject(JSONObject.toJSONString(dto)); |
| | | Map<String, Object> requestParams = new HashMap<>(); |
| | | requestParams.put("search_content", dto.getSearchContent()); |
| | | requestParams.put("page", dto.getPageNo()); |
| | | requestParams.put("page_size", dto.getPageSize()); |
| | | requestParams.put("created_source", dto.getCreatedSource()); |
| | | requestParams.put("tags", dto.getTags()); |
| | | if (dto.getSortBy().equals(1)) { |
| | | requestParams.put("order_by", "modify");//根据创建时间排序 |
| | | requestParams.put("order_type", "降序"); |
| | | requestParams.put("order_type",1); |
| | | } |
| | | |
| | | requestParams.put("sale_status", 1); |
| | | requestParams.put("access_token", getAccessToken()); |
| | | String post = HttpUtil.post(COURSE_PAGE_LIST, requestParams.toJSONString()); |
| | | String post = HttpUtil.post(COURSE_PAGE_LIST, JSONObject.toJSONString(requestParams)); |
| | | Page<XiaoeCourseVO> page = new Page<>(); |
| | | if (StringUtils.isNotBlank(post)) { |
| | | log.info("获取课程列表返回结果:{}" ,post); |
| | |
| | | requestParams.put("course_id", id); |
| | | requestParams.put("access_token", getAccessToken()); |
| | | String post = HttpUtil.post(COURSE_CHAPTER, JSONObject.toJSONString(requestParams)); |
| | | List<XiaoeCourseChapterVO> xiaoeCourseChapterVO = new ArrayList<>(); |
| | | List<XiaoeCourseChapterVO> courseChapterVOList = new ArrayList<>(); |
| | | if (StringUtils.isNotBlank(post)) { |
| | | log.info("查询课程目录小节返回结果:{}" ,post); |
| | | JSONObject jsonObject = JSONObject.parseObject(post); |
| | | if (jsonObject.get("code").equals(0)) { |
| | | String data = jsonObject.getString("data"); |
| | | xiaoeCourseChapterVO = JSONArray.parseArray(data, XiaoeCourseChapterVO.class); |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | courseChapterVOList = JSONArray.parseArray(data.getString("list"), XiaoeCourseChapterVO.class); |
| | | } |
| | | } |
| | | return xiaoeCourseChapterVO; |
| | | return courseChapterVOList; |
| | | } |
| | | public static void main(String[] args) { |
| | | String urlString = BASE_URL + |