123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- package org.jeecg;
- import cn.com.ctop.bytedance.service.IReportService;
- 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.service.IUserAllocationService;
- import cn.com.ctop.common.module.utils.CtopAdConstant;
- import cn.com.ctop.common.module.utils.HttpUtils;
- import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
- import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
- import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
- import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
- 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.modules.ctop.service.IPerformanceSaleService;
- 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<CtopOauthToken> 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<String, String> 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);
- /* String url = "https://ad.e.kuaishou.com/rest/openapi/v1/async_task/download";
- Map<String, String> headers = new HashMap<>();
- headers.put("Access-Token", "eb9a0d18072eabc339ee26ad010ecd6b");
- Map<String,Object> 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(10);
- private static CountDownLatch countDownLatch = null;
- @Autowired
- private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
- @Test
- public void testLoadJob() {
- // try {
- // kuaishouWebInterfaceService.adkuaishouWebLogin("18606113995", "SsjX666!@");
- // kuaishouWebInterfaceService.deleteAllComment(new HashMap<>());
- // } catch (IOException e) {
- // e.printStackTrace();
- // }
- List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
- if (null != tokens && tokens.size() > 0) {
- countDownLatch = new CountDownLatch(tokens.size());
- tokens.forEach(token -> {
- //拉取往期数据
- executorService.submit(new Runnable() {
- @Override
- public void run() {
- try {
- reportService.loadBytedanceHistoryData(token);
- countDownLatch.countDown();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- });
- try {
- countDownLatch.await();
- System.out.println("数据获取完成");
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- @Autowired
- private IReportService reportService;
- @Autowired
- private IUserAllocationService userAllocationService;
- @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", "1659671533108238");
- 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("v02033aa0000bpspgippskdk4jcuso80");
- 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("f925c180e05d585f7a9fce048ba62eecc5dab7c2", url, conditions);
- System.err.println(jsonObject);
- }
- @Autowired
- private IKuaiShouCreativeService creativeService;
- @Test
- public void testSalePerformance() {
- performanceSaleService.loadSalsePerformance();
- }
- @Autowired
- private IPerformanceSaleService performanceSaleService;
- @Test
- public void suZhao() {
- Long accountId = 3917130L;
- String token = "0a42e23921e486108105263e75561404";
- kuaishouInterfaceService.getVideoList("e91c778d7de1bd0e9d8f3213d1e0e57c",3820093L, null,null,1);
- /* String url = "https://ad.e.kuaishou.com/rest/openapi/v1/file/ad/video/su_zao/list";
- Map<String, String> headers = new HashMap<String, String>();
- headers.put("Content-Type", "application/json");
- headers.put("Access-Token", token);
- Map<String, Object> param = new HashMap<String, Object>();
- param.put("advertiser_id", accountId);
- param.put("temporal_granularity", "HOURLY");
- param.put("page", 1);
- String result = HttpUtils.httpPostRequest(url, param, headers);
- System.err.println(result);*/
- }
- }
|