文档

​
​

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
      • Generate a token on a secure server
        • Example: C++
        • Example: C#
        • Example: Python
        • Example: JavaScript
      • Key update API
      • Access token error codes
  • Reference
  1. Vivox Unity SDK 文档

示例:JavaScript

How to generate Vivox access tokens using JavaScript code.
阅读时间1 分钟
最后更新于 8 个月前

以下代码是用于生成访问令牌的 JavaScript 示例。
/** Vivox Token Generation Example - JavaScript** NOTE: There are multiple ways to handle SHA-256 in JavaScript* Stanford JS Crypto Library - https://crypto.stanford.edu/sjcl/ (used below)* Source - http://bitwiseshiftleft.github.io/sjcl/sjcl.js* SHA256 from NPM - https://www.npmjs.com/package/sha256**/function vxGenerateToken(key, payload) { // Header is static - base64url encoded {} var base64urlHeader = base64URLEncode("{}"); // Can also be defined as a constant "e30" // Encode payload var base64urlPayload = base64URLEncode(payload); // Join segments to prepare for signing var segments = [base64urlHeader, base64urlPayload]; var toSign = segments.join("."); // Sign token with key and SHA-256 var hmac = new sjcl.misc.hmac(sjcl.codec.utf8String.toBits(key), sjcl.hash.sha256); signature = sjcl.codec.base64.fromBits(hmac.encrypt(toSign)); var base64urlSigned = signature.replace(/\+/g, "-").replace(/\//g, "_").replace(/\=+$/, ""); segments.push(base64urlSigned); return segments.join(".");}function base64URLEncode(value) { return Base64.encode(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/\=+$/, "");}claims = { "iss": "issuer", "exp": 1559359105, "vxa": "join", "f": "sip:.username.@domain.vivox.com", "t": "sip:confctl-g-channelname@domain.vivox.com"};// Example usagevar token = vxGenerateToken("secret", claims);console.log(token);

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

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

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


    报告此页面的问题