|
@@ -0,0 +1,173 @@
|
|
|
+package com.sooka.sponest.monitor.chinatower.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.dahuatech.hutool.core.util.HexUtil;
|
|
|
+import com.dahuatech.hutool.http.HttpRequest;
|
|
|
+import com.dahuatech.hutool.http.HttpResponse;
|
|
|
+import com.sooka.sponest.monitor.camera.domain.CentermonitorTCamera;
|
|
|
+import com.sooka.sponest.monitor.chinatower.service.ChinaTowerService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.crypto.Mac;
|
|
|
+import javax.crypto.spec.SecretKeySpec;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+import static org.springframework.web.bind.annotation.RequestMethod.POST;
|
|
|
+
|
|
|
+@Api(tags = "铁塔视联控制器")
|
|
|
+@RestController
|
|
|
+@RequestMapping("ChinaTower")
|
|
|
+@Slf4j
|
|
|
+public class ChinaTowerController {
|
|
|
+
|
|
|
+ Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ChinaTowerService chinaTowerService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据铁塔设备编码获取大华摄像头实体
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/getCameraByChinaTowerDeviceCode/{deviceCode}")
|
|
|
+ public CentermonitorTCamera getCameraByChinaTowerDeviceCode(@PathVariable String deviceCode) {
|
|
|
+ return chinaTowerService.getCameraByChinaTowerDeviceCode(deviceCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据铁塔设备编码获取铁塔订单号
|
|
|
+ */
|
|
|
+ @GetMapping("/getOrderCodeByChinaTowerDeviceCode/{deviceCode}")
|
|
|
+ public String getOrderCodeByChinaTowerDeviceCode(@PathVariable("deviceCode") String deviceCode){
|
|
|
+ return chinaTowerService.getOrderCodeByChinaTowerDeviceCode(deviceCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/orderReceiver", method = POST)
|
|
|
+ public void orderReceiver(@RequestBody String body) {
|
|
|
+ logger.info("收到铁塔视联订单信息:" + body);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ static String servicePath = "/file/obsFiles/getObsEncryptUrls";
|
|
|
+ /**
|
|
|
+ * 新网关
|
|
|
+ */
|
|
|
+ static String HOST_IP = "https://sl-neimenggu.chinatowercom.cn:9997";
|
|
|
+ /**
|
|
|
+ * AK 由运管这边提供
|
|
|
+ */
|
|
|
+ static String AK = "012626d75ab147858ff7fdf9ea44b74d";
|
|
|
+ /**
|
|
|
+ * SK 由运管这边提供
|
|
|
+ */
|
|
|
+ static String SK = "dce85f55cad140498936e7832e6528ad";
|
|
|
+ /**
|
|
|
+ * 行业编码 由运管这边提供
|
|
|
+ */
|
|
|
+ static String appCode = "700002";
|
|
|
+ /**
|
|
|
+ * 订购客户编码,用于订购鉴权,需要一一对应
|
|
|
+ */
|
|
|
+ static String customer = "124012301";
|
|
|
+ /**
|
|
|
+ * 订单号,用于订购鉴权,需要一一对应
|
|
|
+ */
|
|
|
+// static String orderCode = "PO124012301202503303260509147136";
|
|
|
+// static String orderCode = "PO124012301202503302702024986624";
|
|
|
+ static String orderCode = "PO124012301202504047918802915328";
|
|
|
+ /**
|
|
|
+ * 用户编码,暂可以填随意值
|
|
|
+ */
|
|
|
+ static String userCode = "0a97fb806ab24ca8bc788dc6ace3d4c2";
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ getObsEncryptUrls();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void getObsEncryptUrls(){
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ // 这里的 url是发送请求拼接url
|
|
|
+ String url = HOST_IP + servicePath;
|
|
|
+ String msgId = UUID.randomUUID().toString().replace("-", "");
|
|
|
+ System.out.println("msgId:" + msgId);
|
|
|
+ String requestTime = dateFormat.format(new Date());
|
|
|
+ System.out.println("requestTime:" + requestTime);
|
|
|
+ String signContext = getSignContext(servicePath, AK, msgId, requestTime, customer, userCode);
|
|
|
+ String sign = getGenerateSign(SK, signContext);
|
|
|
+ System.out.println("sign:" + sign);
|
|
|
+
|
|
|
+ // ********模拟请求头参数,以下参数为通用必填参数************
|
|
|
+ Map<String, String> headerMap = new HashMap<>();
|
|
|
+ headerMap.put("X-AppKey", AK);
|
|
|
+ headerMap.put("X-Signature", sign);
|
|
|
+ headerMap.put("X-MsgId", msgId);
|
|
|
+ headerMap.put("X-RequestTime", requestTime);
|
|
|
+ headerMap.put("X-CustomerCode", customer);
|
|
|
+ headerMap.put("X-UserCode", userCode);
|
|
|
+ headerMap.put("X-AppCode", appCode);
|
|
|
+ headerMap.put("X-OrderCode", orderCode);
|
|
|
+ postObject(url, headerMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void postObject(String appAddress,Map<String, String> headerMap) {
|
|
|
+ String[] files = {"/15000000005/ThirdAlarm/pic/ZGTT-1717140001_339b7c7fb9e14de5a7b2a3f75fb91628393ecd7a07524453a1d6237eb8f2529a_02_001.jpg"};
|
|
|
+// String[] files = {"/15000000005/ThirdAlarm/video/20250411/d918a07284c54004be4722046ff94d78f9d8ef87d8e149a6a1a122f144556941_f550.mp4"};
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("fileUrls", files);
|
|
|
+ HttpResponse result = null;
|
|
|
+ try {
|
|
|
+ result = HttpRequest.post(appAddress)
|
|
|
+ .headerMap(headerMap,true)
|
|
|
+ .body(params.toJSONString())
|
|
|
+ .timeout(30000)
|
|
|
+ .execute();
|
|
|
+ System.out.println(params.toJSONString());
|
|
|
+ log.info("\n请求地址{},\n返回状态:{},\n返回信息{}", appAddress, result.getStatus(), result.body());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("地址{},参数{},发送异常:{}", appAddress, params, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getSignContext(String path, String appkey, String msgId, String requestTime,
|
|
|
+ String customerCode, String userCode) {
|
|
|
+ StringBuilder append = new StringBuilder(path)
|
|
|
+ .append(appkey)
|
|
|
+ .append(msgId)
|
|
|
+ .append(requestTime);
|
|
|
+ if (customerCode != null) {
|
|
|
+ append.append(customerCode);
|
|
|
+ }
|
|
|
+ if (userCode != null) {
|
|
|
+ append.append(userCode);
|
|
|
+ }
|
|
|
+ return append.toString().toUpperCase();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getGenerateSign(final String secret, final String signContext) {
|
|
|
+ String sign = null;
|
|
|
+ try {
|
|
|
+ Mac hmacSha256 = Mac.getInstance("HmacSHA1");
|
|
|
+ byte[] keyBytes = secret.getBytes();
|
|
|
+ hmacSha256.init(new SecretKeySpec(keyBytes, 0, keyBytes.length, "HmacSHA1"));
|
|
|
+ sign = HexUtil.encodeHexStr(hmacSha256.doFinal(signContext.getBytes()));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return sign;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|