|
@@ -1,8 +1,6 @@
|
|
|
package org.jeecg.modules.kuaishou.service.impl;
|
|
|
|
|
|
-import cn.com.ctop.common.utils.Check;
|
|
|
-import cn.com.ctop.common.utils.HttpUtils;
|
|
|
-import cn.com.ctop.common.utils.PropertiesUtils;
|
|
|
+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.*;
|
|
@@ -16,26 +14,28 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.type.TypeFactory;
|
|
|
import constant.KuaishouInterfaceConstant;
|
|
|
-import org.apache.http.HttpEntity;
|
|
|
-import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
-import org.apache.http.client.methods.HttpPost;
|
|
|
-import org.apache.http.entity.StringEntity;
|
|
|
-import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
-import org.apache.http.impl.client.HttpClients;
|
|
|
-import org.apache.http.util.EntityUtils;
|
|
|
+import org.apache.http.ParseException;
|
|
|
import org.jeecg.modules.kuaishou.entity.*;
|
|
|
import org.jeecg.modules.kuaishou.mapper.*;
|
|
|
import org.jeecg.modules.kuaishou.service.IKuaishouInterfaceService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.io.FileSystemResource;
|
|
|
+import org.springframework.http.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.servlet.ServletException;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.lang.reflect.ParameterizedType;
|
|
|
import java.lang.reflect.Type;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
@@ -279,6 +279,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_CREATE;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
|
headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
requestJson.put("advertiser_id", advertiser_id);
|
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
@@ -337,23 +338,79 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
* @return
|
|
|
*/
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouGroupCreateTargetMapper groupCreateTargetMapper;
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouGroupCreateMapper groupCreateMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public Map<String, Object> adUnitCreate(String accessToken, Long advertiser_id, JSONObject requestJson) {
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|
|
|
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)) {
|
|
|
Integer code = resultJson.getInteger("code");
|
|
|
if (code == 0) {
|
|
|
- //TODO 未写完--------------------------
|
|
|
- returnMap.put("code", 0);
|
|
|
- returnMap.put("message", "success");
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ KuaiShouGroupCreate groupCreate = new KuaiShouGroupCreate();
|
|
|
+ Long unitId = dataJson.getLong("unit_id");
|
|
|
+ groupCreate.setUnitId(unitId);
|
|
|
+ groupCreate.setAccountId(advertiser_id);
|
|
|
+ groupCreate.setCampaignId(requestJson.getLong("campaign_id"));
|
|
|
+ groupCreate.setUnitName(requestJson.getString("unit_name"));
|
|
|
+ groupCreate.setBidType(requestJson.getInteger("bid_type"));
|
|
|
+ groupCreate.setBid(requestJson.getInteger("bid"));
|
|
|
+ groupCreate.setCpaBid(requestJson.getInteger("cpa_bid"));
|
|
|
+ groupCreate.setOcpxActionType(requestJson.getInteger("ocpx_action_type"));
|
|
|
+ groupCreate.setDeepConversionType(requestJson.getInteger("deep_conversion_type"));
|
|
|
+ groupCreate.setPage(requestJson.getInteger("page"));
|
|
|
+ groupCreate.setBeginTime(requestJson.getString("begin_time"));
|
|
|
+ groupCreate.setEndTime(requestJson.getString("end_time"));
|
|
|
+ groupCreate.setScheduleTime(requestJson.getString("schedule_time"));
|
|
|
+ groupCreate.setDayBudget(requestJson.getLong("day_budget"));
|
|
|
+ groupCreate.setUrlType(requestJson.getInteger("url_type"));
|
|
|
+ groupCreate.setUrl(requestJson.getString("url"));
|
|
|
+ groupCreate.setAppId(requestJson.getLong("app_id"));
|
|
|
+ groupCreate.setShowModel(requestJson.getInteger("show_mode"));
|
|
|
+ groupCreate.setSpeed(requestJson.getInteger("speed"));
|
|
|
+ groupCreateMapper.insert(groupCreate);
|
|
|
+ //定向信息
|
|
|
+ JSONObject targetJson = requestJson.getJSONObject("target");
|
|
|
+ if (!Check.isNull(targetJson)) {
|
|
|
+ KuaiShouGroupCreateTarget groupCreateTarget = new KuaiShouGroupCreateTarget();
|
|
|
+ groupCreateTarget.setAccountId(advertiser_id);
|
|
|
+ groupCreateTarget.setUnitId(unitId);
|
|
|
+ groupCreateTarget.setRegion(targetJson.getJSONArray("region"));
|
|
|
+ JSONObject ageJson = targetJson.getJSONObject("age");
|
|
|
+ if (!Check.isNull(ageJson)) {
|
|
|
+ groupCreateTarget.setAgeMin(ageJson.getInteger("min"));
|
|
|
+ groupCreateTarget.setAgeMax(ageJson.getInteger("max"));
|
|
|
+ }
|
|
|
+ groupCreateTarget.setGender(targetJson.getInteger("gender"));
|
|
|
+ groupCreateTarget.setPlatformOs(targetJson.getInteger("platform_os"));
|
|
|
+ groupCreateTarget.setAndroidOsv(targetJson.getInteger("android_osv"));
|
|
|
+ groupCreateTarget.setIosOsv(targetJson.getInteger("ios_osv"));
|
|
|
+ groupCreateTarget.setNetwork(targetJson.getInteger("network"));
|
|
|
+ groupCreateTarget.setDeviceBrand(targetJson.getInteger("device_brand"));
|
|
|
+ groupCreateTarget.setDevicePrice(targetJson.getJSONArray("device_price"));
|
|
|
+ groupCreateTargetMapper.insert(groupCreateTarget);
|
|
|
+ }
|
|
|
+
|
|
|
+ returnMap.put("code", 0);
|
|
|
+ returnMap.put("message", "success");
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
logger.error("创建广告信息失败,advertiser_id:{},返回信息:{}", advertiser_id, resultJson);
|
|
@@ -403,6 +460,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_LIST;
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
JSONObject param = new JSONObject();
|
|
|
param.put("advertiser_id", advertiserId);
|
|
|
param.put("page", page);
|
|
@@ -460,6 +518,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
private KuaiShouGroupMapper groupMapper;
|
|
|
@Autowired
|
|
|
private KuaiShouAppInfoMapper appInfoMapper;
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouScheduleMapper shouScheduleMapper;
|
|
|
|
|
|
@Override
|
|
|
public void getGroupList(String accessToken, Long advertiserId, Integer page) {
|
|
@@ -476,6 +536,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
param.put("page", page);
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
try {
|
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
@@ -512,7 +573,6 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
group.setAppId(detail.getLong("app_id"));
|
|
|
group.setAppIconUrl(detail.getString("app_icon_url"));
|
|
|
groupMapper.insert(group);
|
|
|
-
|
|
|
// 添加应用信息
|
|
|
JSONObject diverseJson = detail.getJSONObject("diverse_data");
|
|
|
if (!Check.isNull(diverseJson)) {
|
|
@@ -524,10 +584,23 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
appInfo.setUnitId(unitId);
|
|
|
appInfoMapper.insert(appInfo);
|
|
|
}
|
|
|
+ //时间段信息
|
|
|
+ JSONObject scheduleJson = detail.getJSONObject("schedule");
|
|
|
+ if (!Check.isNull(scheduleJson)) {
|
|
|
+ KuaiShouSchedule schedule = new KuaiShouSchedule();
|
|
|
+ schedule.setUnitId(unitId);
|
|
|
+ schedule.setMon(scheduleJson.getJSONArray("mon").toJSONString());
|
|
|
+ schedule.setTues(scheduleJson.getJSONArray("tues").toJSONString());
|
|
|
+ schedule.setWed(scheduleJson.getJSONArray("wed").toJSONString());
|
|
|
+ schedule.setThur(scheduleJson.getJSONArray("thur").toJSONString());
|
|
|
+ schedule.setFri(scheduleJson.getJSONArray("fri").toJSONString());
|
|
|
+ schedule.setSat(scheduleJson.getJSONArray("sat").toJSONString());
|
|
|
+ schedule.setSun(scheduleJson.getJSONArray("sun").toJSONString());
|
|
|
+ shouScheduleMapper.insert(schedule);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
getGroupList(accessToken, advertiserId, page + 1);
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -565,7 +638,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
|
|
|
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("Content-Type", " application/json");
|
|
|
headers.put("Access-Token", accessToken);
|
|
|
JSONObject param = new JSONObject();
|
|
|
param.put("advertiser_id", advertiserId);
|
|
@@ -638,6 +711,10 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
requestJson.put("auth_code", authCode);
|
|
|
requestJson.put("app_id", PropertiesUtils.getConfig("kuaishou_appid"));
|
|
|
requestJson.put("secret", PropertiesUtils.getConfig("kuaishou_secret"));
|
|
|
+
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
+
|
|
|
KuaishouResultToken kuaiShouResult = null;
|
|
|
try {
|
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), null);
|
|
@@ -661,7 +738,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
public KuaishouResultToken getRefreshToken(String refreshToken) {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.REFRESH_TOKEN;
|
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
|
- headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
Map<String, Object> param = new HashMap<String, Object>();
|
|
|
param.put("app_id", PropertiesUtils.getConfig("kuaishou_appid"));
|
|
|
param.put("secret", PropertiesUtils.getConfig("kuaishou_secret"));
|
|
@@ -669,16 +746,600 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
KuaishouResultToken kuaishouResult = null;
|
|
|
try {
|
|
|
String result = HttpUtils.httpPostRequest(url, param, headers);
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
|
- kuaishouResult = mapper.readValue(result, new TypeReference<KuaishouResultToken>() {
|
|
|
- });
|
|
|
+ System.err.println(result);
|
|
|
+ JSONObject tokenJson = new JSONObject();
|
|
|
+ if (!Check.isNullMap(tokenJson)) {
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("重新获取token返回结果为空");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return kuaishouResult;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取可选的深度转化类型
|
|
|
+ *
|
|
|
+ * @param advertiserId
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouConversionInfosMapper conversionInfosMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouConversionTypesMapper conversionTypesMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void 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");
|
|
|
+ try {
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNullMap(resultJson)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ Map<String, Object> deleteMap = new HashMap<>();
|
|
|
+ deleteMap.put("account_id", advertiserId);
|
|
|
+ conversionInfosMapper.deleteByMap(deleteMap);
|
|
|
+ conversionTypesMapper.deleteByMap(deleteMap); //删除历史数据
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
+ if (!Check.isNullMap(dataJson)) {
|
|
|
+ KuaiShouConversionInfos conversionInfos = new KuaiShouConversionInfos();
|
|
|
+ conversionInfos.setAccountId(advertiserId);
|
|
|
+ conversionInfos.setIsActivate(dataJson.getInteger("is_activate"));
|
|
|
+ conversionInfos.setIsFormSubmit(dataJson.getInteger("is_form_submit"));
|
|
|
+ conversionInfosMapper.insert(conversionInfos);
|
|
|
+ JSONArray ConversionTypeArr = dataJson.getJSONArray("deep_conversion_types");
|
|
|
+ if (!Check.isNull(ConversionTypeArr)) {
|
|
|
+ for (int i = 0; i < ConversionTypeArr.size(); i++) {
|
|
|
+ JSONObject conversionType = JSONObject.parseObject(ConversionTypeArr.get(i).toString());
|
|
|
+ if (!Check.isNull(conversionType)) {
|
|
|
+ KuaiShouConversionTypes conversionTypes = new KuaiShouConversionTypes();
|
|
|
+ conversionTypes.setAccountId(advertiserId);
|
|
|
+ conversionTypes.setDeepConversionTypes(conversionType.getInteger("deep_conversion_type"));
|
|
|
+ conversionTypes.setDesc(conversionType.getString("desc"));
|
|
|
+ conversionTypesMapper.insert(conversionTypes);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("获取可选的深度转化类型返回异常,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("快手,获取可选的深度转化类型返回为空,advertiserId:{}", advertiserId);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (
|
|
|
+ Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建广告创意
|
|
|
+ *
|
|
|
+ * @param accessToken
|
|
|
+ * @param advertiserId
|
|
|
+ * @param requestJson
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouCreativeCreateMapper creativeCreateMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ 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;
|
|
|
+ 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);
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ KuaiShouCreativeCreate creativeCreate = new KuaiShouCreativeCreate();
|
|
|
+ creativeCreate.setCreativeId(dataJson.getLong("creative_id"));
|
|
|
+ creativeCreate.setAccountId(advertiserId);
|
|
|
+ creativeCreate.setUnitId(requestJson.getLong("unit_id"));
|
|
|
+ creativeCreate.setCreativeName(requestJson.getString("creative_name"));
|
|
|
+ creativeCreate.setPhotoId(requestJson.getString("photo_id"));
|
|
|
+ creativeCreate.setImageToken(requestJson.getString("image_token"));
|
|
|
+ creativeCreate.setActionBarText(requestJson.getString("action_bar_text"));
|
|
|
+ creativeCreate.setDescription(requestJson.getString("description"));
|
|
|
+ creativeCreate.setClickTrackUrl(requestJson.getString("click_track_url"));
|
|
|
+ int i = creativeCreateMapper.insert(creativeCreate);
|
|
|
+ if (i > 0) {
|
|
|
+ logger.info("创建广告创意入库完成,advertiser_id:{}", advertiserId);
|
|
|
+ }
|
|
|
+ returnMap.put("code", 0);
|
|
|
+ returnMap.put("message", "success");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ logger.error("创建广告创意失败,advertiser_id:{},返回信息:{}", advertiserId, resultJson);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", resultJson.getString("message"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ logger.error("快手创建广告创意返回内容为空,advertiser_id:{}", advertiserId);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", "result is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("创建广告创意失败,advertiser_id:{}", advertiserId);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", "Interface exception");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return returnMap;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 文件上传
|
|
|
+ *
|
|
|
+ * @param advertiserId
|
|
|
+ * @param accessToken
|
|
|
+ * @param multipartFile
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouVideoUploadMapper videoUploadMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void videoUpload(Long advertiserId, String accessToken, MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
+ 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("上传快手视频完成");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ logger.error("快手上传视频返回信息异常 ,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("快手上传视频返回信息为空,advertiserId:{}", advertiserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("上传视频失败,advertiser_id:{}", advertiserId);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", "Interface exception");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取视频信息
|
|
|
+ *
|
|
|
+ * @param advertiserId
|
|
|
+ * @param accessToken
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouVideoGetMapper videoGetMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void videoGet(Long advertiserId, String accessToken, String photoId) {
|
|
|
+ try {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.VIDEO_GET;
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("advertiser_id", advertiserId);
|
|
|
+ ArrayList<String> strArray = new ArrayList<String>();
|
|
|
+ strArray.add(photoId);
|
|
|
+ param.put("photo_ids", strArray);
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
+ 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) {
|
|
|
+ JSONArray dataArr = resultJson.getJSONArray("data");
|
|
|
+ if (!Check.isNull(dataArr)) {
|
|
|
+ for (int i = 0; i < dataArr.size(); i++) {
|
|
|
+ JSONObject dataJson = JSONObject.parseObject(dataArr.get(i).toString());
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ KuaiShouVideoGet videoGet = new KuaiShouVideoGet();
|
|
|
+ videoGet.setAccountId(advertiserId);
|
|
|
+ videoGet.setWidth(dataJson.getInteger("width"));
|
|
|
+ videoGet.setHeight(dataJson.getInteger("height"));
|
|
|
+ videoGet.setUrl(dataJson.getString("url"));
|
|
|
+ videoGet.setPhotoId(dataJson.getString("photo_id"));
|
|
|
+ videoGet.setCoverUrl(dataJson.getString("cover_url"));
|
|
|
+ videoGetMapper.insert(videoGet);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("获取广告视频失败,advertiser_id:{},返回信息:{}", advertiserId, resultJson);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("获取视频信息返回结果为空,advertiserId:{}", advertiserId);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取图片信息
|
|
|
+ *
|
|
|
+ * @param advertiserId
|
|
|
+ * @param accessToken
|
|
|
+ * @param image_token
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouImageGetMapper imageGetMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void imageGet(Long advertiserId, String accessToken, String image_token) {
|
|
|
+ try {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.IMAGE_GET;
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
+ param.put("advertiser_id", advertiserId);
|
|
|
+ param.put("image_token", image_token);
|
|
|
+
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
|
+ System.err.println(result);
|
|
|
+ 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)) {
|
|
|
+ KuaiShouImageGet imageGet = new KuaiShouImageGet();
|
|
|
+ imageGet.setAccountId(advertiserId);
|
|
|
+ imageGet.setUrl(dataJson.getString("url"));
|
|
|
+ imageGet.setWidth(dataJson.getLong("width"));
|
|
|
+ imageGet.setHeight(dataJson.getLong("height"));
|
|
|
+ imageGet.setSize(dataJson.getLong("size"));
|
|
|
+ imageGet.setFormat(dataJson.getString("format"));
|
|
|
+ imageGet.setImageToken(dataJson.getString("image_token"));
|
|
|
+ imageGetMapper.insert(imageGet);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("获取广告图片失败,advertiser_id:{},返回信息:{}", advertiserId, resultJson);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("获取图片信息返回结果为空,advertiserId:{}", advertiserId);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取 地域列表
|
|
|
+ *
|
|
|
+ * @param accessToken
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouRegionListChildrenMapper regionListChildrenMapper;
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouRegionListParentMapper regionListParentMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void areaList(String accessToken) {
|
|
|
+ try {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.REGION_LIST;
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
+ String result = HttpUtils.httpGet(url, null, headers);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ regionListParentMapper.deleteAll();
|
|
|
+ regionListChildrenMapper.deleteAll();
|
|
|
+ JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ for (Map.Entry<String, Object> entry : dataJson.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ JSONObject keyJson = dataJson.getJSONObject(key);
|
|
|
+ if (!Check.isNull(keyJson)) {
|
|
|
+ KuaiShouRegionListParent regionListParent = new KuaiShouRegionListParent();
|
|
|
+ Long id = keyJson.getLong("id");
|
|
|
+ regionListParent.setRegionId(id);
|
|
|
+ regionListParent.setLevel(keyJson.getInteger("level"));
|
|
|
+ regionListParent.setName(keyJson.getString("name"));
|
|
|
+ regionListParent.setParent(keyJson.getLong("parent"));
|
|
|
+ regionListParentMapper.insert(regionListParent);
|
|
|
+ JSONArray childrenArr = keyJson.getJSONArray("children");
|
|
|
+ if (!Check.isNull(childrenArr)) {
|
|
|
+ for (int i = 0; i < childrenArr.size(); i++) {
|
|
|
+ KuaiShouRegionListChildren regionListChildren = new KuaiShouRegionListChildren();
|
|
|
+ regionListChildren.setParentId(id);
|
|
|
+ regionListChildren.setRegionId(childrenArr.getLong(i));
|
|
|
+ regionListChildrenMapper.insert(regionListChildren);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("获取地域列表失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ logger.error("获取地域列表返回结果为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 图片上传
|
|
|
+ *
|
|
|
+ * @param advertiserId
|
|
|
+ * @param accessToken
|
|
|
+ * @param multipartFile
|
|
|
+ * @param request
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouImageUploandMapper imageUploandMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void imageUpload(Long advertiserId, String accessToken, MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
+ 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("快手-图片上传成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("快手上传图片返回信息异常 ,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("快手上传图片返回信息为空,advertiserId:{}", advertiserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("上传图片失败,advertiser_id:{}", advertiserId);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", "Interface exception");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建应用
|
|
|
+ *
|
|
|
+ * @param advertiserId
|
|
|
+ * @param accessToken
|
|
|
+ * @param multipartFile
|
|
|
+ * @param request
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouAppCreateMapper appCreateMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void appCreate(Long advertiserId, String accessToken, MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
+ 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;
|
|
|
+ JSONObject requestJson = new JSONObject();
|
|
|
+ requestJson.put("app_version", "2.3.6");
|
|
|
+ requestJson.put("app_name", "微信开发1");
|
|
|
+ requestJson.put("image_token", "market81dd2187353e4cb19918b61276797ce5.jpg");
|
|
|
+ requestJson.put("advertiser_id", advertiserId);
|
|
|
+ requestJson.put("package_name", "2");
|
|
|
+ requestJson.put("platform", 1);
|
|
|
+ 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("快手创建应用成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("快手创建应用返回信息异常 ,advertiserId:{},异常信息:{}", advertiserId, resultJson);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("快手创建应用返回信息为空,advertiserId:{}", advertiserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("创建应用失败,advertiser_id:{}", advertiserId);
|
|
|
+ returnMap.put("code", -1);
|
|
|
+ returnMap.put("message", "error");
|
|
|
+ returnMap.put("desc", "Interface exception");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取应用列表
|
|
|
+ *
|
|
|
+ * @param advertiserId
|
|
|
+ * @param accessToken
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouAppListMapper appListMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getAppList(Long advertiserId, String accessToken) {
|
|
|
+ try {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.APP_LIST;
|
|
|
+ Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("advertiser_id", advertiserId);
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, json.toJSONString(), headers);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ Map<String, Object> deleteMap = new HashMap<>();
|
|
|
+ deleteMap.put("account_id", advertiserId);
|
|
|
+ appListMapper.deleteByMap(deleteMap);
|
|
|
+ JSONArray dataArr = resultJson.getJSONArray("data");
|
|
|
+ if (!Check.isNull(dataArr)) {
|
|
|
+ for (int i = 0; i < dataArr.size(); i++) {
|
|
|
+ JSONObject dataJson = JSONObject.parseObject(dataArr.get(i).toString());
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ KuaiShouAppList appList = new KuaiShouAppList();
|
|
|
+ appList.setAccountId(advertiserId);
|
|
|
+ appList.setPlatform(dataJson.getInteger("platform"));
|
|
|
+ appList.setUrl(dataJson.getString("url"));
|
|
|
+ appList.setAppId(dataJson.getLong("app_id"));
|
|
|
+ appList.setAppVersion(dataJson.getString("app_version"));
|
|
|
+ appList.setAppName(dataJson.getString("app_name"));
|
|
|
+ appList.setAppIconUrl(dataJson.getString("app_icon_url"));
|
|
|
+ appList.setImageToken(dataJson.getString("image_token"));
|
|
|
+ appList.setPackageName(dataJson.getString("package_name"));
|
|
|
+ appList.setReturnTime(DateUtils.timeStamp2Date(dataJson.getTimestamp("update_time")));
|
|
|
+ appListMapper.insert(appList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ logger.error("获取地域列表失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ logger.error("获取地域列表返回结果为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public Object jsonToObj(Object t, String jsonStr) throws
|
|
|
JsonParseException, JsonMappingException, IOException {
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
@@ -708,4 +1369,41 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate rest;
|
|
|
+
|
|
|
+ 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.isNullMap(paramMap)) {
|
|
|
+ for (String key : paramMap.keySet()) {
|
|
|
+ param.add(key, paramMap.get(key));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ if (!Check.isNullMap(headerMap)) {
|
|
|
+ for (String key : headerMap.keySet()) {
|
|
|
+ headers.add(key, (String) headerMap.get(key));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(param, headers);
|
|
|
+ ResponseEntity<String> responseEntity = rest.exchange(url, HttpMethod.POST, httpEntity, String.class);
|
|
|
+ System.err.println(responseEntity.getBody());
|
|
|
+ return responseEntity.getBody();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|