文档

​
​

Development

User Acquisition

Monetization

工业

Vivox Unity SDK

Vivox Unity SDK

Vivox
​
​
Vivox Unity SDK
  • Overview
  • Get started
  • Release notes
  • Developer guide
  • Tutorials
    • Implement Vivox Unity
    • Access Token Developer Guide
      • Access token terminology
      • Requests that require access tokens
      • Access token identifiers
      • Access token format
      • Access token examples
      • Generate a token from the client
        • Authentication-based token generation
        • Interface implementation-based token generation
      • Generate a token on a secure server
      • Key update API
      • Access token error codes
  • Reference
  1. Vivox Unity SDK 文档

基于接口实现的令牌生成

How to generate access tokens using an interface implementation.
阅读时间3 分钟
最后更新于 8 个月前

如果要控制 Vivox 访问令牌 (VAT) 的生成方式,请创建一个实现 Vivox SDK 的
IVivoxTokenProvider
接口的类,并将这个类注册到 VivoxService。
如果通过调用
VivoxService.Instance.SetTokenProvider
来注册 IVivoxTokenProvider 的实现,则每当需要令牌进行登录等操作时,Vivox 都会调用您的实现中的
IVivoxTokenProvider.GetTokenAsync
方法。
创建有效负载所需的信息作为覆盖的
IVivoxTokenProvider.GetTokenAsync
方法的输入提供。此信息在制作 VAT 时使用。
您仍然需要设置服务器端令牌供应,并在覆盖的
IVivoxTokenProvider.GetTokenAsync
方法中获取令牌。

订阅

在登录您的用户之前,您必须使用以下方法注册您的
IVivoxTokenProvider
实现:
VivoxService.Instance.SetTokenProvider(new CustomTokenProvider());
重要
**重要:**订阅流程在 v16.5.0 中发生了变化。对于 16.5.0 之前的 Unity Vivox SDK 版本,您必须在初始化 Vivox SDK 之前注册您的
IVivoxTokenProvider
实现。

获取令牌

应使用覆盖的方法中提供的所有参数(即使有些参数为空)创建有效负载,并将有效负载发送到您的安全服务器以生成您的 Vivox 访问令牌。最佳做法是发送所有参数;仅返回有效负载所需的内容。使用有效负载作为
GetTokenAsync
方法的输入。
对于某些令牌,不同的参数将为空。例如,登录令牌的 targetUserUri 和 channelUri 将为空。这是预期的行为。
以下是一个令牌生成示例。
public class VoiceManager : MonoBehaviour{ async void Start() { // Must be done before any other Vivox action otherwise tokens will not be generated properly. VivoxService.Instance.SetTokenProvider(new VivoxTokenProvider()); await UnityServices.InitializeAsync(); await VivoxService.Instance.InitializeAsync(); }}class VivoxTokenProvider : IVivoxTokenProvider{ public Task<string> GetTokenAsync(string issuer = null, TimeSpan? expiration = null, string targetUserUri = null, string action = null, string channelUri = null, string fromUserUri = null, string realm = null) { // Implement token fetching logic here. // The method parameters contain the necessary information for crafting the request payload. // This will be called whenever a token is needed for a Vivox action }}
如需了解有关此特定流程的更多详细信息,请参阅使用 Vivox 访问令牌登录。
要了解有关生成服务器端令牌的更多信息,请参阅在安全服务器上生成令牌。

Copyright © 2026 Unity Technologies
法律信息隐私政策CookiesDocumentation Terms of Use请勿出售或分享我的个人信息您的隐私选择(Cookie 设置)

“Unity”、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属公司在美国和其他地方的商标或注册商标(此处查看更多信息)。其他名称或品牌是其各自所有者的商标。

为方便起见,一些页面是机器翻译的,可能包含不准确的内容。如有信息不一致的情况,以英文版本为准。

  • 在本页上
    • 订阅

    • 获取令牌


报告此页面的问题