Added auth opportunity for VK callback API
This commit is contained in:
parent
657f967a49
commit
e4c2d9673b
3 changed files with 9 additions and 4 deletions
2
main.go
2
main.go
|
|
@ -11,5 +11,5 @@ func main() {
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
rand.Seed(time.Now().UTC().UnixNano())
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
r.POST("callback/message", vk.HandleMessage)
|
r.POST("callback/message", vk.HandleMessage)
|
||||||
r.Run()
|
r.Run(":80")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,12 +7,15 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleMessage(c *gin.Context) {
|
func HandleMessage(c *gin.Context) {
|
||||||
defer c.String(http.StatusOK, "ok")
|
|
||||||
var req MessageRequest
|
var req MessageRequest
|
||||||
c.BindJSON(&req)
|
c.BindJSON(&req)
|
||||||
|
if (req.Type == "confirmation") && (req.GroupId == GROUPID) {
|
||||||
|
c.String(http.StatusOK, CONFIRMATION_STRING)
|
||||||
|
}
|
||||||
if req.Secret != SECRET_KEY {
|
if req.Secret != SECRET_KEY {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cardName := cardsinfo.GetOriginalName(req.Object.Body)
|
cardName := cardsinfo.GetOriginalName(req.Object.Body)
|
||||||
Message(req.Object.UserId, cardName)
|
Message(req.Object.UserId, cardName)
|
||||||
|
c.String(http.StatusOK, "ok")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
package vk
|
package vk
|
||||||
|
|
||||||
type MessageRequest struct {
|
type MessageRequest struct {
|
||||||
Object UserMessage `json:"object"`
|
Type string `json:"type"`
|
||||||
Secret string `json:"secret"`
|
GroupId int64 `json:"group_id"`
|
||||||
|
Object UserMessage `json:"object"`
|
||||||
|
Secret string `json:"secret"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserMessage struct {
|
type UserMessage struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue