Merge remote-tracking branch 'origin/master'

master
bynt 3 years ago
commit 9103d4421b

@ -0,0 +1,35 @@
package com.yuyou.openapi.openapi.model.pojo.token;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TuBoShuTokenResponse {
@JSONField(name = "akey")
private Integer error_code;
@JSONField(name = "status")
private String status;
@JSONField(name = "token")
private String token;
@JSONField(name = "data")
private TOKEN data;
@Data
public static class TOKEN{
@JSONField(name = "expires_in")
private Integer expiresIn;
@JSONField(name = "expires_time")
private Long expiresTime;
}
}

@ -3,26 +3,23 @@ package com.yuyou.openapi.openapi.task;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yuyou.openapi.openapi.api.enums.LuoShiAppIDEnum;
import com.yuyou.openapi.openapi.common.enums.IntentionEnum;
import com.yuyou.openapi.openapi.common.enums.SourceEnum;
import com.yuyou.openapi.openapi.consts.SmsConstant;
import com.yuyou.openapi.openapi.consts.SpecialCityConst;
import com.yuyou.openapi.openapi.dao.PhonesRepository;
import com.yuyou.openapi.openapi.model.dto.*;
import com.yuyou.openapi.openapi.model.pojo.BlackJsonContent;
import com.yuyou.openapi.openapi.model.pojo.QiZhuangDTO;
import com.yuyou.openapi.openapi.model.pojo.token.QiZhuangTokenResponse;
import com.yuyou.openapi.openapi.model.pojo.token.TuBoShuTokenResponse;
import com.yuyou.openapi.openapi.model.vo.ABClientXMJMessageVO;
import com.yuyou.openapi.openapi.model.vo.data.DetailInfo;
import com.yuyou.openapi.openapi.service.ABMessageService;
@ -263,10 +260,10 @@ public class ABDownTask {
@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");
log.info("====== [ task start running, task name is {} ] ======", "doRunTaskTuboShu");
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));
log.info("====== [ task start end, task name is {},cost milliSecond is {} ] ======", "doRunTaskTuboShu", (endMilliSecond-satrtMilliSecond));
}
/**
*
@ -275,22 +272,24 @@ public class ABDownTask {
*/
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();
TuBoShuTokenResponse tuBoShuTokenResponse = abScheduleTask.getTuBoShuTokenResponse();
// 检查如果第一次不存在就手动调用一次
if (null == tuBoShuTokenResponse){
abScheduleTask.executeGetTokenTuboshu();
tuBoShuTokenResponse = abScheduleTask.getTuBoShuTokenResponse();
}
if (tuBoShuTokenResponse != null){
if ("0".equals(tuBoShuTokenResponse.getStatus())) {
log.info("========== [ABDownTask|runTaskTuboShu request success, response is {} ] ==========", tuBoShuTokenResponse.toString());
tokenT = tuBoShuTokenResponse.getToken();
break;
} else {
countToken++;
@ -298,13 +297,24 @@ public class ABDownTask {
// 重新发送前休眠3秒
Thread.sleep(3_0000);
} catch (InterruptedException e) {
log.error("ABDownTask|runTaskTuboShu sleep ERROR. message is", e.getMessage(), e);
log.error("ABDownTask|runTaskTuboShu sleep ERROR. message is {} , {}", e.getMessage(), e);
}
log.error("========== [ABDownTask|runTaskTuboShu request fail, response is {} ] ==========", tuBoShuTokenResponse.toString());
}
}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());
log.error("========== [ABDownTask|runTaskTuboShu request fail, response is {} ] ==========", tuBoShuTokenResponse.toString());
}
}
if (countToken >= 3 || "".equals(tokenT)) {
log.error("========== [ABDownTask|runTaskTuboShu update send status fail, url is {} ] ==========");
log.error("========== [ABDownTask|runTaskTuboShu update send status fail, url is {} ] ==========", tuBoShuTokenUrl);
return Boolean.FALSE;
}
@ -314,8 +324,8 @@ public class ABDownTask {
list -> {
// 匹配城市
if (list.getMobile().length() == 11) {
String substring = StringUtils.substring(list.getMobile(), 0, list.getMobile().length() - 4);
if (Base64.decodeStr(list.getMobile()).length() == 11) {
String substring = StringUtils.substring(Base64.decodeStr(list.getMobile()), 0, Base64.decodeStr(list.getMobile()).length() - 4);
String matchCity = phonesRepository.findByNumber(substring);
if (StringUtils.isNotBlank(matchCity)) {
formMapT.put("city", matchCity.trim());
@ -332,7 +342,9 @@ public class ABDownTask {
formMapT.put("chcode", chcode);
formMapT.put("channel", channelT);
formMapT.put("real_order", Integer.parseInt(realOrder));
formMapT.put("coop_orderid", coopOrderid);
formMapT.put("coop_orderid", ""+list.getRecId()+(int)(Math.random()*90000+1000));
log.info("========== [ABDownTask|runTaskTuboShu request content is {} ] ==========", formMapT.toString());
int count = 0;
while (count < 3) {
// 调用HTTP请求发送数据
@ -347,13 +359,13 @@ public class ABDownTask {
// 重新发送前休眠3秒
Thread.sleep(3_0000);
} catch (InterruptedException e) {
log.error("ABDownTask|runTaskTuboShu sleep ERROR. message is", e.getMessage(), 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 {} ] ==========");
log.error("========== [ABDownTask|runTaskTuboShu update send status fail, url is {} ] ==========", tuBoShuUrl);
}else {
abMessageService.updateSendStatus(Long.valueOf(list.getRecId()), Boolean.TRUE);
}

@ -6,14 +6,25 @@ import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yuyou.openapi.openapi.model.pojo.token.QiZhuangTokeRequest;
import com.yuyou.openapi.openapi.model.pojo.token.QiZhuangTokenResponse;
import com.yuyou.openapi.openapi.model.pojo.token.TuBoShuTokenResponse;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
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.util.HashMap;
import java.util.Map;
@Component
@Slf4j
@Getter
@ -28,8 +39,19 @@ public class ABScheduleTask {
@Value("${ab.qj.ckey}")
private String qiJiaCKey;
@Value("${ab.tbs.password}")
private String passWord;
@Value("${ab.tbs.coopname}")
private String coopname;
@Value("${ab.tbs.tokenurl}")
private String tuBoShuTokenUrl;
private QiZhuangTokenResponse qiZhuangTokenResponse;
private TuBoShuTokenResponse tuBoShuTokenResponse;
/**
@ -47,6 +69,25 @@ public class ABScheduleTask {
qiZhuangTokenResponse = JSONUtil.toBean(body, QiZhuangTokenResponse.class);
}
/**
*
*/
@Scheduled(cron = "0 0 0/2 * * ? ")
public void executeGetTokenTuboshu() {
log.info("ABScheduleTask|executeGetTokenTuboshu is run , run Time is {}", DateUtil.date());
// 先去拿Token
Map<String, Object> formMap = new HashMap<>();
formMap.put("password", passWord);
formMap.put("coopname", coopname);
String body = sendPostReqTuBoShuToken(formMap,tuBoShuTokenUrl);
log.info("ABScheduleTask|executeGetTokenTuboshu , sendPostReqTuBoShuToken is {}", body);
TuBoShuTokenResponse tuBoShuTokenResponse1 = new TuBoShuTokenResponse();
JSONObject jsonObject = JSON.parseObject(body);
tuBoShuTokenResponse1.setToken(jsonObject.getString("msg"));
tuBoShuTokenResponse1.setStatus(jsonObject.getString("status"));
tuBoShuTokenResponse = tuBoShuTokenResponse1;
}
/**
*
@ -75,5 +116,66 @@ public class ABScheduleTask {
return httpResponse;
}
/**
* HTTP token
*
* @param formMap body
* @param urlT url
* @return
*/
private String sendPostReqTuBoShuToken(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;
}
}

@ -1,6 +1,6 @@
spring:
profiles:
active: dev
active: prod
# 序列化忽略null的k-v配置
jackson:
default-property-inclusion: non_null

Loading…
Cancel
Save