代码拉取完成,页面将自动刷新
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。