diff --git a/src/main/java/com/sqx/modules/course/controller/CourseController.java b/src/main/java/com/sqx/modules/course/controller/CourseController.java index 6a3ef5a8..d6d2970a 100644 --- a/src/main/java/com/sqx/modules/course/controller/CourseController.java +++ b/src/main/java/com/sqx/modules/course/controller/CourseController.java @@ -20,7 +20,7 @@ import java.math.BigDecimal; @RestController @Api(value = "短剧信息", tags = {"短剧信息"}) @RequestMapping(value = "/course") -public class CourseController extends AbstractController { +class CourseController extends AbstractController { @Autowired private CourseService courseService; @Autowired @@ -113,61 +113,61 @@ public class CourseController extends AbstractController { return courseService.deleteCourseDetailsByIds(ids); } - @PostMapping("/dyVideoUpload") - @ApiOperation("抖音短剧上传") - public Result dyVideoUpload(Long courseId){ - return courseService.dyVideoUpload(courseId); - } +// @PostMapping("/dyVideoUpload") +// @ApiOperation("抖音短剧上传") +// public Result dyVideoUpload(Long courseId){ +// return courseService.dyVideoUpload(courseId); +// } - @PostMapping("/dyVideoAudit") - @ApiOperation("抖音短剧送审") - public Result dyVideoAudit(Long courseId){ - return courseService.dyVideoAudit(courseId); - } +// @PostMapping("/dyVideoAudit") +// @ApiOperation("抖音短剧送审") +// public Result dyVideoAudit(Long courseId){ +// return courseService.dyVideoAudit(courseId); +// } - @PostMapping("/dyVideoUp") - @ApiOperation("抖音短剧上线") - public Result dyVideoUp(Long courseId){ - return courseService.dyVideoUp(courseId); - } +// @PostMapping("/dyVideoUp") +// @ApiOperation("抖音短剧上线") +// public Result dyVideoUp(Long courseId){ +// return courseService.dyVideoUp(courseId); +// } - @PostMapping("/setDyNotifyUrl") - @ApiOperation("设置抖音视频回调地址") - public Result setDyNotifyUrl(String url){ - return courseService.setDyNotifyUrl(url); - } +// @PostMapping("/setDyNotifyUrl") +// @ApiOperation("设置抖音视频回调地址") +// public Result setDyNotifyUrl(String url){ +// return courseService.setDyNotifyUrl(url); +// } - @PostMapping("/uploadCourseDetails") - @ApiOperation("单个集上传") - public Result uploadCourseDetails(Long courseDetailsId){ - return courseService.uploadCourseDetails(courseDetailsId); - } +// @PostMapping("/uploadCourseDetails") +// @ApiOperation("单个集上传") +// public Result uploadCourseDetails(Long courseDetailsId){ +// return courseService.uploadCourseDetails(courseDetailsId); +// } - @PostMapping("/updateDyCourse") - @ApiOperation("修改抖音短剧") - public Result updateDyCourse(@RequestBody Course course){ - return courseService.updateDyCourse(course); - } +// @PostMapping("/updateDyCourse") +// @ApiOperation("修改抖音短剧") +// public Result updateDyCourse(@RequestBody Course course){ +// return courseService.updateDyCourse(course); +// } - @GetMapping("/sysWxCourse") - @ApiOperation("同步微信已提交审核的短剧") - public Result sysWxCourse(Integer freeNum, BigDecimal coursePrice,Integer maxGood,Integer minGood){ - return courseService.sysWxCourse(freeNum, coursePrice, maxGood, minGood); - } +// @GetMapping("/sysWxCourse") +// @ApiOperation("同步微信已提交审核的短剧") +// public Result sysWxCourse(Integer freeNum, BigDecimal coursePrice,Integer maxGood,Integer minGood){ +// return courseService.sysWxCourse(freeNum, coursePrice, maxGood, minGood); +// } - @PostMapping("/uploadWxCourse") - @ApiOperation("提交微信备案审核") - public Result uploadWxCourse(Long courseId,Integer qualificationType,String registrationNumber, - String qualificationCertificateMaterialId,String costOfProduction,String costCommitmentLetterMaterialId){ - return courseService.uploadWxCourse(courseId, qualificationType, registrationNumber, qualificationCertificateMaterialId, costOfProduction, costCommitmentLetterMaterialId); - } +// @PostMapping("/uploadWxCourse") +// @ApiOperation("提交微信备案审核") +// public Result uploadWxCourse(Long courseId,Integer qualificationType,String registrationNumber, +// String qualificationCertificateMaterialId,String costOfProduction,String costCommitmentLetterMaterialId){ +// return courseService.uploadWxCourse(courseId, qualificationType, registrationNumber, qualificationCertificateMaterialId, costOfProduction, costCommitmentLetterMaterialId); +// } - @GetMapping("/getWxToken") - @ApiOperation("获取微信小程序token") - public Result getWxToken(){ - return Result.success().put("data",SenInfoCheckUtil.getMpToken()); - } +// @GetMapping("/getWxToken") +// @ApiOperation("获取微信小程序token") +// public Result getWxToken(){ +// return Result.success().put("data",SenInfoCheckUtil.getMpToken()); +// } /** * 剧导入列表--导入 diff --git a/src/main/java/com/sqx/modules/course/entity/CourseDetails.java b/src/main/java/com/sqx/modules/course/entity/CourseDetails.java index 21b3c789..1c024f99 100644 --- a/src/main/java/com/sqx/modules/course/entity/CourseDetails.java +++ b/src/main/java/com/sqx/modules/course/entity/CourseDetails.java @@ -88,42 +88,42 @@ public class CourseDetails implements Serializable { /** * 抖音视频id */ - private String dyCourseDetailsId; +// private String dyCourseDetailsId; /** * 视频上传状态 1上传中 2上传成功 3上传失败 */ - private Integer dyUrlStatus; +// private Integer dyUrlStatus; /** * 抖音封面图id */ - private String dyImgId; +// private String dyImgId; /** * 抖音集id */ - private String dyEpisodeId; +// private String dyEpisodeId; /** * 抖音提审状态 1已提交 2已通过 3已拒绝 4已上线 */ - private Integer dyStatus; +// private Integer dyStatus; /** * 抖音审核内容 */ - private String dyStatusContent; +// private String dyStatusContent; /** * 当前版本号 */ - private String dyVersion; +// private String dyVersion; /** * 微信视频id */ - private String wxCourseDetailsId; +// private String wxCourseDetailsId; /** * 排序 @@ -133,7 +133,7 @@ public class CourseDetails implements Serializable { /** * 是否允许广告解锁 1是 */ - private Integer advertising; +// private Integer advertising; /** * 播放量 @@ -156,7 +156,7 @@ public class CourseDetails implements Serializable { @TableField(exist = false) private Integer courseDetailsCount; - @TableField(exist = false) - private String wxUrl; +// @TableField(exist = false) +// private String wxUrl; } diff --git a/src/main/java/com/sqx/modules/course/service/impl/CourseDetailsServiceImpl.java b/src/main/java/com/sqx/modules/course/service/impl/CourseDetailsServiceImpl.java index 1dc133d5..7968cc31 100644 --- a/src/main/java/com/sqx/modules/course/service/impl/CourseDetailsServiceImpl.java +++ b/src/main/java/com/sqx/modules/course/service/impl/CourseDetailsServiceImpl.java @@ -309,7 +309,7 @@ public class CourseDetailsServiceImpl extends ServiceImpl()); + Integer detailCount = baseMapper.selectCount(new LambdaQueryWrapper() + .eq(CourseDetails::getGood,1) + .eq(CourseDetails::getIsPrice,2)); if (detailCount != null) { PageHelper.startPage(RandomUtil.randomInt(1, detailCount / 10), 10); } - List list = baseMapper.selectList(new QueryWrapper<>()); + List list = baseMapper.selectList(new LambdaQueryWrapper() + .eq(CourseDetails::getGood,1) + .eq(CourseDetails::getIsPrice,2)); PageInfo pageInfo = new PageInfo<>(list); diff --git a/src/main/java/com/sqx/modules/course/service/impl/CourseServiceImpl.java b/src/main/java/com/sqx/modules/course/service/impl/CourseServiceImpl.java index 8c1e639c..30b3b392 100644 --- a/src/main/java/com/sqx/modules/course/service/impl/CourseServiceImpl.java +++ b/src/main/java/com/sqx/modules/course/service/impl/CourseServiceImpl.java @@ -431,208 +431,208 @@ public class CourseServiceImpl extends ServiceImpl implements @Override public Result dyVideoUpload(Long courseId) { - uploadVideo(courseId); +// uploadVideo(courseId); return Result.success(); } @Async public void uploadVideo(Long courseId) { - try { - String appid = commonInfoService.findOne(805).getValue(); - Course course = baseMapper.selectById(courseId); - List courseDetailsList = courseDetailsDao.selectList(new QueryWrapper().eq("course_id", courseId)); - if (StringUtils.isEmpty(course.getDyImgId())) { - //上传短剧封面图 - String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("resource_type", 2); - jsonObject.put("ma_app_id", appid); - JSONObject image_meta = new JSONObject(); - image_meta.put("url", course.getTitleImg()); - jsonObject.put("image_meta", image_meta); - String s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); - JSONObject jsonObject1 = JSONObject.parseObject(s); - String err_no = jsonObject1.getString("err_no"); - log.info("抖音短剧封面图上传:" + jsonObject1.toJSONString()); - if ("0".equals(err_no)) { - JSONObject data = jsonObject1.getJSONObject("data"); - JSONObject image_result = data.getJSONObject("image_result"); - String open_pic_id = image_result.getString("open_pic_id"); - course.setDyImgId(open_pic_id); - baseMapper.updateById(course); - } - } - if (StringUtils.isEmpty(course.getDyCourseId())) { - //创建短剧 - String url = "https://open.douyin.com/api/playlet/v2/video/create/"; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("ma_app_id", appid); - JSONObject album_info = new JSONObject(); - album_info.put("title", course.getTitle()); - album_info.put("seq_num", courseDetailsList.size()); - JSONArray cover_list = new JSONArray(); - cover_list.add(course.getDyImgId()); - album_info.put("cover_list", cover_list); - album_info.put("year", DateUtils.format(new Date(), "yyyy")); - album_info.put("album_status", "3"); - album_info.put("recommendation", course.getTitle()); - album_info.put("desp", course.getDetails()); - JSONArray tag_list = new JSONArray(); - if (course.getCourseLabelIds() != null) { - String[] split = course.getCourseLabelIds().split(","); - for (String tag : split) { - tag_list.add(tag); - if (tag_list.size() == 3) { - break; - } - } - } - album_info.put("tag_list", tag_list); - /*if(StringUtils.isNotEmpty(course.getLicenseNum()) || StringUtils.isNotEmpty(course.getRegistrationNum()) || - StringUtils.isNotEmpty(course.getKeyRecordNum()) || StringUtils.isNotEmpty(course.getOrdinaryRecordNum())){ - album_info.put("qualification","1"); - JSONObject record_info=new JSONObject(); - if(StringUtils.isNotEmpty(course.getLicenseNum())){ - record_info.put("license_num",course.getLicenseNum()); - }else if(StringUtils.isNotEmpty(course.getRegistrationNum())){ - record_info.put("registration_num",course.getRegistrationNum()); - }else if(StringUtils.isNotEmpty(course.getOrdinaryRecordNum())){ - record_info.put("ordinary_record_num",course.getOrdinaryRecordNum()); - }else{ - record_info.put("key_record_num",course.getKeyRecordNum()); - } - album_info.put("record_info",record_info); - }else{ +// try { +// String appid = commonInfoService.findOne(805).getValue(); +// Course course = baseMapper.selectById(courseId); +// List courseDetailsList = courseDetailsDao.selectList(new QueryWrapper().eq("course_id", courseId)); +// if (StringUtils.isEmpty(course.getDyImgId())) { +// //上传短剧封面图 +// String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("resource_type", 2); +// jsonObject.put("ma_app_id", appid); +// JSONObject image_meta = new JSONObject(); +// image_meta.put("url", course.getTitleImg()); +// jsonObject.put("image_meta", image_meta); +// String s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); +// JSONObject jsonObject1 = JSONObject.parseObject(s); +// String err_no = jsonObject1.getString("err_no"); +// log.info("抖音短剧封面图上传:" + jsonObject1.toJSONString()); +// if ("0".equals(err_no)) { +// JSONObject data = jsonObject1.getJSONObject("data"); +// JSONObject image_result = data.getJSONObject("image_result"); +// String open_pic_id = image_result.getString("open_pic_id"); +// course.setDyImgId(open_pic_id); +// baseMapper.updateById(course); +// } +// } +// if (StringUtils.isEmpty(course.getDyCourseId())) { +// //创建短剧 +// String url = "https://open.douyin.com/api/playlet/v2/video/create/"; +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("ma_app_id", appid); +// JSONObject album_info = new JSONObject(); +// album_info.put("title", course.getTitle()); +// album_info.put("seq_num", courseDetailsList.size()); +// JSONArray cover_list = new JSONArray(); +// cover_list.add(course.getDyImgId()); +// album_info.put("cover_list", cover_list); +// album_info.put("year", DateUtils.format(new Date(), "yyyy")); +// album_info.put("album_status", "3"); +// album_info.put("recommendation", course.getTitle()); +// album_info.put("desp", course.getDetails()); +// JSONArray tag_list = new JSONArray(); +// if (course.getCourseLabelIds() != null) { +// String[] split = course.getCourseLabelIds().split(","); +// for (String tag : split) { +// tag_list.add(tag); +// if (tag_list.size() == 3) { +// break; +// } +// } +// } +// album_info.put("tag_list", tag_list); +// /*if(StringUtils.isNotEmpty(course.getLicenseNum()) || StringUtils.isNotEmpty(course.getRegistrationNum()) || +// StringUtils.isNotEmpty(course.getKeyRecordNum()) || StringUtils.isNotEmpty(course.getOrdinaryRecordNum())){ +// album_info.put("qualification","1"); +// JSONObject record_info=new JSONObject(); +// if(StringUtils.isNotEmpty(course.getLicenseNum())){ +// record_info.put("license_num",course.getLicenseNum()); +// }else if(StringUtils.isNotEmpty(course.getRegistrationNum())){ +// record_info.put("registration_num",course.getRegistrationNum()); +// }else if(StringUtils.isNotEmpty(course.getOrdinaryRecordNum())){ +// record_info.put("ordinary_record_num",course.getOrdinaryRecordNum()); +// }else{ +// record_info.put("key_record_num",course.getKeyRecordNum()); +// } +// album_info.put("record_info",record_info); +// }else{ +// +// }*/ +// album_info.put("qualification", "1"); +// JSONObject record_audit_info = new JSONObject(); +// JSONObject record_material = new JSONObject(); +// record_material.put("name", course.getTitle()); +// record_material.put("duration", course.getDuration()); +// record_material.put("seqs_count", courseDetailsList.size()); +// record_material.put("production_organisation", course.getProductionOrganisation()); +// String director = course.getDirector(); +// String[] directors = director.split(","); +// record_material.put("director", directors); +// String producer = course.getProducer(); +// String[] producers = producer.split(","); +// record_material.put("producer", producers); +// String actor = course.getActor(); +// String[] actors = actor.split(","); +// record_material.put("actor", actors); +// record_material.put("summary", course.getSummary()); +// +// String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; +// JSONObject imageJSON = new JSONObject(); +// imageJSON.put("resource_type", 2); +// imageJSON.put("ma_app_id", appid); +// JSONObject image_meta = new JSONObject(); +// image_meta.put("url", course.getCostDistributionUri()); +// imageJSON.put("image_meta", image_meta); +// String s = HttpClientUtil.doPostJson(imgUrl, imageJSON.toJSONString(), SenInfoCheckUtil.getDyToken()); +// JSONObject jsonObject1 = JSONObject.parseObject(s); +// String err_no = jsonObject1.getString("err_no"); +// log.info("抖音短剧封面图上传:" + jsonObject1.toJSONString()); +// if ("0".equals(err_no)) { +// JSONObject data = jsonObject1.getJSONObject("data"); +// JSONObject image_result = data.getJSONObject("image_result"); +// String open_pic_id = image_result.getString("open_pic_id"); +// record_material.put("cost_distribution_uri", open_pic_id); +// } +// +// imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; +// imageJSON = new JSONObject(); +// imageJSON.put("resource_type", 2); +// imageJSON.put("ma_app_id", appid); +// image_meta = new JSONObject(); +// image_meta.put("url", course.getAssuranceUri()); +// imageJSON.put("image_meta", image_meta); +// s = HttpClientUtil.doPostJson(imgUrl, imageJSON.toJSONString(), SenInfoCheckUtil.getDyToken()); +// jsonObject1 = JSONObject.parseObject(s); +// err_no = jsonObject1.getString("err_no"); +// log.info("抖音短剧封面图上传:" + jsonObject1.toJSONString()); +// if ("0".equals(err_no)) { +// JSONObject data = jsonObject1.getJSONObject("data"); +// JSONObject image_result = data.getJSONObject("image_result"); +// String open_pic_id = image_result.getString("open_pic_id"); +// record_material.put("assurance_uri", open_pic_id); +// } +// +// record_material.put("playlet_production_cost", course.getPlayletProductionCost()); +// record_audit_info.put("record_material", record_material); +// album_info.put("record_audit_info", record_audit_info); +// jsonObject.put("album_info", album_info); +// s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); +// jsonObject1 = JSONObject.parseObject(s); +// err_no = jsonObject1.getString("err_no"); +// log.info("抖音创建短剧:" + jsonObject1.toJSONString()); +// if ("0".equals(err_no)) { +// JSONObject data = jsonObject1.getJSONObject("data"); +// String album_id = data.getString("album_id"); +// course.setDyCourseId(album_id); +// baseMapper.updateById(course); +// } +// } +// //上传视频 +// for (CourseDetails courseDetails : courseDetailsList) { - }*/ - album_info.put("qualification", "1"); - JSONObject record_audit_info = new JSONObject(); - JSONObject record_material = new JSONObject(); - record_material.put("name", course.getTitle()); - record_material.put("duration", course.getDuration()); - record_material.put("seqs_count", courseDetailsList.size()); - record_material.put("production_organisation", course.getProductionOrganisation()); - String director = course.getDirector(); - String[] directors = director.split(","); - record_material.put("director", directors); - String producer = course.getProducer(); - String[] producers = producer.split(","); - record_material.put("producer", producers); - String actor = course.getActor(); - String[] actors = actor.split(","); - record_material.put("actor", actors); - record_material.put("summary", course.getSummary()); - - String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; - JSONObject imageJSON = new JSONObject(); - imageJSON.put("resource_type", 2); - imageJSON.put("ma_app_id", appid); - JSONObject image_meta = new JSONObject(); - image_meta.put("url", course.getCostDistributionUri()); - imageJSON.put("image_meta", image_meta); - String s = HttpClientUtil.doPostJson(imgUrl, imageJSON.toJSONString(), SenInfoCheckUtil.getDyToken()); - JSONObject jsonObject1 = JSONObject.parseObject(s); - String err_no = jsonObject1.getString("err_no"); - log.info("抖音短剧封面图上传:" + jsonObject1.toJSONString()); - if ("0".equals(err_no)) { - JSONObject data = jsonObject1.getJSONObject("data"); - JSONObject image_result = data.getJSONObject("image_result"); - String open_pic_id = image_result.getString("open_pic_id"); - record_material.put("cost_distribution_uri", open_pic_id); - } - - imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; - imageJSON = new JSONObject(); - imageJSON.put("resource_type", 2); - imageJSON.put("ma_app_id", appid); - image_meta = new JSONObject(); - image_meta.put("url", course.getAssuranceUri()); - imageJSON.put("image_meta", image_meta); - s = HttpClientUtil.doPostJson(imgUrl, imageJSON.toJSONString(), SenInfoCheckUtil.getDyToken()); - jsonObject1 = JSONObject.parseObject(s); - err_no = jsonObject1.getString("err_no"); - log.info("抖音短剧封面图上传:" + jsonObject1.toJSONString()); - if ("0".equals(err_no)) { - JSONObject data = jsonObject1.getJSONObject("data"); - JSONObject image_result = data.getJSONObject("image_result"); - String open_pic_id = image_result.getString("open_pic_id"); - record_material.put("assurance_uri", open_pic_id); - } - - record_material.put("playlet_production_cost", course.getPlayletProductionCost()); - record_audit_info.put("record_material", record_material); - album_info.put("record_audit_info", record_audit_info); - jsonObject.put("album_info", album_info); - s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); - jsonObject1 = JSONObject.parseObject(s); - err_no = jsonObject1.getString("err_no"); - log.info("抖音创建短剧:" + jsonObject1.toJSONString()); - if ("0".equals(err_no)) { - JSONObject data = jsonObject1.getJSONObject("data"); - String album_id = data.getString("album_id"); - course.setDyCourseId(album_id); - baseMapper.updateById(course); - } - } - //上传视频 - for (CourseDetails courseDetails : courseDetailsList) { - - if (StringUtils.isEmpty(courseDetails.getDyCourseDetailsId()) || courseDetails.getDyUrlStatus() == 3) { - String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("resource_type", 1); - jsonObject.put("ma_app_id", appid); - JSONObject video_meta = new JSONObject(); - video_meta.put("url", courseDetails.getVideoUrl()); - video_meta.put("title", courseDetails.getCourseDetailsName()); - video_meta.put("description", courseDetails.getContent()); - if (courseDetails.getVideoUrl().contains(".mp4")) { - video_meta.put("format", "mp4"); - } else { - video_meta.put("format", "m3u8"); - } - jsonObject.put("video_meta", video_meta); - String s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); - JSONObject jsonObject1 = JSONObject.parseObject(s); - log.info("抖音上传短剧视频:" + jsonObject1.toJSONString()); - String err_no = jsonObject1.getString("err_no"); - if (!"0".equals(err_no)) { - continue; - } - JSONObject data = jsonObject1.getJSONObject("data"); - JSONObject video_result = data.getJSONObject("video_result"); - String open_video_id = video_result.getString("open_video_id"); - courseDetails.setDyCourseDetailsId(open_video_id); - courseDetails.setDyUrlStatus(1); - courseDetailsDao.updateById(courseDetails); - } - if (StringUtils.isEmpty(courseDetails.getDyImgId())) { - //上传短剧封面图 - String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("resource_type", 2); - jsonObject.put("ma_app_id", appid); - JSONObject image_meta = new JSONObject(); - image_meta.put("url", courseDetails.getTitleImg()); - jsonObject.put("image_meta", image_meta); - String s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); - JSONObject jsonObject1 = JSONObject.parseObject(s); - log.info("抖音上传短剧视频封面:" + jsonObject1.toJSONString()); - String err_no = jsonObject1.getString("err_no"); - if (!"0".equals(err_no)) { - continue; - } - JSONObject data = jsonObject1.getJSONObject("data"); - JSONObject image_result = data.getJSONObject("image_result"); - String open_pic_id = image_result.getString("open_pic_id"); - courseDetails.setDyImgId(open_pic_id); - courseDetailsDao.updateById(courseDetails); - } - } - } catch (Exception e) { - e.printStackTrace(); - log.error("抖音上传视频出错:" + e.getMessage(), e); - } +// if (StringUtils.isEmpty(courseDetails.getDyCourseDetailsId()) || courseDetails.getDyUrlStatus() == 3) { +// String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("resource_type", 1); +// jsonObject.put("ma_app_id", appid); +// JSONObject video_meta = new JSONObject(); +// video_meta.put("url", courseDetails.getVideoUrl()); +// video_meta.put("title", courseDetails.getCourseDetailsName()); +// video_meta.put("description", courseDetails.getContent()); +// if (courseDetails.getVideoUrl().contains(".mp4")) { +// video_meta.put("format", "mp4"); +// } else { +// video_meta.put("format", "m3u8"); +// } +// jsonObject.put("video_meta", video_meta); +// String s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); +// JSONObject jsonObject1 = JSONObject.parseObject(s); +// log.info("抖音上传短剧视频:" + jsonObject1.toJSONString()); +// String err_no = jsonObject1.getString("err_no"); +// if (!"0".equals(err_no)) { +// continue; +// } +// JSONObject data = jsonObject1.getJSONObject("data"); +// JSONObject video_result = data.getJSONObject("video_result"); +// String open_video_id = video_result.getString("open_video_id"); +// courseDetails.setDyCourseDetailsId(open_video_id); +// courseDetails.setDyUrlStatus(1); +// courseDetailsDao.updateById(courseDetails); +// } +// if (StringUtils.isEmpty(courseDetails.getDyImgId())) { +// //上传短剧封面图 +// String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("resource_type", 2); +// jsonObject.put("ma_app_id", appid); +// JSONObject image_meta = new JSONObject(); +// image_meta.put("url", courseDetails.getTitleImg()); +// jsonObject.put("image_meta", image_meta); +// String s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); +// JSONObject jsonObject1 = JSONObject.parseObject(s); +// log.info("抖音上传短剧视频封面:" + jsonObject1.toJSONString()); +// String err_no = jsonObject1.getString("err_no"); +// if (!"0".equals(err_no)) { +// continue; +// } +// JSONObject data = jsonObject1.getJSONObject("data"); +// JSONObject image_result = data.getJSONObject("image_result"); +// String open_pic_id = image_result.getString("open_pic_id"); +// courseDetails.setDyImgId(open_pic_id); +// courseDetailsDao.updateById(courseDetails); +// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// log.error("抖音上传视频出错:" + e.getMessage(), e); +// } } @@ -713,58 +713,58 @@ public class CourseServiceImpl extends ServiceImpl implements @Override public JSONObject notifyUrl(JSONObject jsonObject) { - log.info("抖音视频回调:" + jsonObject.toJSONString()); - String type = jsonObject.getString("type"); - JSONObject msg = jsonObject.getJSONObject("msg"); - if ("upload_video".equals(type)) { - String open_video_id = msg.getString("open_video_id"); - String success = msg.getString("success"); - CourseDetails courseDetails = courseDetailsDao.selectOne(new QueryWrapper().eq("dy_course_details_id", open_video_id)); - if (courseDetails != null) { - if ("true".equals(success)) { - courseDetails.setDyUrlStatus(2); - } else { - courseDetails.setDyUrlStatus(3); - } - courseDetailsDao.updateById(courseDetails); - //获取是否所有的集都上传成功 如果成功 则添加集 - Integer count = courseDetailsDao.selectCount(new QueryWrapper() - .eq("course_id", courseDetails.getCourseId()).in("dy_url_status", 1, 3)); - log.info("count" + count); - if (count == 0) { - videoEdit(courseDetails); - } - } - } else if ("album_audit".equals(type)) { - String album_id = msg.getString("album_id"); - Course course = baseMapper.selectOne(new QueryWrapper().eq("dy_course_id", album_id)); - if (course != null) { - String audit_status = msg.getString("audit_status"); - if ("1".equals(audit_status)) { - course.setDyStatus(3); - course.setDyStatusContent(msg.getString("audit_msg")); - } else { - course.setDyStatus(2); - course.setDyVersion(msg.getString("version")); - } - baseMapper.updateById(course); - } - } - if ("episode_audit".equals(type)) { - String episode_id = msg.getString("episode_id"); - CourseDetails courseDetails = courseDetailsDao.selectOne(new QueryWrapper().eq("dy_episode_id", episode_id)); - if (courseDetails != null) { - String audit_status = msg.getString("audit_status"); - if ("1".equals(audit_status)) { - courseDetails.setDyStatus(3); - courseDetails.setDyStatusContent(msg.getString("audit_msg")); - } else { - courseDetails.setDyStatus(2); - courseDetails.setDyVersion(msg.getString("version")); - } - courseDetailsDao.updateById(courseDetails); - } - } +// log.info("抖音视频回调:" + jsonObject.toJSONString()); +// String type = jsonObject.getString("type"); +// JSONObject msg = jsonObject.getJSONObject("msg"); +// if ("upload_video".equals(type)) { +// String open_video_id = msg.getString("open_video_id"); +// String success = msg.getString("success"); +// CourseDetails courseDetails = courseDetailsDao.selectOne(new QueryWrapper().eq("dy_course_details_id", open_video_id)); +// if (courseDetails != null) { +// if ("true".equals(success)) { +// courseDetails.setDyUrlStatus(2); +// } else { +// courseDetails.setDyUrlStatus(3); +// } +// courseDetailsDao.updateById(courseDetails); +// //获取是否所有的集都上传成功 如果成功 则添加集 +// Integer count = courseDetailsDao.selectCount(new QueryWrapper() +// .eq("course_id", courseDetails.getCourseId()).in("dy_url_status", 1, 3)); +// log.info("count" + count); +// if (count == 0) { +// videoEdit(courseDetails); +// } +// } +// } else if ("album_audit".equals(type)) { +// String album_id = msg.getString("album_id"); +// Course course = baseMapper.selectOne(new QueryWrapper().eq("dy_course_id", album_id)); +// if (course != null) { +// String audit_status = msg.getString("audit_status"); +// if ("1".equals(audit_status)) { +// course.setDyStatus(3); +// course.setDyStatusContent(msg.getString("audit_msg")); +// } else { +// course.setDyStatus(2); +// course.setDyVersion(msg.getString("version")); +// } +// baseMapper.updateById(course); +// } +// } +// if ("episode_audit".equals(type)) { +// String episode_id = msg.getString("episode_id"); +// CourseDetails courseDetails = courseDetailsDao.selectOne(new QueryWrapper().eq("dy_episode_id", episode_id)); +// if (courseDetails != null) { +// String audit_status = msg.getString("audit_status"); +// if ("1".equals(audit_status)) { +// courseDetails.setDyStatus(3); +// courseDetails.setDyStatusContent(msg.getString("audit_msg")); +// } else { +// courseDetails.setDyStatus(2); +// courseDetails.setDyVersion(msg.getString("version")); +// } +// courseDetailsDao.updateById(courseDetails); +// } +// } JSONObject result = new JSONObject(); result.put("err_no", 0); result.put("err_tips", "success"); @@ -773,158 +773,158 @@ public class CourseServiceImpl extends ServiceImpl implements @Async public void videoEdit(CourseDetails courseDetails) { - //这里进行延迟操作 抖音不允许并发操作 - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - log.info("延迟结束"); - //没有待审核和审核失败的 吧所有的集进行上传 - List courseDetailsList = courseDetailsDao.selectList(new QueryWrapper() - .eq("course_id", courseDetails.getCourseId()).orderByAsc("create_time")); - String appid = commonInfoService.findOne(805).getValue(); - Course course = baseMapper.selectById(courseDetails.getCourseId()); - String url = "https://open.douyin.com/api/playlet/v2/video/edit/"; - JSONObject jsonObject1 = new JSONObject(); - jsonObject1.put("album_id", course.getDyCourseId()); - jsonObject1.put("ma_app_id", appid); - int num = 1; - JSONArray episode_info_list = new JSONArray(); - while (true) { - - CourseDetails courseDetails1 = courseDetailsList.get(num - 1); - JSONObject episode = new JSONObject(); - episode.put("title", courseDetails1.getCourseDetailsName()); - episode.put("seq", num); - JSONArray cover_list = new JSONArray(); - cover_list.add(courseDetails1.getDyImgId()); - episode.put("cover_list", cover_list); - episode.put("open_video_id", courseDetails1.getDyCourseDetailsId()); - episode_info_list.add(episode); - if (courseDetailsList.size() == num) { - jsonObject1.put("episode_info_list", episode_info_list); - String s = HttpClientUtil.doPostJson(url, jsonObject1.toJSONString(), SenInfoCheckUtil.getDyToken()); - log.info("绑定集:" + s); - JSONObject jsonObject2 = JSONObject.parseObject(s); - JSONObject data = jsonObject2.getJSONObject("data"); - JSONObject episode_id_map = data.getJSONObject("episode_id_map"); - Map map = new HashMap<>(episode_id_map); - for (Map.Entry entry : map.entrySet()) { - String key = entry.getKey(); - Object value = entry.getValue(); - CourseDetails courseDetails2 = courseDetailsList.get(Integer.parseInt(key) - 1); - courseDetails2.setDyEpisodeId(String.valueOf(value)); - courseDetailsDao.updateById(courseDetails2); - } - break; - } - if (episode_info_list.size() % 100 == 0) { - jsonObject1.put("episode_info_list", episode_info_list); - String s = HttpClientUtil.doPostJson(url, jsonObject1.toJSONString(), SenInfoCheckUtil.getDyToken()); - JSONObject jsonObject2 = JSONObject.parseObject(s); - log.info("绑定集100:" + s); - JSONObject data = jsonObject2.getJSONObject("data"); - JSONObject episode_id_map = data.getJSONObject("episode_id_map"); - Map map = new HashMap<>(episode_id_map); - for (Map.Entry entry : map.entrySet()) { - String key = entry.getKey(); - Object value = entry.getValue(); - CourseDetails courseDetails2 = courseDetailsList.get(Integer.parseInt(key) - 1); - courseDetails2.setDyEpisodeId(String.valueOf(value)); - courseDetailsDao.updateById(courseDetails2); - } - episode_info_list = new JSONArray(); - } - num++; - } - //对页面进行绑定 这里同样进行延迟操作 - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - url = "https://open.douyin.com/api/playlet/v2/album/bind/"; - jsonObject1 = new JSONObject(); - jsonObject1.put("schema_bind_type", "1"); - - for (CourseDetails courseDetails1 : courseDetailsList) { - JSONObject single_schema_bind = new JSONObject(); - single_schema_bind.put("album_id", course.getDyCourseId()); - single_schema_bind.put("episode_id", courseDetails1.getDyEpisodeId()); - single_schema_bind.put("path", "me/detail/detail"); - JSONArray params = new JSONArray(); - JSONObject param1 = new JSONObject(); - param1.put("key", "id"); - param1.put("value", String.valueOf(course.getCourseId())); - JSONObject param2 = new JSONObject(); - param2.put("key", "courseDetailsId"); - param2.put("value", String.valueOf(courseDetails1.getCourseDetailsId())); - params.add(param1); - params.add(param2); - single_schema_bind.put("params", params); - jsonObject1.put("single_schema_bind", single_schema_bind); - String s = HttpClientUtil.doPostJson(url, jsonObject1.toJSONString(), SenInfoCheckUtil.getDyToken()); - log.info("绑定页面返回值:" + s); - //每次绑定完页面后 延迟后进行操作 - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } +// //这里进行延迟操作 抖音不允许并发操作 +// try { +// Thread.sleep(5000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// log.info("延迟结束"); +// //没有待审核和审核失败的 吧所有的集进行上传 +// List courseDetailsList = courseDetailsDao.selectList(new QueryWrapper() +// .eq("course_id", courseDetails.getCourseId()).orderByAsc("create_time")); +// String appid = commonInfoService.findOne(805).getValue(); +// Course course = baseMapper.selectById(courseDetails.getCourseId()); +// String url = "https://open.douyin.com/api/playlet/v2/video/edit/"; +// JSONObject jsonObject1 = new JSONObject(); +// jsonObject1.put("album_id", course.getDyCourseId()); +// jsonObject1.put("ma_app_id", appid); +// int num = 1; +// JSONArray episode_info_list = new JSONArray(); +// while (true) { +// +// CourseDetails courseDetails1 = courseDetailsList.get(num - 1); +// JSONObject episode = new JSONObject(); +// episode.put("title", courseDetails1.getCourseDetailsName()); +// episode.put("seq", num); +// JSONArray cover_list = new JSONArray(); +// cover_list.add(courseDetails1.getDyImgId()); +// episode.put("cover_list", cover_list); +// episode.put("open_video_id", courseDetails1.getDyCourseDetailsId()); +// episode_info_list.add(episode); +// if (courseDetailsList.size() == num) { +// jsonObject1.put("episode_info_list", episode_info_list); +// String s = HttpClientUtil.doPostJson(url, jsonObject1.toJSONString(), SenInfoCheckUtil.getDyToken()); +// log.info("绑定集:" + s); +// JSONObject jsonObject2 = JSONObject.parseObject(s); +// JSONObject data = jsonObject2.getJSONObject("data"); +// JSONObject episode_id_map = data.getJSONObject("episode_id_map"); +// Map map = new HashMap<>(episode_id_map); +// for (Map.Entry entry : map.entrySet()) { +// String key = entry.getKey(); +// Object value = entry.getValue(); +// CourseDetails courseDetails2 = courseDetailsList.get(Integer.parseInt(key) - 1); +// courseDetails2.setDyEpisodeId(String.valueOf(value)); +// courseDetailsDao.updateById(courseDetails2); +// } +// break; +// } +// if (episode_info_list.size() % 100 == 0) { +// jsonObject1.put("episode_info_list", episode_info_list); +// String s = HttpClientUtil.doPostJson(url, jsonObject1.toJSONString(), SenInfoCheckUtil.getDyToken()); +// JSONObject jsonObject2 = JSONObject.parseObject(s); +// log.info("绑定集100:" + s); +// JSONObject data = jsonObject2.getJSONObject("data"); +// JSONObject episode_id_map = data.getJSONObject("episode_id_map"); +// Map map = new HashMap<>(episode_id_map); +// for (Map.Entry entry : map.entrySet()) { +// String key = entry.getKey(); +// Object value = entry.getValue(); +// CourseDetails courseDetails2 = courseDetailsList.get(Integer.parseInt(key) - 1); +// courseDetails2.setDyEpisodeId(String.valueOf(value)); +// courseDetailsDao.updateById(courseDetails2); +// } +// episode_info_list = new JSONArray(); +// } +// num++; +// } +// //对页面进行绑定 这里同样进行延迟操作 +// try { +// Thread.sleep(10000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// url = "https://open.douyin.com/api/playlet/v2/album/bind/"; +// jsonObject1 = new JSONObject(); +// jsonObject1.put("schema_bind_type", "1"); +// +// for (CourseDetails courseDetails1 : courseDetailsList) { +// JSONObject single_schema_bind = new JSONObject(); +// single_schema_bind.put("album_id", course.getDyCourseId()); +// single_schema_bind.put("episode_id", courseDetails1.getDyEpisodeId()); +// single_schema_bind.put("path", "me/detail/detail"); +// JSONArray params = new JSONArray(); +// JSONObject param1 = new JSONObject(); +// param1.put("key", "id"); +// param1.put("value", String.valueOf(course.getCourseId())); +// JSONObject param2 = new JSONObject(); +// param2.put("key", "courseDetailsId"); +// param2.put("value", String.valueOf(courseDetails1.getCourseDetailsId())); +// params.add(param1); +// params.add(param2); +// single_schema_bind.put("params", params); +// jsonObject1.put("single_schema_bind", single_schema_bind); +// String s = HttpClientUtil.doPostJson(url, jsonObject1.toJSONString(), SenInfoCheckUtil.getDyToken()); +// log.info("绑定页面返回值:" + s); +// //每次绑定完页面后 延迟后进行操作 +// try { +// Thread.sleep(5000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// } } @Override public Result uploadCourseDetails(Long courseDetailsId) { - String appid = commonInfoService.findOne(805).getValue(); - CourseDetails courseDetails = courseDetailsDao.selectById(courseDetailsId); - String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("resource_type", 1); - jsonObject.put("ma_app_id", appid); - JSONObject video_meta = new JSONObject(); - video_meta.put("url", courseDetails.getVideoUrl()); - video_meta.put("title", courseDetails.getCourseDetailsName()); - video_meta.put("description", courseDetails.getContent()); - if (courseDetails.getVideoUrl().contains("mp4")) { - video_meta.put("format", "mp4"); - } else { - video_meta.put("format", "m3u8"); - } - jsonObject.put("video_meta", video_meta); - String s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); - JSONObject jsonObject1 = JSONObject.parseObject(s); - String err_no = jsonObject1.getString("err_no"); - if (!"0".equals(err_no)) { - return Result.error(jsonObject1.getString("err_msg")); - } - JSONObject data = jsonObject1.getJSONObject("data"); - JSONObject video_result = data.getJSONObject("video_result"); - String open_video_id = video_result.getString("open_video_id"); - courseDetails.setDyCourseDetailsId(open_video_id); - courseDetails.setDyUrlStatus(1); - courseDetailsDao.updateById(courseDetails); - //上传短剧封面图 - imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; - jsonObject = new JSONObject(); - jsonObject.put("resource_type", 2); - jsonObject.put("ma_app_id", appid); - JSONObject image_meta = new JSONObject(); - image_meta.put("url", courseDetails.getTitleImg()); - jsonObject.put("image_meta", image_meta); - s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); - jsonObject1 = JSONObject.parseObject(s); - err_no = jsonObject1.getString("err_no"); - if (!"0".equals(err_no)) { - return Result.error(jsonObject1.getString("err_msg")); - } - data = jsonObject1.getJSONObject("data"); - JSONObject image_result = data.getJSONObject("image_result"); - String open_pic_id = image_result.getString("open_pic_id"); - courseDetails.setDyImgId(open_pic_id); - courseDetailsDao.updateById(courseDetails); +// String appid = commonInfoService.findOne(805).getValue(); +// CourseDetails courseDetails = courseDetailsDao.selectById(courseDetailsId); +// String imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("resource_type", 1); +// jsonObject.put("ma_app_id", appid); +// JSONObject video_meta = new JSONObject(); +// video_meta.put("url", courseDetails.getVideoUrl()); +// video_meta.put("title", courseDetails.getCourseDetailsName()); +// video_meta.put("description", courseDetails.getContent()); +// if (courseDetails.getVideoUrl().contains("mp4")) { +// video_meta.put("format", "mp4"); +// } else { +// video_meta.put("format", "m3u8"); +// } +// jsonObject.put("video_meta", video_meta); +// String s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); +// JSONObject jsonObject1 = JSONObject.parseObject(s); +// String err_no = jsonObject1.getString("err_no"); +// if (!"0".equals(err_no)) { +// return Result.error(jsonObject1.getString("err_msg")); +// } +// JSONObject data = jsonObject1.getJSONObject("data"); +// JSONObject video_result = data.getJSONObject("video_result"); +// String open_video_id = video_result.getString("open_video_id"); +// courseDetails.setDyCourseDetailsId(open_video_id); +// courseDetails.setDyUrlStatus(1); +// courseDetailsDao.updateById(courseDetails); +// //上传短剧封面图 +// imgUrl = "https://open.douyin.com/api/playlet/v2/resource/upload/"; +// jsonObject = new JSONObject(); +// jsonObject.put("resource_type", 2); +// jsonObject.put("ma_app_id", appid); +// JSONObject image_meta = new JSONObject(); +// image_meta.put("url", courseDetails.getTitleImg()); +// jsonObject.put("image_meta", image_meta); +// s = HttpClientUtil.doPostJson(imgUrl, jsonObject.toJSONString(), SenInfoCheckUtil.getDyToken()); +// jsonObject1 = JSONObject.parseObject(s); +// err_no = jsonObject1.getString("err_no"); +// if (!"0".equals(err_no)) { +// return Result.error(jsonObject1.getString("err_msg")); +// } +// data = jsonObject1.getJSONObject("data"); +// JSONObject image_result = data.getJSONObject("image_result"); +// String open_pic_id = image_result.getString("open_pic_id"); +// courseDetails.setDyImgId(open_pic_id); +// courseDetailsDao.updateById(courseDetails); return Result.success(); } @@ -992,250 +992,251 @@ public class CourseServiceImpl extends ServiceImpl implements @Override public Result sysWxCourse(Integer freeNum, BigDecimal coursePrice, Integer maxGood, Integer minGood) { - singleThreadPool.submit(() -> sysWxCourses(freeNum, coursePrice, maxGood, minGood)); - +// singleThreadPool.submit(() -> sysWxCourses(freeNum, coursePrice, maxGood, minGood)); +// return Result.success(); } public void sysWxCourses(Integer freeNum, BigDecimal coursePrice, Integer maxGood, Integer minGood) { - try { - int offset = 0; - String value = commonInfoService.findOne(887).getValue(); - String http = commonInfoService.findOne(19).getValue(); - Random rand = new Random(); - while (true) { - String url = "https://api.weixin.qq.com/wxa/sec/vod/listdramas?access_token=" + SenInfoCheckUtil.getMpToken(); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("offset", offset); - jsonObject.put("limit", 100); - String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString()); - JSONObject jsonObject1 = JSONObject.parseObject(s); - log.error("微信同步短剧返回值:" + jsonObject1.toJSONString()); - String errcode = jsonObject1.getString("errcode"); - if (!"0".equals(errcode)) { - log.error("同步微信短剧失败:" + jsonObject1.getString("errmsg")); - break; - } - JSONArray drama_info_list = jsonObject1.getJSONArray("drama_info_list"); - if (drama_info_list == null || drama_info_list.size() == 0) { - break; - } - - for (int i = 0; i < drama_info_list.size(); i++) { - JSONObject jsonObject2 = drama_info_list.getJSONObject(i); - //剧目状态。0为正常可播;1为审核中;2为审核失败;3为平台下架 - String status = jsonObject2.getString("status"); - if (!"0".equals(status)) { - continue; - } - String name = jsonObject2.getString("name"); - name = name.replace(" ", ""); - Course course = baseMapper.selectOne(new QueryWrapper().eq("title", name).eq("is_delete", 0)); - if (course != null) { - course.setWxCourseId(jsonObject2.getString("drama_id")); - baseMapper.updateById(course); - } else { - - String[] split = value.split(","); - int min = 0; // 指定范围的最小值(包含) - int max = split.length - 1; // 指定范围的最大值(包含) - int randomNum1 = min + rand.nextInt(max - min + 1); - int randomNum2 = min + rand.nextInt(max - min + 1); - int randomNum3 = min + rand.nextInt(max - min + 1); - String courseLabel = split[randomNum1] + "," + split[randomNum2] + "," + split[randomNum3]; - String cover_url = jsonObject2.getString("cover_url"); - - //读取微信图片 保存到服务器本地 - String[] splits = http.split("://"); - // 上传文件路径 - String filePath = "/www/wwwroot/" + splits[1] + "/file/uploadPath/duanju/" + name + "/" + name + ".jpg"; - File file = new File(filePath); - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } - - HttpClientUtil.downloadImage(cover_url, filePath); - String img = http + "/file/uploadPath/duanju/" + name + "/" + name + ".jpg"; - ; - - course = new Course(); - course.setTitle(name); - course.setTitleImg(img); - course.setPrice(coursePrice); - course.setCourseLabel(courseLabel); - course.setPayNum(0); - course.setImg(img); - course.setDetails(name); - course.setIsDelete(0); - course.setCreateTime(DateUtils.format(new Date())); - course.setUpdateTime(course.getCreateTime()); - course.setIsRecommend(0); - course.setStatus(1); - course.setIsPrice(1); - course.setViewCounts(0); - course.setIsOver(1); - course.setWxCourseId(jsonObject2.getString("drama_id")); - course.setWxShow(1); - baseMapper.insert(course); - } - } - offset = offset + 100; - } - //同步集 - List courseList = baseMapper.selectList(new QueryWrapper().isNotNull("wx_course_id")); - for (Course course : courseList) { - offset = 0; - while (true) { - String url = "https://api.weixin.qq.com/wxa/sec/vod/listmedia?access_token=" + SenInfoCheckUtil.getMpToken(); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("drama_id", Integer.parseInt(course.getWxCourseId())); - jsonObject.put("limit", 100); - jsonObject.put("offset", offset); - String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString()); - JSONObject jsonObject1 = JSONObject.parseObject(s); - String errcode = jsonObject1.getString("errcode"); - if (!"0".equals(errcode)) { - log.error("同步微信短剧集失败:" + jsonObject1.getString("errmsg")); - break; - } - JSONArray media_info_list = jsonObject1.getJSONArray("media_info_list"); - if (media_info_list == null || media_info_list.size() == 0) { - break; - } - - int priceNum = media_info_list.size() - freeNum; - BigDecimal courseDetailsPrice = BigDecimal.ZERO; - if (priceNum > 0) { - courseDetailsPrice = coursePrice.divide(BigDecimal.valueOf(priceNum), 2, BigDecimal.ROUND_UP); - } - for (int i = 0; i < media_info_list.size(); i++) { - JSONObject jsonObject2 = media_info_list.getJSONObject(i); - String name = jsonObject2.getString("name"); - name = name.replace(".mp4", ""); - name = name.replace(".avi", ""); - name = name.replace(".wmv", ""); - name = name.replace(".flv", ""); - name = name.replace(".m3u8", ""); - name = name.replace(".mov", ""); - name = name.replace(" ", ""); - CourseDetails courseDetails = courseDetailsDao.selectOne(new QueryWrapper() - .eq("course_id", course.getCourseId()).like("course_details_name", name)); - if (courseDetails != null) { - courseDetails.setWxCourseDetailsId(jsonObject2.getString("media_id")); - courseDetailsDao.updateById(courseDetails); - } else { - String cover_url = jsonObject2.getString("cover_url"); - - //读取微信图片 保存到服务器本地 - String[] splits = http.split("://"); - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); - // 上传文件路径 - String filePath = "/www/wwwroot/" + splits[1] + "/file/uploadPath/duanju/" + course.getTitle() + "/" + name + ".jpg"; - ; - File file = new File(filePath); - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } - - HttpClientUtil.downloadImage(cover_url, filePath); - String img = http + "/file/uploadPath/duanju/" + course.getTitle() + "/" + name + ".jpg"; - ; - - int goodNum = minGood + rand.nextInt(maxGood - minGood + 1); - courseDetails = new CourseDetails(); - courseDetails.setWxCourseDetailsId(jsonObject2.getString("media_id")); - courseDetails.setCourseId(course.getCourseId()); - courseDetails.setCourseDetailsName(name); - courseDetails.setCreateTime(DateUtils.format(new Date())); - courseDetails.setTitleImg(img); - courseDetails.setContent(name); - courseDetails.setGoodNum(goodNum); - courseDetails.setViewCount(0L); - courseDetails.setPlayCompleteCount(0L); - if (i <= freeNum) { - courseDetails.setPrice(BigDecimal.ZERO); - courseDetails.setIsPrice(2); - } else { - courseDetails.setPrice(courseDetailsPrice); - courseDetails.setIsPrice(1); - } - courseDetails.setSort(i); - courseDetailsDao.insert(courseDetails); - } - } - offset = offset + 100; - } - - } - } catch (Exception e) { - e.printStackTrace(); - log.error("同步微信短剧失败:" + e.getMessage(), e); - } +// try { +// int offset = 0; +// String value = commonInfoService.findOne(887).getValue(); +// String http = commonInfoService.findOne(19).getValue(); +// Random rand = new Random(); +// while (true) { +// String url = "https://api.weixin.qq.com/wxa/sec/vod/listdramas?access_token=" + SenInfoCheckUtil.getMpToken(); +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("offset", offset); +// jsonObject.put("limit", 100); +// String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString()); +// JSONObject jsonObject1 = JSONObject.parseObject(s); +// log.error("微信同步短剧返回值:" + jsonObject1.toJSONString()); +// String errcode = jsonObject1.getString("errcode"); +// if (!"0".equals(errcode)) { +// log.error("同步微信短剧失败:" + jsonObject1.getString("errmsg")); +// break; +// } +// JSONArray drama_info_list = jsonObject1.getJSONArray("drama_info_list"); +// if (drama_info_list == null || drama_info_list.size() == 0) { +// break; +// } +// +// for (int i = 0; i < drama_info_list.size(); i++) { +// JSONObject jsonObject2 = drama_info_list.getJSONObject(i); +// //剧目状态。0为正常可播;1为审核中;2为审核失败;3为平台下架 +// String status = jsonObject2.getString("status"); +// if (!"0".equals(status)) { +// continue; +// } +// String name = jsonObject2.getString("name"); +// name = name.replace(" ", ""); +// Course course = baseMapper.selectOne(new QueryWrapper().eq("title", name).eq("is_delete", 0)); +// if (course != null) { +// course.setWxCourseId(jsonObject2.getString("drama_id")); +// baseMapper.updateById(course); +// } else { +// +// String[] split = value.split(","); +// int min = 0; // 指定范围的最小值(包含) +// int max = split.length - 1; // 指定范围的最大值(包含) +// int randomNum1 = min + rand.nextInt(max - min + 1); +// int randomNum2 = min + rand.nextInt(max - min + 1); +// int randomNum3 = min + rand.nextInt(max - min + 1); +// String courseLabel = split[randomNum1] + "," + split[randomNum2] + "," + split[randomNum3]; +// String cover_url = jsonObject2.getString("cover_url"); +// +// //读取微信图片 保存到服务器本地 +// String[] splits = http.split("://"); +// // 上传文件路径 +// String filePath = "/www/wwwroot/" + splits[1] + "/file/uploadPath/duanju/" + name + "/" + name + ".jpg"; +// File file = new File(filePath); +// if (!file.getParentFile().exists()) { +// file.getParentFile().mkdirs(); +// } +// +// HttpClientUtil.downloadImage(cover_url, filePath); +// String img = http + "/file/uploadPath/duanju/" + name + "/" + name + ".jpg"; +// ; +// +// course = new Course(); +// course.setTitle(name); +// course.setTitleImg(img); +// course.setPrice(coursePrice); +// course.setCourseLabel(courseLabel); +// course.setPayNum(0); +// course.setImg(img); +// course.setDetails(name); +// course.setIsDelete(0); +// course.setCreateTime(DateUtils.format(new Date())); +// course.setUpdateTime(course.getCreateTime()); +// course.setIsRecommend(0); +// course.setStatus(1); +// course.setIsPrice(1); +// course.setViewCounts(0); +// course.setIsOver(1); +// course.setWxCourseId(jsonObject2.getString("drama_id")); +// course.setWxShow(1); +// baseMapper.insert(course); +// } +// } +// offset = offset + 100; +// } +// //同步集 +// List courseList = baseMapper.selectList(new QueryWrapper().isNotNull("wx_course_id")); +// for (Course course : courseList) { +// offset = 0; +// while (true) { +// String url = "https://api.weixin.qq.com/wxa/sec/vod/listmedia?access_token=" + SenInfoCheckUtil.getMpToken(); +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("drama_id", Integer.parseInt(course.getWxCourseId())); +// jsonObject.put("limit", 100); +// jsonObject.put("offset", offset); +// String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString()); +// JSONObject jsonObject1 = JSONObject.parseObject(s); +// String errcode = jsonObject1.getString("errcode"); +// if (!"0".equals(errcode)) { +// log.error("同步微信短剧集失败:" + jsonObject1.getString("errmsg")); +// break; +// } +// JSONArray media_info_list = jsonObject1.getJSONArray("media_info_list"); +// if (media_info_list == null || media_info_list.size() == 0) { +// break; +// } +// +// int priceNum = media_info_list.size() - freeNum; +// BigDecimal courseDetailsPrice = BigDecimal.ZERO; +// if (priceNum > 0) { +// courseDetailsPrice = coursePrice.divide(BigDecimal.valueOf(priceNum), 2, BigDecimal.ROUND_UP); +// } +// for (int i = 0; i < media_info_list.size(); i++) { +// JSONObject jsonObject2 = media_info_list.getJSONObject(i); +// String name = jsonObject2.getString("name"); +// name = name.replace(".mp4", ""); +// name = name.replace(".avi", ""); +// name = name.replace(".wmv", ""); +// name = name.replace(".flv", ""); +// name = name.replace(".m3u8", ""); +// name = name.replace(".mov", ""); +// name = name.replace(" ", ""); +// CourseDetails courseDetails = courseDetailsDao.selectOne(new QueryWrapper() +// .eq("course_id", course.getCourseId()).like("course_details_name", name)); +// if (courseDetails != null) { +// courseDetails.setWxCourseDetailsId(jsonObject2.getString("media_id")); +// courseDetailsDao.updateById(courseDetails); +// } else { +// String cover_url = jsonObject2.getString("cover_url"); +// +// //读取微信图片 保存到服务器本地 +// String[] splits = http.split("://"); +// SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); +// // 上传文件路径 +// String filePath = "/www/wwwroot/" + splits[1] + "/file/uploadPath/duanju/" + course.getTitle() + "/" + name + ".jpg"; +// ; +// File file = new File(filePath); +// if (!file.getParentFile().exists()) { +// file.getParentFile().mkdirs(); +// } +// +// HttpClientUtil.downloadImage(cover_url, filePath); +// String img = http + "/file/uploadPath/duanju/" + course.getTitle() + "/" + name + ".jpg"; +// ; +// +// int goodNum = minGood + rand.nextInt(maxGood - minGood + 1); +// courseDetails = new CourseDetails(); +// courseDetails.setWxCourseDetailsId(jsonObject2.getString("media_id")); +// courseDetails.setCourseId(course.getCourseId()); +// courseDetails.setCourseDetailsName(name); +// courseDetails.setCreateTime(DateUtils.format(new Date())); +// courseDetails.setTitleImg(img); +// courseDetails.setContent(name); +// courseDetails.setGoodNum(goodNum); +// courseDetails.setViewCount(0L); +// courseDetails.setPlayCompleteCount(0L); +// if (i <= freeNum) { +// courseDetails.setPrice(BigDecimal.ZERO); +// courseDetails.setIsPrice(2); +// } else { +// courseDetails.setPrice(courseDetailsPrice); +// courseDetails.setIsPrice(1); +// } +// courseDetails.setSort(i); +// courseDetailsDao.insert(courseDetails); +// } +// } +// offset = offset + 100; +// } +// +// } +// } catch (Exception e) { +// e.printStackTrace(); +// log.error("同步微信短剧失败:" + e.getMessage(), e); +// } } @Override public Result selectWxVideoUrl(String wxCourseDetailsIds) { - List> list = new ArrayList<>(); - for (String wxCourseDetailsIdStr : wxCourseDetailsIds.split(",")) { - Long wxCourseDetailsId = Long.parseLong(wxCourseDetailsIdStr); - String url = "https://api.weixin.qq.com/wxa/sec/vod/getmedialink?access_token=" + SenInfoCheckUtil.getMpToken(); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("media_id", wxCourseDetailsId); - jsonObject.put("t", (new Date().getTime() / 1000) + 7200); - String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString()); - JSONObject jsonObject1 = JSONObject.parseObject(s); - String errcode = jsonObject1.getString("errcode"); - if (!"0".equals(errcode)) { - log.error(wxCourseDetailsIdStr + " 获取微信播放链接失败:" + jsonObject1.getString("errmsg")); -// return Result.error("获取微信播放链接失败:"+jsonObject1.getString("errmsg")); - continue; - } - JSONObject media_info = jsonObject1.getJSONObject("media_info"); - String duration = media_info.getString("duration"); - String cover_url = media_info.getString("cover_url"); - String mp4_url = media_info.getString("mp4_url"); - Map result = new HashMap<>(); - result.put("duration", duration); - result.put("cover_url", cover_url); - result.put("mp4_url", mp4_url); - result.put("wxCourseDetailsId", String.valueOf(wxCourseDetailsId)); - list.add(result); - } - return Result.success().put("data", list); +// List> list = new ArrayList<>(); +// for (String wxCourseDetailsIdStr : wxCourseDetailsIds.split(",")) { +// Long wxCourseDetailsId = Long.parseLong(wxCourseDetailsIdStr); +// String url = "https://api.weixin.qq.com/wxa/sec/vod/getmedialink?access_token=" + SenInfoCheckUtil.getMpToken(); +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("media_id", wxCourseDetailsId); +// jsonObject.put("t", (new Date().getTime() / 1000) + 7200); +// String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString()); +// JSONObject jsonObject1 = JSONObject.parseObject(s); +// String errcode = jsonObject1.getString("errcode"); +// if (!"0".equals(errcode)) { +// log.error(wxCourseDetailsIdStr + " 获取微信播放链接失败:" + jsonObject1.getString("errmsg")); +//// return Result.error("获取微信播放链接失败:"+jsonObject1.getString("errmsg")); +// continue; +// } +// JSONObject media_info = jsonObject1.getJSONObject("media_info"); +// String duration = media_info.getString("duration"); +// String cover_url = media_info.getString("cover_url"); +// String mp4_url = media_info.getString("mp4_url"); +// Map result = new HashMap<>(); +// result.put("duration", duration); +// result.put("cover_url", cover_url); +// result.put("mp4_url", mp4_url); +// result.put("wxCourseDetailsId", String.valueOf(wxCourseDetailsId)); +// list.add(result); +// } +// return Result.success().put("data", list); + return Result.success(); } @Override public Result uploadWxCourse(Long courseId, Integer qualificationType, String registrationNumber, String qualificationCertificateMaterialId, String costOfProduction, String costCommitmentLetterMaterialId) { - String url = "https://api.weixin.qq.com/wxa/sec/vod/modifydramabasicinfo?access_token=" + SenInfoCheckUtil.getMpToken(); - - //储存信息 - Course course = baseMapper.selectById(courseId); - course.setQualificationType(qualificationType); - course.setRegistrationNumber(registrationNumber); - course.setQualificationCertificateMaterialId(qualificationCertificateMaterialId); - course.setCostOfProduction(costOfProduction); - course.setCostCommitmentLetterMaterialId(costCommitmentLetterMaterialId); - course.setWxCourseStatus(1); - baseMapper.updateById(course); - - JSONObject jsonObject = new JSONObject(); - jsonObject.put("drama_id", course.getWxCourseId()); - jsonObject.put("qualification_type", qualificationType); - jsonObject.put("registration_number", registrationNumber); - jsonObject.put("qualification_certificate_material_id", qualificationCertificateMaterialId); - jsonObject.put("cost_of_production", costOfProduction); - jsonObject.put("cost_commitment_letter_material_id", costCommitmentLetterMaterialId); - String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString()); - log.error("提交微信备案审核:" + s); - JSONObject jsonObject1 = JSONObject.parseObject(s); - String errcode = jsonObject1.getString("errcode"); - if (!"0".equals(errcode)) { - return Result.error(jsonObject1.getString("errmsg")); - } +// String url = "https://api.weixin.qq.com/wxa/sec/vod/modifydramabasicinfo?access_token=" + SenInfoCheckUtil.getMpToken(); +// +// //储存信息 +// Course course = baseMapper.selectById(courseId); +// course.setQualificationType(qualificationType); +// course.setRegistrationNumber(registrationNumber); +// course.setQualificationCertificateMaterialId(qualificationCertificateMaterialId); +// course.setCostOfProduction(costOfProduction); +// course.setCostCommitmentLetterMaterialId(costCommitmentLetterMaterialId); +// course.setWxCourseStatus(1); +// baseMapper.updateById(course); +// +// JSONObject jsonObject = new JSONObject(); +// jsonObject.put("drama_id", course.getWxCourseId()); +// jsonObject.put("qualification_type", qualificationType); +// jsonObject.put("registration_number", registrationNumber); +// jsonObject.put("qualification_certificate_material_id", qualificationCertificateMaterialId); +// jsonObject.put("cost_of_production", costOfProduction); +// jsonObject.put("cost_commitment_letter_material_id", costCommitmentLetterMaterialId); +// String s = HttpClientUtil.doPostJson(url, jsonObject.toJSONString()); +// log.error("提交微信备案审核:" + s); +// JSONObject jsonObject1 = JSONObject.parseObject(s); +// String errcode = jsonObject1.getString("errcode"); +// if (!"0".equals(errcode)) { +// return Result.error(jsonObject1.getString("errmsg")); +// } return Result.success(); }