-
Notifications
You must be signed in to change notification settings - Fork 4
/
api.go
47 lines (38 loc) · 1.01 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package fsBotAPI
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"fmt"
)
const _fmtWebhook = "https://open.feishu.cn/open-apis/bot/v2/hook/%s"
type Bot interface {
PushText(content string) error
PushPost(p Post, ps ...Post) error
PushCard(bgColor CardTitleBgColor, cfg CardConfig, c Card, more ...Card) error
PushImage(imageKey string) error
PushShareChat(chatID string) error
}
// 签名校验
//
// https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN#348211be
func genSign(secret string, timestamp int64) (string, error) {
sign := fmt.Sprintf("%d\n%s", timestamp, secret)
var data []byte
h := hmac.New(sha256.New, []byte(sign))
if _, err := h.Write(data); err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(h.Sum(nil)), nil
}
type Language string
const (
LangChinese Language = "zh_cn"
LangEnglish Language = "en_us"
LangJapanese Language = "ja_jp"
)
type apiResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data any `json:"data"`
}