调⽤说明
调⽤⼊⼝
调⽤环境 | 服务地址(HTTPS) |
---|---|
正式环境 | https://platformx.vetmew.com |
认证⽅式
所有 API 请求均采⽤ HMAC-SHA256 进⾏签名认证,以确保数据完整性和安全性。
签名⽅式
格式:
signature = base64(hmac-sha256(path + body + nonce + timestamp, api_secret))
参数说明:
参数 | 说明 |
---|---|
api_secret | 调⽤⽅API密钥 |
path | 请求路径 |
body | HTTP 请求的 Body(JSON 格式) |
nonce | 8位随机字符串 |
timestamp | 当前秒级时间戳(Unix 时间戳) |
示例
api_secret = "1pkni7hm42zl4tlhwn92mpfto9i957le"
path = "/open/v1/chat"
body = `{"msg":"我的狗⽣病了","breed":1,"birth":"2024-07-01","gender":1,"nick_name":"⼤⻩","fertility":1}`
nonce = "zisbnzzr"
timestamp = 1732072594
拼接后签名字符串:
/open/v1/chat{"msg":"我的狗⽣病了","breed":1,"birth":"2024-07-01","gender":1,"nick_name":"⼤⻩","fertility":1}zisbnzzr1732072594
进⾏HMAC-SHA256加密并且base64后结果:
MM8dJpELERXSZVWn+uWcK7/e+k1CQlae8qHttptq/x4=
代码示例(Golang):
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"fmt"
)
func GenerateSignature(path, body, nonce, timestamp, secret string) string {
data := path + body + nonce + timestamp
h := hmac.New(sha256.New, []byte(secret))
h.Write([]byte(data))
signature := base64.StdEncoding.EncodeToString(h.Sum(nil))
return signature
}
func main() {
path := "/open/v1/chat"
body := `{"msg":"我的狗⽣病了","breed":1,"birth":"2024-07-01","gender":1,"nick_name":"⼤⻩","fertility":1}`
nonce := "randomstr"
timestamp := "1700000000"
secret := "api_secret"
sign := GenerateSignature(path, body, nonce, timestamp, secret)
fmt.Println("Signature:", sign)
}
请求头说明
请求头 | 说明 |
---|---|
X-ApiKey | 调⽤⽅ API Key,匹配计算签名⽤的API密钥 |
X-Timestamp | 计算签名的timestamp,5分钟内有效 |
X-Nonce | 计算签名的nonce |
X-Signature | 计算后的签名值signature |
Content-Type | 请求格式,默认为application/json |
curl⽰例
curl -XPOST -H "Content-Type: application/json" -H "X-ApiKey: vmcd9a2dfa0227fef6" -H "X-Nonce: zisbnzzr" -H "X-Timestamp: 1732072594" -H "X-Signature:MM8dJpELERXSZVWn+uWcK7/e+k1CQlae8qHttptq/x4=" -d '{"msg":"我的狗⽣病了","breed":1,"birth":"2024-07-01","gender":1,"nick_name":"⼤⻩","fertility":1}' 'https://platformx-test.vetmew.com:21006/open/v1/chat'
HTTP状态码
状态码 | 描述 |
---|---|
200 | 成功 |
400 | 请求参数错误 |
500 | 服务内部错误 |
错误码
错误码 | 说明 |
---|---|
0 | 成功 |
6001 | ⽆效API KEY |
6002 | 调⽤过于频繁 |
6003 | 调⽤次数不⾜ |
6004 | 签名参数⽆效 |
6005 | 签名⽆效 |
6006 | 业务参数⽆效 |
6007 | 会话已结束,请新建会话⽆效 |
6008 | 同一个会话无法同时接收多个请求 |
6009 | 所输入的内容涉及敏感词汇,请核对后再发送 |
6101 | 服务内部错误 |