1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-04 12:52:27 +08:00
mahongran 71c8ab58fb F ix work access token (#810)
* feat: enhance WorkAccessToken to include AgentID for improved token management

- Added AgentID field to WorkAccessToken struct.
- Updated NewWorkAccessToken function to accept AgentID as a parameter.
- Modified access token cache key to incorporate AgentID, ensuring unique cache entries per agent.

This change improves the handling of access tokens in a multi-agent environment.

* refactor: enhance WorkAccessToken to improve cache key handling

- Updated the AgentID field in WorkAccessToken struct to clarify its optional nature for distinguishing applications.
- Modified the access token cache key construction to support both new and legacy formats based on the presence of AgentID.
- Added comments for better understanding of the cache key logic and its compatibility with historical versions.

This change improves the flexibility and clarity of access token management in multi-agent scenarios.

* feat: enhance WorkAccessToken with new constructor for AgentID support

- Introduced NewWorkAccessTokenWithAgentID function to maintain backward compatibility while allowing for AgentID usage.
- Updated NewWorkAccessToken to call the new constructor, ensuring seamless integration.
- Improved error handling in GetAccessTokenContext by checking for cache availability and handling potential errors during cache operations.

This change enhances the flexibility of access token management, particularly in multi-agent scenarios, while ensuring compatibility with existing implementations.
2025-01-07 22:19:21 +08:00
2024-04-16 10:52:47 +08:00
2020-01-20 13:54:04 +08:00
2025-01-07 22:19:21 +08:00
2023-09-24 10:44:18 +08:00
2024-08-22 14:21:58 +08:00
2025-01-07 22:19:21 +08:00
2021-07-13 20:49:47 +08:00
2023-08-27 19:13:00 +08:00
2016-09-06 15:25:01 +08:00
2024-01-02 17:19:59 +08:00

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

Description
WeChat SDK for Go (微信SDK:简单、易用)
Readme Apache-2.0 10 MiB
Languages
Go 98.7%
C++ 0.8%
C 0.5%