1
This commit is contained in:
129
src/main/java/cn/van/business/config/SchedulerConfig.java
Normal file
129
src/main/java/cn/van/business/config/SchedulerConfig.java
Normal file
@@ -0,0 +1,129 @@
|
||||
package cn.van.business.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
@Configuration
|
||||
public class SchedulerConfig implements SchedulingConfigurer {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SchedulerConfig.class);
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
|
||||
|
||||
taskRegistrar.setScheduler(new CustomScheduledExecutorService(scheduledExecutorService));
|
||||
}
|
||||
|
||||
private static class CustomScheduledExecutorService implements ScheduledExecutorService {
|
||||
private final ScheduledExecutorService delegate;
|
||||
|
||||
public CustomScheduledExecutorService(ScheduledExecutorService delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
|
||||
return delegate.schedule(wrap(command), delay, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
|
||||
return delegate.scheduleAtFixedRate(wrap(command), initialDelay, period, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
|
||||
return delegate.scheduleWithFixedDelay(wrap(command), initialDelay, delay, unit);
|
||||
}
|
||||
|
||||
private Runnable wrap(Runnable command) {
|
||||
return () -> {
|
||||
try {
|
||||
command.run();
|
||||
} catch (Exception e) {
|
||||
logger.error("Scheduled task error", e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Delegate other methods to the delegate executor
|
||||
@Override
|
||||
public void shutdown() {
|
||||
delegate.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Runnable> shutdownNow() {
|
||||
return delegate.shutdownNow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShutdown() {
|
||||
return delegate.isShutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTerminated() {
|
||||
return delegate.isTerminated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
|
||||
return delegate.awaitTermination(timeout, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> submit(Callable<T> task) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> submit(Runnable task, T result) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<?> submit(Runnable task) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ScheduledFuture<T> schedule(Callable<T> callable, long delay, TimeUnit unit) {
|
||||
return delegate.schedule(callable, delay, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable command) {
|
||||
delegate.execute(wrap(command));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,11 @@ import com.jd.open.api.sdk.DefaultJdClient;
|
||||
import com.jd.open.api.sdk.JdClient;
|
||||
import com.jd.open.api.sdk.domain.kplunion.OrderService.request.query.OrderRowReq;
|
||||
import com.jd.open.api.sdk.domain.kplunion.OrderService.response.query.OrderRowResp;
|
||||
import com.jd.open.api.sdk.domain.kplunion.promotionbysubunioni.PromotionService.request.get.PromotionCodeReq;
|
||||
import com.jd.open.api.sdk.request.kplunion.UnionOpenOrderRowQueryRequest;
|
||||
import com.jd.open.api.sdk.request.kplunion.UnionOpenPromotionBysubunionidGetRequest;
|
||||
import com.jd.open.api.sdk.response.kplunion.UnionOpenOrderRowQueryResponse;
|
||||
import com.jd.open.api.sdk.response.kplunion.UnionOpenPromotionBysubunionidGetResponse;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.slf4j.Logger;
|
||||
@@ -576,6 +579,7 @@ public class JDUtil {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public synchronized void test(LocalDateTime startTime, String appKey) {
|
||||
String oldTimeTag = JD_REFRESH_TAG + startTime.format(DATE_TIME_FORMATTER);
|
||||
String newTimeTag = JD_REFRESH_TAG + appKey + ":" + startTime.format(DATE_TIME_FORMATTER);
|
||||
@@ -1076,37 +1080,45 @@ public class JDUtil {
|
||||
|
||||
/**
|
||||
* 接口描述:通过商品链接、领券链接、活动链接获取普通推广链接或优惠券二合一推广链接
|
||||
* jd.union.open.promotion.bysubunionid.get
|
||||
*/
|
||||
//String transfer(String url) throws Exception {
|
||||
// JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, APP_KEY_DG, SECRET_KEY_DG);
|
||||
// UnionOpenPromotionBysubunionidGetRequest getRequest = new UnionOpenPromotionBysubunionidGetRequest();
|
||||
// getRequest.setVersion("1.0");
|
||||
// getRequest.setSignmethod("md5");
|
||||
//
|
||||
// PromotionCodeReq promotionCodeReq = new PromotionCodeReq();
|
||||
// promotionCodeReq.setMaterialId(url);
|
||||
// promotionCodeReq.setSiteId("4101191512");
|
||||
// promotionCodeReq.setSceneId(2);
|
||||
// promotionCodeReq.setCommand(1);
|
||||
// promotionCodeReq.setProType(5);
|
||||
//
|
||||
//
|
||||
// getRequest.setPromotionCodeReq(promotionCodeReq);
|
||||
// client.execute(getRequest);
|
||||
//
|
||||
// String jsonString = JSON.toJSONString(response);
|
||||
// System.out.println(jsonString);
|
||||
//
|
||||
// System.out.println(request.getAppJsonParams());
|
||||
// System.out.println(request.getPromotionCodeReq());
|
||||
//
|
||||
// System.out.println("--------");
|
||||
// System.out.println(response.getGetResult().getCode());
|
||||
// System.out.println(response.getGetResult().getMessage());
|
||||
// System.out.println(response.getGetResult().getData().getClickURL());
|
||||
// System.out.println(response.getGetResult().getData().getJCommand());
|
||||
// return response.getGetResult().getData().getClickURL();
|
||||
//}
|
||||
String transfer(String url) throws Exception {
|
||||
JdClient client = new DefaultJdClient(SERVER_URL, ACCESS_TOKEN, LPF_APP_KEY_DG, LPF_SECRET_KEY_DG);
|
||||
|
||||
UnionOpenPromotionBysubunionidGetRequest request = new UnionOpenPromotionBysubunionidGetRequest();
|
||||
PromotionCodeReq promotionCodeReq = new PromotionCodeReq();
|
||||
request.setPromotionCodeReq(promotionCodeReq);
|
||||
request.setVersion("1.0");
|
||||
UnionOpenPromotionBysubunionidGetResponse response = client.execute(request);
|
||||
|
||||
/**
|
||||
* {
|
||||
* "jd_union_open_promotion_bysubunionid_get_responce": {
|
||||
* "getResult": {
|
||||
* "code": "200",
|
||||
* "data": {
|
||||
* "clickURL": "https://union-click.jd.com/jdc?e=XXXXXX p=XXXXXXXXXXX",
|
||||
* "weChatShortLink": "#小程序://京小街/****",
|
||||
* "jShortCommand": "短口令",
|
||||
* "shortURL": "https://u.jd.com/XXXXX",
|
||||
* "jCommand": "6.0复制整段话 http://JhT7V5wlKygHDK京口令内容#J6UFE5iMn***"
|
||||
* },
|
||||
* "message": "success"
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* */
|
||||
String result = "";
|
||||
if (Util.isNotEmpty(response)) {
|
||||
if (response.getCode().equals("200")) {
|
||||
result = response.getGetResult().getData().getShortURL();
|
||||
}
|
||||
} else {
|
||||
result = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
|
||||
@@ -288,16 +288,18 @@ public class WxMessageConsumer {
|
||||
}
|
||||
// 只处理超管的消息
|
||||
String fromWxid = innerData.getFromWxid();
|
||||
WXUtil.SuperAdmin superAdmin = super_admins.get(fromWxid);
|
||||
if (Util.isEmpty(superAdmin)){
|
||||
logger.info("不是超管消息,不处理");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//WXUtil.SuperAdmin superAdmin = super_admins.get(fromWxid);
|
||||
//if (Util.isEmpty(superAdmin)){
|
||||
// logger.info("不是超管消息,不处理");
|
||||
// return;
|
||||
//}
|
||||
String msg = innerData.getMsg();
|
||||
//美团 20-7 + https://i.meituan.com/mttouch/page/account?userId=3822095266&token=AgHdIkm2tAGHc9SQSiG7M8xCx1LbTue9D2HPOAun2eYl3ou7BeEw1uGrGZH-DxmEiUgsbA1v9SM4DQAAAAC6HAAAz0rTXmkB_CIHin08hCu68mFv5k6nUc2q6_CfZqEdBcngRK_xD8Sx5fE4rfdq-yAJ, msgbase64=576O5ZuiIDIwLTcgKyBodHRwczovL2kubWVpdHVhbi5jb20vbXR0b3VjaC9wYWdlL2FjY291bnQ/dXNlcklkPTM4MjIwOTUyNjYmdG9rZW49QWdIZElrbTJ0QUdIYzlTUVNpRzdNOHhDeDFMYlR1ZTlEMkhQT0F1bjJlWWwzb3U3QmVFdzF1R3JHWkgtRHhtRWlVZ3NiQTF2OVNNNERRQUFBQUM2SEFBQXowclRYbWtCX0NJSGluMDhoQ3U2OG1GdjVrNm5VYzJxNl9DZlpxRWRCY25nUktfeEQ4U3g1ZkU0cmZkcS15QUo=
|
||||
if (msg.startsWith("转链")) {
|
||||
|
||||
/**
|
||||
* 【京东】https://3.cn/2c-47ATm 「京东京造桌面抽屉式收纳盒」
|
||||
* 点击链接直接打开
|
||||
* */
|
||||
if (msg.contains("【京东】")){
|
||||
String wxid;
|
||||
if (Objects.equals(event, fromGR)) {
|
||||
wxid = innerData.getFromWxid();
|
||||
@@ -310,13 +312,13 @@ public class WxMessageConsumer {
|
||||
// 获取 100065976064
|
||||
logger.info("处理转链消息");
|
||||
|
||||
//String finallyUrl = getUrlStr(msg);
|
||||
String finallyUrl = getUrlStr(msg);
|
||||
//String finallyUrl = extractProductId(msg);
|
||||
//String finallyUrl = msg.substring(2);
|
||||
//if (Util.isNotEmpty(finallyUrl)) {
|
||||
// String transferResultUrl = jdUtils.transfer(finallyUrl);
|
||||
// wxUtil.sendTextMessage(wxid, transferResultUrl, msgType, null);
|
||||
//}
|
||||
if (Util.isNotEmpty(finallyUrl)) {
|
||||
String transferResultUrl = jdUtils.transfer(finallyUrl);
|
||||
wxUtil.sendTextMessage(wxid, transferResultUrl, msgType, null);
|
||||
}
|
||||
} else if (msg.startsWith("京")) {
|
||||
jdUtils.sendOrderToWxByOrderJD(msg.replace("京", ""),fromWxid);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,10 @@ spring:
|
||||
messages:
|
||||
# 国际化资源文件路径
|
||||
basename: i18n/messages
|
||||
task:
|
||||
execution:
|
||||
pool:
|
||||
core-size: 32
|
||||
|
||||
# token配置
|
||||
token:
|
||||
|
||||
Reference in New Issue
Block a user