package com.cool.store.utils;

import com.tencentyun.TLSSigAPIv2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 腾讯实时音视频TRTC工具类
 */
@Component
public class TRTCUtils {

    /**
     * 默认过期时间 30 s
     * 修改为 24 小时（官方建议）
     */
    private static final Long expired = 60 * 60 * 24L;

    /**
     * 生成 userSig 用于进入会议
     * 详见 https://cloud.tencent.com/document/product/647/17275#.E8.B0.83.E8.AF.95.E8.B7.91.E9.80.9A.E9.98.B6.E6.AE.B5.E5.A6.82.E4.BD.95.E8.AE.A1.E7.AE.97-UserSig.EF.BC.9F
     */
    public static String genUserSig(Long sdkAppId, String key, String userId) {
        TLSSigAPIv2 tlsSigAPIv2 = new TLSSigAPIv2(sdkAppId, key);
        return tlsSigAPIv2.genUserSig(userId, expired);
    }

    public static String genUserSig(Long sdkAppId, String key, String userId, Long expiredTime) {
        TLSSigAPIv2 tlsSigAPIv2 = new TLSSigAPIv2(sdkAppId, key);
        return tlsSigAPIv2.genUserSig(userId, expiredTime);
    }

    public static void main(String[] args) {
        System.out.println(genUserSig(1600026212L, "e036b654c665f649f053a01ff6f5652a826980027be298d4d49949f6e26434a5", "6488aeaefa7246de9af141c6c6fdd2c7"));
    }
}
