wecom-go-sdk icon indicating copy to clipboard operation
wecom-go-sdk copied to clipboard

如何监听企微里用户向自建应用发送的消息

Open FlashIvano opened this issue 1 year ago • 1 comments

ListenAndReceiveWecomMsg.go

package wecom_sdk

import (
	"fmt"

	"github.com/gin-gonic/gin"
	"github.com/go-laoji/wecom-go-sdk/pkg/svr/callback"
	"github.com/go-laoji/wecom-go-sdk/v2/pkg/svr/middleware"
)

func InjectWecomMsgRouter(e *gin.Engine) {
	callbackGroup := e.Group("/wecom")
	{
		callbackGroup.GET("/receive", callback.CustomizedGetHandler)
		callbackGroup.POST("/receive", callback.CustomizedPostHandler)
	}
}

func ListenAndReceiveWecomMsg() {
	router := gin.Default()

	router.Use(middleware.InjectSdk(WecomSdk))

	InjectWecomMsgRouter(router)

	ListenAddr := fmt.Sprintf("%s:%s", BindHost, BindPort)
	router.Run(ListenAddr)
}

ListenAndReceiveWecomMsg_test.go

package wecom_sdk

import (
	"testing"
)

func TestListenAndReceiveWecomMsg(t *testing.T) {
	ListenAndReceiveWecomMsg()
}

FlashIvano avatar Sep 12 '23 09:09 FlashIvano