|
|
@ -26,6 +26,7 @@ import org.apache.http.impl.client.HttpClients; |
|
|
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; |
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
@ -40,6 +41,7 @@ import java.security.cert.X509Certificate; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author feikefei |
|
|
@ -54,9 +56,12 @@ public class QichachaConfig { |
|
|
|
@Autowired |
|
|
|
private BusinessRiskDateService businessRiskDateService; |
|
|
|
|
|
|
|
public static String APPkey = "9214e7ce4a3a483c8c115771a5f018e1"; |
|
|
|
private static final String secretKey = "5827FC97C3DBFBC28444ADD3949C6FD4"; |
|
|
|
public static String URL = "https://api.qichacha.com/ExceptionCheck/GetList"; |
|
|
|
@Value("${qichacha.appKey}") |
|
|
|
private String APPkey; |
|
|
|
@Value("${qichacha.secretKey}") |
|
|
|
private String secretKey; |
|
|
|
@Value("${qichacha.URL}") |
|
|
|
private String URL; |
|
|
|
|
|
|
|
//设置连接超时时间,单位毫秒。
|
|
|
|
public final static int CONNECT_TIMEOUT = 30000; |
|
|
@ -66,34 +71,34 @@ public class QichachaConfig { |
|
|
|
public final static int SOCKET_TIMEOUT = 30000; |
|
|
|
|
|
|
|
//每周日凌晨1点执行
|
|
|
|
@Scheduled(cron = "0 0 1 ? * 1") |
|
|
|
// @Scheduled(cron = "0 0 1 ? * 1")
|
|
|
|
public void enterpriseRiskInquiry(){ |
|
|
|
// String currDay = DateUtil.format(DateUtil.offsetDay(new Date(), -1), "yyyy-MM-dd");
|
|
|
|
// List<EnterpriseInformation> list = enterpriseInformationService.enterpriseInformationList();
|
|
|
|
// for (EnterpriseInformation enterpriseInformation : list) {
|
|
|
|
// String paramStr = "searchKey=" + enterpriseInformation.getEnterpriseName();
|
|
|
|
// String status = "";
|
|
|
|
// try {
|
|
|
|
// HttpHead reqHeader = new HttpHead();
|
|
|
|
// String[] autherHeader = RandomAuthentHeader();
|
|
|
|
// reqHeader.setHeader("Token", autherHeader[0]);
|
|
|
|
// reqHeader.setHeader("Timespan", autherHeader[1]);
|
|
|
|
// final String reqUri = URL.concat("?key=").concat(APPkey).concat("&").concat(paramStr);
|
|
|
|
// String tokenJson = httpGet(reqUri, reqHeader.getAllHeaders());
|
|
|
|
// System.out.println(String.format("==========================>this is response:{%s}", tokenJson));
|
|
|
|
// status = FormartJson(tokenJson, "Status");
|
|
|
|
// System.out.println(String.format("==========================>Status:{%s}", status));
|
|
|
|
// BusinessRiskDateDto businessRiskDate = new BusinessRiskDateDto();
|
|
|
|
// businessRiskDate.setExecutionTime(currDay);
|
|
|
|
// businessRiskDate.setBusinessName(enterpriseInformation.getEnterpriseName());
|
|
|
|
// //// TODO: 2023/6/7
|
|
|
|
//// businessRiskData.setBuSid(businessRiskDate.getSid());
|
|
|
|
//// businessRiskDate.setDataList();
|
|
|
|
// businessRiskDateService.save(businessRiskDate);
|
|
|
|
// }catch (Exception e){
|
|
|
|
// e.printStackTrace();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
String currDay = DateUtil.format(new Date(), "yyyy-MM-dd"); |
|
|
|
List<EnterpriseInformation> list = enterpriseInformationService.enterpriseInformationList(); |
|
|
|
for (EnterpriseInformation enterpriseInformation : list) { |
|
|
|
String paramStr = "searchKey=" + enterpriseInformation.getEnterpriseName(); |
|
|
|
try { |
|
|
|
HttpHead reqHeader = new HttpHead(); |
|
|
|
String[] autherHeader = RandomAuthentHeader(); |
|
|
|
reqHeader.setHeader("Token", autherHeader[0]); |
|
|
|
reqHeader.setHeader("Timespan", autherHeader[1]); |
|
|
|
final String reqUri = URL.concat("?key=").concat(APPkey).concat("&").concat(paramStr); |
|
|
|
String tokenJson = httpGet(reqUri, reqHeader.getAllHeaders()); |
|
|
|
System.out.println(String.format("==========================>this is response:{%s}", tokenJson)); |
|
|
|
BusinessRiskDateDto businessRiskDateDto = FormartJson(tokenJson); |
|
|
|
businessRiskDateDto.setBusinessName(enterpriseInformation.getEnterpriseName()); |
|
|
|
businessRiskDateDto.setExecutionTime(currDay); |
|
|
|
Map<String, Object> result = businessRiskDateDto.getResult(); |
|
|
|
if (result == null){ |
|
|
|
businessRiskDateDto.setVerifyResult("0"); |
|
|
|
}else { |
|
|
|
businessRiskDateDto.setVerifyResult(businessRiskDateDto.getResult().get("VerifyResult").toString()); |
|
|
|
} |
|
|
|
businessRiskDateService.save(businessRiskDateDto); |
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception { |
|
|
@ -144,40 +149,35 @@ public class QichachaConfig { |
|
|
|
// }
|
|
|
|
// System.out.println("************-----------****************");
|
|
|
|
// System.out.println(body);
|
|
|
|
String paramStr = "searchKey=石家庄瀚川商贸有限公司"; |
|
|
|
String status = ""; |
|
|
|
// String paramStr = "searchKey=石家庄瀚川商贸有限公司";
|
|
|
|
try { |
|
|
|
HttpHead reqHeader = new HttpHead(); |
|
|
|
String[] autherHeader = RandomAuthentHeader(); |
|
|
|
reqHeader.setHeader("Token", autherHeader[0]); |
|
|
|
reqHeader.setHeader("Timespan", autherHeader[1]); |
|
|
|
final String reqUri = URL.concat("?key=").concat(APPkey).concat("&").concat(paramStr); |
|
|
|
String tokenJson = httpGet(reqUri, reqHeader.getAllHeaders()); |
|
|
|
System.out.println(String.format("==========================>this is response:{%s}", tokenJson)); |
|
|
|
|
|
|
|
status = FormartJson(tokenJson, "Status"); |
|
|
|
System.out.println(String.format("==========================>Status:{%s}", status)); |
|
|
|
// HttpHead reqHeader = new HttpHead();
|
|
|
|
// String[] autherHeader = RandomAuthentHeader();
|
|
|
|
// reqHeader.setHeader("Token", autherHeader[0]);
|
|
|
|
// reqHeader.setHeader("Timespan", autherHeader[1]);
|
|
|
|
// final String reqUri = URL.concat("?key=").concat(APPkey).concat("&").concat(paramStr);
|
|
|
|
// String tokenJson = httpGet(reqUri, reqHeader.getAllHeaders());
|
|
|
|
// System.out.println(String.format("==========================>this is response:{%s}", tokenJson));
|
|
|
|
//
|
|
|
|
// BusinessRiskDateDto businessRiskDateDto = FormartJson(tokenJson);
|
|
|
|
}catch (Exception e){ |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 获取Auth Code
|
|
|
|
protected static final String[] RandomAuthentHeader() { |
|
|
|
protected final String[] RandomAuthentHeader() { |
|
|
|
String timeSpan = String.valueOf(System.currentTimeMillis() / 1000); |
|
|
|
String[] authentHeaders = new String[] { DigestUtils.md5Hex(APPkey.concat(timeSpan).concat(secretKey)).toUpperCase(), timeSpan }; |
|
|
|
return authentHeaders; |
|
|
|
} |
|
|
|
|
|
|
|
// 解析JSON
|
|
|
|
protected static String FormartJson(String jsonString, String key) throws JSONException { |
|
|
|
// 解析JSON
|
|
|
|
protected static BusinessRiskDateDto FormartJson(String jsonString) throws JSONException { |
|
|
|
JSONObject jObject = new JSONObject(jsonString); |
|
|
|
BusinessRiskDataDto businessRiskDataDto = jObject.toBean(BusinessRiskDataDto.class); |
|
|
|
|
|
|
|
// Gson gson = new Gson();
|
|
|
|
// List<BusinessRiskDataDto> businessRiskDataDto = gson.fromJson(jsonString, List.class);
|
|
|
|
// List<BusinessRiskDataDto> riskDataDto = JSON.parseArray(jsonString, BusinessRiskDataDto.class);
|
|
|
|
return (String) jObject.get(key); |
|
|
|
BusinessRiskDateDto businessRiskDateDto = jObject.toBean(BusinessRiskDateDto.class); |
|
|
|
return businessRiskDateDto; |
|
|
|
} |
|
|
|
|
|
|
|
public static String httpGet(String url, Header[] headers) throws Exception { |
|
|
|