-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (44 loc) · 917 Bytes
/
main.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
package main
import (
"AWC-gateway/crontab"
"AWC-gateway/wechat"
_ "AWC-gateway/wolfkill"
"github.com/gin-gonic/gin"
"log"
"time"
)
func main() {
r := gin.Default()
r.GET("/", wechat.VerifyURL)
r.POST("/", wechat.HandleEvent)
// 初始化AccessToken及微信服务IP
wechat.SetAccessToken()
setTrustedProxies(r)
// 定时刷新信任的微信服务IP
crontab.StartCronTab(func() time.Duration {
setTrustedProxies(r)
return 24 * time.Hour
})
// 定时刷新AccessToken
crontab.StartCronTab(func() time.Duration {
return wechat.SetAccessToken()
})
err := r.Run(":80")
if err != nil {
return
}
}
// setTrustedProxies 设置可信任的ip集
func setTrustedProxies(r *gin.Engine) {
ips, err := wechat.GetCallbackIP()
if err != nil {
log.Println(err)
return
}
log.Println("trusted ips : ", ips)
err = r.SetTrustedProxies(ips)
if err != nil {
log.Println(err)
return
}
}