|
@@ -1,6 +1,9 @@
|
|
|
package com.tzld.piaoquan.api.component;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.tzld.piaoquan.api.common.enums.ExceptionEnum;
|
|
|
+import com.tzld.piaoquan.api.common.exception.CommonException;
|
|
|
+import com.tzld.piaoquan.api.model.vo.contentplatform.WxBaseUserInfoVO;
|
|
|
import com.tzld.piaoquan.growth.common.component.HttpPoolClient;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -27,8 +30,96 @@ public class VideoApiService {
|
|
|
JSONObject data = res.getJSONObject("data");
|
|
|
return data.getJSONArray("videoCoverImages").toJavaList(String.class);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("getVideoDetailRequest error", e);
|
|
|
+ log.error("getCoverImagePaths error", e);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ public WxBaseUserInfoVO webLogin(String code, Integer appType, String appId, String machineCode) {
|
|
|
+ String url = videoApiHost + "/longvideoapi/user/webLogin";
|
|
|
+ try {
|
|
|
+ String post = httpPoolClient.post(url, "code=" + code +
|
|
|
+ "&appType=" + appType +
|
|
|
+ "&appId=" + appId +
|
|
|
+ "&path=%2F" +
|
|
|
+ "&clientTimestamp=" + System.currentTimeMillis() +
|
|
|
+ "6&loginUid=" +
|
|
|
+ "&token=" +
|
|
|
+ "&machineCode=" + machineCode, "application/x-www-form-urlencoded;charset=UTF-8");
|
|
|
+ JSONObject res = JSONObject.parseObject(post);
|
|
|
+ return res.getObject("data", WxBaseUserInfoVO.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("webLogin error", e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void saveUserPhoneNumber(Long uid, String phoneNumber) {
|
|
|
+ String url = videoApiHost + "/longvideoapi/openapi/user/saveUserPhoneNumber";
|
|
|
+ try {
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("uid", uid);
|
|
|
+ param.put("phoneNumber", phoneNumber);
|
|
|
+ String post = httpPoolClient.post(url, param.toJSONString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("saveUserPhoneNumber error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Long publishVideo(Long uid, String videoUrl, String coverUrl, String title) {
|
|
|
+ String url = videoApiHost + "/longvideoapi/crawler/video/send";
|
|
|
+ try {
|
|
|
+ String post = httpPoolClient.post(url, "videoPath=" + videoUrl +
|
|
|
+ "&crawlerSrcCode=\"CONTENT\"" +
|
|
|
+ "&crawlerSrcPublishTimestamp=\"" + System.currentTimeMillis() + "\"" +
|
|
|
+ "&crawlerTaskTimestamp=\"" + System.currentTimeMillis() + "\"" +
|
|
|
+ "&coverImgPath=" + coverUrl +
|
|
|
+ "&loginUid=" + uid +
|
|
|
+ "&title=" + title, "application/x-www-form-urlencoded;charset=UTF-8");
|
|
|
+ JSONObject res = JSONObject.parseObject(post);
|
|
|
+ if (res.getInteger("code") != 0) {
|
|
|
+ log.error("publishVideo error, uid:{} videoUrl={} coverUrl={} title={} res={}", uid, videoUrl, coverUrl, title, res);
|
|
|
+ throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
|
|
|
+ }
|
|
|
+ JSONObject data = res.getJSONObject("data");
|
|
|
+ Long videoId = data.getLong("videoId");
|
|
|
+ log.info("publishVideo success, uid:{} videoId={}", uid, videoId);
|
|
|
+ return videoId;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("publishVideo error", e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateVideo(Long uid, Long videoId, String coverUrl, String title) {
|
|
|
+ String url = videoApiHost + "/longvideoapi/openapi/video/update";
|
|
|
+ try {
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("loginUid", uid);
|
|
|
+ param.put("videoId", videoId);
|
|
|
+ param.put("coverImgPath", coverUrl);
|
|
|
+ param.put("title", title);
|
|
|
+ String post = httpPoolClient.post(url, param.toJSONString());
|
|
|
+ JSONObject res = JSONObject.parseObject(post);
|
|
|
+ if (res.getInteger("code") != 0) {
|
|
|
+ log.error("updateVideo error, uid:{} videoId={} coverUrl={} title={} res={}", uid, videoId, coverUrl, title, res);
|
|
|
+ throw new CommonException(ExceptionEnum.VIDEO_PUBLISH_FAILED.getCode(), res.getString("msg"));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("updateVideo error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void deleteVideo(Long uid, Long videoId) {
|
|
|
+ String url = videoApiHost + "/longvideoapi/openapi/video/delete";
|
|
|
+ try {
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("loginUid", uid);
|
|
|
+ param.put("videoId", videoId);
|
|
|
+ String post = httpPoolClient.post(url, param.toJSONString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("deleteVideo error", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|