1 Star 0 Fork 0

h79 / gothird

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
work.go 999 Bytes
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2023-07-28 16:16 . 还是把 token 放在这里
package work
import (
"encoding/json"
"fmt"
"gitee.com/h79/gothird/token"
"gitee.com/h79/gothird/token/access"
"gitee.com/h79/gothird/weixin/consts"
"gitee.com/h79/gothird/weixin/response"
workaccess "gitee.com/h79/gothird/weixin/work/access"
"gitee.com/h79/goutils/common/data"
"gitee.com/h79/goutils/common/http"
)
func GetAccessToken(tk token.Token, d data.D) (access.Token, error) {
var appId = tk.GetAppId()
var secret = tk.GetSecret()
if appId == "" {
return nil, fmt.Errorf("corp id is empty")
}
if secret == "" {
return nil, fmt.Errorf("corp secret is empty")
}
url := fmt.Sprintf("%s/cgi-bin/gettoken?corpid=%s&corpsecret=%s", consts.WorkApiPrefixUrl, appId, secret)
hp := http.Http{}
body, err := hp.DoBytes("GET", url, nil)
if err != nil {
return nil, err
}
type tokenResult struct {
response.Response
workaccess.Token
}
res := tokenResult{}
if err = json.Unmarshal(body, &res); err != nil {
return nil, err
}
return &res.Token, res.ErrorIf()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/h79/gothird.git
git@gitee.com:h79/gothird.git
h79
gothird
gothird
v1.8.21

搜索帮助

344bd9b3 5694891 D2dac590 5694891