wechatgogin

package module
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2023 License: MIT Imports: 15 Imported by: 0

README

wechat-go-gin

暂时解决 每次 http 请求过来都会去调用 officialAccount.GetServer,然而该方法每次都会新建一个 server 对象的问题

    wc := wechat.NewWechat()
	//配置微信参数
	config := &offConfig.Config{
		AppID:         AppID,
		AppSecret:      AppSecret,
		Token:          Token,
		EncodingAESKey: EncodingAESKey,
		Cache:          redis,
	}
	officialAccount := wc.GetOfficialAccount(config)

    // 获取公众号实例的上下文
    wxCtx := officialAccount.GetContext()


    // 获取微信消息 c为 *gin.Context
	ginWxMsg, error := wechatgogin.GetWxMsg(c, wxCtx, false)
	if error == nil {
        // 微信消息处理
		reply := messageReply(ginWxMsg.MixMessage)
        // 设置返回结果
		ginWxMsg.MessageReply = reply
        // 编译返回结果
		wechatgogin.BuildResponse(ginWxMsg)
        // 返回消息给微信
		wechatgogin.Result(ginWxMsg)
	}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildResponse

func BuildResponse(ginWxMsg *GinWxMsg) (err error)

编译响应参数

func Render

func Render(c *gin.Context, bytes []byte)

func Result

func Result(ginWxMsg *GinWxMsg) (err error)

func ResultXml

func ResultXml(c *gin.Context, obj interface{})

func ReulstString

func ReulstString(c *gin.Context, str string)

func Validate

func Validate(ginWxMsg *GinWxMsg) bool

Validate 校验请求是否合法

Types

type GinWxMsg

type GinWxMsg struct {
	Gin           *gin.Context
	WxCtx         *context.Context
	MixMessage    *message.MixMessage
	IsSafeMode    bool
	IsJSONContent bool
	Random        []byte
	Nonce         string
	Timestamp     int64

	SkipValidate bool

	OpenID string

	MessageReply *message.Reply

	RequestRawXMLMsg  []byte
	RequestMsg        *message.MixMessage
	ResponseRawXMLMsg []byte
	ResponseMsg       interface{}
}

gin 微信消息

func GetWxMsg

func GetWxMsg(c *gin.Context, wxCtx *context.Context, skip bool) (ginWxMsg *GinWxMsg, err error)

gin 获取微信消息

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL