3.5. 更新 Token
Github: github.com/bigfile/bigfile
API
在 Token
创建账号,我们可以对它进行更新,相比创建除了多了个 token
参数,其它都是一致的,下面是这个 API
的基本信息:
PATCH /api/bigfile/token/update
参数名 | 类型 | 必填 | 描述 |
---|---|---|---|
appUid | string | yes | app uid |
token | string | yes | 要更新的 Token |
nonce | string | yes | 32 到 48 长度的随机字符串 |
sign | string | yes | 请求参数签名 |
path | string | no | Token 的作用域,默认为:/ ,可以理解为根目录 |
ip | string | no | 限制当前 Token 仅能被使用的 IP 列表,多个 IP 逗号分隔 |
expiredAt | timestamp | no | Token 失效时间,默认永久有效 |
secret | string | no | Token 密钥,12 到 32 位,建议设置,默认为空 |
availableTimes | int | no | Token 可用次数,默认无限次数 |
readOnly | bool | no | 限制此 Token 仅能被用于去下载文件 |
示例
package main
import (
"fmt"
"io/ioutil"
libHttp "net/http"
"strings"
"time"
"github.com/bigfile/bigfile/databases/models"
"github.com/bigfile/bigfile/http"
)
func main() {
appUid := "42c4fcc1a620c9e97188f50b6f2ab199"
appSecret := "f8f2ae1fe4f70b788254dcc991a35558"
body := http.GetParamsSignBody(map[string]interface{}{
"appUid": appUid,
"token": "4d50ae8061c1d6f148a45031356294bd",
"nonce": models.RandomWithMd5(128),
"path": "/images/png",
"expiredAt": time.Now().AddDate(0, 0, 10).Unix(),
"secret": models.RandomWithMd5(44),
"availableTimes": -1,
"readOnly": false,
}, appSecret)
request, err := libHttp.NewRequest(
libHttp.MethodPatch, "https://127.0.0.1:10985/api/bigfile/token/update", strings.NewReader(body))
if err != nil {
fmt.Println(err)
return
}
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := libHttp.DefaultClient.Do(request)
if err != nil {
fmt.Println(err)
return
}
if bodyBytes, err := ioutil.ReadAll(resp.Body); err != nil {
fmt.Println(err)
return
} else {
fmt.Println(string(bodyBytes))
}
}
请求之后,你将会得到如下的响应:
{
"requestId":10003,
"success":true,
"errors":null,
"data":{
"availableTimes":-1,
"expiredAt":1568819447,
"ip":null,
"path":"/images/png",
"readOnly":0,
"secret":"471c983b1e7052ef6a3ed4bd8b3bb42b",
"token":"4d50ae8061c1d6f148a45031356294bd"
}
}
英文文档:bigfile.site
推荐文章: