package org.jeecg; import cn.com.ctop.common.module.entity.CtopOauthToken; import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper; import cn.com.ctop.common.module.service.ICtopOauthTokenService; import cn.com.ctop.common.module.utils.CtopAdConstant; import cn.com.ctop.common.module.utils.HttpUtils; import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService; import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.extern.slf4j.Slf4j; import org.jeecg.common.util.DateUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @RunWith(SpringRunner.class) @SpringBootTest @Slf4j public class SampleTest { @Autowired private IKuaishouInterfaceService kuaishouInterfaceService; @Autowired private IKuaiShouHistoryReportTaskService reportTaskService; @Autowired private CtopOauthTokenMapper tokenMapper; @Test public void kuaisShouReport() { try { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("account_id", 3727345L); CtopOauthToken token = tokenMapper.selectOne(queryWrapper); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date parse = simpleDateFormat.parse("2020-03-12"); kuaishouInterfaceService.getAdvertiserReportDaily(token, parse, parse); // reportTaskService.createTask(3727345L, "871fc2c248782a94ad2962c941555abc", ""); // reportTaskService.getTaskList(); /* reportTaskService.createTask(3727345L, "871fc2c248782a94ad2962c941555abc"); reportTaskService.getTaskList();*/ /* String url = "https://ad.e.kuaishou.com/rest/openapi/v1/async_task/list"; Map headers = new HashMap<>(); headers.put("Content-Type", " application/json"); headers.put("Access-Token", "eb9a0d18072eabc339ee26ad010ecd6b"); JSONObject param = new JSONObject(); param.put("advertiser_id", 142402); JSONArray taskIds = new JSONArray(); taskIds.add(1229917); param.put("task_ids", taskIds); String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers); JSONObject resultJson = JSONObject.parseObject(result); System.err.println(resultJson);*/ /* String url = "https://ad.e.kuaishou.com/rest/openapi/v1/async_task/download"; Map headers = new HashMap<>(); headers.put("Access-Token", "eb9a0d18072eabc339ee26ad010ecd6b"); Map param = new HashMap<>(); param.put("advertiser_id", 142402); param.put("task_id", "1229917"); String result = HttpUtils.KuaiShouttpGetRequest(url, param,headers);*/ /*URL url = new URL("https://ad.e.kuaishou.com/rest/openapi/v1/async_task/download?task_id=1229917&advertiser_id=142402"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //设置超时间为3秒 conn.setConnectTimeout(10 * 1000); //防止屏蔽程序抓取而返回403错误 conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); conn.setRequestProperty("Access-Token", "6a1fbe20e49fe519ec8120aac5c9e55a"); //得到输入流 InputStream inputStream = conn.getInputStream(); //获取自己数组 byte[] getData = readInputStream(inputStream); //文件保存位置 File saveDir = new File("D:\\file"); if (!saveDir.exists()) { saveDir.mkdirs(); } String fileName = "123.csv"; File file = new File(saveDir + File.separator + fileName); FileOutputStream fos = new FileOutputStream(file); fos.write(getData); if (fos != null) { fos.close(); } if (inputStream != null) { inputStream.close(); }*/ /* String localPath = "D:\\file\\123.csv"; reportDailyAccountMapper.loadAccountDailyReport(142402L,localPath);*/ } catch (Exception e) { e.printStackTrace(); } } @Autowired private ICtopOauthTokenService tokenService; private static ExecutorService executorService = Executors.newFixedThreadPool(3); private static CountDownLatch countDownLatch = null; @Test public void testLoadJob() { log.info("快手获取日报数据任务执行开始"); Long start = System.currentTimeMillis(); Date getDate = DateUtils.addDay(new Date(), -1); List tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_KUAISHOU); if (null == tokens || tokens.size() <= 0) { log.info("快手获取日报数据任务执行失败:未获取到可用的token"); return; } String getDateStr = DateUtils.formatDate(getDate); countDownLatch = new CountDownLatch(tokens.size()); for (CtopOauthToken token : tokens) { executorService.submit(new Runnable() { @Override public void run() { //创建任务 try { reportTaskService.createTask(token.getAccountId(), token.getAccessToken(), getDateStr, getDateStr, CtopAdConstant.KUAISHOU_LOAD_JOB_TYPE_DAILY); } catch (Exception e) { e.printStackTrace(); } finally { countDownLatch.countDown(); } } }); } try { countDownLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } Long end = System.currentTimeMillis(); log.info("快手获取日报数据任务执行结束,执行耗时:{}秒", (end - start) / 1000); } @Test public void wanHuaTong() { String url = "https://ad.oceanengine.com/open_api/2/kaleidoscope/job/smart_cut/submit/"; JSONObject conditions = new JSONObject(); // 1629785592929294 conditions.put("advertiser_id", "109437044830"); JSONObject job = new JSONObject(); job.put("job_conf_id", 10); JSONArray input = new JSONArray(); JSONObject inputJson = new JSONObject(); inputJson.put("task_id", 1); JSONArray videoIds = new JSONArray(); videoIds.add("v02033290000bgq1cejpqv6e4k29b2jg"); inputJson.put("video_ids", videoIds); JSONArray music_id = new JSONArray(); JSONArray image_urls = new JSONArray(); JSONArray texts = new JSONArray(); texts.add("哈哈哈哈,这是一个测试文案"); inputJson.put("texts", texts); JSONArray tts = new JSONArray(); tts.add("true"); inputJson.put("tts", tts); JSONArray video_ratio = new JSONArray(); video_ratio.add("1"); inputJson.put("video_ratio", video_ratio); JSONArray music_style = new JSONArray(); music_style.add("1"); inputJson.put("music_style", music_style); JSONArray video_duration = new JSONArray(); video_duration.add("8"); inputJson.put("video_duration", video_duration); JSONArray speed = new JSONArray(); speed.add("1.2"); inputJson.put("speed", speed); job.put("input", inputJson); job.put("mesg", "测试万花筒"); conditions.put("job", job); JSONObject jsonObject = HttpUtils.bytedancePostRequest("8ea30cb02cab8d92b480c4ab01cfc4545fdce33e", url, conditions); System.err.println(jsonObject); } }