1 Star 0 Fork 0

irishcoffeeguo/RTSPtoWeb

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
streamRemoteAuthorization.go 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
deepch 提交于 2022-01-05 19:26 . add video example token
package main
import (
"bytes"
"encoding/json"
"io"
"net/http"
"time"
)
type AuthorizationReq struct {
Proto string `json:"proto,omitempty"`
Stream string `json:"stream,omitempty"`
Channel string `json:"channel,omitempty"`
Token string `json:"token,omitempty"`
IP string `json:"ip,omitempty"`
}
type AuthorizationRes struct {
Status string `json:"status,omitempty"`
}
func RemoteAuthorization(proto string, stream string, channel string, token string, ip string) bool {
if !Storage.ServerTokenEnable() {
return true
}
buf, err := json.Marshal(&AuthorizationReq{proto, stream, channel, token, ip})
if err != nil {
return false
}
request, err := http.NewRequest("POST", Storage.ServerTokenBackend(), bytes.NewBuffer(buf))
if err != nil {
return false
}
request.Header.Set("Content-Type", "application/json; charset=UTF-8")
client := &http.Client{
Timeout: 1 * time.Second,
}
response, err := client.Do(request)
if err != nil {
return false
}
defer response.Body.Close()
bodyBytes, err := io.ReadAll(response.Body)
if err != nil {
return false
}
var res AuthorizationRes
err = json.Unmarshal(bodyBytes, &res)
if err != nil {
return false
}
if res.Status == "1" {
return true
}
return false
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/irishcoffeeguo/RTSPtoWeb.git
git@gitee.com:irishcoffeeguo/RTSPtoWeb.git
irishcoffeeguo
RTSPtoWeb
RTSPtoWeb
master

搜索帮助