|
|
|
@ -33,12 +33,15 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
|
import java.io.OutputStreamWriter;
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.ZoneOffset;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -173,6 +176,33 @@ public class ABDownTask {
|
|
|
|
|
private String shuangyingSecretKey;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 配置文件中加载配置信息 - 土拨鼠
|
|
|
|
|
*/
|
|
|
|
|
@Value("${ab.tbs.coopname}")
|
|
|
|
|
private String coopname;
|
|
|
|
|
|
|
|
|
|
@Value("${ab.tbs.url}")
|
|
|
|
|
private String tuBoShuUrl;
|
|
|
|
|
|
|
|
|
|
@Value("${ab.tbs.tokenurl}")
|
|
|
|
|
private String tuBoShuTokenUrl;
|
|
|
|
|
|
|
|
|
|
@Value("${ab.tbs.chcode}")
|
|
|
|
|
private String chcode;
|
|
|
|
|
|
|
|
|
|
@Value("${ab.tbs.password}")
|
|
|
|
|
private String passWord;
|
|
|
|
|
|
|
|
|
|
@Value("${ab.tbs.coopOrderid}")
|
|
|
|
|
private String coopOrderid;
|
|
|
|
|
|
|
|
|
|
@Value("${ab.tbs.channelT}")
|
|
|
|
|
private String channelT;
|
|
|
|
|
|
|
|
|
|
@Value("${ab.tbs.realOrder}")
|
|
|
|
|
private String realOrder;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${ab.xmj.appId}")
|
|
|
|
|
private String xmjAppid;
|
|
|
|
@ -221,6 +251,188 @@ public class ABDownTask {
|
|
|
|
|
log.info("====== [ task start end, task name is {},cost milliSecond is {} ] ======", "ABDownTask", (endMilliSecond-satrtMilliSecond));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 任务处理入口,主要用于时间记录
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Async(value = "abTaskExecutor")
|
|
|
|
|
public void doRunTaskTuboShu(List<ABMessageDTO> messageDTOList){
|
|
|
|
|
Long satrtMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
|
|
log.info("====== [ task start running, task name is {} ] ======", "ABDownTask");
|
|
|
|
|
runTaskTuboShu(messageDTOList);
|
|
|
|
|
Long endMilliSecond = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
|
|
log.info("====== [ task start end, task name is {},cost milliSecond is {} ] ======", "ABDownTask", (endMilliSecond-satrtMilliSecond));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 执行土拨鼠任务
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private boolean runTaskTuboShu(List<ABMessageDTO> messageDTOList){
|
|
|
|
|
|
|
|
|
|
Map<String, Object> formMap = new HashMap<>();
|
|
|
|
|
Map<String, Object> formMapT = new HashMap<>();
|
|
|
|
|
formMap.put("password", passWord);
|
|
|
|
|
formMap.put("coopname", coopname);
|
|
|
|
|
|
|
|
|
|
int countToken = 0;
|
|
|
|
|
String tokenT = "";
|
|
|
|
|
//获取token
|
|
|
|
|
while (countToken < 3) {
|
|
|
|
|
// 调用HTTP请求发送数据
|
|
|
|
|
String result = sendPostReqTuBoShu(formMap, tuBoShuTokenUrl);
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(result);
|
|
|
|
|
tokenT = jsonObject.get("msg").toString();
|
|
|
|
|
if ("0".equals(jsonObject.getString("status"))) {
|
|
|
|
|
log.info("========== [ABDownTask|runTaskTuboShu request success, response is {} ] ==========", jsonObject.toJSONString());
|
|
|
|
|
tokenT = jsonObject.get("msg").toString();
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
countToken++;
|
|
|
|
|
try {
|
|
|
|
|
// 重新发送前休眠3秒
|
|
|
|
|
Thread.sleep(3_0000);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
log.error("ABDownTask|runTaskTuboShu sleep ERROR. message is", e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
log.error("========== [SaveToFileTask|batchSendToEncrypt request fail, response is {} ] ==========", jsonObject.toJSONString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (countToken >= 3 || "".equals(tokenT)) {
|
|
|
|
|
log.error("========== [ABDownTask|runTaskTuboShu update send status fail, url is {} ] ==========");
|
|
|
|
|
return Boolean.FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String finalTokenT = tokenT;
|
|
|
|
|
//调下游接口
|
|
|
|
|
messageDTOList.forEach(
|
|
|
|
|
list -> {
|
|
|
|
|
|
|
|
|
|
// 匹配城市
|
|
|
|
|
if (list.getMobile().length() == 11) {
|
|
|
|
|
String substring = StringUtils.substring(list.getMobile(), 0, list.getMobile().length() - 4);
|
|
|
|
|
String matchCity = phonesRepository.findByNumber(substring);
|
|
|
|
|
if (StringUtils.isNotBlank(matchCity)) {
|
|
|
|
|
formMapT.put("city", matchCity.trim());
|
|
|
|
|
} else {
|
|
|
|
|
// 查不到随机给一个城市
|
|
|
|
|
formMapT.put("city", SpecialCityConst.SPECIAL_RANDOM_CITYS[RandomUtil.randomInt(0, 42)].trim());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
formMapT.put("coopname", coopname);
|
|
|
|
|
formMapT.put("auth_token", finalTokenT);
|
|
|
|
|
formMapT.put("cellphone", list.getMobile());
|
|
|
|
|
// formMapT.put("city", "宁波");
|
|
|
|
|
formMapT.put("chcode", chcode);
|
|
|
|
|
formMapT.put("channel", channelT);
|
|
|
|
|
formMapT.put("real_order", Integer.parseInt(realOrder));
|
|
|
|
|
formMapT.put("coop_orderid", coopOrderid);
|
|
|
|
|
int count = 0;
|
|
|
|
|
while (count < 3) {
|
|
|
|
|
// 调用HTTP请求发送数据
|
|
|
|
|
String result1 = sendPostReqTuBoShu(formMapT, tuBoShuUrl);
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(result1);
|
|
|
|
|
if ("0".equals(jsonObject.getString("status"))) {
|
|
|
|
|
log.info("========== [ABDownTask|runTaskTuboShu request success, response is {} ] ==========", jsonObject.toJSONString());
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
count++;
|
|
|
|
|
try {
|
|
|
|
|
// 重新发送前休眠3秒
|
|
|
|
|
Thread.sleep(3_0000);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
log.error("ABDownTask|runTaskTuboShu sleep ERROR. message is", e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
log.error("========== [ABDownTask|runTaskTuboShu request fail, response is {} ] ==========", jsonObject.toJSONString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (count >= 3) {
|
|
|
|
|
log.error("========== [ABDownTask|runTaskTuboShu update send status fail, url is {} ] ==========");
|
|
|
|
|
}else {
|
|
|
|
|
abMessageService.updateSendStatus(Long.valueOf(list.getRecId()), Boolean.TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return Boolean.TRUE;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 调用HTTP请求发送Post请求
|
|
|
|
|
*
|
|
|
|
|
* @param json 请求的body内容
|
|
|
|
|
* @return 返回请求结果
|
|
|
|
|
*/
|
|
|
|
|
private HttpResponse sendPostReq(String json,String url) {
|
|
|
|
|
|
|
|
|
|
HttpResponse httpResponse = HttpRequest
|
|
|
|
|
.post(url)
|
|
|
|
|
.header("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
|
|
|
|
|
.body(json)
|
|
|
|
|
.execute();
|
|
|
|
|
|
|
|
|
|
return httpResponse;
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
private String sendPostReqTuBoShu(Map<String, Object> formMap ,String urlT){
|
|
|
|
|
String result = "";
|
|
|
|
|
HttpURLConnection connection = null;
|
|
|
|
|
String boundary = "--------------------------132183525382215881770481";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
URL url = new URL(urlT);
|
|
|
|
|
connection = (HttpURLConnection) url.openConnection();
|
|
|
|
|
connection.setRequestMethod("POST");
|
|
|
|
|
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
|
|
|
|
connection.setDoOutput(true);
|
|
|
|
|
connection.setDoInput(true);
|
|
|
|
|
connection.setRequestProperty("Connection", "Keep-Alive");
|
|
|
|
|
// 不使用缓存
|
|
|
|
|
connection.setUseCaches(false);
|
|
|
|
|
|
|
|
|
|
StringBuffer formSB = new StringBuffer();
|
|
|
|
|
if (formMap != null) {
|
|
|
|
|
if (formMap.size() > 0) {
|
|
|
|
|
for (Map.Entry<String, Object> entry : formMap.entrySet()) {
|
|
|
|
|
String inputName = entry.getKey();
|
|
|
|
|
formSB.append("\r\n").append("--").append(boundary).append("\r\n");
|
|
|
|
|
formSB.append("Content-Disposition: form-data; name=\"" + inputName + "\"\r\n\r\n");
|
|
|
|
|
formSB.append(entry.getValue());
|
|
|
|
|
}
|
|
|
|
|
formSB.append("\r\n").append("--").append(boundary).append("--");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
connection.connect();
|
|
|
|
|
//OutputStream out = new DataOutputStream(connection.getOutputStream());
|
|
|
|
|
PrintWriter out = new PrintWriter(new OutputStreamWriter(connection.getOutputStream(), "UTF-8"));
|
|
|
|
|
out.print(formSB.toString());
|
|
|
|
|
out.flush();
|
|
|
|
|
//获得响应状态
|
|
|
|
|
int resultCode = connection.getResponseCode();
|
|
|
|
|
if (HttpURLConnection.HTTP_OK == resultCode) {
|
|
|
|
|
formSB = new StringBuffer();
|
|
|
|
|
String readLine;
|
|
|
|
|
BufferedReader responseReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
|
|
|
|
while ((readLine = responseReader.readLine()) != null) {
|
|
|
|
|
formSB.append(readLine).append("\n");
|
|
|
|
|
}
|
|
|
|
|
responseReader.close();
|
|
|
|
|
result = formSB.toString();
|
|
|
|
|
}
|
|
|
|
|
out.close();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
connection.disconnect();
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 真实的任务执行入口
|
|
|
|
|
*
|
|
|
|
|