You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
package wecom
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"gitea.codecodify.com/golang/tool/helper"
|
|
)
|
|
|
|
// AccessTokenReq 获取access_token
|
|
type AccessTokenReq struct {
|
|
Corpid string `json:"corpid"` // 企业ID
|
|
Corpsecret string `json:"corpsecret"` // 应用的凭证密钥
|
|
}
|
|
|
|
// AccessTokenResp 获取access_token
|
|
type AccessTokenResp struct {
|
|
Errcode int `json:"errcode"` // 错误码
|
|
Errmsg string `json:"errmsg"` // 错误信息
|
|
AccessToken string `json:"access_token"` // 获取到的凭证
|
|
ExpiresIn int `json:"expires_in"` // 凭证有效时间,单位:秒
|
|
}
|
|
|
|
type AccessToken struct{}
|
|
|
|
func NewAccessToken() *AccessToken {
|
|
return &AccessToken{}
|
|
}
|
|
|
|
// GetAccessToken 获取access_token
|
|
func (a *AccessToken) GetAccessToken(req *AccessTokenReq) (*AccessTokenResp, error) {
|
|
var resp AccessTokenResp
|
|
bytes, err := helper.SendHttpRequest(fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s", req.Corpid, req.Corpsecret),
|
|
"GET", nil, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := json.Unmarshal(bytes, &resp); err != nil {
|
|
return nil, err
|
|
}
|
|
// 逃逸分析
|
|
return &resp, nil
|
|
}
|