WeChat SDK for Go (微信SDK:简单、易用)

houseme d8e3208ef2 feat: upgrade go version 1.18 1 سال پیش
.github d8e3208ef2 feat: upgrade go version 1.18 1 سال پیش
aispeech 15ebd71a04 规范目录 6 سال پیش
cache d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش
credential d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش
doc d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش
domain 56a3734546 Feature: improve code message subscribe (#739) 2 سال پیش
internal d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش
minigame 8e81a416c5 Adaptation of new go-redis components (#546) 4 سال پیش
miniprogram d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش
officialaccount d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش
openplatform d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش
pay d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش
util d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش
work d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش
.gitignore c8522f1875 小程序内容安全 (#415) 5 سال پیش
.golangci.yml d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش
LICENSE f3303e2bb3 Initial commit 9 سال پیش
README.md d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش
doc.go 01eedc4274 chore: improve golangci 1 سال پیش
go.mod d8e3208ef2 feat: upgrade go version 1.18 1 سال پیش
go.sum d8e3208ef2 feat: upgrade go version 1.18 1 سال پیش
wechat.go d8fde54f2d improve comment ,参考:https://github.com/huacnlee/autocorrect 1 سال پیش

README.md

WeChat SDK for Go

Go Go Report Card pkg version

使用 Golang 开发的微信 SDK,简单、易用。

注意:当前版本为 v2 版本,v1 版本已废弃

文档 && 例子

API 列表

Wechat SDK 2.0 文档

Wechat SDK 2.0 例子

快速开始

import "github.com/silenceper/wechat/v2"

以下是一个微信公众号处理消息接收以及回复的例子:

// 使用 memcache 保存 access_token,也可选择 redis 或自定义 cache
wc := wechat.NewWechat()
memory := cache.NewMemory()
cfg := &offConfig.Config{
    AppID:     "xxx",
    AppSecret: "xxx",
    Token:     "xxx",
    // EncodingAESKey: "xxxx",
    Cache: memory,
}
officialAccount := wc.GetOfficialAccount(cfg)

// 传入 request 和 responseWriter
server := officialAccount.GetServer(req, rw)
// 设置接收消息的处理方法
server.SetMessageHandler(func(msg *message.MixMessage) *message.Reply {

    // 回复消息:演示回复用户发送的消息
    text := message.NewText(msg.Content)
    return &message.Reply{MsgType: message.MsgTypeText, MsgData: text}
})

// 处理消息接收以及回复
err := server.Serve()
if err != nil {
    fmt.Println(err)
    return
}
// 发送回复的消息
server.Send()

目录说明

  • officialaccount: 微信公众号 API
  • miniprogram: 小程序 API
  • minigame:小游戏 API
  • pay:微信支付 API
  • openplatform:开放平台 API
  • work:企业微信
  • aispeech:智能对话
  • doc: api 文档

贡献

  • API 列表中查看哪些 API 未实现
  • 提交 issue,描述需要贡献的内容
  • 完成更改后,提交 PR

公众号

img

License

Apache License, Version 2.0