@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSON; | |||
import com.alibaba.fastjson.JSONObject; | |||
import lombok.extern.slf4j.Slf4j; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.Objects; | |||
/** | |||
@@ -14,16 +16,38 @@ import java.util.Objects; | |||
*/ | |||
@Slf4j | |||
public class RefreshKeyUtil { | |||
public static String getRequestSecret(String appKey, String appSecret) { | |||
Long requestTime = System.currentTimeMillis(); | |||
public static String getRequestSecret(String appKey, String appSecret,Long requestTime) { | |||
// 刷新秘钥 | |||
HttpUtil httpUtil = HttpUtil.getInstance(); | |||
log.info("请求密钥" + appSecret); | |||
String refreshSign = Md5Utils.hash (appKey + appSecret + requestTime); | |||
String refreshUrl = String.format ("http://59.202.38.178/gateway/app/refreshTokenByKey.htm" + | |||
"?appKey=%s&requestTime=%s&sign=%s", appKey, requestTime +"",refreshSign); | |||
String sign = Md5Utils.hash (appKey + appSecret + requestTime); | |||
String refreshUrl = "http://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm"; | |||
log.info(refreshUrl); | |||
String result = httpUtil.sendHttpGet(refreshUrl); | |||
Map<String,String> map = new HashMap<>(); | |||
map.put("appKey",appKey); | |||
map.put("sign",sign); | |||
map.put("requestTime",requestTime + ""); | |||
String result = httpUtil.sendHttpPost(refreshUrl,map); | |||
log.info(result); | |||
JSONObject dataJson = JSON.parseObject(result).getJSONObject("datas"); | |||
if(Objects.nonNull(dataJson)){ | |||
return dataJson.getString("requestSecret"); | |||
} | |||
return result; | |||
} | |||
public static String refreshSecret(String appKey, String refreshSecret,Long requestTime) { | |||
// 刷新秘钥 | |||
HttpUtil httpUtil = HttpUtil.getInstance(); | |||
log.info("刷新密钥" + refreshSecret); | |||
String refreshSign = Md5Utils.hash (appKey + refreshSecret + requestTime); | |||
String refreshUrl = "http://interface.zjzwfw.gov.cn/gateway/app/refreshTokenBySec.htm"; | |||
log.info(refreshUrl); | |||
Map<String,String> map = new HashMap<>(); | |||
map.put("appKey",appKey); | |||
map.put("sign",refreshSign); | |||
map.put("requestTime",requestTime + ""); | |||
String result = httpUtil.sendHttpPost(refreshUrl,map); | |||
log.info(result); | |||
JSONObject dataJson = JSON.parseObject(result).getJSONObject("datas"); | |||
if(Objects.nonNull(dataJson)){ | |||
@@ -22,5 +22,7 @@ public class ForwardDTO implements Serializable { | |||
private String url; | |||
private String secret; | |||
private String appKey; | |||
private String sign; | |||
private Long requestTime; | |||
private Map<String,Object> data; | |||
} |
@@ -117,11 +117,7 @@ public class IrsManage { | |||
public String forward(ForwardDTO dto) { | |||
try{ | |||
String url = dto.getUrl(); | |||
String appkey = dto.getAppKey(); | |||
long timestamp = System.currentTimeMillis(); | |||
String requestSecret = dto.getSecret(); | |||
String sign = CryptUtils.MD5Encode(appkey + requestSecret + timestamp); | |||
url = url + "?requestTime=" + timestamp + "&sign=" + sign + asUrlParams(dto.getData()); | |||
url = url + "?" + asUrlParams(dto.getData()); | |||
log.info("url :{}",url); | |||
RestTemplate restTemplate = new RestTemplate(); | |||
ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class); | |||
@@ -7,7 +7,6 @@ import com.ningdatech.pmapi.gov.manage.GovProjectCollectionManage; | |||
import com.ningdatech.pmapi.gov.model.vo.GovBizProjectDetailVO; | |||
import com.ningdatech.pmapi.gov.model.vo.GovBizProjectListVO; | |||
import com.ningdatech.pmapi.projectlib.model.req.ProjectListReq; | |||
import com.ningdatech.pmapi.scheduler.utils.DateUtil; | |||
import lombok.RequiredArgsConstructor; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
@@ -36,9 +35,6 @@ public class SynProjectCollectionTask { | |||
private GovProjectCollectionManage collectionManage; | |||
private final Integer PAGE_NUMBER = 1; | |||
private final Integer TASK_HOUR = 1; | |||
private final Integer TASK_HOUR_TODAY = 18; | |||
/** | |||
* 前置机每天晚上10点自动清空,第二天早上6点获取数据 | |||
@@ -62,10 +58,8 @@ public class SynProjectCollectionTask { | |||
log.info("数据同步任务开始之前 先删除前置机上的所有数据"); | |||
collectionManage.deleteAll(); | |||
//取昨天1点 到今天1点的 项目归集 | |||
//全量项目归集 | |||
ProjectListReq req = new ProjectListReq(); | |||
req.setCreateOnMax(DateUtil.convertDateToLocal(DateUtil.getTodayTime(TASK_HOUR_TODAY))); | |||
req.setCreateOnMin(DateUtil.convertDateToLocal(DateUtil.getTodayTime(TASK_HOUR)).plusDays(-1)); | |||
Long count = collectionManage.count(req); | |||
if(count == 0L){ | |||
log.info("本次同步无数据"); | |||
@@ -223,8 +223,8 @@ irs: | |||
appKey: A331101453557202109017383 | |||
interface-refresh: | |||
method: POST | |||
request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
refresh-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenBySec.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
request-token-url: http://59.202.38.178/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
refresh-token-url: http://59.202.38.178/gateway/app/refreshTokenBySec.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
interface-local-refresh: | |||
method: GET | |||
request-token-url: https://interface.ls.local/a/api/requestTokenKey?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
@@ -226,8 +226,8 @@ irs: | |||
appKey: A331101453557202109017383 | |||
interface-refresh: | |||
method: POST | |||
request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
refresh-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenBySec.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
request-token-url: http://59.202.38.178/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
refresh-token-url: http://59.202.38.178/gateway/app/refreshTokenBySec.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
interface-local-refresh: | |||
method: GET | |||
request-token-url: https://interface.ls.local/a/api/requestTokenKey?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
@@ -226,8 +226,8 @@ irs: | |||
appKey: A331101453557202109017383 | |||
interface-refresh: | |||
method: POST | |||
request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
refresh-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenBySec.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
request-token-url: http://59.202.38.178/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
refresh-token-url: http://59.202.38.178/gateway/app/refreshTokenBySec.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
interface-local-refresh: | |||
method: GET | |||
request-token-url: https://interface.ls.local/a/api/requestTokenKey?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
@@ -6,6 +6,8 @@ import com.ningdatech.irs.service.IRefreshTokenService; | |||
import com.ningdatech.pmapi.AppTests; | |||
import com.ningdatech.pmapi.common.util.CryptUtils; | |||
import com.ningdatech.pmapi.common.util.HttpUtil; | |||
import com.ningdatech.pmapi.common.util.Md5Utils; | |||
import com.ningdatech.pmapi.common.util.RefreshKeyUtil; | |||
import com.ningdatech.pmapi.gov.model.req.ProjectPushReq; | |||
import com.ningdatech.pmapi.irs.model.dto.ForwardDTO; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -27,38 +29,43 @@ import java.util.Objects; | |||
* @Author PoffyZhang | |||
*/ | |||
@Slf4j | |||
public class CoreTest extends AppTests { | |||
public class CoreTest {//extends AppTests | |||
@Value("${irs.core-biz.appKey}") | |||
private String appKey; | |||
// @Value("${irs.core-biz.appKey}") | |||
private String appKey = "A331101453557202109017383"; | |||
@Value("${irs.core-biz.appSecret}") | |||
private String appSecret; | |||
// @Value("${irs.core-biz.appSecret}") | |||
private String appSecret = "496f0f2a19994f76b4fd9dae087366c7"; | |||
@Value("${irs.core-biz.url}") | |||
private String coreBizUrl; | |||
// @Value("${irs.core-biz.url}") | |||
private String coreBizUrl = "https://interface.zjzwfw.gov.cn/gateway/api/001008012012001/dataSharing/Fc3re2cq7r64Qfa7.htm"; | |||
// @Value("${irs.core-biz.interfaceName}") | |||
private String interfaceName = "Fc3re2cq7r64Qfa7"; | |||
@Value("${irs.core-biz.interfaceName}") | |||
private String interfaceName; | |||
@Resource | |||
private IRefreshTokenService refreshTokenService; | |||
@Value("${irs.interface-refresh.request-token-url}") | |||
// @Value("${irs.interface-refresh.request-token-url}") | |||
private String govRequestTokenUrl; | |||
@Value("${irs.interface-refresh.refresh-token-url}") | |||
// @Value("${irs.interface-refresh.refresh-token-url}") | |||
private String govRefreshTokenUrl; | |||
@Test | |||
public void searchCoreBiz() { | |||
long requestTime = System.currentTimeMillis(); | |||
String businessName = ""; | |||
String orgCode = ""; | |||
Integer limit = 10; | |||
Integer page = 1; | |||
long timestamp = System.currentTimeMillis(); | |||
// String secret = refreshTokenService.refreshToken(appKey, appSecret, govRequestTokenUrl, govRefreshTokenUrl, | |||
// interfaceName, HttpMethod.POST.name()); | |||
String secret = appSecret; | |||
// String secret = "a4cffda647a848279646cbb10a9c297c"; | |||
// String secret = appSecret; | |||
String secret = RefreshKeyUtil.getRequestSecret(appKey, appSecret,requestTime); | |||
// String secret = RefreshKeyUtil.refreshSecret(appKey, "78cde959148b4335b8eba556f9c8c7bf",requestTime); | |||
System.out.println("secret:" + secret); | |||
HttpComponentsClientHttpRequestFactory factory = HttpUtil.generateHttpRequestFactory(); | |||
RestTemplate restTemplate; | |||
if(Objects.nonNull(factory)){ | |||
@@ -78,14 +85,18 @@ public class CoreTest extends AppTests { | |||
dto.setUrl(coreBizUrl); | |||
dto.setSecret(secret); | |||
dto.setAppKey(appKey); | |||
dto.setSecret(secret); | |||
dto.setRequestTime(requestTime); | |||
String sign = Md5Utils.hash(appKey + secret + requestTime); | |||
dto.setSign(sign); | |||
HttpHeaders headers = new HttpHeaders(); | |||
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); | |||
headers.setContentType(type); | |||
headers.add("Accept", MediaType.APPLICATION_JSON.toString()); | |||
HttpEntity<ForwardDTO> formEntity = new HttpEntity<ForwardDTO>(dto, headers); | |||
String url = "http://10.53.168.41:38888/pm/api/v1/zwdd/pull/forward"; | |||
String url = "http://10.53.168.41:38088/open/api/v1/project-receive/forward"; | |||
ResponseEntity<String> forEntity = restTemplate.postForEntity(url,formEntity, String.class); | |||
String body = forEntity.getBody(); | |||
System.out.println(body);; | |||
System.out.println(body); | |||
} | |||
} |
@@ -0,0 +1,18 @@ | |||
package com.ningdatech.pmapi.irs; | |||
import org.junit.Test; | |||
/** | |||
* @Classname CurrentTest | |||
* @Description | |||
* @Date 2023/9/4 9:26 | |||
* @Author PoffyZhang | |||
*/ | |||
public class CurrentTest { | |||
@Test | |||
public void currentTime(){ | |||
System.out.println(System.currentTimeMillis()); | |||
} | |||
} |
@@ -223,8 +223,8 @@ irs: | |||
appKey: A331101453557202109017383 | |||
interface-refresh: | |||
method: POST | |||
request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
refresh-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenBySec.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
request-token-url: http://59.202.38.178/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
refresh-token-url: http://59.202.38.178/gateway/app/refreshTokenBySec.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
interface-local-refresh: | |||
method: GET | |||
request-token-url: https://interface.ls.local/a/api/requestTokenKey?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
@@ -226,8 +226,8 @@ irs: | |||
appKey: A331101453557202109017383 | |||
interface-refresh: | |||
method: POST | |||
request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
refresh-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenBySec.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
request-token-url: http://59.202.38.178/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
refresh-token-url: http://59.202.38.178/gateway/app/refreshTokenBySec.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
interface-local-refresh: | |||
method: GET | |||
request-token-url: https://interface.ls.local/a/api/requestTokenKey?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
@@ -226,8 +226,8 @@ irs: | |||
appKey: A331101453557202109017383 | |||
interface-refresh: | |||
method: POST | |||
request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
refresh-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenBySec.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
request-token-url: http://59.202.38.178/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
refresh-token-url: http://59.202.38.178/gateway/app/refreshTokenBySec.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||
interface-local-refresh: | |||
method: GET | |||
request-token-url: https://interface.ls.local/a/api/requestTokenKey?appKey={appKey}&requestTime={requestTime}&sign={sign} | |||