第一步:JAVA后台制作落地页
①:相关的主要表:项目表、计划表、落地页表、信息采集表、信息采集字段表。
简要关系说明:
1、新增计划需要配置所属项目并关联落地页
2、落地页中关联信息采集
3、信息采集中配置信息采集字段
②:采集页生成
参考:使用thymeleaf模板生成静态文件demo_thymeleaf 生成demo-CSDN博客
细节案例:
/**
* 生成静态页面
* @throws IOException
*/
public String generateHtmlTest(String planId) throws Exception {
// String directory = Objects.isNull(LoginUtil.getOrgCode())?"A01":LoginUtil.getOrgCode();
ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
resolver.setPrefix("templates/"); //模板文件的所在目录
resolver.setSuffix(".html"); //模板文件的后缀
//创建模板引擎对象
TemplateEngine templateEngine = new TemplateEngine();
//将加载器放入模板引擎对象中
templateEngine.setTemplateResolver(resolver);
//创建Context对象(存放Model)
Context context = new Context();
String indexFilePath = "D:\\0-开发工作\\cms";
String indexName = planId + SymbolConstant.UNDERLINE + "index-9.html";
//创建字符输出流并且自定义输出文件的位置和文件名
try ( FileOutputStream out = new FileOutputStream(indexFilePath + SymbolConstant.SINGLE_SLASH + indexName)) {
Writer writer = new OutputStreamWriter(out,"UTF-8");
// 计划
TblAdPlan plan = adPlanService.getById(planId);
plan.setUrl(htmlDomain + SymbolConstant.SINGLE_SLASH +indexName);
context.setVariable("plan", plan);
if (Objects.isNull(plan.getPageId())){
throw new Exception("未关联落地页");
}
// 落地页数据
TblAdGroundPage groundPage = adGroundPageService.getById(plan.getPageId());
groundPage.setGroundContentList(JSON.parseArray(groundPage.getGroundContent(), GroundContent.class));
context.setVariable("groundPage", groundPage);
// 采集页
if (Objects.isNull(groundPage.getGatherId())){
throw new Exception("未关联采集数据");
}
TblAdGather gather = adGatherService.getById(groundPage.getGatherId());
context.setVariable("gather", gather);
// 采集字段
if (Objects.isNull(gather.getId())){
throw new Exception("未配置采集字段");
}
QueryWrapper fieldReq = new QueryWrapper();
fieldReq.eq("gather_id",gather.getId());
List<TblAdGatherField> fields = adGatherFieldService.list(fieldReq);
fields.stream().forEach(field ->{
field.setTitleTypeMap(JSON.parseObject(field.getTitleType(), TitleTypeMap.class));
});
context.setVariable("gatherField", fields);
// 项目
TblAdProject adProject = adProjectService.getById(plan.getProjectId());
context.setVariable("adProject", adProject);
//创建静态文件,"template"是模板html名字
templateEngine.process("index", context, writer);
}
// 上传到oss
File file = new File(indexFilePath + SymbolConstant.SINGLE_SLASH + indexName);
ossService.uploadLoadingPage(new FileInputStream(file),indexName);
return indexName;
}
③:落地页的作用,主要是提供给抖音巨量平台,用户刷到广告时候,看到的页面中需要提交的数据。这里的配置字段,可以在java后台配置生成好,给广告平台,用户会根据落地页面进行填写提交
第二步:巨量广告平台添加落地页链接
此处就需要再巨量广告平台配置即可
第三步:JAVA后台新增添加广告的接口,来持久化广告推送数据
此处,后端做个接口,给前端调用即可。请求参数,可以是落地页中的所有保存的你需要的参数,如上案例中的 plan对象中的数据等