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