调⽤说明

调⽤⼊⼝

调⽤环境服务地址(HTTPS)
正式环境https://platformx.vetmew.com

认证⽅式

所有 API 请求均采⽤ HMAC-SHA256 进⾏签名认证,以确保数据完整性和安全性。

签名⽅式

格式:

signature = base64(hmac-sha256(path + body + nonce + timestamp, api_secret))  

参数说明:

参数说明
api_secret调⽤⽅API密钥
path请求路径
bodyHTTP 请求的 Body(JSON 格式)
nonce8位随机字符串
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服务内部错误

宠物品种信息

点击下载宠物品种信息文件open in new window