SampleTest.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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.mapper.CtopOauthTokenMapper;
  5. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  6. import cn.com.ctop.common.module.service.IUserAllocationService;
  7. import cn.com.ctop.common.module.utils.CtopAdConstant;
  8. import cn.com.ctop.common.module.utils.HttpUtils;
  9. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
  10. import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
  11. import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
  12. import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
  13. import com.alibaba.fastjson.JSONArray;
  14. import com.alibaba.fastjson.JSONObject;
  15. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.jeecg.modules.ctop.service.IPerformanceSaleService;
  18. import org.junit.Test;
  19. import org.junit.runner.RunWith;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.boot.test.context.SpringBootTest;
  22. import org.springframework.test.context.junit4.SpringRunner;
  23. import java.text.SimpleDateFormat;
  24. import java.util.Date;
  25. import java.util.List;
  26. import java.util.concurrent.CountDownLatch;
  27. import java.util.concurrent.ExecutorService;
  28. import java.util.concurrent.Executors;
  29. @RunWith(SpringRunner.class)
  30. @SpringBootTest
  31. @Slf4j
  32. public class SampleTest {
  33. @Autowired
  34. private IKuaishouInterfaceService kuaishouInterfaceService;
  35. @Autowired
  36. private IKuaiShouHistoryReportTaskService reportTaskService;
  37. @Autowired
  38. private CtopOauthTokenMapper tokenMapper;
  39. @Test
  40. public void kuaisShouReport() {
  41. try {
  42. QueryWrapper<CtopOauthToken> queryWrapper = new QueryWrapper<>();
  43. queryWrapper.eq("account_id", 3727345L);
  44. CtopOauthToken token = tokenMapper.selectOne(queryWrapper);
  45. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  46. Date parse = simpleDateFormat.parse("2020-03-12");
  47. kuaishouInterfaceService.getAdvertiserReportDaily(token, parse, parse);
  48. // reportTaskService.createTask(3727345L, "871fc2c248782a94ad2962c941555abc", "");
  49. // reportTaskService.getTaskList();
  50. /*
  51. reportTaskService.createTask(3727345L, "871fc2c248782a94ad2962c941555abc");
  52. reportTaskService.getTaskList();*/
  53. /* String url = "https://ad.e.kuaishou.com/rest/openapi/v1/async_task/list";
  54. Map<String, String> headers = new HashMap<>();
  55. headers.put("Content-Type", " application/json");
  56. headers.put("Access-Token", "eb9a0d18072eabc339ee26ad010ecd6b");
  57. JSONObject param = new JSONObject();
  58. param.put("advertiser_id", 142402);
  59. JSONArray taskIds = new JSONArray();
  60. taskIds.add(1229917);
  61. param.put("task_ids", taskIds);
  62. String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
  63. JSONObject resultJson = JSONObject.parseObject(result);
  64. /* String url = "https://ad.e.kuaishou.com/rest/openapi/v1/async_task/download";
  65. Map<String, String> headers = new HashMap<>();
  66. headers.put("Access-Token", "eb9a0d18072eabc339ee26ad010ecd6b");
  67. Map<String,Object> param = new HashMap<>();
  68. param.put("advertiser_id", 142402);
  69. param.put("task_id", "1229917");
  70. String result = HttpUtils.KuaiShouttpGetRequest(url, param,headers);*/
  71. /*URL url = new URL("https://ad.e.kuaishou.com/rest/openapi/v1/async_task/download?task_id=1229917&advertiser_id=142402");
  72. HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  73. //设置超时间为3秒
  74. conn.setConnectTimeout(10 * 1000);
  75. //防止屏蔽程序抓取而返回403错误
  76. conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
  77. conn.setRequestProperty("Access-Token", "6a1fbe20e49fe519ec8120aac5c9e55a");
  78. //得到输入流
  79. InputStream inputStream = conn.getInputStream();
  80. //获取自己数组
  81. byte[] getData = readInputStream(inputStream);
  82. //文件保存位置
  83. File saveDir = new File("D:\\file");
  84. if (!saveDir.exists()) {
  85. saveDir.mkdirs();
  86. }
  87. String fileName = "123.csv";
  88. File file = new File(saveDir + File.separator + fileName);
  89. FileOutputStream fos = new FileOutputStream(file);
  90. fos.write(getData);
  91. if (fos != null) {
  92. fos.close();
  93. }
  94. if (inputStream != null) {
  95. inputStream.close();
  96. }*/
  97. /* String localPath = "D:\\file\\123.csv";
  98. reportDailyAccountMapper.loadAccountDailyReport(142402L,localPath);*/
  99. } catch (Exception e) {
  100. e.printStackTrace();
  101. }
  102. }
  103. @Autowired
  104. private ICtopOauthTokenService tokenService;
  105. private static ExecutorService executorService = Executors.newFixedThreadPool(10);
  106. private static CountDownLatch countDownLatch = null;
  107. @Autowired
  108. private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
  109. @Test
  110. public void testLoadJob() {
  111. // try {
  112. // kuaishouWebInterfaceService.adkuaishouWebLogin("18606113995", "SsjX666!@");
  113. // kuaishouWebInterfaceService.deleteAllComment(new HashMap<>());
  114. // } catch (IOException e) {
  115. // e.printStackTrace();
  116. // }
  117. List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
  118. if (null != tokens && tokens.size() > 0) {
  119. countDownLatch = new CountDownLatch(tokens.size());
  120. tokens.forEach(token -> {
  121. //拉取往期数据
  122. executorService.submit(new Runnable() {
  123. @Override
  124. public void run() {
  125. try {
  126. reportService.loadBytedanceHistoryData(token);
  127. countDownLatch.countDown();
  128. } catch (Exception e) {
  129. e.printStackTrace();
  130. }
  131. }
  132. });
  133. });
  134. try {
  135. countDownLatch.await();
  136. System.out.println("数据获取完成");
  137. } catch (InterruptedException e) {
  138. e.printStackTrace();
  139. }
  140. }
  141. }
  142. @Autowired
  143. private IReportService reportService;
  144. @Autowired
  145. private IUserAllocationService userAllocationService;
  146. @Test
  147. public void wanHuaTong() {
  148. String url = "https://ad.oceanengine.com/open_api/2/kaleidoscope/job/smart_cut/submit/";
  149. JSONObject conditions = new JSONObject();
  150. // 1629785592929294
  151. conditions.put("advertiser_id", "1659671533108238");
  152. JSONObject job = new JSONObject();
  153. job.put("job_conf_id", 10);
  154. JSONArray input = new JSONArray();
  155. JSONObject inputJson = new JSONObject();
  156. inputJson.put("task_id", 1);
  157. JSONArray videoIds = new JSONArray();
  158. videoIds.add("v02033aa0000bpspgippskdk4jcuso80");
  159. inputJson.put("video_ids", videoIds);
  160. JSONArray music_id = new JSONArray();
  161. JSONArray image_urls = new JSONArray();
  162. JSONArray texts = new JSONArray();
  163. texts.add("哈哈哈哈,这是一个测试文案");
  164. inputJson.put("texts", texts);
  165. JSONArray tts = new JSONArray();
  166. tts.add("true");
  167. inputJson.put("tts", tts);
  168. JSONArray video_ratio = new JSONArray();
  169. video_ratio.add("1");
  170. inputJson.put("video_ratio", video_ratio);
  171. JSONArray music_style = new JSONArray();
  172. music_style.add("1");
  173. inputJson.put("music_style", music_style);
  174. JSONArray video_duration = new JSONArray();
  175. video_duration.add("8");
  176. inputJson.put("video_duration", video_duration);
  177. JSONArray speed = new JSONArray();
  178. speed.add("1.2");
  179. inputJson.put("speed", speed);
  180. job.put("input", inputJson);
  181. job.put("mesg", "测试万花筒");
  182. conditions.put("job", job);
  183. JSONObject jsonObject = HttpUtils.bytedancePostRequest("f925c180e05d585f7a9fce048ba62eecc5dab7c2", url, conditions);
  184. System.err.println(jsonObject);
  185. }
  186. @Autowired
  187. private IKuaiShouCreativeService creativeService;
  188. @Test
  189. public void testSalePerformance() {
  190. performanceSaleService.loadSalsePerformance();
  191. }
  192. @Autowired
  193. private IPerformanceSaleService performanceSaleService;
  194. @Test
  195. public void suZhao() {
  196. Long accountId = 3917130L;
  197. String token = "0a42e23921e486108105263e75561404";
  198. kuaishouInterfaceService.getVideoList("e91c778d7de1bd0e9d8f3213d1e0e57c",3820093L, null,null,1);
  199. /* String url = "https://ad.e.kuaishou.com/rest/openapi/v1/file/ad/video/su_zao/list";
  200. Map<String, String> headers = new HashMap<String, String>();
  201. headers.put("Content-Type", "application/json");
  202. headers.put("Access-Token", token);
  203. Map<String, Object> param = new HashMap<String, Object>();
  204. param.put("advertiser_id", accountId);
  205. param.put("temporal_granularity", "HOURLY");
  206. param.put("page", 1);
  207. String result = HttpUtils.httpPostRequest(url, param, headers);
  208. System.err.println(result);*/
  209. }
  210. }