使用 Nonce Authorization 来进行鉴权 (推荐客户端程序使用)。步骤如下:
在 UOS 网站上获取当前需要使用的 UOS APP 的 AppId 和 AppSecret
注:此处 AppId 和 AppSecret,可在 UOS 网站上获取


在请求任意 Sync API 的 Request Header 中增加如下 Header:
- X-TIMESTAMP: 当前时间戳
- X-NONCE: 随机生成的UUID
- X-APPID: 当前需要使用的 UOS APP 的 AppId
- Authorization: nonce hexadecimal(sha256(appId + ":" + appSecret + ":" + X-TIMESTAMP + ":" + X-NONCE))
示例代码:
C## C# 使用示例 - Nonce 授权方式 using System; using System.Collections.Generic; using System.Net.Http; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; class Program { private static Dictionary<string, string GetNonceAuthorization(string appId, string appSecret) { string nonce = Guid.NewGuid().ToString(); long timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); string signString = $"{appId}:{appSecret}:{timestamp}:{nonce}"; byte[] signBytes = Encoding.UTF8.GetBytes(signString); using (SHA256 sha256 = SHA256.Create()) { byte[] hashBytes = sha256.ComputeHash(signBytes); string token = BitConverter.ToString(hashBytes).Replace("-", "").ToLower(); return new Dictionary<string, string { { "X-APPID", appId }, { "X-TIMESTAMP", timestamp.ToString() }, { "X-NONCE", nonce }, { "Authorization", $"nonce {token}" } }; } } public static async Task Main(string[] args) { using (HttpClient client = new HttpClient()) { // 使用项目的 APP_ID, APP_SECRET 获取 headers var headers = GetNonceAuthorization(APP_ID, APP_SECRET); foreach (var header in headers) { client.DefaultRequestHeaders.Add(header.Key, header.Value); } // 以get方法为例,替换 url 为你需要请求的 url HttpResponseMessage response = await client.GetAsync(url); // 其他处理…… } } }Python# Python 使用示例 - Nonce 授权方式 import hashlib import time import uuid import binascii import requests def get_nonce_authorization(app_id, app_secret): """生成 nonce 授权 Headers""" nonce = str(uuid.uuid4()) timestamp = int(time.time()) calculated_check_sum = hashlib.sha256(f'{app_id}:{app_secret}:{timestamp}:{nonce}'.encode()).digest() token = binascii.hexlify(calculated_check_sum).decode() headers = { 'X-APPID': app_id, 'X-TIMESTAMP': str(timestamp), 'X-NONCE': nonce, 'Authorization': f'nonce {token}', 'Content-Type': 'application/json' } return headers # 使用项目的 APP_ID, APP_SECRET 获取 headers headers = get_nonce_authorization(APP_ID, APP_SECRET) # 替换 url 为你需要请求的 url response = requests.get(url, headers=headers)JavaScript// JavaScript - Nonce 授权方式 const axios = require('axios'); function getNonceAuthorization(appId, appSecret) { const nonce = crypto.randomUUID(); const timestamp = Math.floor(Date.now() / 1000); const signString = `${appId}:${appSecret}:${timestamp}:${nonce}`; const hash = crypto.createHash('sha256').update(signString).digest('hex'); return { 'X-APPID': appId, 'X-TIMESTAMP': timestamp.toString(), 'X-NONCE': nonce, 'Authorization': `nonce ${hash}` }; } // 使用 APP_ID, APP_SECRET 获取Nonce Token Header const headers = getNonceAuthorization(APP_ID, APP_SECRET); // 以get方法为例,替换 url 为你需要请求的 url const response = await axios.get(url, { headers });