xuzuoyun 5 vuotta sitten
vanhempi
commit
ed4762cc1c

+ 2 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -9,6 +9,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.jeecg.modules.ctop.service.ICreateInternalService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -23,7 +24,7 @@ public class TestController {
     @Autowired
     private ICreateInternalService createInternalService;
 
-    @GetMapping(value = "/create")
+    @PostMapping(value = "/create")
     public void authorization() {
         JSONObject json = new JSONObject();
         System.err.println(json);

+ 0 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/TestJob.java

@@ -25,7 +25,6 @@ public class TestJob implements Job {
         options.addArguments("--window-size=1290,1080");
         WebDriver driver = new FirefoxDriver(options);
         try {
-            service.start();
             driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
             driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);
             driver.get("http://b.e.kuaishou.com");

+ 9 - 8
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/CreateInternalServiceImpl.java

@@ -32,15 +32,16 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
         String url = "https://ad.oceanengine.com/pages/login/index.html";
         System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
         ChromeOptions chromeOptions = new ChromeOptions();
+//        chromeOptions.addArguments("--headless");
+        chromeOptions.addArguments("--incognito");
+        chromeOptions.addArguments("--no-sandbox");
+//        chromeOptions.addArguments("--disable-gpu");
+        chromeOptions.addArguments("--window-size=1920,1080");
+        chromeOptions.addArguments("--user-agent=" + HttpUtils.USER_AGENT);
+        chromeOptions.setAcceptInsecureCerts(true);
         WebDriver webDriver = new ChromeDriver(chromeOptions);
         try {
-            chromeOptions.addArguments("--headless");
-            chromeOptions.addArguments("--incognito");
-            chromeOptions.addArguments("--no-sandbox");
-            chromeOptions.addArguments("--disable-gpu");
-            chromeOptions.addArguments("--window-size=1290,1080");
-            chromeOptions.addArguments("--user-agent=" + HttpUtils.USER_AGENT);
-            chromeOptions.setAcceptInsecureCerts(true);
+
             webDriver.get(url);  //获取登录页面
             for (Cookie cookie : webDriver.manage().getCookies()) {
                 BasicClientCookie ck = new BasicClientCookie(cookie.getName(), cookie.getValue());
@@ -61,7 +62,7 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
             param.put("mobile", "");
             param.put("code", "");
             param.put("account", "dcd_ad@bytedance.com");
-            param.put("password", "typdDCD@20181");
+            param.put("password", "typdDCD@2018");
             param.put("captcha", "hqde");
             param.put("is_30_days_no_login", "true");
             param.put("service", "https://ad.oceanengine.com");

+ 2 - 2
jeecg-boot-module-system/src/main/resources/application-dev.yml

@@ -94,9 +94,9 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          url: jdbc:mysql://192.168.0.23:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
+          url: jdbc:mysql://39.106.184.70:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
           username: hcst
-          password: 123456
+          password: hcst2019
           driver-class-name: com.mysql.jdbc.Driver
           # 多数据源配置
           #multi-datasource1:

+ 1 - 1
jeecg-boot-module-system/src/main/resources/application.yml

@@ -1,6 +1,6 @@
 spring:
   profiles:
-    active: prod
+    active: dev
 swagger:
   production: false
   basic:

+ 280 - 0
module-common/src/main/java/cn/com/ctop/common/utils/ImageUtils.java

@@ -0,0 +1,280 @@
+package cn.com.ctop.common.utils;
+
+import javax.imageio.IIOException;
+import javax.imageio.ImageIO;
+import javax.swing.*;
+import java.awt.*;
+import java.awt.font.FontRenderContext;
+import java.awt.font.GlyphVector;
+import java.awt.font.TextLayout;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.UUID;
+import java.util.List;
+
+public class ImageUtils {
+    public BufferedImage toBufferedImage(Image image) {
+        if (image instanceof BufferedImage) {
+            return (BufferedImage) image;
+        }
+
+        // This code ensures that all the pixels in the image are loaded
+        image = new ImageIcon(image).getImage();
+
+        // Determine if the image has transparent pixels; for this method's
+        // implementation, see e661 Determining If an Image Has Transparent Pixels
+        //boolean hasAlpha = hasAlpha(image);
+
+        // Create a buffered image with a format that's compatible with the screen
+        BufferedImage bimage = null;
+        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+        try {
+            // Determine the type of transparency of the new buffered image
+            int transparency = Transparency.OPAQUE;
+       /* if (hasAlpha) {
+         transparency = Transparency.BITMASK;
+         }*/
+
+            // Create the buffered image
+            GraphicsDevice gs = ge.getDefaultScreenDevice();
+            GraphicsConfiguration gc = gs.getDefaultConfiguration();
+            bimage = gc.createCompatibleImage(
+                    image.getWidth(null), image.getHeight(null), transparency);
+        } catch (HeadlessException e) {
+            // The system does not have a screen
+        }
+
+        if (bimage == null) {
+            // Create a buffered image using the default color model
+            int type = BufferedImage.TYPE_INT_RGB;
+            //int type = BufferedImage.TYPE_3BYTE_BGR;//by wang
+        /*if (hasAlpha) {
+         type = BufferedImage.TYPE_INT_ARGB;
+         }*/
+            bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
+        }
+
+        // Copy image to buffered image
+        Graphics g = bimage.createGraphics();
+
+        // Paint the image onto the buffered image
+        g.drawImage(image, 0, 0, null);
+        g.dispose();
+
+        return bimage;
+    }
+
+    public void resize(int width, int height, String sourcePath, String targetPath) {
+        File inputFile = new File(sourcePath);
+        File outputFile = new File(targetPath);
+        try {
+            Image sourceImage = ImageIO.read(inputFile);
+            int sourceWidth = sourceImage.getWidth(null);
+            int sourceHeight = sourceImage.getHeight(null);
+            int newWidth = 0;
+            int newHeight = 0;
+            if (sourceWidth / sourceHeight >= width / height) {
+                //放大高度
+                newHeight = height;
+                newWidth = (int) (((float) height / (float) sourceHeight) * sourceWidth);
+            } else {
+                //放大宽度
+                newWidth = width;
+                newHeight = (int) (((float) width / (float) sourceWidth) * sourceHeight);
+            }
+            Image resizeImage = sourceImage.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH);
+            BufferedImage bufferedImage = toBufferedImage(resizeImage);
+            bufferedImage = bufferedImage.getSubimage((newWidth - width) / 2, (newHeight - height) / 2, width, height);
+            ImageIO.write(bufferedImage, "jpg", outputFile);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+
+    public void addTextInImage(InputStream input, String content, Color color, Font font) throws IOException {
+        Image image = ImageIO.read(input);
+        int width = image.getWidth(null);
+        int height = image.getHeight(null);
+        BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+        Graphics2D graphics2D = bufferedImage.createGraphics();
+        graphics2D.drawImage(image, 0, 0, width, height, null);
+        graphics2D.setColor(color);
+        graphics2D.setFont(font);
+
+        Image borderImage = ImageIO.read(new File("D:/border/images/white01.png"));
+//        BufferedImage bufferedImage2 = new BufferedImage(borderImage.getWidth(null),borderImage.getHeight(null),BufferedImage.TYPE_INT_RGB);
+        graphics2D.drawImage(borderImage, 50, height / 2 + 100, null);
+
+//        graphics2D.setColor(Color.BLUE.darker().darker());
+//        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
+        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
+        graphics2D.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
+//        graphics2D.setStroke(new BasicStroke(5.0f ,
+//                BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 15.0f, new float[] {10.0f,10.0f}, 5.0f));
+        FontRenderContext frc = graphics2D.getFontRenderContext();
+        int x = 150;
+        int y = height / 2 + 220;
+        if (content.length() < 9) {
+//            TextLayout tl = new TextLayout(content, font, frc);
+//            Shape sha = tl.getOutline(AffineTransform.getTranslateInstance(5,25));
+//            graphics2D.setStroke(new BasicStroke(3.0f));
+//            graphics2D.setColor(Color.black);
+//            graphics2D.draw(sha);
+//            graphics2D.setColor(Color.white);
+//            graphics2D.fill(sha);
+//            graphics2D.dispose();
+            graphics2D.drawString(content, x, y);
+        } else {
+            graphics2D.drawString(content.substring(0, 8), x, y);
+            graphics2D.drawString(content.substring(8), x, y + 60);
+//            TextLayout tl = new TextLayout(content.substring(0,8), font, frc);
+//            Shape sha = tl.getOutline(AffineTransform.getTranslateInstance(5,25));
+//            graphics2D.setStroke(new BasicStroke(3.0f));
+//            graphics2D.setColor(Color.WHITE);
+//            graphics2D.draw(sha);
+//            graphics2D.setColor(Color.BLACK);
+//            graphics2D.fill(sha);
+////            graphics2D.dispose();
+//
+//            TextLayout t2 = new TextLayout(content.substring(8), font, frc);
+//            Shape sha2 = t2.getOutline(AffineTransform.getTranslateInstance(5,25));
+//            graphics2D.setStroke(new BasicStroke(3.0f));
+//            graphics2D.setColor(Color.WHITE);
+//            graphics2D.draw(sha2);
+//            graphics2D.setColor(Color.BLACK);
+//            graphics2D.fill(sha);
+////            graphics2D.dispose();
+        }
+
+        graphics2D.dispose();
+        FileOutputStream fileOutputStream = new FileOutputStream("D:/image/cover/" + UUID.randomUUID() + ".jpg");
+        ImageIO.write(bufferedImage, "jpg", fileOutputStream);
+
+    }
+
+    public int getContentLength(String content, Graphics2D graphics2D) {
+        return graphics2D.getFontMetrics(graphics2D.getFont()).charsWidth(content.toCharArray(), 0, content.length());
+    }
+
+    public static void main(String[] args) {
+        ImageUtils i = new ImageUtils();
+        Font font = new Font("微软雅黑", Font.BOLD + Font.PLAIN, 35);
+
+//        String content = "测试封面文字内容\n最多可以十五字";
+        Color color = new Color(0, 0, 0, 255);
+        List<String> list = i.getContentList();
+//        File file = new File("D:/bg1.jpg");
+        File file = new File("D:/image/target");
+        String[] files = file.list();
+        for (String str : files) {
+            String imagePath = file.getAbsolutePath() + "/" + str;
+            try {
+                File imageFile = new File(imagePath);
+                for (String content : list) {
+                    InputStream inputStream = new FileInputStream(imageFile);
+                    i.addTextInImage(inputStream, content, color, font);
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+//            new ImageUtils().resize(720,1280,imageFile,"D:/image/target/"+ UUID.randomUUID()+".jpg");
+        }
+
+
+        System.out.println();
+//
+    }
+
+    public List<String> getContentList() {
+        List<String> list = new ArrayList<String>();
+        list.add("想尝试一下这种风格");
+        list.add("想看一下效果");
+        list.add("这是个狠人");
+        list.add("难得一见");
+        list.add("每一个都很饱满");
+        list.add("土豪吃法");
+        list.add("怕了怕了");
+        list.add("我反正不敢");
+        list.add("贪吃的后果");
+        list.add("求打败,在线等");
+        list.add("女人心海底针");
+        list.add("撕开赚钱的真相");
+        list.add("这是啥味儿");
+        list.add("爪子的妙用");
+        list.add("把聊天记录删除后..");
+        list.add("章鱼,太狠了");
+        list.add("先下手为强");
+        list.add("爪子的妙用");
+        list.add("听说这是村里的帅哥");
+        list.add("听说这是村里的美女");
+        list.add("没想到,饭还能这样吃");
+        list.add("没想到,水还能这样喝");
+        list.add("没想到,衣服还能这样穿");
+        list.add("没想到,车还能这样骑");
+        list.add("没想到,妆还能这样画");
+        list.add("她扒拉我");
+        list.add("三者必有一伤");
+        list.add("最新机械皮肤");
+        list.add("妹子,这吃的啥");
+        list.add("活下来,算我输");
+        list.add("不哭算我输");
+        list.add("不摔算我输");
+        list.add("送礼物吓傻女友");
+        list.add("是谁在唱歌");
+        list.add("表情包不够,大长腿来凑");
+        list.add("这场面真没见过");
+        list.add("这蔬菜得回家供着");
+        list.add("挖掘机哪家强");
+        list.add("高手过招");
+        list.add("还没怕过谁");
+        list.add("手有点干巴");
+        list.add("准备装箱");
+        list.add("手把手教学");
+        list.add("别怪我不客气");
+        list.add("放大招了!");
+        list.add("难怪我这么穷");
+        list.add("招招毙命");
+        list.add("随时准备辞职");
+        list.add("不秀的李白");
+        list.add("没大的黄忠");
+        list.add("总是碰见猴子的鲁班");
+        list.add("这样哄女友很管用");
+        list.add("三年的聊天记录");
+        list.add("用它不怕女神追不到");
+        list.add("就靠你了");
+        list.add("比谁快!");
+        list.add("城里人真会玩");
+        list.add("斗图我还没输过谁");
+        list.add("开局斗图,把它斗哭了");
+        list.add("敢和我来斗图");
+        list.add("一起斗图啊");
+        list.add("斗图你怕了吗");
+        list.add("斗图输了的结果");
+        list.add("斗图王者重出江湖");
+        list.add("斗图还是我最强");
+        list.add("打字就是表情包");
+        list.add("现在表白都靠斗图了");
+        list.add("斗图啊,王者在线等");
+        list.add("斗图吗,年轻人");
+        list.add("斗图能赚零花钱");
+        list.add("确认过眼神,是我斗不过的人");
+        list.add("年轻人爱的斗图软件");
+        list.add("教你一招,包情包用不完");
+        list.add("从此人生很有趣");
+        list.add("我不认输,我只斗图");
+        list.add("表情包不够用?");
+        list.add("斗图,你过来呀!");
+        list.add("斗图输了不开心");
+        list.add("斗图输了不要怕");
+        list.add("还怕表情包不够用?");
+        list.add("表情包太少的后果");
+        list.add("斗图秒赢!");
+        list.add("是谁还在盗图?");
+        return list;
+    }
+}

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

@@ -20,6 +20,8 @@ import java.awt.Rectangle;
 import org.openqa.selenium.chrome.ChromeDriver;
 import org.openqa.selenium.chrome.ChromeDriverService;
 import org.openqa.selenium.chrome.ChromeOptions;
+import org.openqa.selenium.firefox.FirefoxDriver;
+import org.openqa.selenium.firefox.FirefoxOptions;
 import org.openqa.selenium.html5.Location;
 import org.openqa.selenium.interactions.Actions;
 import org.openqa.selenium.remote.DesiredCapabilities;
@@ -495,9 +497,24 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
 
     public static void main(String[] args) {
         try {
-            KuaishouWebInterfaceServiceImpl i = new KuaishouWebInterfaceServiceImpl();
-            String result = ChaojiyingUtils.process(Base64Utils.ImageToBase64("D:/capter.png"));
-            System.out.println(result);
+//            KuaishouWebInterfaceServiceImpl i = new KuaishouWebInterfaceServiceImpl();
+//            String result = ChaojiyingUtils.process(Base64Utils.ImageToBase64("D:/capter.png"));
+//            System.out.println(result);
+//            System.getProperties().setProperty("webdriver.gecko.drive", "D:/geckodriver.exe");
+            System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
+            ChromeOptions options = new ChromeOptions();
+            options.addArguments("--headless");
+            options.addArguments("--incognito");
+            options.addArguments("--no-sandbox");
+            options.addArguments("--disable-gpu");
+            options.addArguments("--window-size=1290,1080");
+            WebDriver driver = new ChromeDriver(options);
+            driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
+            driver.manage().timeouts().setScriptTimeout(5, TimeUnit.SECONDS);
+            driver.get("http://b.e.kuaishou.com");
+            System.out.println(driver.getPageSource());
+            driver.quit();
+//            driver.quit();
 //            i.adkuaishouWebLogin("17611760019", "a123456");
 //            i.adkuaishouWebLogin("18822179577", "a123456");
 //            i.adkuaishouWebLogin("13552374039", "hcst2019");

+ 6 - 1
pom.xml

@@ -300,7 +300,12 @@
         <dependency>
             <groupId>org.seleniumhq.selenium</groupId>
             <artifactId>selenium-java</artifactId>
-            <version>3.14.0</version>
+            <version>3.141.59</version>
+        </dependency>
+        <dependency>
+            <groupId>org.seleniumhq.selenium</groupId>
+            <artifactId>selenium-firefox-driver</artifactId>
+            <version>3.141.59</version>
         </dependency>
         <dependency>
             <groupId>org.json</groupId>