serverchan_sdk

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 6 Imported by: 3 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ServerChan SDK for Golang

这是用于调用 ServerChan 推送服务的 Go SDK,包名为 serverchan-sdk,仓库地址为 github.com/easychen/serverchan-sdk-golang。

同时支持 Server酱 Max、Server酱³ (SC3) 与 Server酱 Turbo,按 SendKey 前缀自动选择推送入口:

SendKey 形态 平台 实际请求地址
scx-<uid>-<token> Server酱 Max https://<uid>.max.ft07.com/<sendkey>.send
sctp<uid>t<token> Server酱³ (SC3) https://<uid>.push.ft07.com/send/<sendkey>.send
其余(SCT…) Server酱 Turbo https://sctapi.ftqq.com/<sendkey>.send

Max 的 Key 区分大小写,SDK 不做大小写转换。Key 以 scx- / sctp 开头但格式非法时 ScSend 会返回错误, 不会静默回落到 Turbo 入口。想在不发请求的情况下确认某个 Key 会打到哪个地址,可以用 ResolveURL。

安装

go get github.com/easychen/serverchan-sdk-golang

使用示例

package main

import (
    "fmt"
    "github.com/easychen/serverchan-sdk-golang"
)

func main() {
    sendkey := "your-sendkey"
    title := "Test Message"
    desp := "This is a test message"
    
    resp, err := serverchan_sdk.ScSend(sendkey, title, desp, nil)
    if err != nil {
        fmt.Println("Error:", err)
    } else {
        fmt.Println("Response:", resp)
    }
}

查询推送地址

url, err := serverchan_sdk.ResolveURL("scx-1-xxxxxxxxxxxxxxxxxxxxxxxx")
// url == "https://1.max.ft07.com/scx-1-xxxxxxxxxxxxxxxxxxxxxxxx.send"

测试

go test ./...                                        # 单元测试(不联网)
SERVERCHAN_REAL_SENDKEY='scx-...' go test -run Real  # 真实推送

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveURL added in v1.2.0

func ResolveURL(sendkey string) (string, error)

ResolveURL 根据 SendKey 前缀解析推送入口(不做网络请求):

scx-<uid>-<token>  → Server酱 Max   : https://<uid>.max.ft07.com/<key>.send
sctp<uid>t<token>  → Server酱³(SC3) : https://<uid>.push.ft07.com/send/<key>.send
其余(SCT…)        → Server酱Turbo : https://sctapi.ftqq.com/<key>.send

注意:Max 的 Key 区分大小写,不做任何大小写转换。 Key 以 scx- / sctp 开头但格式非法时返回错误,不会静默回落到 Turbo 入口。

Types

type ScSendOptions

type ScSendOptions struct {
	Tags    string `json:"tags,omitempty"`
	Short   string `json:"short,omitempty"`
	Noip    int    `json:"noip,omitempty"`
	Channel string `json:"channel,omitempty"`
	Openid  string `json:"openid,omitempty"`
}

type ScSendResponse

type ScSendResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

func ScSend

func ScSend(sendkey, title, desp string, options *ScSendOptions) (*ScSendResponse, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL