|
@@ -975,6 +975,8 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
getImageList(token, null, null);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ getAppList(token.getAccountId(), token.getAccessToken());
|
|
|
}
|
|
|
|
|
|
|
|
@@ -990,31 +992,37 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
Map<String, Object> returnMap = new HashMap<>();
|
|
|
try {
|
|
|
String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.CAMPAIGN_CREATE;
|
|
|
- Map<String, String> headers = new HashMap<String, String>();
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("Access-Token", accessToken);
|
|
|
headers.put("Content-Type", " application/json");
|
|
|
requestJson.put("advertiser_id", advertiserId);
|
|
|
String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
|
|
|
JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
if (!Check.isNull(resultJson)) {
|
|
|
+ System.err.println(requestJson);
|
|
|
Integer code = resultJson.getInteger("code");
|
|
|
if (code == 0) {
|
|
|
- KuaiShouCampaignCreate campaignCreate = new KuaiShouCampaignCreate();
|
|
|
JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
Long campaignId = dataJson.getLong("campaign_id");
|
|
|
- campaignCreate.setCampaignId(campaignId);
|
|
|
- campaignCreate.setAccountId(advertiserId);
|
|
|
- campaignCreate.setCampaignName(requestJson.getString("campaign_name"));
|
|
|
- campaignCreate.setDayBudget(requestJson.getInteger("day_budget"));
|
|
|
- campaignCreate.setType(requestJson.getInteger("type"));
|
|
|
- int i = kuaiShouCampaignCreateMapper.insert(campaignCreate);
|
|
|
- if (i > 0) {
|
|
|
- log.info("创建广告信息入库完成,advertiser_id:{}", advertiserId);
|
|
|
- }
|
|
|
returnMap.put("code", 0);
|
|
|
returnMap.put("message", "success");
|
|
|
- returnMap.put("campaign_id", campaignId);
|
|
|
+ returnMap.put("campaignId", campaignId);
|
|
|
returnMap.put("success", true);
|
|
|
+ // 创建成功 拉取广告组信息
|
|
|
+ Thread thread = new Thread() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ Thread.sleep(2 * 1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ getCampaign(accessToken, advertiserId, campaignId);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ };
|
|
|
+ thread.start();
|
|
|
} else {
|
|
|
log.error("创建广告计划失败,advertiser_id:{},返回信息:{}", advertiserId, resultJson);
|
|
|
returnMap.put("code", -1);
|
|
@@ -2163,6 +2171,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
if (code == 0) {
|
|
|
JSONObject dataJson = resultJson.getJSONObject("data");
|
|
|
if (!Check.isNull(dataJson)) {
|
|
|
+ String signature = dataJson.getString("signature");
|
|
|
KuaiShouImageGet imageGet = new KuaiShouImageGet();
|
|
|
imageGet.setAccountId(advertiserId);
|
|
|
imageGet.setUrl(dataJson.getString("url"));
|
|
@@ -2170,7 +2179,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
imageGet.setHeight(dataJson.getLong("height"));
|
|
|
imageGet.setSize(dataJson.getLong("size"));
|
|
|
imageGet.setFormat(dataJson.getString("format"));
|
|
|
- String signature = dataJson.getString("signature");
|
|
|
+
|
|
|
imageGet.setSignature(signature);
|
|
|
imageGet.setImageToken(dataJson.getString("image_token"));
|
|
|
Map<String, Object> deleteMap = new HashMap<>();
|
|
@@ -2387,23 +2396,10 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
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) {
|
|
|
- log.info("快手创建应用成功,共耗时:{} ms", System.currentTimeMillis() - startTime);
|
|
|
- }
|
|
|
+ requestJson.put("url", dataJson.getString("url"));
|
|
|
+ requestJson.put("app_id", dataJson.getLong("app_id"));
|
|
|
+ this.insertAppList(advertiserId, requestJson);
|
|
|
+ log.info("应用创建成功,耗时:{} s", (System.currentTimeMillis() - startTime) / 1000);
|
|
|
returnMap.put("appId", dataJson.getLong("app_id"));
|
|
|
returnMap.put("success", true);
|
|
|
returnMap.put("code", 0);
|
|
@@ -2471,20 +2467,10 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
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) {
|
|
|
- log.info("快手创建应用成功");
|
|
|
- }
|
|
|
+ apkJson.put("url", dataJson.getString("url"));
|
|
|
+ apkJson.put("app_id", dataJson.getLong("app_id"));
|
|
|
+ this.insertAppList(accountId, apkJson);
|
|
|
+
|
|
|
returnMap.put("code", 0);
|
|
|
returnMap.put("message", "success");
|
|
|
returnMap.put("appId", dataJson.getLong("app_id"));
|
|
@@ -2513,6 +2499,34 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
|
|
|
|
|
|
/**
|
|
|
+ * 添加 应用信息
|
|
|
+ */
|
|
|
+ private void insertAppList(Long accountId, JSONObject dataJson) {
|
|
|
+
|
|
|
+ Map<String, Object> deleteMap = new HashMap<>();
|
|
|
+ deleteMap.put("account_id", accountId);
|
|
|
+ deleteMap.put("app_version", dataJson.getString("app_version"));
|
|
|
+ appListMapper.deleteByMap(deleteMap);
|
|
|
+ KuaiShouAppList appList = new KuaiShouAppList();
|
|
|
+ appList.setAccountId(accountId);
|
|
|
+ appList.setUrl(dataJson.getString("url"));
|
|
|
+ appList.setPlatform(dataJson.getInteger("platform"));
|
|
|
+ appList.setAppVersion(dataJson.getString("app_version"));
|
|
|
+ appList.setAppName(dataJson.getString("app_name"));
|
|
|
+ appList.setImageToken(dataJson.getString("image_token"));
|
|
|
+ appList.setPackageName(dataJson.getString("package_name"));
|
|
|
+ appList.setAppId(dataJson.getLong("app_id"));
|
|
|
+ appList.setAppIconUrl(dataJson.getString("app_icon_url"));
|
|
|
+ appList.setReturnTime(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm"));
|
|
|
+ int i = appListMapper.insert(appList);
|
|
|
+ if (i > 0) {
|
|
|
+ log.info("同步应用成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取快手广告租信息
|
|
|
*
|
|
|
* @param accountId
|
|
@@ -2992,4 +3006,115 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取人群包接口
|
|
|
+ *
|
|
|
+ * @param accountId
|
|
|
+ * @param accessToken
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONArray getPopulationList(Long accountId, String accessToken) {
|
|
|
+ try {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.POPULATION_LIST;
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ JSONObject requestJson = new JSONObject();
|
|
|
+ requestJson.put("advertiser_id", accountId);
|
|
|
+ requestJson.put("status", 4);
|
|
|
+ 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) {
|
|
|
+ JSONArray data = resultJson.getJSONArray("data");
|
|
|
+ return data;
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ log.error("获取人群包管理返回数据为空,accountId:{}", accountId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取定向标签
|
|
|
+ *
|
|
|
+ * @param accountId
|
|
|
+ * @param accessToken
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private KuaiShouTargetingTagsMapper targetingTagsMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getTargetingTags(Long accountId, String accessToken) {
|
|
|
+ try {
|
|
|
+ String url = PropertiesUtils.getConfig("kuaishou_api_url") + KuaishouInterfaceConstant.TARGETING_TAGS;
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Access-Token", accessToken);
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ JSONObject requestJson = new JSONObject();
|
|
|
+ requestJson.put("advertiser_id", accountId);
|
|
|
+
|
|
|
+
|
|
|
+ JSONArray typeArr = new JSONArray();
|
|
|
+ typeArr.add("BUSINESS_INTEREST");
|
|
|
+ typeArr.add("APP_INTEREST");
|
|
|
+ typeArr.add("FANS_STAR");
|
|
|
+ typeArr.add("INTEREST_VIDEO");
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < typeArr.size(); i++) {
|
|
|
+ String type = typeArr.get(i).toString();
|
|
|
+ requestJson.put("type", type);
|
|
|
+ String result = HttpUtils.kuaiShouhttpPostRequest(url, requestJson.toJSONString(), headers);
|
|
|
+ JSONObject resultJson = JSONObject.parseObject(result);
|
|
|
+ System.err.println(resultJson);
|
|
|
+ if (!Check.isNull(resultJson)) {
|
|
|
+ Integer code = resultJson.getInteger("code");
|
|
|
+ if (code == 0) {
|
|
|
+ JSONArray dataArr = resultJson.getJSONArray("data");
|
|
|
+ if (!Check.isNull(dataArr)) {
|
|
|
+ Map<String, Object> deleteMap = new HashMap<>();
|
|
|
+ deleteMap.put("tag_type", type);
|
|
|
+ targetingTagsMapper.deleteByMap(deleteMap);
|
|
|
+ for (int j = 0; j < dataArr.size(); j++) {
|
|
|
+ JSONObject dataJson = dataArr.getJSONObject(j);
|
|
|
+ if (!Check.isNull(dataJson)) {
|
|
|
+ KuaiShouTargetingTags targetingTags = new KuaiShouTargetingTags();
|
|
|
+ targetingTags.setTagId(dataJson.getLong("id"));
|
|
|
+ targetingTags.setTagName(dataJson.getString("name"));
|
|
|
+ targetingTags.setTagType(type);
|
|
|
+ targetingTagsMapper.insert(targetingTags);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ log.error("获取定向标签返回数据为空,accountId:{}", accountId);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|