Forráskód Böngészése

添加头条账号密码绑定登录校验

syh 5 éve
szülő
commit
23920ee1b6

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

@@ -62,7 +62,6 @@ public class BindAccountAuthController {
         try {
             String advertiserId = json.getString("advertiserId");
             if (Check.isNull(advertiserId)) {
-//                System.err.println("advertiserId不能为空");
                 result.setSuccess(false);
                 return result;
             }

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

@@ -65,7 +65,7 @@ public class BindAccountLoginController {
      */
     @PostMapping(value = "/login")
     public Result<IPage<BindAccountLogin>> login(@RequestBody JSONObject json) {
-        Result<IPage<BindAccountLogin>> result = new Result<IPage<BindAccountLogin>>();
+        Result<IPage<BindAccountLogin>> result = new Result<>();
         String advertiserId = json.getString("advertiserId");
         if (Check.isNull(advertiserId)) {
             System.err.println("advertiserId不能为空");

+ 6 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/BindAccountLogin.java

@@ -42,6 +42,12 @@ public class BindAccountLogin {
     /**
      * 广告id
      */
+    @Excel(name = "平台账户id", width = 15)
+    @ApiModelProperty(value = "平台账户id")
+    private String accountId;
+    /**
+     * 广告id
+     */
     @Excel(name = "用户Id", width = 15)
     @ApiModelProperty(value = "用户id")
     private String userId;

+ 2 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/ICreateInternalService.java

@@ -6,4 +6,6 @@ import java.util.Map;
 
 public interface ICreateInternalService {
     Map<String, Object> createInternal(JSONObject requestJson);
+
+    Map<String, Object> checkAccountPassword(String account, String password);
 }

+ 15 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/BindAccountLoginServiceImpl.java

@@ -3,9 +3,11 @@ package org.jeecg.modules.ctop.service.impl;
 import cn.com.ctop.common.utils.Check;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.constant.CtopAdConstant;
 import org.jeecg.modules.ctop.entity.BindAccountLogin;
 import org.jeecg.modules.ctop.mapper.BindAccountLoginMapper;
 import org.jeecg.modules.ctop.service.IBindAccountLoginService;
+import org.jeecg.modules.ctop.service.ICreateInternalService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,7 +28,8 @@ import java.util.Map;
 public class BindAccountLoginServiceImpl extends ServiceImpl<BindAccountLoginMapper, BindAccountLogin> implements IBindAccountLoginService {
     @Autowired
     private BindAccountLoginMapper bindAccountLoginMapper;
-
+    @Autowired
+    private ICreateInternalService createInternalService;
     @Override
     public boolean bindLogin(String advertiserId, String accountName, String password, String loginType, String userId) {
         Map<String, Object> requestMap = new HashMap<>();
@@ -37,10 +40,21 @@ public class BindAccountLoginServiceImpl extends ServiceImpl<BindAccountLoginMap
         if (!Check.isNull(bindAccounts)) {
             return false;
         }
+        String accountId = "";
+        //头条登录
+        if (null != loginType && loginType.equals(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE_PY)) {
+            Map<String, Object> result = createInternalService.checkAccountPassword(accountName, password);
+            Boolean checkSuccess = (Boolean) result.get("success");
+            if (!checkSuccess) {
+                return false;
+            }
+            accountId = (String) result.get("id");
+        }
         BindAccountLogin bindAccountLogin = new BindAccountLogin();
         bindAccountLogin.setAdvertiserId(advertiserId);
         bindAccountLogin.setAccountName(accountName);
         bindAccountLogin.setPassword(password);
+        bindAccountLogin.setAccountId(accountId);
         bindAccountLogin.setLoginType(loginType);
         bindAccountLogin.setUserId(userId);
         int i = bindAccountLoginMapper.insert(bindAccountLogin);

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

@@ -15,10 +15,11 @@ import org.jeecg.modules.ctop.entity.BindAccountLogin;
 import org.jeecg.modules.ctop.entity.BytedanceUrlInfo;
 import org.jeecg.modules.ctop.mapper.BindAccountLoginMapper;
 import org.jeecg.modules.ctop.mapper.BytedanceUrlInfoMapper;
-import org.jeecg.modules.ctop.service.IBindAccountLoginService;
 import org.jeecg.modules.ctop.service.ICreateInternalService;
+import org.openqa.selenium.By;
 import org.openqa.selenium.Cookie;
 import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
 import org.openqa.selenium.chrome.ChromeDriver;
 import org.openqa.selenium.chrome.ChromeOptions;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -38,6 +39,105 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
 
     @Autowired
     private BytedanceUrlInfoMapper urlInfoMapper;
+
+    @Override
+    public Map<String, Object> checkAccountPassword(String account, String password) {
+        Map<String, Object> resultMap = new HashMap<>();
+        //selenium打开登录页面
+        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("--no-sandbox");
+        chromeOptions.addArguments("--window-size=1920,1080");
+        chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
+        chromeOptions.setAcceptInsecureCerts(true);
+        WebDriver webDriver = new ChromeDriver(chromeOptions);
+        try {
+            webDriver.get(url);  //获取登录页面
+            for (Cookie cookie : webDriver.manage().getCookies()) {
+                BasicClientCookie ck = new BasicClientCookie(cookie.getName(), cookie.getValue());
+                ck.setDomain("ad.oceanengine.com");
+                ck.setExpiryDate(cookie.getExpiry());
+                ck.setPath(cookie.getPath());
+                HttpUtils2.cookieStore.addCookie(ck);
+            }
+            Map<String, String> header = new HashMap<>();
+            header.put("Accept", "*/*");
+            header.put("Connection", "keep-alive");
+            header.put("Host", "sso.toutiao.com");
+            header.put("Content-Type", "application/x-www-form-urlencoded");
+            header.put("Origin", "https://ad.oceanengine.com");
+            header.put("Referer", "https://ad.oceanengine.com/pages/login/index.html");
+            Map<String, Object> param = new HashMap<>();
+            param.put("mobile", "");
+            param.put("code", "");
+            param.put("account", account);
+            param.put("password", password);
+            param.put("captcha", "hqde");
+            param.put("is_30_days_no_login", "true");
+            param.put("service", "https://ad.oceanengine.com");
+            String res = HttpUtils2.httpPostParamRequest("https://sso.toutiao.com/account_login/", param, header);
+
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode jsonNode = mapper.readTree(res);
+            //errorcode == 1102 验证码错误,请重新输入验证码
+            //errorcode == 1101 验证码为空
+
+            Integer errorCode = jsonNode.get("error_code").asInt();
+            String orderId = null;
+            while (errorCode != 0) {
+                //用户名或者密码错误
+                if (null != errorCode && errorCode == 1009) {
+                    ResultMapUtils.setResultMap(resultMap, StatusCode.USERNAME_OR_PASSWORD_ERROR.getCode());
+                    return resultMap;
+                }
+                FateadmUtil fateadmUtil = new FateadmUtil();
+                fateadmUtil.init();
+                if (orderId != null) {
+                    fateadmUtil.Justice(orderId);
+                }
+                String captcha = jsonNode.get("captcha").asText();
+                BASE64Decoder decoder = new BASE64Decoder();
+                FateadmHttpUtil.HttpResp resp = fateadmUtil.Predict("30400", decoder.decodeBuffer(captcha));
+                param.put("captcha", resp.pred_resl);
+                orderId = resp.req_id;
+                res = HttpUtils2.httpPostParamRequest("https://sso.toutiao.com/account_login/", param, header);
+                System.out.println("res:" + res);
+                jsonNode = mapper.readTree(res);
+                errorCode = jsonNode.get("error_code").asInt();
+            }
+            if (errorCode == 0) {
+                //表示登录成功
+                String csrftoken = "";
+                List<org.apache.http.cookie.Cookie> cookies = HttpUtils2.cookieStore.getCookies();
+                for (org.apache.http.cookie.Cookie ck : cookies) {
+                    Cookie cookie = new Cookie(ck.getName(), ck.getValue(), "." + ck.getDomain(), ck.getPath(), ck.getExpiryDate());
+                    webDriver.manage().addCookie(cookie);
+                }
+
+                webDriver.get("https://ad.oceanengine.com/pages/promotion.html#/ad");//登录成功 进入推广页面
+                Thread.sleep(3000);
+                WebElement element = webDriver.findElement(By.xpath("//div[contains(@class,'-user-account-id')] "));
+                if (null != element) {
+                    ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SUCCESS.getCode());
+                    String text = element.getText();
+                    text = text.replace("ID:", "").trim();
+                    resultMap.put("id", text);
+                } else {
+                    ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SERVER_ERROR.getCode());
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            ResultMapUtils.setResultMap(resultMap, StatusCode.COMMON_SERVER_ERROR.getCode());
+        } finally {
+            webDriver.quit();
+            return resultMap;
+        }
+
+    }
     @Override
     public Map<String, Object> createInternal(JSONObject requestJson) {
         Map<String, Object> resultMap = new HashMap<>();

+ 15 - 13
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -1,23 +1,15 @@
 package org.jeecg;
 
-import java.io.*;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Resource;
-
 import cn.com.ctop.common.utils.OSSUtils;
 import com.alibaba.fastjson.JSONObject;
-import org.apache.ibatis.annotations.Param;
 import org.apache.poi.hssf.usermodel.HSSFDataFormat;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.xssf.usermodel.XSSFCell;
-import org.apache.poi.xssf.usermodel.XSSFDataFormat;
 import org.apache.poi.xssf.usermodel.XSSFSheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.shiro.crypto.hash.Hash;
 import org.jeecg.common.util.ResultMapUtils;
 import org.jeecg.common.util.StatusCode;
 import org.jeecg.modules.ctop.mapper.PlatformCampaignStatisticInfoMapper;
@@ -25,17 +17,21 @@ import org.jeecg.modules.ctop.service.ICreateInternalService;
 import org.jeecg.modules.ctop.service.IReportService;
 import org.jeecg.modules.ctop.vo.StatisticCampaignVo;
 import org.jeecg.modules.demo.mock.MockController;
-import org.jeecg.modules.demo.test.entity.JeecgDemo;
 import org.jeecg.modules.demo.test.mapper.JeecgDemoMapper;
 import org.jeecg.modules.demo.test.service.IJeecgDemoService;
 import org.jeecg.modules.system.service.ISysDataLogService;
-import org.junit.Assert;
 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 javax.annotation.Resource;
+import java.io.*;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 @RunWith(SpringRunner.class)
 @SpringBootTest
 public class SampleTest {
@@ -69,6 +65,14 @@ public class SampleTest {
         reportService.insertPlatformInfo(csvPath1, "GBK", 1L);
     }
 
+    @Autowired
+    private ICreateInternalService createInternalService;
+
+    @Test
+    public void testLogin() {
+        Map<String, Object> map = createInternalService.checkAccountPassword("dcd_ad@bytedance.com", "typdDCD@2018");
+        System.out.println(map.toString());
+    }
     @Test
     public void getExcelData() throws Exception {
         String statisticDate = "2019-08-23";
@@ -393,8 +397,6 @@ public class SampleTest {
 
     @Autowired
     private PlatformCampaignStatisticInfoMapper statisticInfoMapper;
-    @Autowired
-    private ICreateInternalService createInternalService;
 
     @Test
     public void testNg() {