//向对应业务平台发起消息通知 try { TBpMonitorAnchor monitorAnchor = monitorAnchorService.selectByPrimaryKey(anchorId); if (monitorAnchor != null) { TBpBusinessPlatformInfo businessPlatformInfo = businessPlatformInfoService.selectByPrimaryKey(monitorAnchor.getPlatformId());
//获取到回调地址 String callbackUrl = businessPlatformInfo.getCallbackUrl(); RestTemplate restTemplate = new RestTemplate(); //封装请求参数 Map<String, Object> requestBody = new HashMap<String, Object>(16); Map<String, Object> map = new HashMap<>(16); map.put("anchorArchivesCode", monitorAnchor.getAnchorArchivesCode()); map.put("anchorStatus", "-1");
//将参数转化为字节类型(注意了类型为UTF-8) byte[] bytes = JSON.toJSONString(map).getBytes(StandardCharsets.UTF_8); //通过Base64对参数进行编码,对应的获取到参数是也要对其使用Base64解码,类型为编码类型(UTF-8) requestBody.put("data", Base64.getEncoder().encodeToString(bytes)); requestBody.put("type", "monitorAnchorStatus"); HttpHeaders requestHeaders = new HttpHeaders();
//这三个一般为固定写法 requestHeaders.setContentType(MediaType.APPLICATION_JSON); requestHeaders.set(HttpHeaders.ACCEPT_CHARSET, StandardCharsets.UTF_8.toString()); requestHeaders.set(HttpHeaders.ACCEPT_ENCODING, StandardCharsets.UTF_8.toString()); HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(requestBody, requestHeaders); //发送post请求 restTemplate.postForObject(callbackUrl, httpEntity, HttpDataResult.class); } } catch (Exception e) { log.error("发送消息拆除通知失败!"); e.printStackTrace(); }