rozetta logo
收费标准 
Menu Expand
API价格
Menu Expand
Change Theme

暗色

亮色

AUTHENTICATION
Nonce 认证
For security purpose, it is required to access this API with the generated signature.
Header
Header
Description
accessKey
您所持有的AccessKey。
nonce
一个数字字符串,每次请求,该字符串都需要比上一次更大。一般来讲您可以使用当前的Unix时间戳(毫秒)。 nonce的最大可指定值为9223372036854775807
signature
加密签名。 使用sha256和hmac算法,对secretKey依次用nonce和url(不包含domain的部分)进行签名,生成的16进制字符串。

具体计算过程,可以参考各种语言的示例代码。


使用任何API时,均需进行加密签名。以下,将以「hello」这个API做为示例。

/api/v1/hello
「hello」是一个不具任何功能的API。请将「hello」替换成您想要使用的API。

01

/

首先用一个方法来生成签名。

Go
JavaScript
Java
PHP
C#
VB.NET
func MakeHMAC(nonce, path, secretKey string) string {
    // Create a new HMAC by defining the hash type and the key (as byte array)
    h := hmac.New(sha256.New, []byte(secretKey))
  
    // Write Data to it
    h.Write([]byte(nonce))
    h.Write([]byte(path))
  
    // Get result and encode as hexadecimal string
    sha := hex.EncodeToString(h.Sum(nil))
  
    fmt.Println("Result: " + sha)
    return sha
  }

02

/

然后设置各Header并调用该API。

Go
JavaScript
Java
PHP
C#
VB.NET
// Generate a full URL
func GetFullUrl(base, path string) string {
  var buffer bytes.Buffer
  buffer.WriteString(base)
  buffer.WriteString(path)
  return buffer.String()
}

func GetApiExample(accessKey, secretKey, basePath, nonce string) {
  helloPath := "/api/v1/hello"
  // Generate a signature
  signHello := MakeHMAC(nonce, helloPath, secretKey)

  // Set headers and call the api
  client := &http.Client{}
  req, _ := http.NewRequest("GET", GetFullUrl(basePath, helloPath), nil)
  req.Header.Set("nonce", nonce)
  req.Header.Set("accessKey", accessKey)
  req.Header.Set("signature", signHello)
  res, err := client.Do(req)

  // Output response
  if err != nil {
    fmt.Printf("The HTTP request failed with error %s\n", err)
  } else {
    data, _ := ioutil.ReadAll(res.Body)
    fmt.Println(string(data))
  }
}

03

/

最后在Main方法里执行。

Go
JavaScript
Java
PHP
C#
VB.NET
import "strconv"

  func main() {
    fmt.Println("Starting the application...")

    accessKey := "Your Access Key"
    secretKey := "Your Secret Key"
    BasePath := "https://translate.rozetta-api.io"
    millis:= time.Now().UnixNano() / 1e6
    nonce := strconv.FormatInt(millis, 10)

    GetApiExample(accessKey, secretKey, BasePath, nonce)
    fmt.Println("Terminating the application...")
  }
关于各语言完整的示例代码,请参考这裡
CLASSIII Logo
©️ 2019 Rozetta API  ・  Powered by Rozetta

Rozetta股份有限公司

^