zhaotx пре 1 година
родитељ
комит
f650ed7ab3

+ 4 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/BytedanceProductUpdateMapper.java

@@ -34,4 +34,8 @@ public interface BytedanceProductUpdateMapper {
                         @Param("canPromotion") int status,
                         @Param("canPromotion") int status,
                         @Param("cannotReason") String failReason);
                         @Param("cannotReason") String failReason);
 
 
+    List<JSONObject> getDouyinMovieAuthList();
+
+    int updateMovieAuthStatus(@Param("platformId") String platformId);
+
 }
 }

+ 10 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/mapper/xml/BytedanceProductUpdateMapper.xml

@@ -17,6 +17,11 @@
         set can_promotion = #{canPromotion}, cannot_reason = #{cannotReason}
         set can_promotion = #{canPromotion}, cannot_reason = #{cannotReason}
         where album_id = #{albumId}
         where album_id = #{albumId}
     </update>
     </update>
+    <update id="updateMovieAuthStatus">
+        update deepthink.bytedance_product_main_advertiser
+        set movie_auth_status = 1
+        where platform_id = #{platformId}
+    </update>
 
 
 
 
     <select id="getIAPPlatformList" resultType="com.alibaba.fastjson.JSONObject">
     <select id="getIAPPlatformList" resultType="com.alibaba.fastjson.JSONObject">
@@ -96,4 +101,9 @@
         left join thirtpart.ly_videos tb2 on tb1.ly_video_id=tb2.id
         left join thirtpart.ly_videos tb2 on tb1.ly_video_id=tb2.id
         where can_promotion is null or can_promotion=0
         where can_promotion is null or can_promotion=0
     </select>
     </select>
+    <select id="getDouyinMovieAuthList" resultType="com.alibaba.fastjson.JSONObject">
+        select platform_id, social_credit_code
+        from deepthink.bytedance_product_main_advertiser
+        where type=1 and _status=0 and movie_auth_status=0
+    </select>
 </mapper>
 </mapper>

+ 2 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/IBytedanceProductUpdateService.java

@@ -6,6 +6,8 @@ public interface IBytedanceProductUpdateService {
 
 
     void run() throws Exception;
     void run() throws Exception;
 
 
+    void authMovieResource();
+
     void initNew();
     void initNew();
 
 
     void test() throws Exception;
     void test() throws Exception;

+ 39 - 0
job-bytedance/src/main/java/cn/com/ctop/job/bytedance/data/service/impl/BytedanceProductUpdateServiceImpl.java

@@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.StringUtils;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
@@ -21,6 +22,10 @@ import java.util.stream.Collectors;
 public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdateService {
 public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdateService {
     @Resource
     @Resource
     BytedanceProductUpdateMapper bytedanceProductUpdateMapper;
     BytedanceProductUpdateMapper bytedanceProductUpdateMapper;
+    @Resource
+    private RedisTemplate redis2Template_db5;
+
+    public static final String DOUYIN_MOVIE_SOURCE_APP="ttd652a0ef496310bd01";
 
 
 
 
     //商品上传结果通知群
     //商品上传结果通知群
@@ -41,6 +46,39 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
         }
         }
     }
     }
 
 
+    @Override
+    public void authMovieResource() {
+        //原片授权
+        List<JSONObject> authList = bytedanceProductUpdateMapper.getDouyinMovieAuthList();
+        if (!Check.isNull(authList)){
+            try {
+                String tokenKey = "client-token-key_"+ DOUYIN_MOVIE_SOURCE_APP;
+                String token = (String) redis2Template_db5.opsForValue().get(tokenKey);
+                if (Check.isNull(token)){
+                    log.warn("没有找到字节小程序access_token,无法进行原片授权");
+                    return;
+                }
+                for (JSONObject obj : authList){
+                    String socialCreditCode = obj.getString("social_credit_code");
+                    if (Check.isNull(socialCreditCode)){
+                        log.warn("没有找到社会信用代码,跳过授权: " + obj.getString("name"));
+                        continue;
+                    }
+                    String url = "https://open.douyin.com/api/resource_library/util/v1/batch_auth_contents/";
+                    Map<String, String> headers = new HashMap<>();
+                    headers.put("Access-Token", token);
+                    Map<String, Object> body = new HashMap<>();
+                    body.put("auth_all_album", true);
+                    body.put("auth_type", 1);
+                    body.put("authed_corp", socialCreditCode);
+                    HttpUtils.httpPostRequest(url, body, headers);
+                }
+            }catch (Exception e){
+                log.error("获取字节小程序access_token失败", e);
+            }
+        }
+    }
+
 
 
     /**
     /**
      * 初始化新的字节小程序; 新增字节用的商品库时调用
      * 初始化新的字节小程序; 新增字节用的商品库时调用
@@ -51,6 +89,7 @@ public class BytedanceProductUpdateServiceImpl implements IBytedanceProductUpdat
         List<JSONObject> iaaPlatformList = bytedanceProductUpdateMapper.getIAAPlatformList();
         List<JSONObject> iaaPlatformList = bytedanceProductUpdateMapper.getIAAPlatformList();
         initNew(iaaPlatformList);
         initNew(iaaPlatformList);
         initNew(iapPlatformList);
         initNew(iapPlatformList);
+        authMovieResource();
     }
     }
 
 
     @Override
     @Override