第三方接口绕过签名

/**

* 删除

* @param fileId

*/

@Transactional(rollbackFor = AppRuntimeException.class)

@Override

public void del(String fileId,long userId)throws IOException {

Integer user_Id=new Long(userId).intValue();

int row=LiveTapeFileDao.del(fileId,  user_Id);

if(row !=1){

throw  new AppRuntimeException("删除失败"+fileId);

}

String url="v2/index.php";

final ObjectMapper mapper =new ObjectMapper();

String resp =null;

try {

resp = executePost(url ,fileId);

}catch (Exception e) {

e.printStackTrace();

}

logger.info("resp************={}",resp);

LiveTapeFileCodeVO liveTapeFileCodeVO = mapper.readValue(resp, LiveTapeFileCodeVO.class);

if(liveTapeFileCodeVO.getCode() !=0){

throw  new AppRuntimeException("腾讯云录播文件删除失败");

}

logger.info("liveTapeFileCodeVO************={}",liveTapeFileCodeVO);

}

private String executePost(String apiUrl ,String fileId)throws Exception {

logger.debug("api url = {}", apiUrl);

logger.debug("fileId  = {}", fileId);

String Action="DeleteVodFile";

String Region="gz";

String Timestamp =Long.toString(new Date().getTime());

int temp=0;

int[] arr =new int[10];

for(int i=0; i<10; i++){

arr[i] = i +1;

}

Random random =new Random();

int size = arr.length;

for(int k=0; k

int index =0;

if((size -1)-k !=0){

index = random.nextInt((size -1)-k);

}

temp=arr[index];

arr[index] = arr[size - (k +1)];

arr[size - (k +1)] = temp;

}

Integer Nonce=temp;

String SecretId="xxxxxxx";

String Signature="mysignature";

JSONObject JSONObject=new JSONObject();

JSONObject.put("Action",Action);

JSONObject.put("Region",Region);

JSONObject.put("Timestamp",Timestamp);

JSONObject.put("Nonce",Nonce);

JSONObject.put("SecretId",SecretId);

JSONObject.put("Signature",Signature);

logger.info("组件的json"+JSONObject.toString());

try {

final ResponseEntity responseEntity = getRestTemplateBypassingHostNameVerifcation().postForEntity(buildUri(apiUrl,fileId,JSONObject),"{}", String.class);

logger.debug("HTTP status code = {}", responseEntity.getStatusCode());

if (!responseEntity.getStatusCode().is2xxSuccessful()) {

throw new Exception("HTTP请求失败!");

}

return responseEntity.getBody();

}catch (RestClientException e) {

throw new Exception("RestClientException: " + e.getMessage());

}catch (URISyntaxException e) {

throw new Exception("组装请求URL失败!请求未发出");

}

}

public RestTemplate getRestTemplateBypassingHostNameVerifcation() {

CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();

HttpComponentsClientHttpRequestFactory requestFactory =new HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(httpClient);

return new RestTemplate(requestFactory);

}

private URI buildUri(final String apiUrl, String fileId, JSONObject JSONObject)throws URISyntaxException {

return new URIBuilder()

.setScheme("https")

.setHost("vod.api.qcloud.com")

.setPath(apiUrl)

.setParameter("Action","DeleteVodFile")

.setParameter("fileId",fileId)

.setParameter("priority","0")

.setParameter("COMMON_PARAMS",JSONObject.toString())

.build();

}

你可能感兴趣的:(第三方接口绕过签名)