|
@@ -116,6 +116,8 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
|
|
|
chromeOptions.setAcceptInsecureCerts(true);
|
|
|
WebDriver webDriver = new ChromeDriver(chromeOptions);
|
|
|
+ //清除所有的缓存
|
|
|
+ webDriver.manage().deleteAllCookies();
|
|
|
try {
|
|
|
webDriver.get(url); //获取登录页面
|
|
|
for (Cookie cookie : webDriver.manage().getCookies()) {
|
|
@@ -172,14 +174,13 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
}
|
|
|
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");//登录成功 进入推广页面
|
|
|
+ //登录成功 进入推广页面
|
|
|
+ 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) {
|
|
@@ -237,6 +238,7 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
chromeOptions.setAcceptInsecureCerts(true);
|
|
|
WebDriver webDriver = new ChromeDriver(chromeOptions);
|
|
|
try {
|
|
|
+ webDriver.manage().deleteAllCookies();
|
|
|
//获取登录页面
|
|
|
webDriver.get(url);
|
|
|
for (Cookie cookie : webDriver.manage().getCookies()) {
|
|
@@ -305,50 +307,43 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
Thread.sleep(3000);
|
|
|
String templateName = requestJson.getString("templateName");
|
|
|
String uuid = UUID.randomUUID().toString();
|
|
|
- if (null == campaignId || campaignId.equals("")) {
|
|
|
- //创建广告组页面
|
|
|
- webDriver.get("https://ad.oceanengine.com/pages/campaign/create.html");
|
|
|
- Map<String, Object> campaignParam = new HashMap<>();
|
|
|
- campaignParam.put("campaign_id", "");
|
|
|
- campaignParam.put("campaign_name", templateName + "-广告组-" + uuid.substring(1, 7));
|
|
|
- campaignParam.put("landing_type", 3);
|
|
|
- campaignParam.put("campaign_type", 1);
|
|
|
- Map<String, Object> budgetMap = new HashMap<>();
|
|
|
- budgetMap.put("budget", 0);
|
|
|
- budgetMap.put("budget_mode", -1);
|
|
|
- campaignParam.put("budget", budgetMap);
|
|
|
- for (Cookie cookie : webDriver.manage().getCookies()) {
|
|
|
- if ("csrftoken".equals(cookie.getName())) {
|
|
|
- csrftoken = cookie.getValue();
|
|
|
- }
|
|
|
- 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);
|
|
|
+
|
|
|
+ //创建广告组页面
|
|
|
+ webDriver.get("https://ad.oceanengine.com/pages/campaign/create.html");
|
|
|
+ Map<String, Object> campaignParam = new HashMap<>();
|
|
|
+ campaignParam.put("campaign_id", "");
|
|
|
+ campaignParam.put("campaign_name", templateName + "-广告组-" + uuid.substring(1, 7));
|
|
|
+ campaignParam.put("landing_type", 3);
|
|
|
+ campaignParam.put("campaign_type", 1);
|
|
|
+ Map<String, Object> budgetMap = new HashMap<>();
|
|
|
+ budgetMap.put("budget", 0);
|
|
|
+ budgetMap.put("budget_mode", -1);
|
|
|
+ campaignParam.put("budget", budgetMap);
|
|
|
+ for (Cookie cookie : webDriver.manage().getCookies()) {
|
|
|
+ if ("csrftoken".equals(cookie.getName())) {
|
|
|
+ csrftoken = cookie.getValue();
|
|
|
}
|
|
|
+ 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);
|
|
|
+ }
|
|
|
|
|
|
- header.put("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
|
- header.put("Connection", "keep-alive");
|
|
|
- header.put("Host", "ad.oceanengine.com");
|
|
|
- header.put("Content-Type", "application/json");
|
|
|
- header.put("Origin", "https://ad.oceanengine.com");
|
|
|
- header.put("X-CSRFToken", csrftoken);
|
|
|
- header.put("X-Requested-With", "XMLHttpRequest");
|
|
|
- header.put("Referer", "https://ad.oceanengine.com/pages/campaign/create.html");
|
|
|
+ header.put("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
|
+ header.put("Connection", "keep-alive");
|
|
|
+ header.put("Host", "ad.oceanengine.com");
|
|
|
+ header.put("Content-Type", "application/json");
|
|
|
+ header.put("Origin", "https://ad.oceanengine.com");
|
|
|
+ header.put("X-CSRFToken", csrftoken);
|
|
|
+ header.put("X-Requested-With", "XMLHttpRequest");
|
|
|
+ header.put("Referer", "https://ad.oceanengine.com/pages/promotion.html");
|
|
|
// 创建广告组返回信息
|
|
|
+ if (null == campaignId || "".equals(campaignId.trim())) {
|
|
|
res = HttpUtils2.httpPostRequest("https://ad.oceanengine.com/overture/campaign/create/", campaignParam, header);
|
|
|
JsonNode node = mapper.readTree(res);
|
|
|
campaignId = node.get("data").get("campaign_id").asText();
|
|
|
- System.out.println(res);
|
|
|
- } else {
|
|
|
- header.put("Accept", "application/json, text/javascript, */*; q=0.01");
|
|
|
- header.put("Connection", "keep-alive");
|
|
|
- header.put("Host", "ad.oceanengine.com");
|
|
|
- header.put("Content-Type", "application/json");
|
|
|
- header.put("Origin", "https://ad.oceanengine.com");
|
|
|
- header.put("X-Requested-With", "XMLHttpRequest");
|
|
|
- header.put("Referer", "https://ad.oceanengine.com/pages/campaign/create.html");
|
|
|
+ System.out.println("创建广告组返回信息" + res);
|
|
|
}
|
|
|
|
|
|
Integer itratorNum = requestJson.getInteger("itratorNum");
|
|
@@ -400,8 +395,6 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
// 落地页链接
|
|
|
planParam.put("external_url", urlInfo.getUrl());
|
|
|
}
|
|
|
- // 投放范围
|
|
|
- planParam.put("delivery_range", 1);
|
|
|
//广告类别 5 内广
|
|
|
planParam.put("classify", 5);
|
|
|
planParam.put("projectid", "");
|
|
@@ -487,7 +480,7 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
System.out.println(planParam);
|
|
|
String createResult = HttpUtils2.httpPostRequest("https://ad.oceanengine.com/overture/ad/create/", planParam, header);
|
|
|
JSONObject result = JSONObject.parseObject(createResult);
|
|
|
- System.out.println(result.toJSONString());
|
|
|
+ System.out.println("创建广告计划返回信息:" + result.toJSONString());
|
|
|
String status = result.getString("status");
|
|
|
String msg = result.getString("msg");
|
|
|
if (null != status && !"success".equals(status)) {
|
|
@@ -515,31 +508,40 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
BytedanceCreativeLaunchTemplate launchTemplate = launchTemplateMapper.selectById(creativeTemplateId);
|
|
|
data.put("ad_id", adId);
|
|
|
String advertiseLoaction = launchTemplate.getAdvertiseLocation();
|
|
|
+ if (deliveryRange == 2) {
|
|
|
+ //按媒体指定位置
|
|
|
+ JSONArray inventoryType = new JSONArray();
|
|
|
+ inventoryType.add("INVENTORY_UNION_SLOT");
|
|
|
+ data.put("inventory_type", inventoryType);
|
|
|
+ } else {
|
|
|
+ //穿山甲
|
|
|
+ //按媒体指定位置
|
|
|
+ if (null != advertiseLoaction && "media".equals(advertiseLoaction)) {
|
|
|
+ String inventoryTypeStr = launchTemplate.getInventoryType();
|
|
|
+ JSONArray inventoryType = JSONArray.parseArray(inventoryTypeStr);
|
|
|
+ data.put("inventory_type", inventoryType);
|
|
|
+ }
|
|
|
+ //按场景指定位置
|
|
|
+ if (null != advertiseLoaction && "sence".equals(advertiseLoaction)) {
|
|
|
+ data.put("scene_inventory", launchTemplate.getSceneInventory());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //创意展现方式
|
|
|
+ data.put("creative_display_mode", launchTemplate.getCreativeDisplayMode());
|
|
|
//优选广告位
|
|
|
if (null != advertiseLoaction && advertiseLoaction.equals("great") && null != launchTemplate.getSmartInventory() && !"".equals(launchTemplate.getSmartInventory())) {
|
|
|
data.put("smart_inventory", launchTemplate.getSmartInventory());
|
|
|
}
|
|
|
- //按媒体指定位置
|
|
|
- if (null != advertiseLoaction && "media".equals(advertiseLoaction)) {
|
|
|
- String inventoryTypeStr = launchTemplate.getInventoryType();
|
|
|
- JSONArray inventoryType = JSONArray.parseArray(inventoryTypeStr);
|
|
|
- data.put("inventory_type", inventoryType);
|
|
|
- }
|
|
|
- //按场景指定位置
|
|
|
- if (null != advertiseLoaction && "sence".equals(advertiseLoaction)) {
|
|
|
- data.put("scene_inventory", launchTemplate.getSceneInventory());
|
|
|
- }
|
|
|
|
|
|
//广告评论
|
|
|
data.put("is_comment_disable", launchTemplate.getCommentDisable());
|
|
|
- //创意展现方式
|
|
|
- data.put("creative_display_mode", launchTemplate.getCreativeDisplayMode());
|
|
|
//创意分类
|
|
|
JSONArray categorys = JSONArray.parseArray(launchTemplate.getThirdIndustryId());
|
|
|
String thirdIndustryId = categorys.getString(2);
|
|
|
data.put("third_industry_id", thirdIndustryId);
|
|
|
//创意标签
|
|
|
data.put("ad_keywords", JSONArray.parseArray(launchTemplate.getAdKeywords()));
|
|
|
+
|
|
|
//创意标题
|
|
|
data.put("title", name + "_" + System.currentTimeMillis() + "_" + "汇创广告创意");
|
|
|
|
|
@@ -594,7 +596,6 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
JSONArray titleList = new JSONArray();
|
|
|
titleArray.forEach(v -> {
|
|
|
JSONObject getTitleObject = JSONObject.parseObject(JSONObject.toJSONString(v));
|
|
|
- ;
|
|
|
JSONObject titleObject = new JSONObject();
|
|
|
String getTitle = getTitleObject.getString("text");
|
|
|
titleObject.put("title", getTitle);
|
|
@@ -655,8 +656,6 @@ public class CreateInternalServiceImpl implements ICreateInternalService {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
- //获得cookie
|
|
|
- Set<Cookie> coo = webDriver.manage().getCookies();
|
|
|
//清除所有的缓存
|
|
|
webDriver.manage().deleteAllCookies();
|
|
|
webDriver.quit();
|