| | |
| | | String uploadImages(InputStream inputStream, String ext); |
| | | |
| | | String uploadVideo(MultipartFile file); |
| | | |
| | | } |
| | |
| | | String accessKeySecret = ConstantPropertiesUtils.ACCESS_KEY_SECRET; |
| | | String bucketName = ConstantPropertiesUtils.BUCKET_NAME; |
| | | |
| | | DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | System.out.println("åå¤ä¸ä¼ --" + dtf2.format(LocalDateTime.now())); |
| | | // å建OSSClientå®ä¾ã |
| | | OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); |
| | | // ä¸ä¼ æä»¶æµ |
| | |
| | | LocalDate date = LocalDate.now(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); |
| | | String fileName = "sczf/" + date.format(formatter) + RandomUtils.generateRandomInt(8) + "." + ext; |
| | | System.out.println("æä»¶å°åï¼" + fileName); |
| | | |
| | | ObjectMetadata objectMetadata = new ObjectMetadata(); |
| | | objectMetadata.setContentType(getcontentType(ext)); |
| | | // è°ç¨ossçæ¹æ³å®ç°é¿ä¼ |
| | | // 第ä¸ä¸ªåæ° bucketName |
| | | // 第äºä¸ªåæ° ä¸ä¼ å°ossçæä»¶è·¯å¾åæä»¶åç§° |
| | | ossClient.putObject(bucketName, fileName, inputStream, objectMetadata); |
| | | // å
³éOSSClientã |
| | | ossClient.shutdown(); |
| | | // æä¸ä¼ çæä»¶è·¯å¾è¿å ï¼æå¨æ¼æ¥ï¼ |
| | | // è¿é设置å¾çæææ¶é´ æè®¾ç½®äº30å¹´ |
| | | Date expiration = new Date(System.currentTimeMillis() + (long) 946080000 * 1000); |
| | | String url = ossClient.generatePresignedUrl(bucketName, fileName, expiration).toString(); |
| | | System.out.println("ossä¸ä¼ æåï¼" + url); |
| | | |
| | | // URL urlO = new URL(url); |
| | | // HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); |
| | | // conn.setRequestMethod("GET"); |
| | | // conn.setConnectTimeout(10 * 1000); |
| | | // conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); |
| | | // |
| | | // InputStream inputStream2 = conn.getInputStream();// éè¿è¾å
¥æµè·åå¾çæ°æ® |
| | | // |
| | | // byte[] data = readInputStream(inputStream2); |
| | | // |
| | | // System.out.println("è·åå¾çæå:" + url); |
| | | System.out.println("å¼å§ä¸ä¼ --" + dtf2.format(LocalDateTime.now())); |
| | | |
| | | ossClient.putObject(bucketName, fileName, inputStream, objectMetadata); |
| | | ossClient.shutdown(); |
| | | |
| | | Date expiration = new Date(System.currentTimeMillis() + (long) 946080000 * 1000); |
| | | |
| | | String url = ossClient.generatePresignedUrl(bucketName, fileName, expiration).toString(); |
| | | // System.out.println("ossä¸ä¼ æåï¼" + url); |
| | | |
| | | System.out.println("ä¸ä¼ 宿--" + dtf2.format(LocalDateTime.now())); |
| | | return url; |
| | | } catch (Exception e) { |
| | | System.out.println("osså¼å¸¸ï¼" + e.getMessage()); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | public static String getcontentType(String FilenameExtension) { |
| | | if (FilenameExtension.equalsIgnoreCase(".mp4")||FilenameExtension.equalsIgnoreCase(".mov")) { |
| | | return "video/mp4"; |
| | |
| | | package com.ycl; |
| | | |
| | | import com.ycl.util.VideoUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | |
| | | env.getProperty("server.servlet.context-path"), |
| | | "127.0.0.1", |
| | | env.getProperty("server.port")); |
| | | |
| | | |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | public String createCaseCode() { |
| | | String ymd = getYMD(); |
| | | Integer number = generatedCodeMapper.createNumber(ymd, "case"); |
| | | double num = Math.random(); |
| | | int myRandInt = (int)(num*100+1); |
| | | // Integer number = myRandInt; |
| | | Integer number = generatedCodeMapper.createNumber(ymd, "case"); |
| | | String numberStr = RandomUtils.formatSign(number, 4); |
| | | String year = String.valueOf(LocalDateTime.now().getYear()); |
| | | String areaCode = "331123"; |
| | |
| | | |
| | | @PostMapping("/oss/sign") |
| | | public CommonResult ossSign(@RequestBody OssFileDto dto) { |
| | | log.info("æ¥æ¶å°file"); |
| | | |
| | | DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | if (StringUtils.isNullOrEmpty(dto.getMediaId()) || StringUtils.isNullOrEmpty(dto.getExtension())) { |
| | | return CommonResult.failed("åæ°ä¸è½ä¸ºç©ºï¼"); |
| | | } |
| | | ExecutableClient executableClient = DdTest.getExecutableClient(); |
| | | CloseableHttpResponse response = null; |
| | | OSS ossClient = null; |
| | | |
| | | DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | System.out.println("å¼å§è·å--" + dtf2.format(LocalDateTime.now())); |
| | | try { |
| | |
| | | HttpEntity entity = response.getEntity(); |
| | | InputStream is = entity.getContent(); |
| | | |
| | | System.out.println("è·å宿--" + dtf2.format(LocalDateTime.now())); |
| | | DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); |
| | | // MultipartFile file = getMultipartFile(is, fileName); |
| | | |
| | | String strDate2 = dtf.format(LocalDateTime.now()); |
| | | |
| | | String fileName = strDate2 + RandomUtils.generateRandomInt(4) + "." + dto.getExtension(); |
| | | MultipartFile file = getMultipartFile(is, fileName); |
| | | |
| | | String url = ossService.uploadImages(file); |
| | | String url = ossService.uploadImages(is,dto.getExtension()); |
| | | return CommonResult.success(url); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | jsonBody.put("streamType", 0); |
| | | jsonBody.put("protocol", "hls"); |
| | | jsonBody.put("transmode", 0); |
| | | jsonBody.put("expand","transcode=1&videotype=h264"); |
| | | String body = jsonBody.toString(); |
| | | //åæ°æ ¹æ®æ¥å£å®é
æ
åµè®¾ç½® |
| | | HttpResponse result = ArtemisHttpUtil.doPostStringImgArtemis(config, path, body, query, null, "application/json", head); |
| | |
| | | |
| | | aliyun: |
| | | oss: |
| | | endpoint: https://oss-cn-zhangjiakou.aliyuncs.com |
| | | endpoint: https://oss-accelerate.aliyuncs.com |
| | | keyId: LTAIDlTWjHW0IVyW |
| | | keySecret: 6fO78NmgyF49TK5GWFAzXuSAexl9PL |
| | | bucketName: hcjs-mte-internal |
| | | bucketName: xshlivelesson |
| | | |
| | | #䏿ééåæ° |
| | | zzding : |
| | |
| | | package com.ycl.sccgplatform; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ycl.common.util.UtilNumber; |
| | | import com.ycl.dto.video.Camera; |
| | | import com.ycl.dto.video.HttpResponseResult; |
| | | import com.ycl.dto.video.PageResult; |
| | |
| | | |
| | | @Resource |
| | | private UnlawfulMapper unlawfuldao; |
| | | @Autowired |
| | | UtilNumber utilNumber; |
| | | |
| | | @Test |
| | | void test() { |
| | | // List<CategoryDto> data = unlawfuldao.getDataByType(0, 5,"2022-12-14 17:19:01", "2022-12-14 17:19:03"); |
| | | // System.out.println(data); |
| | | |
| | | |
| | | String msg = "{\n" + |
| | | " \"code\": \"0\",\n" + |
| | | " \"msg\": \"success\",\n" + |
| | | " \"data\": {\n" + |
| | | " \"total\": 1,\n" + |
| | | " \"pageSize\": 20,\n" + |
| | | " \"pageNo\": 1,\n" + |
| | | " \"list\": [\n" + |
| | | " {\n" + |
| | | " \"cameraIndexCode\": \"90ad77d8057c43dab140b77361606927\",\n" + |
| | | " \"gbIndexCode\": \"12000000051210000000\",\n" + |
| | | " \"name\": \"Camera_01\",\n" + |
| | | " \"deviceIndexCode\": \"f5da3e320bcb483da6bef4b3f86de779\",\n" + |
| | | " \"longitude\": \"120.216123284763\",\n" + |
| | | " \"latitude\": \"30.21168569675452\",\n" + |
| | | " \"altitude\": \"88\",\n" + |
| | | " \"pixel\": 1,\n" + |
| | | " \"cameraType\": 1,\n" + |
| | | " \"cameraTypeName\": \"åç\",\n" + |
| | | " \"installPlace\": \"è¡é\",\n" + |
| | | " \"matrixCode\": \"2076c586b0a94a6ba639b44eda9e76e9\",\n" + |
| | | " \"chanNum\": 1,\n" + |
| | | " \"viewshed\": \"{\\\"horizontalValue\\\":\\\"13.80000\\\",\\\"azimuth\\\":\\\"109.23000\\\",\\\"visibleRadius\\\":\\\"48.00000\\\"}\",\n" + |
| | | " \"capabilitySet\": \"@event_face@\",\n" + |
| | | " \"capabilitySetName\": \"人è¸ééè½å\",\n" + |
| | | " \"intelligentSet\": \"@face@\",\n" + |
| | | " \"intelligentSetName\": \"人è¸ç»æåè½å\",\n" + |
| | | " \"recordLocation\": \"0\",\n" + |
| | | " \"recordLocationName\": \"ä¸å¿åå¨\",\n" + |
| | | " \"ptzController\": 1,\n" + |
| | | " \"ptzControllerName\": \"DVR\",\n" + |
| | | " \"deviceResourceType\": \"ENCODE_DEVICE\",\n" + |
| | | " \"deviceResourceTypeName\": \"ç¼ç 设å¤\",\n" + |
| | | " \"channelType\": \"digital\",\n" + |
| | | " \"channelTypeName\": \"æ°åéé\",\n" + |
| | | " \"transType\": 0,\n" + |
| | | " \"transTypeName\": \"UDP\",\n" + |
| | | " \"updateTime\": \"2021-06-15T00:00:00.000+08:00\",\n" + |
| | | " \"unitIndexCode\": \"083b2031c1db4f368f015fe2562e0012\",\n" + |
| | | " \"treatyType\": \"20005\",\n" + |
| | | " \"treatyTypeName\": \"ONVIF\",\n" + |
| | | " \"createTime\": \"2021-06-15T00:00:00.000+08:00\",\n" + |
| | | " \"status\": 0,\n" + |
| | | " \"statusName\": \"ä¸å¨çº¿\"\n" + |
| | | " }\n" + |
| | | " ]\n" + |
| | | " }\n" + |
| | | "}\n"; |
| | | HttpResponseResult responseResult = com.alibaba.fastjson.JSONObject.parseObject(msg, HttpResponseResult.class); |
| | | if ("0".equals(responseResult.getCode())) { |
| | | JSONObject jsonObject = responseResult.getData(); |
| | | String strList = jsonObject.getString("list"); |
| | | Integer total = Integer.parseInt(jsonObject.getString("total")); |
| | | Integer pageSize = Integer.parseInt(jsonObject.getString("pageSize")); |
| | | Integer pageNo = Integer.parseInt(jsonObject.getString("pageNo")); |
| | | List<Camera> ls = JSONObject.parseArray(strList, Camera.class); |
| | | |
| | | PageResult<Camera> pageResult = new PageResult<>(total, pageSize, pageNo, ls); |
| | | System.out.println(ls.size()); |
| | | } |
| | | System.out.println(utilNumber.createShopCode()); |
| | | System.out.println(utilNumber.createCaseCode()); |
| | | } |
| | | |
| | | // @Test |
| | |
| | | @Scheduled(cron = "0 */1 * * * ?") // æ¯5åéæ§è¡ |
| | | public void listDataInTime() { |
| | | DataIntimeParamDto paramDto = DataIntimeParamDto.builder().build(); |
| | | // {"StartAt":0,"Size":20,"Typ":2,"SortBy":"status","SortMode":"asc","Param":{"StatusOfRecord":"NORMAL"}}: |
| | | paramDto.setSize(200); |
| | | // {"StartAt":0,"Size":20,"Typ":2,"SortBy":"status","SortMode":"asc","Param":{"StatusOfRecord":"NORMAL"}} |
| | | paramDto.setSize(20); |
| | | paramDto.setStartAt(0); |
| | | paramDto.setTyp(2); |
| | | paramDto.setSortBy("status"); |
New file |
| | |
| | | package com.ycl.smoke.utils; |
| | | |
| | | import com.ycl.service.redis.RedisService; |
| | | import com.ycl.utils.redis.RedisKey; |
| | | import org.apache.http.*; |
| | | import org.apache.http.client.ResponseHandler; |
| | | import org.apache.http.client.entity.UrlEncodedFormEntity; |
| | | import org.apache.http.client.methods.CloseableHttpResponse; |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.entity.StringEntity; |
| | | import org.apache.http.impl.client.BasicResponseHandler; |
| | | import org.apache.http.impl.client.CloseableHttpClient; |
| | | import org.apache.http.impl.client.HttpClients; |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | import org.apache.http.util.EntityUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.BufferedReader; |
| | | import java.io.IOException; |
| | | import java.io.InputStreamReader; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | |
| | | public class HttpUtil { |
| | | |
| | | private static final CloseableHttpClient httpclient = HttpClients.createDefault(); |
| | | |
| | | public static String doGet(String urlPath, Map<String, Object> params) |
| | | throws Exception { |
| | | StringBuilder sb = new StringBuilder(urlPath); |
| | | if (params != null && !params.isEmpty()) { // 说ææåæ° |
| | | sb.append("?"); |
| | | |
| | | Set<Map.Entry<String, Object>> set = params.entrySet(); |
| | | for (Map.Entry<String, Object> entry : set) { // éåmapéé¢çåæ° |
| | | String key = entry.getKey(); |
| | | String value = ""; |
| | | if (null != entry.getValue()) { |
| | | value = entry.getValue().toString(); |
| | | // 转ç |
| | | value = URLEncoder.encode(value, "UTF-8"); |
| | | } |
| | | sb.append(key).append("=").append(value).append("&"); |
| | | } |
| | | |
| | | sb.deleteCharAt(sb.length() - 1); // å 餿åä¸ä¸ª& |
| | | } |
| | | // System.out.println(sb.toString()); |
| | | |
| | | URL url = new URL(sb.toString()); |
| | | HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
| | | conn.setConnectTimeout(5000); // 5sè¶
æ¶ |
| | | conn.setRequestMethod("GET"); |
| | | |
| | | if (conn.getResponseCode() == HttpStatus.SC_OK) {// HttpStatus.SC_OK == |
| | | // 200 |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader( |
| | | conn.getInputStream())); |
| | | StringBuilder sbs = new StringBuilder(); |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | sbs.append(line); |
| | | } |
| | | // JSONObject jsonObject = new JSONObject(sbs.toString()); |
| | | return sbs.toString(); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * åéHttpPost请æ±ï¼åæ°ä¸ºmap |
| | | * @param url |
| | | * @param map |
| | | * @return |
| | | */ |
| | | public static String sendPost(String url, Map<String, Object> map) { |
| | | List<NameValuePair> formparams = new ArrayList<NameValuePair>(); |
| | | for (Map.Entry<String, Object> entry : map.entrySet()) { |
| | | formparams.add(new BasicNameValuePair(entry.getKey(), entry.getValue().toString())); |
| | | } |
| | | UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, Consts.UTF_8); |
| | | HttpPost httppost = new HttpPost(url); |
| | | httppost.setEntity(entity); |
| | | CloseableHttpResponse response = null; |
| | | try { |
| | | response = httpclient.execute(httppost); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | HttpEntity entity1 = response.getEntity(); |
| | | String result = null; |
| | | try { |
| | | result = EntityUtils.toString(entity1); |
| | | } catch (ParseException | IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static String HttpPostWithJson(String url, String json,String token) { |
| | | String returnValue = "è¿æ¯é»è®¤è¿åå¼ï¼æ¥å£è°ç¨å¤±è´¥"; |
| | | CloseableHttpClient httpClient = HttpClients.createDefault(); |
| | | ResponseHandler<String> responseHandler = new BasicResponseHandler(); |
| | | try{ |
| | | //ç¬¬ä¸æ¥ï¼å建HttpClient对象 |
| | | httpClient = HttpClients.createDefault(); |
| | | |
| | | //ç¬¬äºæ¥ï¼å建httpPost对象 |
| | | HttpPost httpPost = new HttpPost(url); |
| | | |
| | | //ç¬¬ä¸æ¥ï¼ç»httpPost设置JSONæ ¼å¼çåæ° |
| | | StringEntity requestEntity = new StringEntity(json,"utf-8"); |
| | | requestEntity.setContentEncoding("UTF-8"); |
| | | httpPost.setHeader("Content-type", "application/json"); |
| | | httpPost.setHeader("Auth",token); |
| | | httpPost.setEntity(requestEntity); |
| | | |
| | | //ç¬¬åæ¥ï¼åéHttpPost请æ±ï¼è·åè¿åå¼ |
| | | returnValue = httpClient.execute(httpPost,responseHandler); //è°æ¥å£è·åè¿å弿¶ï¼å¿
é¡»ç¨æ¤æ¹æ³ |
| | | |
| | | } |
| | | catch(Exception e) |
| | | { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | finally { |
| | | try { |
| | | httpClient.close(); |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | //ç¬¬äºæ¥ï¼å¤çè¿åå¼ |
| | | return returnValue; |
| | | } |
| | | } |