|
@@ -1,8 +1,6 @@
|
|
package org.jeecg.modules.kuaishou.service.impl;
|
|
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.KuaishouResult;
|
|
import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
|
|
import cn.com.ctop.kuaishou.modules.material.entity.KuaishouResultToken;
|
|
import cn.com.ctop.kuaishou.modules.report.entity.*;
|
|
import cn.com.ctop.kuaishou.modules.report.entity.*;
|
|
@@ -16,19 +14,28 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.type.TypeFactory;
|
|
import com.fasterxml.jackson.databind.type.TypeFactory;
|
|
import constant.KuaishouInterfaceConstant;
|
|
import constant.KuaishouInterfaceConstant;
|
|
|
|
+import org.apache.http.ParseException;
|
|
import org.jeecg.modules.kuaishou.entity.*;
|
|
import org.jeecg.modules.kuaishou.entity.*;
|
|
import org.jeecg.modules.kuaishou.mapper.*;
|
|
import org.jeecg.modules.kuaishou.mapper.*;
|
|
import org.jeecg.modules.kuaishou.service.IKuaishouInterfaceService;
|
|
import org.jeecg.modules.kuaishou.service.IKuaishouInterfaceService;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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.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.io.IOException;
|
|
import java.lang.reflect.ParameterizedType;
|
|
import java.lang.reflect.ParameterizedType;
|
|
import java.lang.reflect.Type;
|
|
import java.lang.reflect.Type;
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
@@ -272,6 +279,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_CREATE;
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_CREATE;
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
headers.put("Access-Token", accessToken);
|
|
headers.put("Access-Token", accessToken);
|
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
requestJson.put("advertiser_id", advertiser_id);
|
|
requestJson.put("advertiser_id", advertiser_id);
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
@@ -347,6 +355,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
requestJson.put("advertiser_id", advertiser_id);
|
|
requestJson.put("advertiser_id", advertiser_id);
|
|
headers.put("Access-Token", accessToken);
|
|
headers.put("Access-Token", accessToken);
|
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
|
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
@@ -451,6 +460,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_LIST;
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_LIST;
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
headers.put("Access-Token", accessToken);
|
|
headers.put("Access-Token", accessToken);
|
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
JSONObject param = new JSONObject();
|
|
JSONObject param = new JSONObject();
|
|
param.put("advertiser_id", advertiserId);
|
|
param.put("advertiser_id", advertiserId);
|
|
param.put("page", page);
|
|
param.put("page", page);
|
|
@@ -526,6 +536,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
param.put("page", page);
|
|
param.put("page", page);
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
headers.put("Access-Token", accessToken);
|
|
headers.put("Access-Token", accessToken);
|
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
try {
|
|
try {
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
@@ -627,7 +638,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_LIST;
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CREATIVE_LIST;
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
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);
|
|
headers.put("Access-Token", accessToken);
|
|
JSONObject param = new JSONObject();
|
|
JSONObject param = new JSONObject();
|
|
param.put("advertiser_id", advertiserId);
|
|
param.put("advertiser_id", advertiserId);
|
|
@@ -700,6 +711,10 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
requestJson.put("auth_code", authCode);
|
|
requestJson.put("auth_code", authCode);
|
|
requestJson.put("app_id", PropertiesUtils.getConfig("kuaishou_appid"));
|
|
requestJson.put("app_id", PropertiesUtils.getConfig("kuaishou_appid"));
|
|
requestJson.put("secret", PropertiesUtils.getConfig("kuaishou_secret"));
|
|
requestJson.put("secret", PropertiesUtils.getConfig("kuaishou_secret"));
|
|
|
|
+
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
|
|
+
|
|
KuaishouResultToken kuaiShouResult = null;
|
|
KuaishouResultToken kuaiShouResult = null;
|
|
try {
|
|
try {
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), null);
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), null);
|
|
@@ -723,7 +738,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
public KuaishouResultToken getRefreshToken(String refreshToken) {
|
|
public KuaishouResultToken getRefreshToken(String refreshToken) {
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.REFRESH_TOKEN;
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.REFRESH_TOKEN;
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
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>();
|
|
Map<String, Object> param = new HashMap<String, Object>();
|
|
param.put("app_id", PropertiesUtils.getConfig("kuaishou_appid"));
|
|
param.put("app_id", PropertiesUtils.getConfig("kuaishou_appid"));
|
|
param.put("secret", PropertiesUtils.getConfig("kuaishou_secret"));
|
|
param.put("secret", PropertiesUtils.getConfig("kuaishou_secret"));
|
|
@@ -766,6 +781,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
param.put("advertiser_id", advertiserId);
|
|
param.put("advertiser_id", advertiserId);
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
Map<String, String> headers = new HashMap<String, String>();
|
|
headers.put("Access-Token", accessToken);
|
|
headers.put("Access-Token", accessToken);
|
|
|
|
+ headers.put("Content-Type", " application/json");
|
|
try {
|
|
try {
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, param.toJSONString(), headers);
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
@@ -831,6 +847,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_CREATE;
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_CREATE;
|
|
requestJson.put("advertiser_id", advertiserId);
|
|
requestJson.put("advertiser_id", advertiserId);
|
|
Map<String, String> header = new HashMap<String, String>();
|
|
Map<String, String> header = new HashMap<String, String>();
|
|
|
|
+ header.put("Content-Type", " application/json");
|
|
|
|
+
|
|
header.put("Access-Token", accessToken);
|
|
header.put("Access-Token", accessToken);
|
|
|
|
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), header);
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), header);
|
|
@@ -881,6 +899,315 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 文件上传
|
|
|
|
+ *
|
|
|
|
+ * @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 = new FileEntity();
|
|
|
|
+ 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();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
public Object jsonToObj(Object t, String jsonStr) throws
|
|
public Object jsonToObj(Object t, String jsonStr) throws
|
|
JsonParseException, JsonMappingException, IOException {
|
|
JsonParseException, JsonMappingException, IOException {
|
|
@@ -911,4 +1238,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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|