-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (42 loc) · 1.02 KB
/
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
package main
import (
"fmt"
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
"net/http"
"wechatccs/accessToken"
"wechatccs/ticket"
)
func getToken(c echo.Context) error {
appid := c.QueryParam("appid")
secret := c.QueryParam("secret")
accessToken, err := accessToken.Get(appid, secret)
if err != nil {
fmt.Println(err)
return err
} else {
return c.JSON(http.StatusCreated, accessToken)
}
}
func getTicket(c echo.Context) error {
token := c.QueryParam("access_token")
ticket, err := ticket.Get(token)
if err != nil {
fmt.Println(err)
return err
} else {
return c.JSON(http.StatusCreated, ticket)
}
}
func main() {
e := echo.New()
e.GET("/", func(c echo.Context) error {
html := "<p>获取access_token请访问: /token?appid=APPID&secret=APPSECRET</p>"
html += "<p>获取jsapi_ticket请访问: /ticket?access_token=ACCESS_TOKEN</p>"
return c.HTML(http.StatusOK, html)
})
e.GET("/token", getToken)
e.GET("/ticket", getTicket)
fmt.Println("listen:2266")
e.Run(standard.New(":2266"))
}