|
@@ -1,20 +1,15 @@
|
|
|
package com.dderp.business.service.flycat;
|
|
package com.dderp.business.service.flycat;
|
|
|
|
|
|
|
|
-import com.dderp.common.api.flycat.DouyinService;
|
|
|
|
|
|
|
+import com.dderp.common.api.flycat.IncomePlatformService;
|
|
|
import com.dderp.common.base.BaseService;
|
|
import com.dderp.common.base.BaseService;
|
|
|
-import com.dderp.common.datas.ERPModule;
|
|
|
|
|
import com.dderp.common.datas.RedisKeys;
|
|
import com.dderp.common.datas.RedisKeys;
|
|
|
-import com.dderp.common.entity.base.ProcessStringItem;
|
|
|
|
|
import com.dderp.common.entity.invoke.douyin.DouyinTokenRequest;
|
|
import com.dderp.common.entity.invoke.douyin.DouyinTokenRequest;
|
|
|
import com.dderp.common.entity.invoke.douyin.DouyinTokenResponse;
|
|
import com.dderp.common.entity.invoke.douyin.DouyinTokenResponse;
|
|
|
-import com.dderp.common.entity.order.BusinessOrder;
|
|
|
|
|
-import com.dderp.common.entity.site.ERPTokenUser;
|
|
|
|
|
import com.dderp.common.http.HttpTools;
|
|
import com.dderp.common.http.HttpTools;
|
|
|
import com.dySweetFishPlugin.redis.RedisService;
|
|
import com.dySweetFishPlugin.redis.RedisService;
|
|
|
import com.dySweetFishPlugin.tool.lang.ThreadFactoryWithNamePrefix;
|
|
import com.dySweetFishPlugin.tool.lang.ThreadFactoryWithNamePrefix;
|
|
|
import com.sweetfish.convert.json.JsonConvert;
|
|
import com.sweetfish.convert.json.JsonConvert;
|
|
|
import com.sweetfish.service.Local;
|
|
import com.sweetfish.service.Local;
|
|
|
-import com.sweetfish.service.RetResult;
|
|
|
|
|
import com.sweetfish.util.AnyValue;
|
|
import com.sweetfish.util.AnyValue;
|
|
|
import com.sweetfish.util.AutoLoad;
|
|
import com.sweetfish.util.AutoLoad;
|
|
|
import com.sweetfish.util.ResourceType;
|
|
import com.sweetfish.util.ResourceType;
|
|
@@ -29,26 +24,27 @@ import java.util.concurrent.*;
|
|
|
|
|
|
|
|
@AutoLoad(false)
|
|
@AutoLoad(false)
|
|
|
@Local
|
|
@Local
|
|
|
-@ResourceType(DouyinService.class)
|
|
|
|
|
-public class DouyinServiceImpl extends BaseService implements DouyinService {
|
|
|
|
|
|
|
+@ResourceType(IncomePlatformService.class)
|
|
|
|
|
+public class IncomePlatformServiceImpl extends BaseService implements IncomePlatformService {
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private RedisService redisService;
|
|
private RedisService redisService;
|
|
|
|
|
|
|
|
- private ScheduledThreadPoolExecutor accessTokenThread;
|
|
|
|
|
|
|
+ //抖音来客token线程池
|
|
|
|
|
+ private ScheduledThreadPoolExecutor dyAccessTokenThread;
|
|
|
private String runEnvironment;
|
|
private String runEnvironment;
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private JsonConvert jsonConvert;
|
|
private JsonConvert jsonConvert;
|
|
|
|
|
|
|
|
@Resource(name = "property.douyin.appId")
|
|
@Resource(name = "property.douyin.appId")
|
|
|
- private String appId;
|
|
|
|
|
|
|
+ private String dyAppId;
|
|
|
|
|
|
|
|
@Resource(name = "property.douyin.appSecret")
|
|
@Resource(name = "property.douyin.appSecret")
|
|
|
- private String appSecret;
|
|
|
|
|
|
|
+ private String dyAppSecret;
|
|
|
|
|
|
|
|
@Resource(name = "property.douyin.reqUrl")
|
|
@Resource(name = "property.douyin.reqUrl")
|
|
|
- private String reqUrl;
|
|
|
|
|
|
|
+ private String dyReqUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -69,11 +65,11 @@ public class DouyinServiceImpl extends BaseService implements DouyinService {
|
|
|
if (master) {
|
|
if (master) {
|
|
|
if (StringUtils.equalsIgnoreCase(runEnvironment, "dev")) {
|
|
if (StringUtils.equalsIgnoreCase(runEnvironment, "dev")) {
|
|
|
//开发环境
|
|
//开发环境
|
|
|
- accessTokenThread = null;
|
|
|
|
|
|
|
+ dyAccessTokenThread = null;
|
|
|
} else {
|
|
} else {
|
|
|
//启动的时候10分钟之后获取,然后每隔1个半小时刷新一次token
|
|
//启动的时候10分钟之后获取,然后每隔1个半小时刷新一次token
|
|
|
//为什么10分钟,因为企点是每10分钟发送ticket,没有ticket的情况通过ticket是换不到开发商token的
|
|
//为什么10分钟,因为企点是每10分钟发送ticket,没有ticket的情况通过ticket是换不到开发商token的
|
|
|
- accessTokenThread = new ScheduledThreadPoolExecutor(1,
|
|
|
|
|
|
|
+ dyAccessTokenThread = new ScheduledThreadPoolExecutor(1,
|
|
|
new ThreadFactoryWithNamePrefix("[抖音Access_Token线程池]"));
|
|
new ThreadFactoryWithNamePrefix("[抖音Access_Token线程池]"));
|
|
|
|
|
|
|
|
long tokenInitialDelay = 30;
|
|
long tokenInitialDelay = 30;
|
|
@@ -91,7 +87,7 @@ public class DouyinServiceImpl extends BaseService implements DouyinService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- accessTokenThread.scheduleWithFixedDelay(() -> {
|
|
|
|
|
|
|
+ dyAccessTokenThread.scheduleWithFixedDelay(() -> {
|
|
|
scanRefreshToken();
|
|
scanRefreshToken();
|
|
|
//写入当前时间
|
|
//写入当前时间
|
|
|
redisService.set(RedisKeys.KEY_DOUYIN_LASTTOKENDATE, String.valueOf(Date.from(Instant.now()).getTime()));
|
|
redisService.set(RedisKeys.KEY_DOUYIN_LASTTOKENDATE, String.valueOf(Date.from(Instant.now()).getTime()));
|
|
@@ -102,8 +98,8 @@ public class DouyinServiceImpl extends BaseService implements DouyinService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void destroy(AnyValue config) {
|
|
public void destroy(AnyValue config) {
|
|
|
- if (accessTokenThread != null) {
|
|
|
|
|
- accessTokenThread.shutdownNow();
|
|
|
|
|
|
|
+ if (dyAccessTokenThread != null) {
|
|
|
|
|
+ dyAccessTokenThread.shutdownNow();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -111,7 +107,7 @@ public class DouyinServiceImpl extends BaseService implements DouyinService {
|
|
|
DouyinTokenResponse dyToken = null;
|
|
DouyinTokenResponse dyToken = null;
|
|
|
//抖音有可能获取不到token,这里循环获取,直到有值?
|
|
//抖音有可能获取不到token,这里循环获取,直到有值?
|
|
|
do {
|
|
do {
|
|
|
- dyToken = this.requestAccessToken(appId, appSecret);
|
|
|
|
|
|
|
+ dyToken = this.requestAccessToken(dyAppId, dyAppSecret);
|
|
|
|
|
|
|
|
} while ((dyToken == null) || (StringUtils.isEmpty(dyToken.getData().getAccess_token())));
|
|
} while ((dyToken == null) || (StringUtils.isEmpty(dyToken.getData().getAccess_token())));
|
|
|
|
|
|
|
@@ -128,7 +124,7 @@ public class DouyinServiceImpl extends BaseService implements DouyinService {
|
|
|
header.put("Content-Type", "application/json");
|
|
header.put("Content-Type", "application/json");
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- String responseStr = HttpTools.postHttpContentAsync(reqUrl + "/oauth/client_token/", header,
|
|
|
|
|
|
|
+ String responseStr = HttpTools.postHttpContentAsync(dyReqUrl + "/oauth/client_token/", header,
|
|
|
jsonConvert.convertTo(tokenRequest)).get(5, TimeUnit.SECONDS);
|
|
jsonConvert.convertTo(tokenRequest)).get(5, TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
return jsonConvert.convertFrom(DouyinTokenResponse.class, responseStr);
|
|
return jsonConvert.convertFrom(DouyinTokenResponse.class, responseStr);
|
|
@@ -150,14 +146,14 @@ public class DouyinServiceImpl extends BaseService implements DouyinService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public String postInvoker(String subUrl, String body) {
|
|
|
|
|
|
|
+ public String dyPostInvoker(String subUrl, String body) {
|
|
|
Map<String, String> header = new HashMap<>();
|
|
Map<String, String> header = new HashMap<>();
|
|
|
header.put("access-token", getAccessToken());
|
|
header.put("access-token", getAccessToken());
|
|
|
header.put("log_id", String.valueOf(new Date().getTime()));
|
|
header.put("log_id", String.valueOf(new Date().getTime()));
|
|
|
header.put("Content-Type", "application/json");
|
|
header.put("Content-Type", "application/json");
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- return HttpTools.postHttpContentAsync(reqUrl + subUrl, header, body).get(20, TimeUnit.SECONDS);
|
|
|
|
|
|
|
+ return HttpTools.postHttpContentAsync(dyReqUrl + subUrl, header, body).get(20, TimeUnit.SECONDS);
|
|
|
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
|
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
|
|
logger.error("请求抖音来客接口[" + subUrl + "]失败", e);
|
|
logger.error("请求抖音来客接口[" + subUrl + "]失败", e);
|
|
|
return null;
|
|
return null;
|
|
@@ -165,14 +161,14 @@ public class DouyinServiceImpl extends BaseService implements DouyinService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public String getInvoker(String subUrl, String body) {
|
|
|
|
|
|
|
+ public String dyGetInvoker(String subUrl, String body) {
|
|
|
Map<String, String> header = new HashMap<>();
|
|
Map<String, String> header = new HashMap<>();
|
|
|
header.put("access-token", getAccessToken());
|
|
header.put("access-token", getAccessToken());
|
|
|
header.put("log_id", String.valueOf(new Date().getTime()));
|
|
header.put("log_id", String.valueOf(new Date().getTime()));
|
|
|
header.put("Content-Type", "application/json");
|
|
header.put("Content-Type", "application/json");
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- return HttpTools.getHttpContentAsync(reqUrl + subUrl, header, body).get(20, TimeUnit.SECONDS);
|
|
|
|
|
|
|
+ return HttpTools.getHttpContentAsync(dyReqUrl + subUrl, header, body).get(20, TimeUnit.SECONDS);
|
|
|
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
|
} catch (InterruptedException | ExecutionException | TimeoutException e) {
|
|
|
logger.error("请求抖音来客接口[" + subUrl + "]失败", e);
|
|
logger.error("请求抖音来客接口[" + subUrl + "]失败", e);
|
|
|
return null;
|
|
return null;
|