markwang d28ca4f334 feat: optimized-error-handling&remove unused constant (#772) 2 years ago
..
account 96c1f98944 [feature] Format the code and improve Mini Program authorization to o… (#473) 4 years ago
config 96c1f98944 [feature] Format the code and improve Mini Program authorization to o… (#473) 4 years ago
context d28ca4f334 feat: optimized-error-handling&remove unused constant (#772) 2 years ago
miniprogram ceb006bf58 开放平台修改小程序基础信息 (#642) 2 years ago
officialaccount 96c1f98944 [feature] Format the code and improve Mini Program authorization to o… (#473) 4 years ago
README.md 8e81a416c5 Adaptation of new go-redis components (#546) 4 years ago
openplatform.go d6371c7289 chore: 移除 panic,转移 cache 初始化到 Wechat 结构体方法下;在使用时可以只设置一次 cache 同时避免 panic 出现 (#668) 3 years ago

README.md

微信开放平台

官方文档

快速入门

服务端处理

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


openPlatform := wc.GetOpenPlatform(cfg)
// 传入request和responseWriter
server := openPlatform.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()


待授权处理消息


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