|
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.google.gson.Gson;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.logging.LogFactory;
|
|
|
import org.apache.fontbox.ttf.CmapSubtable;
|
|
|
import org.apache.fontbox.ttf.GlyphData;
|
|
|
import org.apache.fontbox.ttf.TTFParser;
|
|
@@ -701,6 +702,138 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
+ System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
|
|
|
+ System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
|
|
|
+ System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
|
|
|
+ KuaishouWebInterfaceServiceImpl k = new KuaishouWebInterfaceServiceImpl();
|
|
|
+ try {
|
|
|
+ k.adekuaishouWebLogin("19845004383", "a123456");
|
|
|
+ k.sendPreview(106126205, "xuzuoyun");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void sendPreview(Integer creativeId, String kwid) {
|
|
|
+ try {
|
|
|
+ List<Cookie> list = HttpUtils2.cookieStore.getCookies();
|
|
|
+ String ph = null;
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
+ for (Cookie ck : list) {
|
|
|
+ if (ck.getName().equals("kuaishou.ad.dsp_ph")) {
|
|
|
+ ph = ck.getValue();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> userList = new ArrayList<String>();
|
|
|
+ userList.add("xuzuoyun");
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/json;charset=utf-8");
|
|
|
+ headers.put("Referer", "https://ad.e.kuaishou.com/");
|
|
|
+ headers.put("Host", "ad.e.kuaishou.com");
|
|
|
+ Map<String, Object> bodys = new HashMap<>();
|
|
|
+ bodys.put("creativeId", creativeId);
|
|
|
+ bodys.put("userIds", userList);
|
|
|
+ String securityUrl = "https://ad.e.kuaishou.com/rest/dsp/control-panel/creative/preview?kuaishou.ad.dsp_ph=" + ph;
|
|
|
+ String html2 = HttpUtils2.httpPostRequest(securityUrl, bodys, headers);
|
|
|
+ System.out.println(html2);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void adekuaishouWebLogin(String phone, String password) throws IOException {
|
|
|
+ ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new File("D:/chromedriver.exe")).usingAnyFreePort().build();
|
|
|
+ service.start();
|
|
|
+ ChromeOptions chromeOptions = new ChromeOptions();
|
|
|
+ chromeOptions.addArguments("--headless");
|
|
|
+ chromeOptions.addArguments("--no-sandbox");
|
|
|
+ chromeOptions.addArguments("--disable-dev-shm-usage");
|
|
|
+ chromeOptions.addArguments("--disable-gpu");
|
|
|
+ chromeOptions.addArguments("--window-size=1920,1080");
|
|
|
+ chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
|
|
|
+ chromeOptions.setAcceptInsecureCerts(true);
|
|
|
+ WebDriver webDriver = new RemoteWebDriver(service.getUrl(), chromeOptions);
|
|
|
+// WebDriver webDriver = new ChromeDriver(chromeOptions);
|
|
|
+ try {
|
|
|
+
|
|
|
+ //全局隐式等待
|
|
|
+ webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
|
|
|
+ //设定网址
|
|
|
+ webDriver.get("https://ad.e.kuaishou.com");
|
|
|
+ //显示等待控制对象
|
|
|
+ WebDriverWait webDriverWait = new WebDriverWait(webDriver, 10);
|
|
|
+ webDriverWait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".phone input"))).sendKeys(phone);
|
|
|
+ webDriverWait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".password input"))).sendKeys(password);
|
|
|
+ //点击登录
|
|
|
+ webDriver.findElement(By.className("foot")).click();
|
|
|
+// //等待2秒用于页面加载,保证Cookie响应全部获取。
|
|
|
+//
|
|
|
+ Thread.sleep(10000);
|
|
|
+// String text = webDriver.findElement(By.tagName("iframe")).getAttribute("src");
|
|
|
+// webDriver.get(text);
|
|
|
+
|
|
|
+// String src = webDriver.findElement(By.id("clickCharTips")).getAttribute("src");
|
|
|
+// Actions actions = new Actions(webDriver);
|
|
|
+// actions.moveToElement(webDriver.findElement(By.className("aq_icon_refresh")));
|
|
|
+// actions.moveByOffset(10,10);
|
|
|
+// actions.moveByOffset(100,100);
|
|
|
+// actions.click();
|
|
|
+
|
|
|
+// webDriver.switchTo().frame(webDriver.findElement(By.tagName("iframe")));
|
|
|
+// File scrFile = ((TakesScreenshot)webDriver).getScreenshotAs(OutputType.FILE);
|
|
|
+// WebElement iframeElement = webDriver.findElement(By.tagName("iframe"));
|
|
|
+// if (iframeElement != null) {
|
|
|
+// File scrFile = captureElement(webDriver.findElement(By.tagName("iframe")));
|
|
|
+// String savePath = "D:/capter.png";
|
|
|
+// FileUtils.copyFile(scrFile, new File(savePath));
|
|
|
+// webDriver.switchTo().frame(webDriver.findElement(By.tagName("iframe")));
|
|
|
+// String result = ChaojiyingUtils.process(Base64Utils.ImageToBase64(savePath));
|
|
|
+// ((JavascriptExecutor) webDriver).executeScript("arguments[0].click();", webDriver.findElement(By.className("aq_icon_refresh")));
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ webDriver.get("https://ad.e.kuaishou.com/#/index");
|
|
|
+ System.out.println(webDriver.getPageSource());
|
|
|
+ webDriver.get("https://ad.e.kuaishou.com/#/manage?campaignId=5012466&unitId=6577717&tab=creative");
|
|
|
+ System.out.println(webDriver.getPageSource());
|
|
|
+ //获取Cookie并打印
|
|
|
+ Set<org.openqa.selenium.Cookie> cookies = webDriver.manage().getCookies();
|
|
|
+ Iterator iterator = cookies.iterator();
|
|
|
+
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ String cookieStr = iterator.next().toString();
|
|
|
+ String[] cookieArray = cookieStr.split(";");
|
|
|
+ Map<String, String> cookieMap = new HashMap<String, String>();
|
|
|
+ for (String cookie : cookieArray) {
|
|
|
+ String[] kv = cookie.split("=");
|
|
|
+ if (kv.length > 1) {
|
|
|
+ cookieMap.put(kv[0].trim(), kv[1].trim());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BasicClientCookie clientCookie = new BasicClientCookie(cookieArray[0].split("=")[0],
|
|
|
+ cookieArray[0].split("=")[1]);
|
|
|
+ clientCookie.setDomain("ad.e.kuaishou.com");
|
|
|
+ clientCookie.setPath(cookieMap.get("path"));
|
|
|
+ HttpUtils2.cookieStore.addCookie(clientCookie);
|
|
|
+// clientCookie.setDomain("id.kuaishou.com");
|
|
|
+//// HttpUtils2.cookieStore.addCookie(clientCookie);
|
|
|
+//// clientCookie.setDomain("uc.e.kuaishou.com");
|
|
|
+//// HttpUtils2.cookieStore.addCookie(clientCookie);
|
|
|
+ }
|
|
|
+ String result = HttpUtils2.httpGetRequest("https://uc.e.kuaishou.com/rest/web/login?sid=kuaishou.ad.dsp&followUrl=https%3A%2F%2Fad.e.kuaishou.com%2F%23%2Findex");
|
|
|
+ System.out.println(result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+// webDriver.quit();
|
|
|
+// service.stop();
|
|
|
+// HttpUtils.cookieStore.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public File captureElement(WebElement element) throws Exception {
|
|
|
// TODO Auto-generated method stub
|
|
|
WrapsDriver wrapsDriver = (WrapsDriver) element;
|