|
@@ -0,0 +1,109 @@
|
|
|
|
+package com.ruixuan.open.service.impl;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.kuaishou.merchant.open.api.client.AccessTokenKsMerchantClient;
|
|
|
|
+import com.kuaishou.merchant.open.api.common.utils.GsonUtils;
|
|
|
|
+import com.kuaishou.merchant.open.api.request.video.OpenPhotoListRequest;
|
|
|
|
+import com.kuaishou.merchant.open.api.response.video.OpenPhotoListResponse;
|
|
|
|
+import com.ruixuan.common.utils.DateUtils;
|
|
|
|
+import com.ruixuan.open.entity.KuaishouOpenPhotoList;
|
|
|
|
+import com.ruixuan.open.mapper.KuaishouOpenPhotoListMapper;
|
|
|
|
+import com.ruixuan.open.service.IKuaishouOpenPhotoListService;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 用户视频列Service业务层处理
|
|
|
|
+ *
|
|
|
|
+ * @author ruoyi
|
|
|
|
+ * @date 2024-07-09
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Service
|
|
|
|
+public class KuaishouOpenPhotoListServiceImpl implements IKuaishouOpenPhotoListService {
|
|
|
|
+ @Autowired
|
|
|
|
+ private KuaishouOpenPhotoListMapper kuaishouOpenPhotoListMapper;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询用户视频列
|
|
|
|
+ *
|
|
|
|
+ * @param id 用户视频列主键
|
|
|
|
+ * @return 用户视频列
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public KuaishouOpenPhotoList selectKuaishouOpenPhotoListById(Long id) {
|
|
|
|
+ return kuaishouOpenPhotoListMapper.selectKuaishouOpenPhotoListById(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询用户视频列列表
|
|
|
|
+ *
|
|
|
|
+ * @param kuaishouOpenPhotoList 用户视频列
|
|
|
|
+ * @return 用户视频列
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public List<KuaishouOpenPhotoList> selectKuaishouOpenPhotoListList(KuaishouOpenPhotoList kuaishouOpenPhotoList) {
|
|
|
|
+ return kuaishouOpenPhotoListMapper.selectKuaishouOpenPhotoListList(kuaishouOpenPhotoList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void insertKuaishouOpenPhotoList(Long userId, String cursor) {
|
|
|
|
+ try {
|
|
|
|
+ String url = "https://openapi.kwaixiaodian.com";
|
|
|
|
+
|
|
|
|
+ String appKey = "ks690458118961229051";
|
|
|
|
+ String signSecret = "6ef1e2a231733bb0c38fb2bf0f50e45b";
|
|
|
|
+ String accessToken = "ChFvYXV0aC5hY2Nlc3NUb2tlbhJAhhjrjfDtPkuAuUN5pOWY1hl3SUdOrNORPbgFhIJ1uxNFUrKSaCTdaOcWUvlLqPOZWnnR-1_wWga0cNw-ZsmuYBoSdJTaZfTbRbe4zPS88hU0zxRHIiBA8uLLXu_BaAsO7k5WZayprQWLkUi_G-cvvV_XJMVzBCgFMAE";
|
|
|
|
+
|
|
|
|
+ AccessTokenKsMerchantClient client = new AccessTokenKsMerchantClient(url, appKey, signSecret);
|
|
|
|
+
|
|
|
|
+ OpenPhotoListRequest request = new OpenPhotoListRequest();
|
|
|
|
+ request.setAccessToken(accessToken);
|
|
|
|
+ request.setApiMethodVersion(1L);
|
|
|
|
+
|
|
|
|
+ //游标,用于分页,值为作品id。分页查询时,传上一页create_time最小的photo_id。第一页不传此参数。
|
|
|
|
+ request.setCursor(cursor);
|
|
|
|
+ //数量,默认为20,最大不超过200
|
|
|
|
+ request.setCount(20);
|
|
|
|
+
|
|
|
|
+ OpenPhotoListResponse response = client.execute(request);
|
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(GsonUtils.toJSON(response));
|
|
|
|
+ String code = resultJson.getString("code");
|
|
|
|
+ String minPhotoId = null;
|
|
|
|
+ if ("1".equals(code)) {
|
|
|
|
+ List<KuaishouOpenPhotoList> list = new ArrayList<>();
|
|
|
|
+ JSONArray jsonArray = resultJson.getJSONObject("data").getJSONArray("videoList");
|
|
|
|
+ Long min = jsonArray.getJSONObject(0).getLong("createTime");
|
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
+ JSONObject obj = jsonArray.getJSONObject(i);
|
|
|
|
+ KuaishouOpenPhotoList photo = JSONObject.parseObject(obj.toJSONString(), KuaishouOpenPhotoList.class);
|
|
|
|
+ //获取最小
|
|
|
|
+ if (obj.getLong("createTime") < min) {
|
|
|
|
+ min = obj.getLong("createTime");
|
|
|
|
+ minPhotoId = photo.getPhotoId();
|
|
|
|
+ }
|
|
|
|
+ photo.setPromoterId(userId);
|
|
|
|
+ photo.setPhotoCreateTime(DateUtils.timestamptoMinutesAndSecondsStr(obj.getLong("createTime")));
|
|
|
|
+ photo.setPending(String.valueOf(obj.getBoolean("pending") ? 1 : 0));
|
|
|
|
+ list.add(photo);
|
|
|
|
+ }
|
|
|
|
+ if (list.size() > 0) {
|
|
|
|
+ kuaishouOpenPhotoListMapper.replaceBatchKuaishouOpenPhotoList(list);
|
|
|
|
+ }
|
|
|
|
+ if (jsonArray.size() == 20) {
|
|
|
|
+ insertKuaishouOpenPhotoList(userId, minPhotoId);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ log.error("===新增视频列表(open.photo.list)失败,userID:{},信息:{}", userId, resultJson.getString("msg"));
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|