|
@@ -4,8 +4,10 @@ import cn.com.ctop.common.utils.*;
|
|
|
import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResult;
|
|
|
import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
|
|
|
import cn.com.ctop.kuaishou.modules.report.entity.*;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.fasterxml.jackson.core.JsonParseException;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
@@ -15,6 +17,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.type.TypeFactory;
|
|
|
import constant.KuaishouInterfaceConstant;
|
|
|
import org.apache.http.ParseException;
|
|
|
+import org.jeecg.common.util.LoadFileUtil;
|
|
|
import org.jeecg.modules.kuaishou.entity.*;
|
|
|
import org.jeecg.modules.kuaishou.mapper.*;
|
|
|
import org.jeecg.modules.kuaishou.service.IKuaishouInterfaceService;
|
|
@@ -38,6 +41,7 @@ import java.io.IOException;
|
|
|
import java.lang.reflect.ParameterizedType;
|
|
|
import java.lang.reflect.Type;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -46,7 +50,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(KuaishouInterfaceServiceImpl.class);
|
|
|
|
|
|
|
|
|
- @Override
|
|
|
public KuaishouResult<KuaishouReportHourlyAccount> getAccountHourlyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.ACCOUNT_REPORT;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
@@ -76,7 +79,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
return kuaishouResult;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
public KuaishouResult<KuaishouReportDailyAccount> getAccountDailyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.ACCOUNT_REPORT;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
@@ -103,7 +105,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
return kuaishouResult;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
public KuaishouResult<KuaishouReportDailyCampaign> getCampaignDailyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_REPORT;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
@@ -130,7 +131,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
return kuaishouResult;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
public KuaishouResult<KuaishouReportHourlyCampaign> getCampaignHourlyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_REPORT;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
@@ -157,7 +157,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
return kuaishouResult;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
public KuaishouResult<KuaishouReportDailyGroup> getGroupDailyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GTOUP_REPORT;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
@@ -184,7 +183,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
return kuaishouResult;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
public KuaishouResult<KuaishouReportHourlyGroup> getGroupHourlyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.GTOUP_REPORT;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
@@ -211,7 +209,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
return kuaishouResult;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
public KuaishouResult<KuaishouReportDailyCreative> getCreativeDailyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_REPORT;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
@@ -238,7 +235,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
return kuaishouResult;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
public KuaishouResult<KuaishouReportHourlyCreative> getCreativeHourlyReport(String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_REPORT;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
@@ -304,6 +300,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
}
|
|
|
returnMap.put("code", 0);
|
|
|
returnMap.put("message", "success");
|
|
|
+ returnMap.put("campaign_id", campaign_id);
|
|
|
|
|
|
} else {
|
|
|
logger.error("创建广告信息失败,advertiser_id:{},返回信息:{}", advertiser_id, resultJson);
|
|
@@ -353,14 +350,12 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
try {
|
|
|
if (Check.isNull(requestJson)) {
|
|
|
throw new Exception("参数不能为空");
|
|
|
-
|
|
|
}
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.AD_UNIT_CREATE;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
|
requestJson.put("advertiser_id", advertiser_id);
|
|
|
headers.put("Access-Token", accessToken);
|
|
|
headers.put("Content-Type", " application/json");
|
|
|
-
|
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
if (!Check.isNull(resultJson)) {
|
|
@@ -414,6 +409,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
|
|
|
returnMap.put("code", 0);
|
|
|
returnMap.put("message", "success");
|
|
|
+ returnMap.put("unitId", unitId);
|
|
|
}
|
|
|
|
|
|
} else {
|
|
@@ -744,18 +740,20 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
private KuaiShouConversionTypesMapper conversionTypesMapper;
|
|
|
|
|
|
@Override
|
|
|
- public void getDeepConversionInfos(Long advertiserId, String accessToken) {
|
|
|
+ public Map<String, Object> getDeepConversionInfos(Long advertiserId, String accessToken) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.DEEP_CONVERSION_INFOS;
|
|
|
JSONObject param = new JSONObject();
|
|
|
param.put("advertiser_id", advertiserId);
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
|
headers.put("Access-Token", accessToken);
|
|
|
headers.put("Content-Type", " application/json");
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
try {
|
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
if (!Check.isNullMap(resultJson)) {
|
|
|
Integer code = resultJson.getInteger("code");
|
|
|
+ boolean isActivate = false;
|
|
|
if (code == 0) {
|
|
|
Map<String, Object> deleteMap = new HashMap<>();
|
|
|
deleteMap.put("account_id", advertiserId);
|
|
@@ -765,7 +763,11 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
if (!Check.isNullMap(dataJson)) {
|
|
|
KuaiShouConversionInfos conversionInfos = new KuaiShouConversionInfos();
|
|
|
conversionInfos.setAccountId(advertiserId);
|
|
|
- conversionInfos.setIsActivate(dataJson.getInteger("is_activate"));
|
|
|
+ Integer is_activate = dataJson.getInteger("is_activate");
|
|
|
+ if (is_activate == 1) {
|
|
|
+ isActivate = true;
|
|
|
+ }
|
|
|
+ conversionInfos.setIsActivate(is_activate);
|
|
|
conversionInfos.setIsFormSubmit(dataJson.getInteger("is_form_submit"));
|
|
|
conversionInfosMapper.insert(conversionInfos);
|
|
|
JSONArray ConversionTypeArr = dataJson.getJSONArray("deep_conversion_types");
|
|
@@ -783,19 +785,32 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ resultMap.put("code", 0);
|
|
|
+ resultMap.put("success", true);
|
|
|
+ resultMap.put("isActivate", isActivate);
|
|
|
+
|
|
|
} else {
|
|
|
logger.error("获取可选的深度转化类型返回异常,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+ resultMap.put("code", -1);
|
|
|
+ resultMap.put("success", false);
|
|
|
+ resultMap.put("message", "获取可选的深度转化类型返回异常");
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
logger.error("快手,获取可选的深度转化类型返回为空,advertiserId:{}", advertiserId);
|
|
|
+ resultMap.put("code", -1);
|
|
|
+ resultMap.put("success", false);
|
|
|
+ resultMap.put("message", "获取可选的深度转化类型返回为空");
|
|
|
}
|
|
|
|
|
|
- } catch (
|
|
|
- Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ resultMap.put("code", -1);
|
|
|
+ resultMap.put("success", false);
|
|
|
+ resultMap.put("message", "接口异常");
|
|
|
}
|
|
|
+ return resultMap;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -813,7 +828,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
public Map<String, Object> creativeCreate(String accessToken, Long advertiserId, JSONObject requestJson) {
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|
|
|
try {
|
|
|
- String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_CREATE;
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.AD_CREATIVE_CREATE;
|
|
|
requestJson.put("advertiser_id", advertiserId);
|
|
|
Map<String, String> header = new HashMap<String, String>();
|
|
|
header.put("Content-Type", " application/json");
|
|
@@ -877,56 +892,83 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
private KuaiShouVideoUploadMapper videoUploadMapper;
|
|
|
|
|
|
@Override
|
|
|
- public void videoUpload(Long advertiserId, String accessToken, MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
+ public Map<String, Object> videoUpload(Long advertiserId, String accessToken, String videoUrl) {
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|
|
|
try {
|
|
|
- String savaPath = "D:\\tets1";
|
|
|
- FileUploadTool fileUploadTool = new FileUploadTool();
|
|
|
- FileEntity entity;
|
|
|
- entity = fileUploadTool.createFile(multipartFile, request, savaPath);
|
|
|
- if (!Check.isNull(entity)) {
|
|
|
- String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.VIDEO_UPLOAD;
|
|
|
- JSONObject requestJson = new JSONObject();
|
|
|
- requestJson.put("advertiser_id", advertiserId);
|
|
|
- Map<String, String> headerMap = new HashMap<String, String>();
|
|
|
- headerMap.put("Access-Token", accessToken);
|
|
|
- headerMap.put("Content-Type", "multipart/form-data");
|
|
|
- String result = exceptInfoForRestTemplate(url, requestJson, headerMap, entity.getPath());
|
|
|
- JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
- if (!Check.isNull(result)) {
|
|
|
- Integer code = resultJson.getInteger("code");
|
|
|
- if (code == 0) {
|
|
|
- JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
- if (!Check.isNull(dataJson)) {
|
|
|
- KuaiShouVideoUpload videoUpload = new KuaiShouVideoUpload();
|
|
|
- videoUpload.setPhotoId(dataJson.getString("photo_id"));
|
|
|
- videoUpload.setAccountId(advertiserId);
|
|
|
- videoUpload.setSavaPath(entity.getPath());
|
|
|
- videoUpload.setSize(entity.getSize());
|
|
|
- videoUpload.setType(entity.getType());
|
|
|
- videoUpload.setUploadTime(DateUtils.timeStamp2Date(entity.getUploadTime()));
|
|
|
- int i = videoUploadMapper.insert(videoUpload);
|
|
|
- if (i > 0) {
|
|
|
- logger.info("上传快手视频完成");
|
|
|
- }
|
|
|
+ QueryWrapper<KuaiShouVideoUpload> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("account_id", advertiserId).eq("sava_path", videoUrl).orderByDesc("create_time");
|
|
|
+ wrapper.last("limit 1");
|
|
|
+ KuaiShouVideoUpload videoUpload = videoUploadMapper.selectOne(wrapper);
|
|
|
+ if (!Check.isNull(videoUpload)) {
|
|
|
+ returnMap.put("code", 0);
|
|
|
+ returnMap.put("message", "视频已上传文件");
|
|
|
+ returnMap.put("success", true);
|
|
|
+ returnMap.put("photoId", videoUpload.getPhotoId());
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+ String localUrl = LoadFileUtil.downLoadFromUrl(videoUrl, PropertiesUtils.getValue("kuaishou_config", "video_sava_path"));
|
|
|
+ if (Check.isNull(localUrl)) {
|
|
|
+ logger.error("下载文件到本地文件夹失败,filePath:{},accountId:{}", videoUrl, advertiserId);
|
|
|
+ throw new Exception("下载文件到本地失败");
|
|
|
+ }
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.VIDEO_UPLOAD;
|
|
|
+ JSONObject requestJson = new JSONObject();
|
|
|
+ requestJson.put("advertiser_id", advertiserId);
|
|
|
+ Map<String, String> headerMap = new HashMap<String, String>();
|
|
|
+ headerMap.put("Access-Token", accessToken);
|
|
|
+ headerMap.put("Content-Type", "multipart/form-data");
|
|
|
+ String result = exceptInfoForRestTemplate(url, requestJson, headerMap, localUrl);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(result)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ KuaiShouVideoUpload kuaiShouVideoUpload = new KuaiShouVideoUpload();
|
|
|
+ kuaiShouVideoUpload.setPhotoId(dataJson.getString("photo_id"));
|
|
|
+ kuaiShouVideoUpload.setAccountId(advertiserId);
|
|
|
+ kuaiShouVideoUpload.setSavaPath(videoUrl);
|
|
|
+ kuaiShouVideoUpload.setSize(null);
|
|
|
+ kuaiShouVideoUpload.setType(null);
|
|
|
+ kuaiShouVideoUpload.setUploadTime(DateUtils.timeStamp2Date(System.currentTimeMillis()));
|
|
|
+ int i = videoUploadMapper.insert(kuaiShouVideoUpload);
|
|
|
+ if (i > 0) {
|
|
|
+ logger.info("上传快手视频完成");
|
|
|
}
|
|
|
- } else {
|
|
|
- logger.error("快手上传视频返回信息异常 ,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+ returnMap.put("code", 0);
|
|
|
+ returnMap.put("message", "视频已上传文件");
|
|
|
+ returnMap.put("success", true);
|
|
|
+ returnMap.put("photoId", dataJson.getString("photo_id"));
|
|
|
+ return returnMap;
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
- logger.error("快手上传视频返回信息为空,advertiserId:{}", advertiserId);
|
|
|
+ logger.error("快手上传视频返回信息异常 ,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "视频上传失败");
|
|
|
+ returnMap.put("success", false);
|
|
|
+ return returnMap;
|
|
|
}
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("快手上传视频返回信息为空,advertiserId:{}", advertiserId);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "视频上传失败");
|
|
|
+ returnMap.put("success", false);
|
|
|
+ return returnMap;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
logger.error("上传视频失败,advertiser_id:{}", advertiserId);
|
|
|
+
|
|
|
+ e.printStackTrace();
|
|
|
returnMap.put("code", -1);
|
|
|
returnMap.put("message", "error");
|
|
|
returnMap.put("desc", "Interface exception");
|
|
|
- e.printStackTrace();
|
|
|
+ returnMap.put("success", false);
|
|
|
+ return returnMap;
|
|
|
}
|
|
|
-
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1120,51 +1162,75 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
private KuaiShouImageUploandMapper imageUploandMapper;
|
|
|
|
|
|
@Override
|
|
|
- public void imageUpload(Long advertiserId, String accessToken, MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
+ public Map<String, Object> imageUpload(Long advertiserId, String accessToken, String filePath, Integer type) {
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|
|
|
try {
|
|
|
- String savaPath = "D:\\tets1\\image";
|
|
|
- FileUploadTool fileUploadTool = new FileUploadTool();
|
|
|
- FileEntity entity;
|
|
|
- entity = fileUploadTool.createFile(multipartFile, request, savaPath);
|
|
|
-
|
|
|
- if (!Check.isNull(entity)) {
|
|
|
- String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
|
|
|
- JSONObject requestJson = new JSONObject();
|
|
|
- requestJson.put("advertiser_id", advertiserId);
|
|
|
- Map<String, String> headerMap = new HashMap<String, String>();
|
|
|
- headerMap.put("Content-Type", "multipart/form-data");
|
|
|
- headerMap.put("Access-Token", accessToken);
|
|
|
- String result = exceptInfoForRestTemplate(url, requestJson, headerMap, entity.getPath());
|
|
|
- JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
- if (!Check.isNull(result)) {
|
|
|
- Integer code = resultJson.getInteger("code");
|
|
|
- if (code == 0) {
|
|
|
- JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
- if (!Check.isNull(dataJson)) {
|
|
|
- KuaiShouImageUploand imageUploand = new KuaiShouImageUploand();
|
|
|
- imageUploand.setAccountId(advertiserId);
|
|
|
- imageUploand.setSavaPath(entity.getPath());
|
|
|
- imageUploand.setUploadTime(DateUtils.timeStamp2Date(entity.getUploadTime()));
|
|
|
- imageUploand.setUrl(dataJson.getString("url"));
|
|
|
- imageUploand.setImageToken(dataJson.getString("image_token"));
|
|
|
- imageUploand.setHeight(dataJson.getLong("height"));
|
|
|
- imageUploand.setSize(dataJson.getLong("size"));
|
|
|
- imageUploand.setFormat(dataJson.getString("format"));
|
|
|
- imageUploand.setWidth(dataJson.getLong("width"));
|
|
|
- int i = imageUploandMapper.insert(imageUploand);
|
|
|
- if (i > 0) {
|
|
|
- logger.info("快手-图片上传成功");
|
|
|
- }
|
|
|
+ QueryWrapper<KuaiShouImageUploand> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("account_id", advertiserId).eq("sava_path", filePath).orderByDesc("create_time");
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
+ KuaiShouImageUploand kuaiShouImageUploand = imageUploandMapper.selectOne(queryWrapper);
|
|
|
+ if (!Check.isNull(kuaiShouImageUploand)) {
|
|
|
+ returnMap.put("code", 0);
|
|
|
+ returnMap.put("message", "图片已上传文件已上传");
|
|
|
+ returnMap.put("success", true);
|
|
|
+ returnMap.put("imageToken", kuaiShouImageUploand.getImageToken());
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+ String localUrl = LoadFileUtil.downLoadFromUrl(filePath, PropertiesUtils.getValue("kuaishou_config", "image_sava_path"));
|
|
|
+ if (Check.isNull(localUrl)) {
|
|
|
+ logger.error("下载文件到本地文件夹失败,filePath:{},accountId:{}", filePath, advertiserId);
|
|
|
+ throw new Exception("下载文件到本地失败");
|
|
|
+ }
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_UPLOAD;
|
|
|
+ JSONObject requestJson = new JSONObject();
|
|
|
+ requestJson.put("advertiser_id", advertiserId);
|
|
|
+ requestJson.put("type", type);
|
|
|
+ Map<String, String> headerMap = new HashMap<String, String>();
|
|
|
+ headerMap.put("Content-Type", "multipart/form-data");
|
|
|
+ headerMap.put("Access-Token", accessToken);
|
|
|
+ String result = exceptInfoForRestTemplate(url, requestJson, headerMap, localUrl);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(result)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ KuaiShouImageUploand imageUploand = new KuaiShouImageUploand();
|
|
|
+ imageUploand.setAccountId(advertiserId);
|
|
|
+ imageUploand.setSavaPath(filePath);
|
|
|
+ imageUploand.setUploadTime(new Date().toString());
|
|
|
+ imageUploand.setUrl(dataJson.getString("url"));
|
|
|
+ imageUploand.setImageToken(dataJson.getString("image_token"));
|
|
|
+ imageUploand.setHeight(dataJson.getLong("height"));
|
|
|
+ imageUploand.setSize(dataJson.getLong("size"));
|
|
|
+ imageUploand.setFormat(dataJson.getString("format"));
|
|
|
+ imageUploand.setWidth(dataJson.getLong("width"));
|
|
|
+ int i = imageUploandMapper.insert(imageUploand);
|
|
|
+ if (i > 0) {
|
|
|
+ logger.info("快手-图片上传成功");
|
|
|
}
|
|
|
-
|
|
|
- } else {
|
|
|
- logger.error("快手上传图片返回信息异常 ,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+ returnMap.put("code", 0);
|
|
|
+ returnMap.put("desc", "上传图片完成");
|
|
|
+ returnMap.put("imageToken", dataJson.getString("image_token"));
|
|
|
+ return returnMap;
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- logger.error("快手上传图片返回信息为空,advertiserId:{}", advertiserId);
|
|
|
+ logger.error("快手上传图片返回信息异常 ,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", resultJson.getString("message"));
|
|
|
}
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("快手上传图片返回信息为空,advertiserId:{}", advertiserId);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", "上传失败");
|
|
|
+ }
|
|
|
+ boolean trueOrFalse = LoadFileUtil.delFile(localUrl);
|
|
|
+ if (trueOrFalse) {
|
|
|
+ logger.info("删除本地文件成功,accountId:{}", advertiserId);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error("上传图片失败,advertiser_id:{}", advertiserId);
|
|
@@ -1173,6 +1239,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
returnMap.put("desc", "Interface exception");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ return returnMap;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1188,50 +1255,76 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
private KuaiShouAppCreateMapper appCreateMapper;
|
|
|
|
|
|
@Override
|
|
|
- public void appCreate(Long advertiserId, String accessToken, MultipartFile multipartFile, HttpServletRequest request, JSONObject requestJson) {
|
|
|
+ public Map<String, Object> appCreate(Long advertiserId, String accessToken, JSONObject requestJson) {
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|
|
|
try {
|
|
|
- String savaPath = "D:\\tets1\\app";
|
|
|
- FileUploadTool fileUploadTool = new FileUploadTool();
|
|
|
- FileEntity entity;
|
|
|
- entity = fileUploadTool.createFile(multipartFile, request, savaPath);
|
|
|
- if (!Check.isNull(entity)) {
|
|
|
- String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.APP_CREATE;
|
|
|
- Map<String, String> header = new HashMap<String, String>();
|
|
|
- header.put("Content-Type", "multipart/form-data");
|
|
|
- header.put("Access-Token", accessToken);
|
|
|
- String result = exceptInfoForRestTemplate(url, requestJson, header, entity.getPath());
|
|
|
- JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
- if (!Check.isNull(result)) {
|
|
|
- Integer code = resultJson.getInteger("code");
|
|
|
- if (code == 0) {
|
|
|
- JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
- if (!Check.isNull(dataJson)) {
|
|
|
- KuaiShouAppCreate appCreate = new KuaiShouAppCreate();
|
|
|
- appCreate.setAccountId(advertiserId);
|
|
|
- appCreate.setSavaPath(entity.getPath());
|
|
|
- appCreate.setUrl(requestJson.getString("url"));// 上传应用地址
|
|
|
- appCreate.setAppVersion(requestJson.getString("app_version"));
|
|
|
- appCreate.setAppName(requestJson.getString("app_name"));
|
|
|
- appCreate.setImageToken(requestJson.getString("image_token"));
|
|
|
- appCreate.setPackageName(requestJson.getString("package_name"));
|
|
|
- appCreate.setPlatform(requestJson.getInteger("platform"));
|
|
|
- appCreate.setReturnUrl(dataJson.getString("url"));
|
|
|
- appCreate.setAppId(dataJson.getLong("app_id"));
|
|
|
- appCreate.setUploadTime(DateUtils.timeStamp2Date(entity.getUploadTime()));
|
|
|
- int i = appCreateMapper.insert(appCreate);
|
|
|
- if (i > 0) {
|
|
|
- logger.info("快手创建应用成功");
|
|
|
- }
|
|
|
+ String filePath = requestJson.getString("file");
|
|
|
+
|
|
|
+ QueryWrapper<KuaiShouAppCreate> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("account_id", advertiserId).eq("sava_path", filePath).orderByDesc("create_time");
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
+ KuaiShouAppCreate kuaiShouAppCreate = appCreateMapper.selectOne(queryWrapper);
|
|
|
+ if (!Check.isNull(kuaiShouAppCreate)) {
|
|
|
+ returnMap.put("code", 0);
|
|
|
+ returnMap.put("message", "文件已上传");
|
|
|
+ returnMap.put("success", true);
|
|
|
+ returnMap.put("appId", kuaiShouAppCreate.getAppId());
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+ String localUrl = LoadFileUtil.downLoadFromUrl(filePath, PropertiesUtils.getValue("kuaishou_config", "apk_sava_path"));
|
|
|
+ if (Check.isNull(localUrl)) {
|
|
|
+ logger.error("下载文件到本地文件夹失败,filePath:{},accountId:{}", filePath, advertiserId);
|
|
|
+ throw new Exception("下载文件到本地失败");
|
|
|
+ }
|
|
|
+ requestJson.put("advertiser_id", advertiserId);
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.APP_CREATE;
|
|
|
+ Map<String, String> header = new HashMap<String, String>();
|
|
|
+ header.put("Content-Type", "multipart/form-data");
|
|
|
+ header.put("Access-Token", accessToken);
|
|
|
+ String result = exceptInfoForRestTemplate(url, requestJson, header, localUrl);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(result)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ KuaiShouAppCreate appCreate = new KuaiShouAppCreate();
|
|
|
+ appCreate.setAccountId(advertiserId);
|
|
|
+ appCreate.setSavaPath(filePath);
|
|
|
+ appCreate.setUrl(requestJson.getString("url"));// 上传应用地址
|
|
|
+ appCreate.setAppVersion(requestJson.getString("app_version"));
|
|
|
+ appCreate.setAppName(requestJson.getString("app_name"));
|
|
|
+ appCreate.setImageToken(requestJson.getString("image_token"));
|
|
|
+ appCreate.setPackageName(requestJson.getString("package_name"));
|
|
|
+ appCreate.setPlatform(requestJson.getInteger("platform"));
|
|
|
+ appCreate.setReturnUrl(dataJson.getString("url"));
|
|
|
+ appCreate.setAppId(dataJson.getLong("app_id"));
|
|
|
+ appCreate.setUploadTime(new Date().toString());
|
|
|
+ int i = appCreateMapper.insert(appCreate);
|
|
|
+ if (i > 0) {
|
|
|
+ logger.info("快手创建应用成功");
|
|
|
}
|
|
|
-
|
|
|
- } else {
|
|
|
- logger.error("快手创建应用返回信息异常 ,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+ returnMap.put("code", 0);
|
|
|
+ returnMap.put("message", "success");
|
|
|
+ returnMap.put("appId", dataJson.getLong("app_id"));
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- logger.error("快手创建应用返回信息为空,advertiserId:{}", advertiserId);
|
|
|
+ logger.error("快手创建应用返回信息异常 ,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", "Interface exception");
|
|
|
}
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("快手创建应用返回信息为空,advertiserId:{}", advertiserId);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", "Interface exception");
|
|
|
+ }
|
|
|
+ boolean trueOrFalse = LoadFileUtil.delFile(localUrl);
|
|
|
+ if (trueOrFalse) {
|
|
|
+ logger.info("删除本地文件成功,accountId:{}", advertiserId);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
logger.error("创建应用失败,advertiser_id:{}", advertiserId);
|
|
@@ -1240,8 +1333,76 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
returnMap.put("desc", "Interface exception");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> urlAppCreate(Long accountId, String accessToken, JSONObject apkJson) {
|
|
|
+ Map<String, Object> returnMap = new HashMap<>();
|
|
|
+ try {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.APP_CREATE;
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", "multipart/form-data");
|
|
|
+ apkJson.put("advertiser_id", accountId + "");
|
|
|
+ String result = exceptInfoForRestTemplate(url, apkJson, headers, null);
|
|
|
+ System.err.println(apkJson);
|
|
|
+ System.err.println(url);
|
|
|
+ System.err.println(JSON.toJSONString(headers));
|
|
|
+
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(result)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ KuaiShouAppCreate appCreate = new KuaiShouAppCreate();
|
|
|
+ appCreate.setAccountId(accountId);
|
|
|
+ appCreate.setUrl(apkJson.getString("url"));
|
|
|
+ appCreate.setPackageName(apkJson.getString("package_name"));
|
|
|
+ appCreate.setPlatform(apkJson.getInteger("platform"));
|
|
|
+ appCreate.setReturnUrl(dataJson.getString("url"));
|
|
|
+ appCreate.setAppId(dataJson.getLong("app_id"));
|
|
|
+ appCreate.setAppVersion(apkJson.getString("app_version"));
|
|
|
+
|
|
|
+ appCreate.setImageToken(apkJson.getString("image_token"));
|
|
|
+ appCreate.setAppName(apkJson.getString("app_name"));
|
|
|
+ int i = appCreateMapper.insert(appCreate);
|
|
|
+ if (i > 0) {
|
|
|
+ logger.info("快手创建应用成功");
|
|
|
+ }
|
|
|
+ returnMap.put("code", 0);
|
|
|
+ returnMap.put("message", "success");
|
|
|
+ returnMap.put("appId", dataJson.getLong("app_id"));
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("快手创建应用返回信息异常 ,advertiserId:{},异常信息:{}", accountId, resultJson);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", "Interface exception");
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("快手创建应用返回信息为空,advertiserId:{}", accountId);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", "Interface exception");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("创建应用失败,advertiser_id:{}", accountId);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", "Interface exception");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return returnMap;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 获取应用列表
|
|
|
*
|
|
@@ -1350,13 +1511,15 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
@Autowired
|
|
|
private RestTemplate rest;
|
|
|
|
|
|
- @Override
|
|
|
public String exceptInfoForRestTemplate(String url, Map<String, Object> paramMap, Map<String, String> headerMap, String filePath) throws ParseException {
|
|
|
|
|
|
try {
|
|
|
- FileSystemResource resource = new FileSystemResource(new File(filePath));
|
|
|
MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
|
|
|
- param.add("file", resource);
|
|
|
+ if (!Check.isNull(filePath)) {
|
|
|
+ FileSystemResource resource = new FileSystemResource(new File(filePath));
|
|
|
+ param.add("file", resource);
|
|
|
+ }
|
|
|
+
|
|
|
if (!Check.isNullMap(paramMap)) {
|
|
|
for (String key : paramMap.keySet()) {
|
|
|
param.add(key, paramMap.get(key));
|