| | |
| | | |
| | | import cn.hutool.json.JSONConverter; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.aliyun.oss.ClientBuilderConfiguration; |
| | | import com.aliyun.oss.OSS; |
| | | import com.aliyun.oss.OSSClientBuilder; |
| | | import com.aliyun.oss.OSSException; |
| | | import com.aliyun.oss.common.auth.CredentialsProviderFactory; |
| | | import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider; |
| | | import com.aliyun.oss.common.comm.SignVersion; |
| | | import com.aliyuncs.exceptions.ClientException; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.ycl.annotation.LogSave; |
| | |
| | | import com.ycl.service.video.IVideoAlarmReportService; |
| | | import com.ycl.service.video.impl.IVideoPointService; |
| | | import com.ycl.util.VideoUtil; |
| | | import com.ycl.utils.ConstantPropertiesUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.SneakyThrows; |
| | |
| | | import java.io.InputStream; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.util.Base64; |
| | | import java.util.Dictionary; |
| | | import java.util.Hashtable; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author admin |
| | |
| | | @PostMapping("/HK/alarmReport") |
| | | @LogSave(operationType = "报警管理", contain = "海康视频报警推送") |
| | | public CommonResult hkAlarmReport(@RequestBody @Validated HKAlarmParam alarmParam) { |
| | | System.out.println("海康视频报警推送API:" + JSONObject.toJSONString(alarmParam)); |
| | | // System.out.println("海康视频报警推送API:" + JSONObject.toJSONString(alarmParam)); |
| | | videoAlarmReportService.saveFromHK(alarmParam); |
| | | return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage()); |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | private URL translateOSSUrl(String fileUrl) { |
| | | OSS ossClient = null; |
| | | try { |
| | | String endpoint = ConstantPropertiesUtils.END_POINT; |
| | | String accessKeyId = ConstantPropertiesUtils.ACCESS_KEY_ID; |
| | | String accessKeySecret = ConstantPropertiesUtils.ACCESS_KEY_SECRET; |
| | | String bucketName = ConstantPropertiesUtils.BUCKET_NAME; |
| | | |
| | | String[] urlArray = fileUrl.split("Expires="); |
| | | |
| | | String[] urlArray2 = urlArray[0].split("aliyuncs.com/"); |
| | | |
| | | String objectName = urlArray2[1].replace("?", ""); |
| | | |
| | | ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); |
| | | |
| | | // 设置签名URL过期时间,单位为毫秒。本示例以设置过期时间为1小时为例。 |
| | | Date expiration = new Date(new Date().getTime() + 3600 * 1000L); |
| | | // 生成以GET方法访问的签名URL。本示例没有额外请求头,其他人可以直接通过浏览器访问相关内容。 |
| | | URL url = ossClient.generatePresignedUrl(bucketName, objectName, expiration); |
| | | |
| | | return url; |
| | | } catch (OSSException oe) { |
| | | System.out.println("Caught an OSSException, which means your request made it to OSS, " |
| | | + "but was rejected with an error response for some reason."); |
| | | System.out.println("Error Message:" + oe.getErrorMessage()); |
| | | System.out.println("Error Code:" + oe.getErrorCode()); |
| | | System.out.println("Request ID:" + oe.getRequestId()); |
| | | System.out.println("Host ID:" + oe.getHostId()); |
| | | } finally { |
| | | if (ossClient != null) { |
| | | ossClient.shutdown(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private byte[] getBytes(String fileUrl, String OSSAccessKeyId, String Signature, String sessionId) { |
| | | int index = sessionDic.get(sessionId); |
| | | try { |
| | | if (sessionDic.get(sessionId) < 10) { |
| | | sessionDic.remove(sessionId); |
| | | fileUrl = fileUrl.replace("Expires", "v"); |
| | | System.out.println("getImages获取图片地址:" + fileUrl + "&OSSAccessKeyId=" + OSSAccessKeyId + "&Signature=" + Signature); |
| | | URL url = null; |
| | | if (StringUtils.isNotBlank(OSSAccessKeyId) && StringUtils.isNotBlank(Signature)) { |
| | | url = new URL(fileUrl + "&OSSAccessKeyId=" + OSSAccessKeyId + "&Signature=" + Signature); |
| | | } else { |
| | | url = new URL(fileUrl); |
| | | } |
| | | URL url = translateOSSUrl(fileUrl); |
| | | // fileUrl = fileUrl.replace("Expires", "v"); |
| | | //// System.out.println("getImages获取图片地址:" + fileUrl + "&OSSAccessKeyId=" + OSSAccessKeyId + "&Signature=" + Signature); |
| | | // URL url = null; |
| | | // if (StringUtils.isNotBlank(OSSAccessKeyId) && StringUtils.isNotBlank(Signature)) { |
| | | // url = new URL(fileUrl + "&OSSAccessKeyId=" + OSSAccessKeyId + "&Signature=" + Signature); |
| | | // } else { |
| | | // url = new URL(fileUrl); |
| | | // } |
| | | |
| | | HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
| | | conn.setRequestMethod("GET"); |
| | | conn.setConnectTimeout(10 * 1000); |
| | |
| | | InputStream inputStream = conn.getInputStream();// 通过输入流获取图片数据 |
| | | |
| | | byte[] data = readInputStream(inputStream); |
| | | System.out.println("getImages获取图片成功"); |
| | | // System.out.println("getImages获取图片成功"); |
| | | |
| | | return data; |
| | | } |