微信开放平台

状态:beta

官方文档

快速入门

wc := wechat.NewWechat()
memory := cache.NewMemory()
cfg := &openplatform.Config{
    AppID:     "xxx",
    AppSecret: "xxx",
    Token:     "xxx",
    EncodingAESKey: "xxx",
    Cache: memory,
}

//授权的第三方公众号的appID
appID := "xxx"
openPlatform := wc.GetOpenPlatform(cfg)
officialAccount := openPlatform.GetOfficialAccount(appID)

// 传入request和responseWriter
server := officialAccount.GetServer(req, rw)
//设置接收消息的处理方法
server.SetMessageHandler(func(msg message.MixMessage) *message.Reply {
    if msg.InfoType == message.InfoTypeVerifyTicket {
        componentVerifyTicket, err := openPlatform.SetComponentAccessToken(msg.ComponentVerifyTicket)
        if err != nil {
            log.Println(err)
            return nil
        }
        //debug 
        fmt.Println(componentVerifyTicket)
        rw.Write([]byte("success"))
        return nil
    }
    //handle other message
    //


    return nil
})

//处理消息接收以及回复
err := server.Serve()
if err != nil {
    fmt.Println(err)
    return
}
//发送回复的消息
server.Send()
Copyright © Wechat SDK For Go 2020 all right reserved,powered by Gitbook该文件修订时间: 2020-05-30 08:12:07

results matching ""

    No results matching ""