|
@@ -0,0 +1,838 @@
|
|
|
+package cn.com.ctop.kuaishou.modules.ai.service.impl;
|
|
|
+
|
|
|
+import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
+import cn.com.ctop.common.module.entity.MaterialCutFrame;
|
|
|
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
+import cn.com.ctop.common.module.service.IMaterialCutFrameService;
|
|
|
+import cn.com.ctop.common.module.utils.Check;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaiShouAppInfo;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouAdvertiserStrategy;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.entity.AiKuaishouStrategyMapCreative;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouAccountCreativeOverrunInfo;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaiShouAppInfoService;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouCreateCreativeService;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.service.IAiKuaishouStrategyMapCreativeService;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAccountCreativeOverrunInfoService;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouImageGet;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.*;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class AiKuaishouCreateCreativeServiceImpl implements IAiKuaishouCreateCreativeService {
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouGroupTemplateService groupTemplateService;
|
|
|
+ @Autowired
|
|
|
+ private ICtopOauthTokenService tokenService;
|
|
|
+ @Autowired
|
|
|
+ private IKuaishouInterfaceService kuaishouInterfaceService;
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouVideoGetService videoGetService;
|
|
|
+ @Autowired
|
|
|
+ private IAiKuaishouStrategyMapCreativeService mapCreativeService;
|
|
|
+ @Autowired
|
|
|
+ private IMaterialCutFrameService materialCutFrameService;
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouImageGetService imageGetService;
|
|
|
+ @Autowired
|
|
|
+ private IKuaiShouMaterialUploadService materialUploadService;
|
|
|
+ @Autowired
|
|
|
+ private IKuaishouAccountCreativeOverrunInfoService overrunInfoService;
|
|
|
+ @Autowired
|
|
|
+ private IAiKuaiShouAppInfoService appInfoService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建自定义创意
|
|
|
+ * @param strategy
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void autoCreateCreative(AiKuaishouAdvertiserStrategy strategy){
|
|
|
+ strategy.setUnitType(4);
|
|
|
+ Long accountId = strategy.getAccountId();
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
|
|
|
+ if(null == token){
|
|
|
+ log.info("token获取失败=>accountId:{}",accountId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //1:获取视频信息
|
|
|
+ kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(),DateUtils.date2Str());
|
|
|
+ int timeStart = -10;
|
|
|
+ int timeEnd = -5;
|
|
|
+ Long now = System.currentTimeMillis();
|
|
|
+ String startTime = DateUtils.formatDate(new Date(now + timeStart*60*1000),"yyyy-MM-dd HH:mm:ss");
|
|
|
+ String endTime = DateUtils.formatDate(new Date(now + timeEnd*60*1000),"yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ //2:判定账户是否单一应用
|
|
|
+ Integer singleAppid = strategy.getSingleAppid();
|
|
|
+ if(null!=singleAppid&&singleAppid==0){
|
|
|
+ //非单一应用
|
|
|
+ String appidString = strategy.getAppIdArray();
|
|
|
+ JSONArray appIdArray = JSONArray.parseArray(appidString);
|
|
|
+ if(null!=appIdArray&&!appIdArray.isEmpty()){
|
|
|
+ for(int i=0;i<appIdArray.size();i++){
|
|
|
+ AiKuaiShouAppInfo appInfo = appInfoService.getByParams(strategy.getAccountId(),appIdArray.getLong(i));
|
|
|
+ if(null == appInfo){
|
|
|
+ log.info("账户:{},appid({}) 数据不存在",accountId, appIdArray.getLong(i));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(null!=strategy.getGeneralTrack()&&strategy.getGeneralTrack() == 0){
|
|
|
+ strategy.setClickTrackUrl(appInfo.getTrackUrl());
|
|
|
+ strategy.setImpressionUrl(appInfo.getTrackUrl());
|
|
|
+ }
|
|
|
+ String replaceString = appInfo.getAppVersion()+"自动上新";
|
|
|
+ //1:查询通用素材
|
|
|
+ List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy,startTime,endTime,appInfo);
|
|
|
+ if(null == allVideos||allVideos.isEmpty()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long newCampaignId = getCampaignId(strategy,token,replaceString,"ALL_CAMPAIGN");
|
|
|
+
|
|
|
+ //开始创建组+创意
|
|
|
+ String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
|
|
+ String unitNamePrefix = strategy.getGroupName().replace("自定义",replaceString)+ timestamp;
|
|
|
+ int unitCnt = 0;
|
|
|
+ for(KuaiShouVideoGet videoItem: allVideos) {
|
|
|
+ KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
|
+ if (null != overrunInfo) {
|
|
|
+ log.info("该账户创意创建已超限=>accountId:{}",accountId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ unitCnt++;
|
|
|
+ String unitName = unitNamePrefix + "-" + unitCnt;
|
|
|
+ JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName,appInfo.getAppId());
|
|
|
+ Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
|
|
|
+ Integer unitCode = (Integer) unitCreateResult.get("code");
|
|
|
+ String unitMessage = (String) unitCreateResult.get("message");
|
|
|
+ if (unitCode != 0) {
|
|
|
+ log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
+
|
|
|
+ // 每个组,搭配n个创意
|
|
|
+ List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
|
+ if ((null == cutFrameList || cutFrameList.isEmpty())) {
|
|
|
+ log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
|
|
|
+ createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //单一应用
|
|
|
+ List<KuaiShouVideoGet> newVideos = videoGetService.getNewVideoBetweenTime(accountId,startTime,endTime,strategy.getChannelType(),null);
|
|
|
+ if (null == newVideos ||newVideos.isEmpty()){
|
|
|
+ log.info("账户:{},{} 到 {} 这段时间没有上新素材",accountId, startTime, endTime);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long newCampaignId = getCampaignId(strategy,token,"素材上新","TODAY");
|
|
|
+ if(null== newCampaignId){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
|
|
|
+ String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
|
|
+ String unitNamePrefix = strategy.getGroupName().replace("自定义","素材上新")+ timestamp;
|
|
|
+ int unitCnt = 0;
|
|
|
+ for(KuaiShouVideoGet videoItem: newVideos) {
|
|
|
+ KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
|
+ if (null != overrunInfo) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ unitCnt++;
|
|
|
+ String unitName = unitNamePrefix + "-" + unitCnt;
|
|
|
+ Long appId = JSONArray.parseArray(strategy.getAppIdArray()).getLong(0);
|
|
|
+ JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName,appId);
|
|
|
+ Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
|
|
|
+ Integer unitCode = (Integer) unitCreateResult.get("code");
|
|
|
+ String unitMessage = (String) unitCreateResult.get("message");
|
|
|
+ if (unitCode != 0) {
|
|
|
+ log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
+
|
|
|
+ // 每个组,搭配5个创意
|
|
|
+ List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
|
+ if ((null == cutFrameList || cutFrameList.isEmpty())) {
|
|
|
+ log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
|
|
|
+ createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建程序化创意
|
|
|
+ * @param strategy
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void autoCreateProgramCreative(AiKuaishouAdvertiserStrategy strategy){
|
|
|
+ strategy.setUnitType(7);
|
|
|
+ Long accountId = strategy.getAccountId();
|
|
|
+ CtopOauthToken token = tokenService.getOauthTokenByAccountId(accountId.toString());
|
|
|
+ if(null == token){
|
|
|
+ log.info("token获取失败=>accountId:{}",accountId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //1:获取视频信息
|
|
|
+ kuaishouInterfaceService.getVideoList(token, DateUtils.date2Str(),DateUtils.date2Str());
|
|
|
+ int timeStart = -10;
|
|
|
+ int timeEnd = -5;
|
|
|
+ Long now = System.currentTimeMillis();
|
|
|
+ String startTime = DateUtils.formatDate(new Date(now + timeStart*60*1000),"yyyy-MM-dd HH:mm:ss");
|
|
|
+ String endTime = DateUtils.formatDate(new Date(now + timeEnd*60*1000),"yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ //2:判定账户是否单一应用
|
|
|
+ Integer singleAppid = strategy.getSingleAppid();
|
|
|
+ if(null!=singleAppid&&singleAppid==0){
|
|
|
+ //非单一应用
|
|
|
+ String appidString = strategy.getAppIdArray();
|
|
|
+ JSONArray appIdArray = JSONArray.parseArray(appidString);
|
|
|
+ if(null!=appIdArray&&!appIdArray.isEmpty()){
|
|
|
+ for(int i=0;i<appIdArray.size();i++){
|
|
|
+ AiKuaiShouAppInfo appInfo = appInfoService.getByParams(strategy.getAccountId(),appIdArray.getLong(i));
|
|
|
+ if(null == appInfo){
|
|
|
+ log.info("账户:{},appid({}) 数据不存在",accountId, appIdArray.getLong(i));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String replaceString = appInfo.getAppVersion()+"程序化";
|
|
|
+ //1:查询可用素材
|
|
|
+ List<KuaiShouVideoGet> allVideos = getVideosByParams(strategy,startTime,endTime,appInfo);
|
|
|
+ if(null == allVideos){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long newCampaignId = getCampaignId(strategy,token,replaceString,"ALL_CAMPAIGN");
|
|
|
+ //开始创建组+创意
|
|
|
+ String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
|
|
+ String unitNamePrefix = strategy.getGroupName().replace("自定义",replaceString)+ timestamp;
|
|
|
+ int unitCnt = 0;
|
|
|
+ for(KuaiShouVideoGet videoItem: allVideos) {
|
|
|
+ KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
|
+ if (null != overrunInfo) {
|
|
|
+ log.info("该账户创意创建已超限=>accountId:{}",accountId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ unitCnt++;
|
|
|
+ String unitName = unitNamePrefix + "-" + unitCnt;
|
|
|
+ JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName,appInfo.getAppId());
|
|
|
+ Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
|
|
|
+ Integer unitCode = (Integer) unitCreateResult.get("code");
|
|
|
+ String unitMessage = (String) unitCreateResult.get("message");
|
|
|
+ if (unitCode != 0) {
|
|
|
+ log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
+
|
|
|
+ // 每个组,搭配n个创意
|
|
|
+ List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
|
+ if ((null == cutFrameList || cutFrameList.isEmpty())) {
|
|
|
+ log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
|
|
|
+ createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ //单一应用
|
|
|
+ List<KuaiShouVideoGet> newVideos = videoGetService.getNewVideoBetweenTime(accountId,startTime,endTime,strategy.getChannelType(),null);
|
|
|
+ if (null == newVideos ||newVideos.isEmpty()){
|
|
|
+ log.info("账户:{},{} 到 {} 这段时间没有上新素材",accountId, startTime, endTime);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long newCampaignId = getCampaignId(strategy,token,"素材上新","TODAY");
|
|
|
+ if(null== newCampaignId){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ //3、在“上新”计划中新增广告组,一个素材搭配n张封面,组成一个广告组
|
|
|
+ String timestamp = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
|
|
+ String unitNamePrefix = strategy.getGroupName().replace("自定义","素材上新")+ timestamp;
|
|
|
+ int unitCnt = 0;
|
|
|
+ for(KuaiShouVideoGet videoItem: newVideos) {
|
|
|
+ KuaishouAccountCreativeOverrunInfo overrunInfo = overrunInfoService.getByParams(accountId, DateUtils.formatDate(new Date()));
|
|
|
+ if (null != overrunInfo) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ unitCnt++;
|
|
|
+ String unitName = unitNamePrefix + "-" + unitCnt;
|
|
|
+ Long appId = JSONArray.parseArray(strategy.getAppIdArray()).getLong(0);
|
|
|
+ JSONObject unitParams = createUnitParams(token, newCampaignId, strategy, unitName,appId);
|
|
|
+ Map<String, Object> unitCreateResult = kuaishouInterfaceService.adUnitCreate(token.getAccessToken(), token.getAccountId(), unitParams, 1);
|
|
|
+ Integer unitCode = (Integer) unitCreateResult.get("code");
|
|
|
+ String unitMessage = (String) unitCreateResult.get("message");
|
|
|
+ if (unitCode != 0) {
|
|
|
+ log.info("组创建失败=>accountId:{};message:{}", accountId, unitMessage);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Long unitId = (Long) unitCreateResult.get("unitId");
|
|
|
+
|
|
|
+ // 每个组,搭配5个创意
|
|
|
+ List<MaterialCutFrame> cutFrameList = materialCutFrameService.getListByVideoSignature(videoItem.getSignature());
|
|
|
+ if ((null == cutFrameList || cutFrameList.isEmpty())) {
|
|
|
+ log.info("未获取到视频封面=>videoSignature:{}", videoItem.getSignature());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject creativeParams = creativeParams(token, unitId, videoItem, strategy);
|
|
|
+ createCreativeByImage(cutFrameList, token, creativeParams, newCampaignId, unitId, videoItem, strategy.getImageCnt());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<KuaiShouVideoGet> getVideosByParams(AiKuaishouAdvertiserStrategy strategy,String startTime,String endTime,AiKuaiShouAppInfo appInfo) {
|
|
|
+ List<KuaiShouVideoGet> generalVideos = videoGetService.getNewVideoBetweenTime(strategy.getAccountId(),startTime,endTime,strategy.getChannelType(),null);
|
|
|
+ //2:查询特定素材
|
|
|
+ List<KuaiShouVideoGet> customVideos = videoGetService.getNewVideoBetweenTime(strategy.getAccountId(),startTime,endTime,strategy.getChannelType(),appInfo.getAppVersion());
|
|
|
+ if(null == generalVideos||generalVideos.isEmpty()||null == customVideos||customVideos.isEmpty()){
|
|
|
+ log.info("账户:{},appId({}){}到{}这段时间没有上新素材",strategy.getAccountId(),appInfo.getAppId(),startTime, endTime);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //合并
|
|
|
+ if(null == generalVideos||generalVideos.isEmpty()){
|
|
|
+ return customVideos;
|
|
|
+ }else if(null == customVideos||customVideos.isEmpty()){
|
|
|
+ return generalVideos;
|
|
|
+ }else {
|
|
|
+ generalVideos.addAll(customVideos);
|
|
|
+ return generalVideos;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long getCampaignId(AiKuaishouAdvertiserStrategy strategy,CtopOauthToken token,String replaceString,String checkType) {
|
|
|
+ JSONArray campaignList = null;
|
|
|
+ Date campaignDate = new Date();
|
|
|
+ String timestamp = "";
|
|
|
+ if(null!=checkType&&checkType.equals("ALL_CAMPAIGN")){
|
|
|
+ campaignList = kuaishouInterfaceService.getCampaignList(token, null, null,1);
|
|
|
+ }else{
|
|
|
+ timestamp = DateUtils.formatDate(campaignDate,"yyyyMMddHHmmss");
|
|
|
+ campaignList = kuaishouInterfaceService.getCampaignList(token, new Date(), new Date(),1);
|
|
|
+ }
|
|
|
+ Long newCampaignId = 0L;
|
|
|
+ if (null!=campaignList&&campaignList.size()>0){
|
|
|
+ for(int i = 0;i<campaignList.size();i++){
|
|
|
+ JSONObject jsonObject = campaignList.getJSONObject(i);
|
|
|
+ if (jsonObject.getString("campaign_name").contains(replaceString)){
|
|
|
+ newCampaignId = jsonObject.getLong("campaign_id");
|
|
|
+ return newCampaignId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 不存在“上新”计划,则创建一个计划
|
|
|
+ JSONObject campaignParams = new JSONObject();
|
|
|
+ campaignParams.put("advertiser_id",token.getAccountId());
|
|
|
+ String campaignName = strategy.getCampaignName().replace("自定义",replaceString)+timestamp;
|
|
|
+ campaignParams.put("campaign_name",campaignName);
|
|
|
+ campaignParams.put("type",strategy.getCampaignType());
|
|
|
+ //TODO 目前设定为不限
|
|
|
+ campaignParams.put("day_budget",0L);
|
|
|
+ Map<String, Object> campaignCreateResult = kuaishouInterfaceService.campaignCreate(token.getAccessToken(), token.getAccountId(), campaignParams);
|
|
|
+ Integer code = (Integer) campaignCreateResult.get("code");
|
|
|
+ String message = (String) campaignCreateResult.get("message");
|
|
|
+ if(code != 0 ){
|
|
|
+ //TODO 写入日志信息表
|
|
|
+ log.info("计划创建失败=>message:{}",message);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ newCampaignId = (Long) campaignCreateResult.get("campaignId");
|
|
|
+ return newCampaignId;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private JSONObject createUnitParams(CtopOauthToken token, Long campaignId, AiKuaishouAdvertiserStrategy strategy,
|
|
|
+ String unitName,Long appId) {
|
|
|
+ // 拼装创建组的入参 json
|
|
|
+ JSONObject unitParams = new JSONObject();
|
|
|
+ Integer unitType = strategy.getUnitType();
|
|
|
+ //创意制作方式
|
|
|
+ unitParams.put("unit_type",unitType);
|
|
|
+ unitParams.put("advertiser_id",token.getAccountId());
|
|
|
+ unitParams.put("campaign_id",campaignId);
|
|
|
+ unitParams.put("unit_name", unitName);
|
|
|
+ //出价类型
|
|
|
+ unitParams.put("bid_type",strategy.getBidType());
|
|
|
+ // 优先从系统应用商店下载
|
|
|
+ if(null!=strategy.getUseAppMarket()){
|
|
|
+ unitParams.put("use_app_market",strategy.getUseAppMarket());
|
|
|
+ }
|
|
|
+ //应用商店列表
|
|
|
+ if(null!=strategy.getAppStore()&&!"".equals(strategy.getAppStore())){
|
|
|
+ unitParams.put("app_store",JSONArray.parseArray(strategy.getAppStore()));
|
|
|
+ }
|
|
|
+ unitParams.put("ocpx_action_type",strategy.getOcpxActionType());
|
|
|
+
|
|
|
+
|
|
|
+ // 在本策略中,都是 OCPM 的出价方式
|
|
|
+ //出价
|
|
|
+ if (null!=strategy.getBid()&&strategy.getBid()!=0) {
|
|
|
+ unitParams.put("bid", strategy.getBid());
|
|
|
+ }
|
|
|
+ if (null!=strategy.getCpaBid()&&strategy.getCpaBid()!=0) {
|
|
|
+ unitParams.put("cpa_bid", strategy.getCpaBid());
|
|
|
+ }
|
|
|
+ //优先低成本
|
|
|
+ if (null!=strategy.getSmartBid()&&strategy.getSmartBid()!=0) {
|
|
|
+ unitParams.put("smart_bid", strategy.getSmartBid());
|
|
|
+ }
|
|
|
+ //优化目标
|
|
|
+ if (!Check.isNull(strategy.getOcpxActionType())) {
|
|
|
+ unitParams.put("ocpx_action_type", strategy.getOcpxActionType());
|
|
|
+ }
|
|
|
+ //深度转化目标
|
|
|
+ if (!Check.isNull(strategy.getDeepConversionType())) {
|
|
|
+ unitParams.put("deep_conversion_type", strategy.getDeepConversionType());
|
|
|
+ }
|
|
|
+ //付费ROI系数
|
|
|
+ if (!Check.isNull(strategy.getRoiRatio())) {
|
|
|
+ unitParams.put("roi_ratio", strategy.getRoiRatio());
|
|
|
+ }
|
|
|
+ //深度转化目标出价
|
|
|
+ if (!Check.isNull(strategy.getDeepConversionBid())) {
|
|
|
+ unitParams.put("deep_conversion_bid", strategy.getDeepConversionBid());
|
|
|
+ }
|
|
|
+ //资源位置
|
|
|
+ Integer sceneId = null;
|
|
|
+ String scenceIdString = strategy.getSceneId();
|
|
|
+ if (null!=scenceIdString&&!scenceIdString.trim().equals(scenceIdString)&&Check.isNull(JSONArray.parseArray(scenceIdString))) {
|
|
|
+ sceneId = JSONArray.parseArray(strategy.getSceneId()).getInteger(0);
|
|
|
+ unitParams.put("scene_id", JSONArray.parseArray(strategy.getSceneId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ //投放开始时间
|
|
|
+ if (!Check.isNull(strategy.getBeginTime())) {
|
|
|
+ unitParams.put("begin_time", strategy.getBeginTime());
|
|
|
+ }
|
|
|
+ //投放结束时间
|
|
|
+ if (!Check.isNull(strategy.getEndTime())) {
|
|
|
+ unitParams.put("end_time", strategy.getEndTime());
|
|
|
+ }
|
|
|
+ //投放时间段
|
|
|
+ if (!Check.isNull(strategy.getScheduleTime())) {
|
|
|
+ unitParams.put("schedule_time", strategy.getScheduleTime());
|
|
|
+ }
|
|
|
+// if (!Check.isNull(strategy.getLong("day_budget"))) {
|
|
|
+// unitParams.put("day_budget", groupCreateJson.getLong("day_budget")); //投放时间段
|
|
|
+// }
|
|
|
+ //转化id
|
|
|
+ if (!Check.isNull(strategy.getConvertId())) {
|
|
|
+ unitParams.put("convert_id", strategy.getConvertId());
|
|
|
+ }
|
|
|
+ //url类型
|
|
|
+ if (!Check.isNull(strategy.getUrlType())) {
|
|
|
+ unitParams.put("url_type", strategy.getUrlType());
|
|
|
+ }
|
|
|
+ //url类型
|
|
|
+ if (!Check.isNull(strategy.getWebUriType())) {
|
|
|
+ unitParams.put("web_uri_type", strategy.getWebUriType());
|
|
|
+ }
|
|
|
+ //url
|
|
|
+ if (!Check.isNull(strategy.getUrl())) {
|
|
|
+ unitParams.put("url", strategy.getUrl());
|
|
|
+ }
|
|
|
+ //调起链接
|
|
|
+ if (!Check.isNull(strategy.getSchemaUri())) {
|
|
|
+ unitParams.put("schema_uri", strategy.getSchemaUri());
|
|
|
+ }
|
|
|
+ //应用ID
|
|
|
+ if (!Check.isNull(appId)) {
|
|
|
+ unitParams.put("app_id", appId);
|
|
|
+ }
|
|
|
+ //创意展现方式
|
|
|
+ if (!Check.isNull(strategy.getShowMode())) {
|
|
|
+ unitParams.put("show_mode", strategy.getShowMode());
|
|
|
+ }
|
|
|
+ //投放方式
|
|
|
+ if (!Check.isNull(strategy.getSpeed())) {
|
|
|
+ unitParams.put("speed", strategy.getSpeed());
|
|
|
+ }
|
|
|
+ //预约广告
|
|
|
+ if (!Check.isNull(strategy.getSiteType())) {
|
|
|
+ unitParams.put("site_type", strategy.getSiteType());
|
|
|
+ }
|
|
|
+// if (!Check.isNull(strategy.getInteger("target_action_type")) || !Check.isNull(strategy.getString("code"))) {
|
|
|
+// JSONObject gift_data = new JSONObject();
|
|
|
+// if (!Check.isNull(groupCreateJson.getInteger("target_action_type"))) {
|
|
|
+// gift_data.put("target_action_type", groupCreateJson.getInteger("target_action_type"));
|
|
|
+// }
|
|
|
+// if (!Check.isNull(groupCreateJson.getString("code"))) {
|
|
|
+// gift_data.put("code", groupCreateJson.getString("code"));
|
|
|
+// }
|
|
|
+// unitParams.put("gift_data", gift_data); //游戏礼包码
|
|
|
+// }
|
|
|
+// if (!Check.isNull(groupCreateJson.getBoolean("video_landing_page"))) {
|
|
|
+// unitParams.put("video_landing_page", groupCreateJson.getBoolean("video_landing_page")); //是否使用落地页前置功能
|
|
|
+// }
|
|
|
+ //智能定向
|
|
|
+ if (!Check.isNull(strategy.getAutoTarget())) {
|
|
|
+ unitParams.put("auto_target", strategy.getAutoTarget());
|
|
|
+ }
|
|
|
+ //是否开启自动生成视频
|
|
|
+ if (!Check.isNull(strategy.getAutoCreatePhoto())) {
|
|
|
+ unitParams.put("auto_create_photo", strategy.getAutoCreatePhoto());
|
|
|
+ }
|
|
|
+// if (!Check.isNull(strategy.getItemId())) {
|
|
|
+// unitParams.put("item_id", groupCreateJson.getLong("item_id")); //电商关联Id (小店通)
|
|
|
+// }
|
|
|
+// if (!Check.isNull(groupCreateJson.getLong("merchant_item_put_type"))) {
|
|
|
+// unitParams.put("merchant_item_put_type", groupCreateJson.getLong("merchant_item_put_type")); //电商广告投放类型(小店通)
|
|
|
+// }
|
|
|
+// if (!Check.isNull(groupCreateJson.getLong("fiction_id"))) {
|
|
|
+// unitParams.put("fiction_id", groupCreateJson.getLong("fiction_id")); //小说ID
|
|
|
+// }
|
|
|
+
|
|
|
+ if (unitType == 7) {
|
|
|
+ //是否开启智能抽帧
|
|
|
+ if (!Check.isNull(strategy.getSmartCover())) {
|
|
|
+ unitParams.put("smart_cover", strategy.getSmartCover());
|
|
|
+ }
|
|
|
+ //程序化创意2.0素材挖掘
|
|
|
+ if (!Check.isNull(strategy.getAssetMining())) {
|
|
|
+ unitParams.put("asset_mining", strategy.getAssetMining());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Check.isNull(strategy.getTemplateId())) {
|
|
|
+ if (sceneId != 5) {
|
|
|
+ unitParams.put("template_id", strategy.getTemplateId()); //定向模板id
|
|
|
+ } else { // 联盟广告位 需要根据模板id 获取定向数据
|
|
|
+ JSONObject unionJson = groupTemplateService.getUnionJson(Long.parseLong(strategy.getTemplateId()+""));
|
|
|
+ Integer code = unionJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject target = unionJson.getJSONObject("target");
|
|
|
+ unitParams.put("target", target);
|
|
|
+ } else {
|
|
|
+ log.info("组创建异常=》accountId({})联盟广告位定向模板错误",strategy.getAccountId());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ JSONObject target = getTarget(sceneId,strategy);
|
|
|
+ // 定向数据
|
|
|
+ unitParams.put("target", target);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 设置定向内容
|
|
|
+ JSONObject targetJsonObject = new JSONObject();
|
|
|
+ if(null!=strategy.getRegion()&&!"".equals(strategy.getRegion())){
|
|
|
+ targetJsonObject.put("region",JSONArray.parseArray(strategy.getRegion()));
|
|
|
+ }
|
|
|
+ if(null!=strategy.getAgesRange()&&!"".equals(strategy.getAgesRange())){
|
|
|
+ targetJsonObject.put("ages_range",JSONArray.parseArray(strategy.getAgesRange()));
|
|
|
+ }
|
|
|
+ if(null!=strategy.getGender()){
|
|
|
+ targetJsonObject.put("gender",strategy.getGender());
|
|
|
+ }
|
|
|
+ if(null!=strategy.getPlatformOs()){
|
|
|
+ targetJsonObject.put("platform_os",strategy.getPlatformOs());
|
|
|
+ }
|
|
|
+ if(null!=strategy.getAndroidOsv()){
|
|
|
+ targetJsonObject.put("android_osv",strategy.getAndroidOsv());
|
|
|
+ }
|
|
|
+ if(null!=strategy.getIosOsv()){
|
|
|
+ targetJsonObject.put("ios_osv",strategy.getIosOsv());
|
|
|
+ }
|
|
|
+ if(null!=strategy.getDeviceBrand()&&!"".equals(strategy.getDeviceBrand())&&!"[]".equals(strategy.getDeviceBrand())){
|
|
|
+ targetJsonObject.put("device_brand",JSONArray.parseArray(strategy.getDeviceBrand()));
|
|
|
+ }
|
|
|
+ if(null!=strategy.getDevicePrice()&&!"".equals(strategy.getDevicePrice())&&!"[]".equals(strategy.getDevicePrice())){
|
|
|
+ targetJsonObject.put("device_price",JSONArray.parseArray(strategy.getDevicePrice()));
|
|
|
+ }
|
|
|
+ if(null!=strategy.getPopulation()&&!"".equals(strategy.getPopulation())){
|
|
|
+ JSONArray population = JSONArray.parseArray(strategy.getPopulation());
|
|
|
+ targetJsonObject.put("population",population);
|
|
|
+ }
|
|
|
+ if(null!=strategy.getFilterConvertedLevel()&&strategy.getFilterConvertedLevel()!=0){
|
|
|
+ targetJsonObject.put("filter_converted_level",strategy.getFilterConvertedLevel());
|
|
|
+ }
|
|
|
+ if(null!=strategy.getExcludePopulation()&&!"".equals(strategy.getExcludePopulation())){
|
|
|
+ JSONArray excludePopulation = JSONArray.parseArray(strategy.getExcludePopulation());
|
|
|
+ targetJsonObject.put("exclude_population",excludePopulation);
|
|
|
+ }
|
|
|
+ //是否开启智能扩量
|
|
|
+ if(null!=strategy.getIsOpen()&&strategy.getIsOpen().equals(1)){
|
|
|
+ JSONObject intelliExtend = new JSONObject();
|
|
|
+ intelliExtend.put("is_open",1);
|
|
|
+ if(null!=strategy.getNoAgeBreak()&&strategy.getNoAgeBreak().equals(1)){
|
|
|
+ intelliExtend.put("no_age_break",1);
|
|
|
+ }
|
|
|
+ if(null!=strategy.getNoGenderBreak()&&strategy.getNoGenderBreak().equals(1)){
|
|
|
+ intelliExtend.put("no_gender_break",1);
|
|
|
+ }
|
|
|
+ if(null!=strategy.getNoAreaBreak()&&strategy.getNoAreaBreak().equals(1)){
|
|
|
+ intelliExtend.put("no_area_break",1);
|
|
|
+ }
|
|
|
+ targetJsonObject.put("intelli_extend",intelliExtend);
|
|
|
+ }
|
|
|
+ unitParams.put("target",targetJsonObject);
|
|
|
+ return unitParams;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取定向包
|
|
|
+ *
|
|
|
+ * @param sceneId
|
|
|
+ * @param strategy
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private JSONObject getTarget(Integer sceneId,AiKuaishouAdvertiserStrategy strategy) {
|
|
|
+ JSONObject target = new JSONObject();
|
|
|
+ // 地域
|
|
|
+ String regionString = strategy.getRegion();
|
|
|
+ if (null!=regionString&&!"".equals(regionString.trim())) {
|
|
|
+ target.put("region", JSONArray.parseArray(regionString));
|
|
|
+ }
|
|
|
+ String districtIdString = strategy.getDistrictIds();
|
|
|
+ // 商圈定向
|
|
|
+ if (null!=districtIdString&&!"".equals(districtIdString.trim())) {
|
|
|
+ target.put("district_ids", JSONArray.parseArray(districtIdString));
|
|
|
+ }
|
|
|
+ // 用户类型
|
|
|
+ if (null!=strategy.getUserType()) {
|
|
|
+ target.put("user_type", strategy.getUserType());
|
|
|
+ }
|
|
|
+ //自定义年龄段
|
|
|
+ if (null!=strategy.getAgeMin() || null!=strategy.getAgeMax()) {
|
|
|
+ JSONObject age = new JSONObject();
|
|
|
+ age.put("min", strategy.getAgeMin());
|
|
|
+ age.put("max", strategy.getAgeMax());
|
|
|
+ target.put("age", age);
|
|
|
+ }
|
|
|
+ // 固定年龄段
|
|
|
+ String ageRangeString = strategy.getAgesRange();
|
|
|
+ if (null!=ageRangeString&&!"".equals(ageRangeString.trim())) {
|
|
|
+ target.put("ages_range", JSONArray.parseArray(ageRangeString));
|
|
|
+ }
|
|
|
+ // 性别
|
|
|
+ if (null!=strategy.getGender()) {
|
|
|
+ target.put("gender", strategy.getGender());
|
|
|
+ }
|
|
|
+ // 操作系统
|
|
|
+ if (null!=strategy.getPlatformOs()) {
|
|
|
+ target.put("platform_os", strategy.getPlatformOs());
|
|
|
+ }
|
|
|
+ // Android版本
|
|
|
+ if (null!=strategy.getAndroidOsv()) {
|
|
|
+ target.put("android_osv", strategy.getAndroidOsv());
|
|
|
+ }
|
|
|
+ // Android版本
|
|
|
+ if (null!=strategy.getIosOsv()) {
|
|
|
+ target.put("ios_osv", strategy.getIosOsv());
|
|
|
+ }
|
|
|
+ // 网络环境
|
|
|
+ if (null!=strategy.getNetwork()) {
|
|
|
+ target.put("network",strategy.getNetwork());
|
|
|
+ }
|
|
|
+ // 设备品牌
|
|
|
+ String deviceBrandString = strategy.getDeviceBrand();
|
|
|
+ if (null != deviceBrandString&&!"".equals(deviceBrandString.trim())) {
|
|
|
+ target.put("device_brand", JSONArray.parseArray(deviceBrandString));
|
|
|
+ }
|
|
|
+ // 设备价格
|
|
|
+ String devicePriceString = strategy.getDevicePrice();
|
|
|
+ if (null != devicePriceString&&!"".equals(devicePriceString.trim())) {
|
|
|
+ target.put("device_price", JSONArray.parseArray(devicePriceString));
|
|
|
+ }
|
|
|
+ if (sceneId != 5) {
|
|
|
+ // 商业兴趣类型
|
|
|
+ if (null!=strategy.getBusinessInterestType()) {
|
|
|
+ target.put("business_interest_type", strategy.getBusinessInterestType());
|
|
|
+ }
|
|
|
+ // 商业兴趣
|
|
|
+ String businessInterestString = strategy.getBusinessInterest();
|
|
|
+ if (null != businessInterestString&&!"".equals(businessInterestString.trim())) {
|
|
|
+ target.put("business_interest", JSONArray.parseArray(businessInterestString));
|
|
|
+ }
|
|
|
+ // 网红粉丝
|
|
|
+ String fansStarString = strategy.getFansStar();
|
|
|
+ if (null != fansStarString&&!"".equals(fansStarString.trim())) {
|
|
|
+ target.put("fans_star", JSONArray.parseArray(fansStarString));
|
|
|
+ }
|
|
|
+ // 兴趣视频用户
|
|
|
+ String interestVideoString = strategy.getInterestVideo();
|
|
|
+ if (null != interestVideoString&&!"".equals(interestVideoString.trim())) {
|
|
|
+ target.put("interest_video", JSONArray.parseArray(interestVideoString));
|
|
|
+ }
|
|
|
+ // 过滤已转化人群
|
|
|
+ if (null!=strategy.getFilterConvertedLevel()) {
|
|
|
+ target.put("filter_converted_level", strategy.getFilterConvertedLevel());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开启智能扩量
|
|
|
+ if (null!=strategy.getIsOpen()&&strategy.getIsOpen() == 1) {
|
|
|
+ JSONObject intelli_extend = new JSONObject();
|
|
|
+ intelli_extend.put("is_open", strategy.getIsOpen());
|
|
|
+ // 不可突破年龄
|
|
|
+ if (!Check.isNull(strategy.getNoAgeBreak())) {
|
|
|
+ intelli_extend.put("no_age_break", strategy.getNoAgeBreak());
|
|
|
+ }
|
|
|
+ // 不可突破性别
|
|
|
+ if (!Check.isNull(strategy.getNoGenderBreak())) {
|
|
|
+ intelli_extend.put("no_gender_break", strategy.getNoGenderBreak());
|
|
|
+ }
|
|
|
+ // 不可突破地域
|
|
|
+ if (!Check.isNull(strategy.getNoAreaBreak())) {
|
|
|
+ intelli_extend.put("no_area_break", strategy.getNoAreaBreak());
|
|
|
+ }
|
|
|
+ target.put("intelli_extend", intelli_extend); // 智能扩量
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ // APP行为-按分类
|
|
|
+ String appInterestString = strategy.getAppInterest();
|
|
|
+ if (null != appInterestString&&!"".equals(appInterestString.trim())) {
|
|
|
+ target.put("app_interest", JSONArray.parseArray(appInterestString));
|
|
|
+ }
|
|
|
+ // APP行为-按APP名称
|
|
|
+ String appIdsString = strategy.getAppIds();
|
|
|
+ if (null != appIdsString&&!"".equals(appIdsString.trim())) {
|
|
|
+ target.put("app_ids", JSONArray.parseArray(appIdsString));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 人群包定向
|
|
|
+ String populationString = strategy.getPopulation();
|
|
|
+ if (null != populationString&&!"".equals(populationString.trim())) {
|
|
|
+ target.put("population", JSONArray.parseArray(populationString));
|
|
|
+ }
|
|
|
+ // 人群包排除
|
|
|
+ String excludePopulationString = strategy.getExcludePopulation();
|
|
|
+ if (null != excludePopulationString&&!"".equals(excludePopulationString.trim())) {
|
|
|
+ target.put("exclude_population", JSONArray.parseArray(excludePopulationString));
|
|
|
+ }
|
|
|
+ // 付费人群包id
|
|
|
+ String paidAudienceString = strategy.getPaidAudience();
|
|
|
+ if (null != paidAudienceString&&!"".equals(paidAudienceString.trim())) {
|
|
|
+ target.put("paid_audience", JSONArray.parseArray(paidAudienceString));
|
|
|
+ }
|
|
|
+ if (Check.isNull(strategy.getBehaviorInterest())){
|
|
|
+ // TODO 只是单独结构体 后续需要优化
|
|
|
+ target.put("behavior_interest", JSONObject.parseObject(strategy.getBehaviorInterest()));
|
|
|
+ }
|
|
|
+ return target;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void createCreativeByImage(List<MaterialCutFrame> cutFrameList, CtopOauthToken token, JSONObject creativeParams,
|
|
|
+ Long campaignId, Long unitId, KuaiShouVideoGet videoItem,
|
|
|
+ int imageNumber){
|
|
|
+ int creativeCnt = 1;
|
|
|
+
|
|
|
+ if ((null!=cutFrameList&&!cutFrameList.isEmpty())){
|
|
|
+ for (int i = 0; i < cutFrameList.size(); i++) {
|
|
|
+ String imageCode = cutFrameList.get(i).getSignature();
|
|
|
+ String imageUrl = cutFrameList.get(i).getUrl();
|
|
|
+ String imageToken = getImageToken(imageUrl,imageCode,token.getAccountId(),token.getAccessToken());
|
|
|
+ creativeParams.put("image_token",imageToken);
|
|
|
+ createCreative(token, creativeParams, campaignId, unitId, creativeCnt,videoItem);
|
|
|
+ creativeCnt ++;
|
|
|
+ if (creativeCnt > imageNumber) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getImageToken(String imageUrl, String imageCode, Long accountId,String token){
|
|
|
+ // 根据imageUrl 和 imageCode,获取 imageToken (创建创意用)
|
|
|
+ KuaiShouImageGet imageGet = imageGetService.getOneByParams(null,imageCode);
|
|
|
+ if ((null == imageGet) || ("".equals(imageGet.getImageToken()))){
|
|
|
+ // 如果取不到image_token
|
|
|
+ // 则调用上传url的方法 kuauiShouImageUpload(url, signature, accountId, oauthToken.getAccessToken());
|
|
|
+ return materialUploadService.kuauiShouImageUpload(imageUrl,imageCode,accountId,token);
|
|
|
+ }
|
|
|
+ return imageGet.getImageToken();
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject creativeParams(CtopOauthToken token,Long unitId,KuaiShouVideoGet videoItem,AiKuaishouAdvertiserStrategy strategy){
|
|
|
+ JSONObject creativeParams = new JSONObject();
|
|
|
+ creativeParams.put("advertiser_id",token.getAccountId());
|
|
|
+ creativeParams.put("unit_id",unitId);
|
|
|
+ creativeParams.put("photo_id",videoItem.getPhotoId());
|
|
|
+ creativeParams.put("creative_material_type",videoItem.getMaterialType());
|
|
|
+ creativeParams.put("action_bar_text",strategy.getActionBarText());
|
|
|
+ creativeParams.put("description",strategy.getDescription());
|
|
|
+ // 封面广告语标题
|
|
|
+ if (!Check.isNull(strategy.getStickerTitle())) {
|
|
|
+ creativeParams.put("sticker_title", strategy.getStickerTitle());
|
|
|
+ }
|
|
|
+ // 贴纸样式类型
|
|
|
+ if (!Check.isNull(strategy.getOverlayType())) {
|
|
|
+ creativeParams.put("overlay_type", strategy.getOverlayType());
|
|
|
+ }
|
|
|
+ // 广告标签
|
|
|
+ if (!Check.isNull(strategy.getExposeTag())) {
|
|
|
+ creativeParams.put("expose_tag", strategy.getExposeTag());
|
|
|
+ }
|
|
|
+ // 广告标签2期
|
|
|
+ if (null!=strategy.getNewExposeTag()&&!"".equals(strategy.getNewExposeTag())) {
|
|
|
+ creativeParams.put("new_expose_tag", JSONArray.parseArray(strategy.getNewExposeTag()));
|
|
|
+ }
|
|
|
+ // 安卓下载中间页ID
|
|
|
+ if(null!=strategy.getSiteId()){
|
|
|
+ creativeParams.put("site_id",strategy.getSiteId());
|
|
|
+ }
|
|
|
+ if(null != strategy.getClickTrackUrl()&&!"".equals(strategy.getClickTrackUrl())){
|
|
|
+ creativeParams.put("click_track_url",strategy.getClickTrackUrl());
|
|
|
+ }
|
|
|
+ if(null != strategy.getImpressionUrl()&&!"".equals(strategy.getImpressionUrl())){
|
|
|
+ creativeParams.put("impression_url",strategy.getImpressionUrl());
|
|
|
+ }
|
|
|
+ // 第三方有效播放监测链接
|
|
|
+ if (!Check.isNull(strategy.getAdPhotoPlayedT3sUrl())) {
|
|
|
+ creativeParams.put("ad_photo_played_t3s_url", strategy.getAdPhotoPlayedT3sUrl());
|
|
|
+ }
|
|
|
+ if(null != strategy.getActionbarClickUrl()&&!"".equals(strategy.getActionbarClickUrl())){
|
|
|
+ creativeParams.put("actionbar_click_url",strategy.getActionbarClickUrl());
|
|
|
+ }
|
|
|
+ if(null!=strategy.getCreativeCategory()){
|
|
|
+ creativeParams.put("creative_category",strategy.getCreativeCategory());
|
|
|
+ }
|
|
|
+ if(null!=strategy.getCreativeTag()&&!"".equals(strategy.getCreativeTag())){
|
|
|
+ creativeParams.put("creative_tag",JSONArray.parseArray(strategy.getCreativeTag()));
|
|
|
+ }
|
|
|
+ return creativeParams;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void createCreative(CtopOauthToken token,JSONObject creativeParams,Long campaignId,Long unitId,
|
|
|
+ int creativeCnt,KuaiShouVideoGet videoGet){
|
|
|
+ creativeParams.put("creative_name","自定义创意_"+creativeCnt);
|
|
|
+ Map<String, Object> creativeCreateResult = kuaishouInterfaceService.creativeCreate
|
|
|
+ (token.getAccessToken(), token.getAccountId(), creativeParams,1);
|
|
|
+ Integer creativeCode = (Integer) creativeCreateResult.get("code");
|
|
|
+ String creativeMessage = (String) creativeCreateResult.get("message");
|
|
|
+ if(creativeCode != 0 ){
|
|
|
+ log.info("创意创建失败=>message:{}",creativeMessage);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long creativeId = (Long) creativeCreateResult.get("creativeId");
|
|
|
+ AiKuaishouStrategyMapCreative mapCreative = new AiKuaishouStrategyMapCreative();
|
|
|
+ mapCreative.setAccountId(token.getAccountId());
|
|
|
+ mapCreative.setCampaignId(campaignId);
|
|
|
+ mapCreative.setUnitId(unitId);
|
|
|
+ mapCreative.setVideoSignature(videoGet.getSignature());
|
|
|
+ mapCreative.setCreativeId(creativeId);
|
|
|
+ mapCreativeService.save(mapCreative);
|
|
|
+ }
|
|
|
+}
|