From 9011a5bd0721a5b29387a6b34a3fe82e1169c36d Mon Sep 17 00:00:00 2001 From: mi9688 Date: Thu, 7 Nov 2024 17:52:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=90=A4=E7=9F=B3=E4=BA=91=E9=89=B4=E6=9D=83?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=8E=B7=E5=8F=96=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E5=9C=B0=E5=9D=80=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yingshiyun/service/YingshiyunService.java | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 fastbee-service/fastbee-deviceData-service/src/main/java/com/fastbee/deviceData/api/yingshiyun/service/YingshiyunService.java diff --git a/fastbee-service/fastbee-deviceData-service/src/main/java/com/fastbee/deviceData/api/yingshiyun/service/YingshiyunService.java b/fastbee-service/fastbee-deviceData-service/src/main/java/com/fastbee/deviceData/api/yingshiyun/service/YingshiyunService.java new file mode 100644 index 0000000..cf4d905 --- /dev/null +++ b/fastbee-service/fastbee-deviceData-service/src/main/java/com/fastbee/deviceData/api/yingshiyun/service/YingshiyunService.java @@ -0,0 +1,73 @@ +package com.fastbee.deviceData.api.yingshiyun.service; + +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; + +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Service; + +import java.text.SimpleDateFormat; +import java.util.Date; + + +@Service +public class YingshiyunService { + + @Autowired + private StringRedisTemplate stringRedisTemplate; + + //获取鉴权 + public String getAuth(){ + if(Boolean.TRUE.equals(stringRedisTemplate.hasKey("yingshiyun:user:accessToken"))){ + return stringRedisTemplate.opsForValue().get("yingshiyun:user:accessToken"); + } + // 鉴权请求 + String AUTH_URL = "https://open.ys7.com/api/lapp/token/get"; + String appKey = "b21f910dc7044d668e7625a3c0392e62"; + String appSecret = "b4beff5f8f6694dd6993c8c5b618417b"; + // 构建请求体参数 + String body = StrUtil.format("appKey={}&appSecret={}", appKey, appSecret); + HttpResponse response = HttpRequest.post(AUTH_URL) + .body(body).execute(); + JSONObject jsonObject = JSONUtil.parseObj(response.body()); + String accessToken = JSONUtil.parseObj(jsonObject.get("data")).get("accessToken").toString(); + stringRedisTemplate.opsForValue().set("yingshiyun:user:accessToken",accessToken, 60*60*24*6); + return accessToken; + } + + //获取视频播放地址 + public String getVideoPlayUrl(String deviceSerial){ + String accessToken = getAuth(); + String VIDEO_PLAY_URL = "https://open.ys7.com/api/lapp/v2/live/address/get"; + String body = StrUtil.format("accessToken={}&deviceSerial={}",accessToken ,deviceSerial ); + HttpResponse response = HttpRequest.post(VIDEO_PLAY_URL) + .form(body).execute(); + JSONObject jsonObject = JSONUtil.parseObj(response.body()); + String videoPlayUrl = JSONUtil.parseObj(jsonObject.get("data")).get("url").toString(); + String expireTime = JSONUtil.parseObj(jsonObject.get("data")).get("expireTime").toString(); + return videoPlayUrl; + } + + + + + + + + + + public static void main(String[] args) { + YingshiyunService yingshiyunService = new YingshiyunService(); + yingshiyunService.getAuth(); + long timeStamp = 1731571309231L; + Date date = new Date(timeStamp); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); + sdf.setTimeZone(java.util.TimeZone.getTimeZone("Asia/Shanghai")); + String formattedDate = sdf.format(date); + System.out.println(formattedDate); + } +}