123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- package org.jeecg;
- import cn.com.ctop.bytedance.service.IReportService;
- import cn.com.ctop.common.module.entity.CtopOauthToken;
- import cn.com.ctop.common.module.entity.UserAllocation;
- 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.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<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(3);
- private static CountDownLatch countDownLatch = null;
- @Test
- public void testLoadJob() {
- Date getDate = DateUtils.addDay(new Date(), -1);
- //1:查询当日数据
- QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("project_id", 222);
- List<UserAllocation> allocations = userAllocationService.list(queryWrapper);
- allocations.forEach(allocation -> {
- CtopOauthToken token = tokenService.getTokenByAccountId(allocation.getAccountId());
- reportService.getAdvertiserPlanReport(token, getDate, getDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
- });
- }
- @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", "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);
- }
- }
|