1 Star 7 Fork 4

littletow/qywx

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
app.go 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
eagle 提交于 2021-04-07 10:32 +08:00 . 调整实例化方法
package apps
import (
"gitee.com/littletow/qywx/services/commons"
"gitee.com/littletow/qywx/services/tokens"
)
// 自建应用管理
// CustomAppManager 自建应用管理
type CustomAppManager struct {
tokenStore *tokens.AccessTokenStore
config *commons.QywxConfig
}
// NewCustomAppManager 返回一个manager的实例
func NewCustomAppManager(corpid string, agentid string, secret string, tokenStore *tokens.AccessTokenStore) *CustomAppManager {
config := commons.QywxConfig{
CorpID: corpid,
AgentID: agentid,
Secret: secret,
}
// 不在这里获取token,是防止token失效问题,每次调用都从tokenStore中获取。例如:(实例化在10:00,停止2个小时,再调用方法,就会出现问题)
return &CustomAppManager{tokenStore: tokenStore, config: &config}
}
// getToken 获取token
func (manager *CustomAppManager) getToken() (string, error) {
req := tokens.AccessTokenReq{
CorpID: manager.config.CorpID,
AgentID: manager.config.AgentID,
Secret: manager.config.Secret,
}
// 获取token
token, err := manager.tokenStore.GetToken(manager.config.AgentID, req)
if err != nil {
return "", err
}
return token, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/littletow/qywx.git
git@gitee.com:littletow/qywx.git
littletow
qywx
qywx
v1.0.1

搜索帮助