Kaynağa Gözat

Merge branch 'test' of https://gitee.com/hcst/adsp-boot into test

syh 5 yıl önce
ebeveyn
işleme
5311c221c9

+ 1 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/config/ShiroConfig.java

@@ -123,7 +123,7 @@ public class ShiroConfig {
 
 		//爬虫接口
 		filterChainDefinitionMap.put("/graphql/video", "anon");
-
+		filterChainDefinitionMap.put("/ks/web/test", "anon");
 		// 添加自己的过滤器并且取名为jwt
 		Map<String, Filter> filterMap = new HashMap<String, Filter>(1);
 		filterMap.put("jwt", new JwtFilter());

Dosya farkı çok büyük olduğundan ihmal edildi
+ 704 - 211
module-crawler/src/main/java/cn/com/ctop/crawler/modules/core/util/AppiumUtil.java


+ 13 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/controller/KuaishouWebController.java

@@ -83,6 +83,19 @@ public class KuaishouWebController {
         return result;
     }
 
+    @PostMapping(value = "/test")
+    public Result<Object> test(KuaishouCommentConfig kuaishouCommentConfig) {
+        Result<Object> result = new Result<>();
+        try {
+            kuaishouWebInterfaceService.adekuaishouWebLogin("19845004383", "a123456");
+            kuaishouWebInterfaceService.sendPreview(106126205, "xuzuoyun");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        result.setSuccess(true);
+        return result;
+    }
+
     @PostMapping(value = "/login/status")
     public Result<Map<String, Object>> getStatus(String requestId) {
         Result<Map<String, Object>> result = new Result<Map<String, Object>>();

+ 3 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/IKuaishouWebInterfaceService.java

@@ -24,5 +24,8 @@ public interface IKuaishouWebInterfaceService {
 
     public Map<String, Object> commentAdd(String userId, String ksid, String photoId, String content, Long replyToCommentId, Long replyTo);
 
+    public void sendPreview(Integer creativeId, String kwid);
+
+    public void adekuaishouWebLogin(String phone, String password) throws IOException;
     public Map<String, Object> subCommentList(String userId, String ksid, String photoId, Long rootCommentId, String pcursor);
 }

+ 133 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/impl/KuaishouWebInterfaceServiceImpl.java

@@ -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;

+ 2 - 0
module-kuaishou/src/main/resources/log4j.properties

@@ -0,0 +1,2 @@
+log4j.logger.org.apache.http=debug
+log4j.logger.httpclient.wire=debug

+ 19 - 0
module-kuaishou/src/main/resources/logback.xml

@@ -0,0 +1,19 @@
+<configuration debug="true">
+    <logger name="org.apache" level="DEBUG"/>
+    <logger name="org.apache.http.wire" level="DEBUG"/>
+    <logger name="org.apache.http.headers" level="DEBUG"/>
+
+    <property name="CONSOLE_LOG_PATTERN"
+              value="%date{yyyy-MM-dd HH:mm:ss}  %highlight(%-5level) %magenta(%-4relative) --- [%yellow(%15.15thread)] %cyan(%-40.40logger{39}) : %msg%n"/>
+
+
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
+        </encoder>
+    </appender>
+
+    <root level="ERROR">
+        <appender-ref ref="STDOUT"/>
+    </root>
+</configuration>