|
|
@@ -0,0 +1,195 @@
|
|
|
+package com.moka.gdtauto.service;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.GsonBuilder;
|
|
|
+import com.moka.gdtauto.GdtAutoApplication;
|
|
|
+import com.tencent.ads.model.v3.*;
|
|
|
+import org.junit.jupiter.api.DisplayName;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.context.ActiveProfiles;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 腾讯广告创建测试
|
|
|
+ *
|
|
|
+ * @author moka
|
|
|
+ * @since 2026-02-04
|
|
|
+ */
|
|
|
+@SpringBootTest(classes = GdtAutoApplication.class)
|
|
|
+@ActiveProfiles("local")
|
|
|
+class TencentAdsAdgroupCreateTest {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TencentAdsAdgroupService adgroupService;
|
|
|
+
|
|
|
+ private static final String TEST_ACCOUNT_ID = "66612379";
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("测试创建广告-使用提供的测试数据")
|
|
|
+ void testCreateAdgroupWithTestData() {
|
|
|
+ System.out.println("\n========================================");
|
|
|
+ System.out.println("开始创建广告");
|
|
|
+ System.out.println("账户ID: " + TEST_ACCOUNT_ID);
|
|
|
+ System.out.println("========================================\n");
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 构建测试数据(您提供的JSON数据)
|
|
|
+ AdgroupsAddRequest request = buildTestRequest();
|
|
|
+
|
|
|
+ // 输出请求参数
|
|
|
+ System.out.println("========== 请求参数 ==========");
|
|
|
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
|
+ System.out.println(gson.toJson(request));
|
|
|
+ System.out.println("========================================\n");
|
|
|
+
|
|
|
+ // 调用创建广告接口
|
|
|
+ System.out.println("正在调用腾讯广告创建API...");
|
|
|
+ AdgroupsAddResponseData response = adgroupService.createAdgroup(TEST_ACCOUNT_ID, request);
|
|
|
+
|
|
|
+ // 输出响应结果
|
|
|
+ System.out.println("\n========== API返回结果 ==========");
|
|
|
+ Gson gson2 = new GsonBuilder().setPrettyPrinting().create();
|
|
|
+ System.out.println(gson2.toJson(response));
|
|
|
+ System.out.println("========================================\n");
|
|
|
+
|
|
|
+ // 输出摘要信息
|
|
|
+ if (response != null) {
|
|
|
+ System.out.println("✅ 成功创建广告");
|
|
|
+ System.out.println("📊 广告ID: " + response.getAdgroupId());
|
|
|
+ System.out.println("📊 广告名称: " + request.getAdgroupName());
|
|
|
+ } else {
|
|
|
+ System.out.println("⚠️ 返回结果为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("\n❌ API调用失败");
|
|
|
+ System.err.println("错误信息: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException("测试失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建测试请求对象
|
|
|
+ */
|
|
|
+ private AdgroupsAddRequest buildTestRequest() {
|
|
|
+ AdgroupsAddRequest request = new AdgroupsAddRequest();
|
|
|
+
|
|
|
+ // 基础字段
|
|
|
+ request.setAdgroupName("测试ROI-0204" + System.currentTimeMillis());
|
|
|
+ request.setMarketingGoal(MarketingGoal.USER_GROWTH);
|
|
|
+ request.setMarketingCarrierType(MarketingCarrierType.JUMP_PAGE);
|
|
|
+
|
|
|
+ // 投放时间
|
|
|
+ request.setBeginDate("2026-02-04");
|
|
|
+ request.setEndDate("2026-02-05");
|
|
|
+
|
|
|
+ // 优化目标
|
|
|
+ request.setOptimizationGoal(OptimizationGoal.APP_REGISTER);
|
|
|
+
|
|
|
+ // 时间序列(全部1表示24小时投放,共7天*48个半小时=336位)
|
|
|
+ request.setTimeSeries("111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111");
|
|
|
+
|
|
|
+ // 投放站点
|
|
|
+ List<String> siteSet = new ArrayList<>();
|
|
|
+ siteSet.add("SITE_SET_SEARCH_SCENE");
|
|
|
+ siteSet.add("SITE_SET_MOBILE_UNION");
|
|
|
+ siteSet.add("SITE_SET_WECHAT");
|
|
|
+ siteSet.add("SITE_SET_KANDIAN");
|
|
|
+ siteSet.add("SITE_SET_QQ_MUSIC_GAME");
|
|
|
+ siteSet.add("SITE_SET_TENCENT_NEWS");
|
|
|
+ siteSet.add("SITE_SET_TENCENT_VIDEO");
|
|
|
+ request.setSiteSet(siteSet);
|
|
|
+
|
|
|
+ // 出价金额(单位:分)
|
|
|
+ request.setBidAmount(100L);
|
|
|
+
|
|
|
+ // 日预算(单位:分)
|
|
|
+ request.setDailyBudget(1000L);
|
|
|
+
|
|
|
+ // 转化ID
|
|
|
+ request.setConversionId(74719216L);
|
|
|
+
|
|
|
+ // 出价模式
|
|
|
+ request.setBidMode(BidMode.OCPM);
|
|
|
+
|
|
|
+ // 自动衍生创意
|
|
|
+ request.setAutoDerivedCreativeEnabled(false);
|
|
|
+
|
|
|
+ // 出价场景
|
|
|
+ request.setBidScene(BidScene.UNKNOWN);
|
|
|
+
|
|
|
+ // 定向设置
|
|
|
+ WriteTargetingSetting targeting = buildTargetingSetting();
|
|
|
+ request.setTargeting(targeting);
|
|
|
+
|
|
|
+ return request;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建定向设置
|
|
|
+ */
|
|
|
+ private WriteTargetingSetting buildTargetingSetting() {
|
|
|
+ WriteTargetingSetting targeting = new WriteTargetingSetting();
|
|
|
+
|
|
|
+ // 地域定向
|
|
|
+ GeoLocations geoLocation = new GeoLocations();
|
|
|
+ List<String> locationTypes = new ArrayList<>();
|
|
|
+ locationTypes.add("LIVE_IN"); // 居住地
|
|
|
+ geoLocation.setLocationTypes(locationTypes);
|
|
|
+ List<Long> regions = new ArrayList<>();
|
|
|
+ regions.add(1156L); // 地域ID:1156(中国)
|
|
|
+ geoLocation.setRegions(regions);
|
|
|
+ targeting.setGeoLocation(geoLocation);
|
|
|
+
|
|
|
+ // 性别定向
|
|
|
+ List<String> gender = new ArrayList<>();
|
|
|
+ gender.add("MALE"); // 男性
|
|
|
+ targeting.setGender(gender);
|
|
|
+
|
|
|
+ // 年龄定向
|
|
|
+ List<AgeStruct> age = new ArrayList<>();
|
|
|
+ AgeStruct ageRange = new AgeStruct();
|
|
|
+ ageRange.setMin(35L);
|
|
|
+ ageRange.setMax(66L);
|
|
|
+ age.add(ageRange);
|
|
|
+ targeting.setAge(age);
|
|
|
+
|
|
|
+ // 排除转化用户
|
|
|
+ ExcludedConvertedAudience excludedConverted = new ExcludedConvertedAudience();
|
|
|
+ excludedConverted.setExcludedDimension(ExcludedDimension.EXCLUDED_DIMENSION_GROUP);
|
|
|
+
|
|
|
+ List<String> conversionBehaviorList = new ArrayList<>();
|
|
|
+ conversionBehaviorList.add("OPTIMIZATIONGOAL_BRAND_CONVERSION");
|
|
|
+ conversionBehaviorList.add("OPTIMIZATIONGOAL_PAGE_SCAN_CODE");
|
|
|
+ excludedConverted.setConversionBehaviorList(conversionBehaviorList);
|
|
|
+
|
|
|
+ excludedConverted.setExcludedDay(ExcludedDay.valueOf("EXCLUDED_DAY_ONE_MONTH"));
|
|
|
+ targeting.setExcludedConvertedAudience(excludedConverted);
|
|
|
+
|
|
|
+ // 排除自定义人群
|
|
|
+ List<Long> excludedCustomAudience = new ArrayList<>();
|
|
|
+ excludedCustomAudience.add(43712084L);
|
|
|
+ excludedCustomAudience.add(44107982L);
|
|
|
+ excludedCustomAudience.add(44106830L);
|
|
|
+ excludedCustomAudience.add(44241932L);
|
|
|
+ targeting.setExcludedCustomAudience(excludedCustomAudience);
|
|
|
+
|
|
|
+ return targeting;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("打印测试数据JSON")
|
|
|
+ void printTestDataJson() {
|
|
|
+ AdgroupsAddRequest request = buildTestRequest();
|
|
|
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
|
+ String json = gson.toJson(request);
|
|
|
+ System.out.println("\n========== 测试数据JSON ==========");
|
|
|
+ System.out.println(json);
|
|
|
+ System.out.println("========================================\n");
|
|
|
+ }
|
|
|
+}
|