mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.panzhihua.service_equipment.until;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Date;
import java.util.Map;
 
@Slf4j
@Service
public class MonitorUtil {
 
    /**
     * 开门
     * @return  返回结果
     * @throws Exception
     */
    public Map getToken() {
        String url="https://openaisc.sctel.com.cn/video-manage/appToken/getToken";
        String accesskey = "96a88ccd5f42458b304ca291e710036d";
        String accessKeySecret = "7b2ef41e0bcf8c94b193c7ec2e10d727";
        long timestamp = new Date().getTime();
        String signtype = "SHA1";
        String params = ""; // 替换为你的请求参数
 
        String appPolicy = accesskey + accessKeySecret + timestamp + params.substring(0, Math.min(params.length(), 512));
 
        try {
            Mac sha1Hmac = Mac.getInstance("HmacSHA1");
            SecretKeySpec secretKey = new SecretKeySpec(accessKeySecret.getBytes(StandardCharsets.UTF_8), "HmacSHA 1");
            sha1Hmac.init(secretKey);
            byte[] hashBytes = sha1Hmac.doFinal(appPolicy.getBytes(StandardCharsets.UTF_8));
            String sign = Base64.getEncoder().encodeToString(hashBytes);
 
            System.out.println("Sign: " + sign);
        } catch (NoSuchAlgorithmException | InvalidKeyException e) {
            e.printStackTrace();
        }
        return null;
    }
 
}