-
Notifications
You must be signed in to change notification settings - Fork 0
/
dingent.go
53 lines (47 loc) · 1.38 KB
/
dingent.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
48
49
50
51
52
53
package main
import (
"encoding/json"
"strings"
"time"
"github.com/toolkits/net/httplib"
"go.uber.org/zap"
)
type DingEntMsg struct {
tos string `json:"tos"`
content string `json:"content"`
}
func (this *DingEntMsg) send() error {
for _, tel := range strings.Split(this.tos, ",") {
r := httplib.Post(cfg.DingEnt.URL).SetTimeout(5*time.Second, 30*time.Second)
data := struct {
Content string `json:"content"`
Tel string `json:"tel"`
}{
Content: this.content,
Tel: tel,
}
datajb, err := json.Marshal(data)
if err != nil {
return err
}
r.Header("X-Requested-With", "XMLHttpRequest")
r.Header("Accept-Encoding", "identity")
r.Header("Content-Type", "application/x-www-form-urlencoded")
/* r.SetProxy(
func(req *http.Request) (*url.URL, error) {
u, _ := url.ParseRequestURI("http://127.0.0.1:44444")
return u, nil
},
) */
// r.Header("Accept-Encoding", "")
body := "client_id=" + cfg.APP.ClientId + "¤tUserId=0&data=" + string(datajb)
r.Body(body)
resp, err := r.String()
if err != nil {
logger.Error("send dingent fail", zap.String("type", "dingent"), zap.String("tel", tel), zap.String("content", this.content), zap.Error(err))
return err
}
logger.Debug("send dingent success", zap.String("type", "dingent"), zap.String("tel", tel), zap.String("content", this.content), zap.String("resp", resp))
}
return nil
}