|
@@ -1,17 +1,124 @@
|
|
|
package org.jeecg;
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
|
|
+import java.io.*;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
+
|
|
|
@RunWith(SpringRunner.class)
|
|
|
@SpringBootTest
|
|
|
@Slf4j
|
|
|
public class SampleTest {
|
|
|
@Value("${jeecg.path.chrome-driver}")
|
|
|
private String chromeDriver;
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void kuaisShouReport() {
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ /* String url = "https://ad.e.kuaishou.com/rest/openapi/v1/async_task/create";
|
|
|
+ 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);
|
|
|
+ param.put("task_name", "142402-test");
|
|
|
+
|
|
|
+ JSONObject taskParams = new JSONObject();
|
|
|
+ taskParams.put("start_date", "2020-01-01");
|
|
|
+ taskParams.put("end_date", "2020-03-05");
|
|
|
+ taskParams.put("view_type", 1);
|
|
|
+ param.put("task_params",taskParams);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ System.err.println(resultJson);*/
|
|
|
+
|
|
|
+ // 1229917 142402
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /* 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);
|
|
|
+ System.err.println(resultJson);*/
|
|
|
+
|
|
|
+
|
|
|
+ /* 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", "eb9a0d18072eabc339ee26ad010ecd6b");
|
|
|
+ //得到输入流
|
|
|
+ InputStream inputStream = conn.getInputStream();
|
|
|
+ //获取自己数组
|
|
|
+ byte[] getData = readInputStream(inputStream);
|
|
|
+
|
|
|
+ //文件保存位置
|
|
|
+ File saveDir = new File("D:\\file");
|
|
|
+ if (!saveDir.exists()) {
|
|
|
+ saveDir.mkdirs();
|
|
|
+ }
|
|
|
+ File file = new File(saveDir + File.separator + "qqww.csv");
|
|
|
+ FileOutputStream fos = new FileOutputStream(file);
|
|
|
+ fos.write(getData);
|
|
|
+ if (fos != null) {
|
|
|
+ fos.close();
|
|
|
+ }
|
|
|
+ if (inputStream != null) {
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static byte[] readInputStream(InputStream inputStream) throws IOException {
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int len = 0;
|
|
|
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
+ while ((len = inputStream.read(buffer)) != -1) {
|
|
|
+ bos.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ bos.close();
|
|
|
+ return bos.toByteArray();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|