|
@@ -1604,6 +1604,121 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
+ public void getCreativeByCreativeIds(String accessToken, Long advertiserId, JSONArray creativeIds) {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_LIST;
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("advertiser_id", advertiserId);
|
|
|
+ // param.put("creative_id", creativeId);
|
|
|
+ if (!Check.isNull(creativeIds)) {
|
|
|
+ param.put("creative_ids", creativeIds);
|
|
|
+ }
|
|
|
+ param.put("page_size", 200);
|
|
|
+ param.put("page", 1);
|
|
|
+ try {
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ JSONArray details = dataJson.getJSONArray("details");
|
|
|
+ if (!Check.isNull(details)) {
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
+ JSONObject detailJson = JSONObject.parseObject(details.get(i).toString());
|
|
|
+ if (!Check.isNull(detailJson)) {
|
|
|
+ KuaiShouCreative creative = new KuaiShouCreative();
|
|
|
+ creative.setId("" + advertiserId + detailJson.getLong("creative_id"));
|
|
|
+ creative.setAccountId(advertiserId);
|
|
|
+ creative.setCampaignId(detailJson.getLong("campaign_id"));
|
|
|
+ creative.setUnitId(detailJson.getLong("unit_id"));
|
|
|
+ creative.setCreativeId(detailJson.getLong("creative_id"));
|
|
|
+ creative.setCreativeName(detailJson.getString("creative_name"));
|
|
|
+ creative.setCreativeMaterialType(detailJson.getInteger("creative_material_type"));
|
|
|
+ if (!Check.isNull(detailJson.getJSONArray("material_url"))) {
|
|
|
+ creative.setMaterialUrl(detailJson.getJSONArray("material_url").toJSONString());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(detailJson.getJSONArray("image_tokens"))) {
|
|
|
+ creative.setImageTokens(detailJson.getJSONArray("image_tokens").toJSONString());
|
|
|
+ }
|
|
|
+ creative.setStatus(detailJson.getInteger("status"));
|
|
|
+ creative.setPutStatus(detailJson.getInteger("put_status"));
|
|
|
+ creative.setCreateChannel(detailJson.getInteger("create_channel"));
|
|
|
+ creative.setReviewDetail(detailJson.getString("review_detail"));
|
|
|
+ creative.setCoverUrl(detailJson.getString("cover_url"));
|
|
|
+ creative.setImageToken(detailJson.getString("image_token"));
|
|
|
+ creative.setCoverWidth(detailJson.getString("cover_width"));
|
|
|
+ creative.setCoverHeight(detailJson.getString("cover_height"));
|
|
|
+ creative.setOverlayBgUrl(detailJson.getString("overlay_bg_url"));
|
|
|
+ creative.setOverlayBgImageToken(detailJson.getString("overlay_bg_image_token"));
|
|
|
+ creative.setStickerTitle(detailJson.getString("sticker_title"));
|
|
|
+ creative.setOverlayType(detailJson.getString("overlay_type"));
|
|
|
+ creative.setClickTrackUrl(detailJson.getString("click_track_url"));
|
|
|
+ creative.setImpressionUrl(detailJson.getString("impression_url"));
|
|
|
+ creative.setAdPhotoPlayedT3sUrl(detailJson.getString("ad_photo_played_t3s_url"));
|
|
|
+ creative.setCreativeCreateTime(detailJson.getDate("create_time"));
|
|
|
+ creative.setCreativeUpdateTime(detailJson.getDate("update_time"));
|
|
|
+ creative.setFirstFrameType(detailJson.getInteger("first_frame_type"));
|
|
|
+ creative.setShortSlogan(detailJson.getString("short_slogan"));
|
|
|
+ creative.setActionbarClickUrl(detailJson.getString("actionbar_click_url"));
|
|
|
+ JSONObject displayInfoJson = detailJson.getJSONObject("display_info");
|
|
|
+
|
|
|
+ creative.setCreativeCategory(detailJson.getInteger("creative_category"));
|
|
|
+ if (!Check.isNull(detailJson.getJSONArray("creative_tag"))) {
|
|
|
+ creative.setCreativeTag(detailJson.getJSONArray("creative_tag").toJSONString());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!Check.isNull(displayInfoJson)) {
|
|
|
+ creative.setDescription(displayInfoJson.getString("description"));
|
|
|
+ creative.setActionBarText(displayInfoJson.getString("action_bar_text"));
|
|
|
+ }
|
|
|
+ creative.setCreateTime(new Date());
|
|
|
+ creative.setUpdateTime(new Date());
|
|
|
+ creative.setSiteId(detailJson.getLong("site_id"));
|
|
|
+ creative.setPhotoId(detailJson.getString("photo_id"));
|
|
|
+ if (detailJson.getLong("photo_id") == 0) {
|
|
|
+ JSONArray photoIds = new JSONArray();
|
|
|
+ JSONObject programmed_creative_material = detailJson.getJSONObject("programmed_creative_material");
|
|
|
+ if (!Check.isNull(programmed_creative_material)) {
|
|
|
+ creative.setProgrammedCreativeMaterial(programmed_creative_material.toJSONString());
|
|
|
+ JSONArray materials = programmed_creative_material.getJSONArray("materials");
|
|
|
+ if (!Check.isNull(materials)) {
|
|
|
+ for (int j = 0; j < materials.size(); j++) {
|
|
|
+ JSONObject materialJson = materials.getJSONObject(j);
|
|
|
+ if (!Check.isNull(materialJson)) {
|
|
|
+ Long photo_id = materialJson.getLong("photo_id");
|
|
|
+ photoIds.add(String.valueOf(photo_id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ creative.setPhotoIds(photoIds.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ creativeService.saveOrUpdate(creative);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("获取广告创意组返回结果异常,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ log.error("获取广告创意返回结果异常,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取token
|
|
|
*
|
|
@@ -1863,6 +1978,85 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
|
|
|
|
|
|
@Override
|
|
|
+ public Map<String, Object> batchCreativeCreate(String accessToken, Long advertiserId, JSONObject requestJson, Integer count) {
|
|
|
+ Map<String, Object> returnMap = new HashMap<>();
|
|
|
+ try {
|
|
|
+ String url = "https://ad.e.kuaishou.com/rest/openapi/v2/creative/batch/update";
|
|
|
+ requestJson.put("advertiser_id", advertiserId);
|
|
|
+ Map<String, String> header = new HashMap<String, String>();
|
|
|
+ header.put("Content-Type", " application/json");
|
|
|
+ header.put("Access-Token", accessToken);
|
|
|
+
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), header);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ log.info("快手创建创意返回:accountId:{},返回结果{}", advertiserId, resultJson);
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ JSONArray add_creative_ids = dataJson.getJSONArray("add_creative_ids");
|
|
|
+ if (!Check.isNull(add_creative_ids)) {
|
|
|
+ Thread thread = new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ Thread.sleep(100);
|
|
|
+ getCreativeByCreativeIds(accessToken, advertiserId, add_creative_ids);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+ thread.start();
|
|
|
+ }
|
|
|
+
|
|
|
+ returnMap.put("code", 0);
|
|
|
+ returnMap.put("message", "success");
|
|
|
+ returnMap.put("success", true);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (code == 500000 && count <= 4) {
|
|
|
+ creativeCreate(accessToken, advertiserId, requestJson, count + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (code == 400001 && resultJson.getString("message").equals("/rest/openapi/v2/creative/create已超日限")) {
|
|
|
+ overRunSendMessageService.creativeOverRunSendMessage(advertiserId);
|
|
|
+ }
|
|
|
+ log.error("创建广告创意失败,advertiser_id:{},返回信息:{},入参:{}", advertiserId, resultJson, requestJson, count + 1);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", resultJson.getString("message"));
|
|
|
+ returnMap.put("desc", "创意创建失败");
|
|
|
+ returnMap.put("success", false);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (count <= 4) {
|
|
|
+ batchCreativeCreate(accessToken, advertiserId, requestJson, count + 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.error("快手创建广告创意返回内容为空,advertiser_id:{},入参:{}", advertiserId, requestJson);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "系统异常");
|
|
|
+ returnMap.put("desc", "result is null");
|
|
|
+ returnMap.put("success", false);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("创建广告创意失败,advertiser_id:{}", advertiserId);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", "Interface exception");
|
|
|
+ returnMap.put("success", false);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return returnMap;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
public Map<String, Object> videoUpload(Long advertiserId, String accessToken, String videoUrl) {
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|
|
|
try {
|
|
@@ -2620,11 +2814,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
List<KuaiShouImageGet> imageGets = new ArrayList<>();
|
|
|
for (int i = 0; i < details.size(); i++) {
|
|
|
var detailJson = details.getJSONObject(i);
|
|
|
-
|
|
|
- /* if (Check.isNull(detailJson.getString("signature"))) {
|
|
|
- continue;
|
|
|
- }*/
|
|
|
-
|
|
|
var kuaiShouImageGet = JSONObject.toJavaObject(detailJson, KuaiShouImageGet.class);
|
|
|
|
|
|
if (StringUtils.isBlank(String.valueOf(kuaiShouImageGet.getImageToken()))) {
|