1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-10 07:42:26 +08:00

添加微信客服SDK (#436)

* 添加微信客服SDK

* polish:优化签名函数

* polish:优化注释内容

* polish:复用已有的Token以及CommonError,移除无用的输出

* polish:复用已有的消息加解密

* fix:修复错误信息被覆盖的问题

* polish:go fmt 文件
This commit is contained in:
Afeyer
2021-08-17 10:19:01 +08:00
committed by GitHub
parent fc1fc7e84e
commit 8ceabc2d0b
17 changed files with 1299 additions and 1 deletions

43
work/kf/client.go Normal file
View File

@@ -0,0 +1,43 @@
package kf
import (
"github.com/silenceper/wechat/v2/cache"
"github.com/silenceper/wechat/v2/credential"
"github.com/silenceper/wechat/v2/work/config"
"github.com/silenceper/wechat/v2/work/context"
)
// Client 微信客服实例
type Client struct {
corpID string // 企业ID企业开通的每个微信客服都对应唯一的企业ID企业可在微信客服管理后台的企业信息处查看
secret string // Secret是微信客服用于校验开发者身份的访问密钥企业成功注册微信客服后可在「微信客服管理后台-开发配置」处获取
token string // 用于生成签名校验回调请求的合法性
encodingAESKey string // 回调消息加解密参数是AES密钥的Base64编码用于解密回调消息内容对应的密文
cache cache.Cache
ctx *context.Context
}
// NewClient 初始化微信客服实例
func NewClient(cfg *config.Config) (client *Client, err error) {
if cfg.Cache == nil {
return nil, NewSDKErr(50001)
}
//初始化 AccessToken Handle
defaultAkHandle := credential.NewWorkAccessToken(cfg.CorpID, cfg.CorpSecret, credential.CacheKeyWorkPrefix, cfg.Cache)
ctx := &context.Context{
Config: cfg,
AccessTokenHandle: defaultAkHandle,
}
client = &Client{
corpID: cfg.CorpID,
secret: cfg.CorpSecret,
token: cfg.Token,
encodingAESKey: cfg.EncodingAESKey,
cache: cfg.Cache,
ctx: ctx,
}
return client, nil
}