SampleTest.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package org.jeecg;
  2. import cn.com.ctop.bytedance.service.IReportService;
  3. import cn.com.ctop.common.module.entity.CtopOauthToken;
  4. import cn.com.ctop.common.module.entity.UserAllocation;
  5. import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
  6. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  7. import cn.com.ctop.common.module.service.IUserAllocationService;
  8. import cn.com.ctop.common.module.utils.CtopAdConstant;
  9. import cn.com.ctop.common.module.utils.HttpUtils;
  10. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
  11. import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
  12. import com.alibaba.fastjson.JSONArray;
  13. import com.alibaba.fastjson.JSONObject;
  14. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.jeecg.common.util.DateUtils;
  17. import org.junit.Test;
  18. import org.junit.runner.RunWith;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.boot.test.context.SpringBootTest;
  21. import org.springframework.test.context.junit4.SpringRunner;
  22. import java.text.SimpleDateFormat;
  23. import java.util.Date;
  24. import java.util.List;
  25. import java.util.concurrent.CountDownLatch;
  26. import java.util.concurrent.ExecutorService;
  27. import java.util.concurrent.Executors;
  28. @RunWith(SpringRunner.class)
  29. @SpringBootTest
  30. @Slf4j
  31. public class SampleTest {
  32. @Autowired
  33. private IKuaishouInterfaceService kuaishouInterfaceService;
  34. @Autowired
  35. private IKuaiShouHistoryReportTaskService reportTaskService;
  36. @Autowired
  37. private CtopOauthTokenMapper tokenMapper;
  38. @Test
  39. public void kuaisShouReport() {
  40. try {
  41. QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  42. queryWrapper.eq("account_id", 3727345L);
  43. CtopOauthToken token = tokenMapper.selectOne(queryWrapper);
  44. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  45. Date parse = simpleDateFormat.parse("2020-03-12");
  46. kuaishouInterfaceService.getAdvertiserReportDaily(token, parse, parse);
  47. // reportTaskService.createTask(3727345L, "871fc2c248782a94ad2962c941555abc", "");
  48. // reportTaskService.getTaskList();
  49. /*
  50. reportTaskService.createTask(3727345L, "871fc2c248782a94ad2962c941555abc");
  51. reportTaskService.getTaskList();*/
  52. /* String url = "https://ad.e.kuaishou.com/rest/openapi/v1/async_task/list";
  53. Map<String, String> headers = new HashMap<>();
  54. headers.put("Content-Type", " application/json");
  55. headers.put("Access-Token", "eb9a0d18072eabc339ee26ad010ecd6b");
  56. JSONObject param = new JSONObject();
  57. param.put("advertiser_id", 142402);
  58. JSONArray taskIds = new JSONArray();
  59. taskIds.add(1229917);
  60. param.put("task_ids", taskIds);
  61. String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
  62. JSONObject resultJson = JSONObject.parseObject(result);
  63. /* String url = "https://ad.e.kuaishou.com/rest/openapi/v1/async_task/download";
  64. Map<String, String> headers = new HashMap<>();
  65. headers.put("Access-Token", "eb9a0d18072eabc339ee26ad010ecd6b");
  66. Map<String,Object> param = new HashMap<>();
  67. param.put("advertiser_id", 142402);
  68. param.put("task_id", "1229917");
  69. String result = HttpUtils.KuaiShouttpGetRequest(url, param,headers);*/
  70. /*URL url = new URL("https://ad.e.kuaishou.com/rest/openapi/v1/async_task/download?task_id=1229917&advertiser_id=142402");
  71. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  72. //设置超时间为3秒
  73. conn.setConnectTimeout(10 * 1000);
  74. //防止屏蔽程序抓取而返回403错误
  75. conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
  76. conn.setRequestProperty("Access-Token", "6a1fbe20e49fe519ec8120aac5c9e55a");
  77. //得到输入流
  78. InputStream inputStream = conn.getInputStream();
  79. //获取自己数组
  80. byte[] getData = readInputStream(inputStream);
  81. //文件保存位置
  82. File saveDir = new File("D:\\file");
  83. if (!saveDir.exists()) {
  84. saveDir.mkdirs();
  85. }
  86. String fileName = "123.csv";
  87. File file = new File(saveDir + File.separator + fileName);
  88. FileOutputStream fos = new FileOutputStream(file);
  89. fos.write(getData);
  90. if (fos != null) {
  91. fos.close();
  92. }
  93. if (inputStream != null) {
  94. inputStream.close();
  95. }*/
  96. /* String localPath = "D:\\file\\123.csv";
  97. reportDailyAccountMapper.loadAccountDailyReport(142402L,localPath);*/
  98. } catch (Exception e) {
  99. e.printStackTrace();
  100. }
  101. }
  102. @Autowired
  103. private ICtopOauthTokenService tokenService;
  104. private static ExecutorService executorService = Executors.newFixedThreadPool(3);
  105. private static CountDownLatch countDownLatch = null;
  106. @Test
  107. public void testLoadJob() {
  108. Date getDate = DateUtils.addDay(new Date(), -1);
  109. //1:查询当日数据
  110. QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
  111. queryWrapper.eq("project_id", 222);
  112. List<UserAllocation> allocations = userAllocationService.list(queryWrapper);
  113. allocations.forEach(allocation -> {
  114. CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
  115. reportService.getAdvertiserPlanReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  116. });
  117. }
  118. @Autowired
  119. private IReportService reportService;
  120. @Autowired
  121. private IUserAllocationService userAllocationService;
  122. @Test
  123. public void wanHuaTong() {
  124. String url = "https://ad.oceanengine.com/open_api/2/kaleidoscope/job/smart_cut/submit/";
  125. JSONObject conditions = new JSONObject();
  126. // 1629785592929294
  127. conditions.put("advertiser_id", "109437044830");
  128. JSONObject job = new JSONObject();
  129. job.put("job_conf_id", 10);
  130. JSONArray input = new JSONArray();
  131. JSONObject inputJson = new JSONObject();
  132. inputJson.put("task_id", 1);
  133. JSONArray videoIds = new JSONArray();
  134. videoIds.add("v02033290000bgq1cejpqv6e4k29b2jg");
  135. inputJson.put("video_ids", videoIds);
  136. JSONArray music_id = new JSONArray();
  137. JSONArray image_urls = new JSONArray();
  138. JSONArray texts = new JSONArray();
  139. texts.add("哈哈哈哈,这是一个测试文案");
  140. inputJson.put("texts", texts);
  141. JSONArray tts = new JSONArray();
  142. tts.add("true");
  143. inputJson.put("tts", tts);
  144. JSONArray video_ratio = new JSONArray();
  145. video_ratio.add("1");
  146. inputJson.put("video_ratio", video_ratio);
  147. JSONArray music_style = new JSONArray();
  148. music_style.add("1");
  149. inputJson.put("music_style", music_style);
  150. JSONArray video_duration = new JSONArray();
  151. video_duration.add("8");
  152. inputJson.put("video_duration", video_duration);
  153. JSONArray speed = new JSONArray();
  154. speed.add("1.2");
  155. inputJson.put("speed", speed);
  156. job.put("input", inputJson);
  157. job.put("mesg", "测试万花筒");
  158. conditions.put("job", job);
  159. JSONObject jsonObject = HttpUtils.bytedancePostRequest("8ea30cb02cab8d92b480c4ab01cfc4545fdce33e", url, conditions);
  160. System.err.println(jsonObject);
  161. }
  162. }