0

我正在将 c# 与 mvc 一起使用。

我使用此代码生成令牌并成功生成。但是在使用.join()加入频道时生成令牌后,它会返回 DYNAMIC_KEY_EXPIRED。我使用“AgoraRTCSDK-3.1.0.js”

我使用https://github.com/AgoraIO/Tools/blob/master/DynamicKey/AgoraDynamicKey/csharp生成动态令牌

如果有人对 Agora.io 有经验,请帮助我。

示例代码是..

AccessToken token = new AccessToken(apiKey, appCertificate, channelName, "0");
token.addPrivilege(Privileges.kJoinChannel, _expiredTs);
token.addPrivilege(Privileges.kPublishAudioStream, _expiredTs);
token.addPrivilege(Privileges.kPublishVideoStream, _expiredTs);
string strToken = token.build();

public string build()
    {
        this._messageRawContent = Utils.pack(this.message);
        this._signature = generateSignature(_appCertificate
                , _appId
                , _channelName
                , _uid
                , _messageRawContent);

        this._crcChannelName = Crc32CAlgorithm.Compute(this._channelName.GetByteArray());
        this._crcUid = Crc32CAlgorithm.Compute(this._uid.GetByteArray());

        PackContent packContent = new PackContent(_signature, _crcChannelName, _crcUid, this._messageRawContent);
        byte[] content = Utils.pack(packContent);
        return getVersion() + this._appId + Utils.base64Encode(content);
    }
4

1 回答 1

0

每当您为 Agora 应用程序生成令牌时,您需要记住过期时间是按时间戳(自 1970 年以来的时间)计算的,因此您需要确保将过期时间设置为currentTime + expirationTimeInSeconds.

在上面的示例中,您将过期时间传递为​​ 0,这会生成一个已被视为过期的令牌。

考虑使用:

  // set a expiration time of 1 hour in seconds
  let expireTime = 3600;

  // calculate current time in seconds
  const currentTime = Math.floor(Date.now() / 1000);

  // calculate privilege expire time
  const privilegeExpireTime = currentTime + expireTime;
于 2020-07-23T15:58:15.483 回答