1 Star 0 Fork 0

h79/gothird

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
baidu
dingtalk
feishu
filter
fxg
gdt
notify
ocean
result
taobao
token
weixin
access
app3
consts
errors
iv
media
message
mini
oauth2
offia
response
session
template
work
access
errors
service
account.go
api.go
order.go
provider.go
readme.md
structs.go
structs
agent.go
api.go
auth.go
contact.go
department.go
kf.go
message.go
msgaudit.go
tags.go
token.go
user.go
work.go
work_test.go
readme.md
token.go
wx.go
wx_test.go
.gitignore
LICENSE
Makefile
README.md
doc.go
error.md
go.mod
go.sum
version.go
克隆/下载
api.go 8.29 KB
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2年前 . 企业微信
package service
import (
"encoding/json"
"fmt"
"gitee.com/h79/gothird/token"
"gitee.com/h79/gothird/weixin/consts"
"gitee.com/h79/gothird/weixin/response"
"gitee.com/h79/goutils/common/http"
)
//https://developer.work.weixin.qq.com/document
// GetPreAuthCode 获取预授权码
func GetPreAuthCode(api *token.Api) (*PreAuthCode, error) {
url := fmt.Sprintf("%s/get_pre_auth_code?", consts.WorkServiceApiPrefixUrl)
type Result struct {
response.Response
PreAuthCode
}
res := Result{}
err := api.Request("GET", url, nil, func(hp *http.Http, body []byte) error {
if er := json.Unmarshal(body, &res); er != nil {
return er
}
return res.ReturnIf(api)
})
if err != nil {
return nil, err
}
if res.ErrCode != 0 {
return nil, res
}
return &res.PreAuthCode, nil
}
// GetAuthInfo 获取企业授权信息 POST(HTTPS)
// https://qyapi.weixin.qq.com/cgi-bin/service/get_auth_info?suite_access_token=SUITE_ACCESS_TOKEN
func GetAuthInfo(api *token.Api, authCorpId, permanentCode string) (*Permanent, error) {
url := fmt.Sprintf("%s/get_auth_info?", consts.WorkServiceApiPrefixUrl)
var in = authCorp{
AuthCorpId: authCorpId,
PermanentCode: permanentCode,
}
buf, _ := json.Marshal(&in)
var res = struct {
response.Response
Permanent
}{}
err := api.Request("POST", url, buf, func(hp *http.Http, body []byte) error {
if er := json.Unmarshal(body, &res); er != nil {
return er
}
return res.ReturnIf(api)
})
if err != nil {
return nil, err
}
if res.ErrCode != 0 {
return nil, res
}
return &res.Permanent, nil
}
// GetAdminList 获取应用的管理员列表
// 第三方服务商可以用此接口获取授权企业中某个第三方应用的管理员列表(不包括外部管理员),以便服务商在用户进入应用主页之后根据是否管理员身份做权限的区分。
// 该应用必须与SUITE_ACCESS_TOKEN对应的suiteid对应,否则没权限查看
// POST(HTTPS)
// https://qyapi.weixin.qq.com/cgi-bin/service/get_admin_list?suite_access_token=SUITE_ACCESS_TOKEN
func GetAdminList(api *token.Api, authCorpId string, agentId int64) (*AdminList, error) {
url := fmt.Sprintf("%s/get_admin_list?", consts.WorkServiceApiPrefixUrl)
var in = struct {
AuthCorpId string `json:"auth_corpid"`
AgentId int64 `json:"agentid"`
}{
AuthCorpId: authCorpId,
AgentId: agentId,
}
buf, _ := json.Marshal(&in)
var res = struct {
response.Response
AdminList
}{}
err := api.Request("POST", url, buf, func(hp *http.Http, body []byte) error {
if er := json.Unmarshal(body, &res); er != nil {
return er
}
return res.ReturnIf(api)
})
if err != nil {
return nil, err
}
if res.ErrCode != 0 {
return nil, res
}
return &res.AdminList, nil
}
// CorpIdToOpenCorpId 明文corpid转换为加密corpid POST(HTTPS)
// 为更好地保护企业与用户的数据,第三方应用获取的corpid不再是明文的corpid,将升级为第三方服务商级别的加密corpid(了解更多)。第三方可以将已有的明文corpid转换为第三方的加密corpid。
// 请求地址:https://qyapi.weixin.qq.com/cgi-bin/service/corpid_to_opencorpid?provider_access_token=ACCESS_TOKEN
func CorpIdToOpenCorpId(api *token.Api, corpId string) (string, error) {
url := fmt.Sprintf("%s/corpid_to_opencorpid?", consts.WorkServiceApiPrefixUrl)
var in = struct {
CorpId string `json:"corpid"`
}{
CorpId: corpId,
}
buf, _ := json.Marshal(&in)
var res = struct {
response.Response
OpenCorpId string `json:"open_corpid"`
}{}
err := api.Request("POST", url, buf, func(hp *http.Http, body []byte) error {
if er := json.Unmarshal(body, &res); er != nil {
return er
}
return res.ReturnIf(api)
})
if err != nil {
return "", err
}
if res.ErrCode != 0 {
return "", res
}
return res.OpenCorpId, nil
}
// GetAppQrCode 获取应用二维码 POST(HTTPS)
// 用于获取第三方应用二维码。
// 要求第三方应用是已上线的第三方 "通用" 应用,不能是代应用
// https://qyapi.weixin.qq.com/cgi-bin/service/get_app_qrcode?suite_access_token=SUITE_ACCESS_TOKEN
func GetAppQrCode(api *token.Api, qr QRCodeReq) (string, error) {
url := fmt.Sprintf("%s/get_app_qrcode?", consts.WorkServiceApiPrefixUrl)
buf, _ := json.Marshal(&qr)
var res = struct {
response.Response
Qrcode string `json:"qrcode"`
}{}
err := api.Request("POST", url, buf, func(hp *http.Http, body []byte) error {
if er := json.Unmarshal(body, &res); er != nil {
return er
}
return res.ReturnIf(api)
})
if err != nil {
return "", err
}
if res.ErrCode != 0 {
return "", res
}
return res.Qrcode, nil
}
// GetCustomizedAuthUrl 获取带参授权链接
// 该API用于获取代开发自建应用授权链接,用于生成带参临时二维码。
// 可用来生成二维码的授权url,需要开发者自行生成为二维码
// 请求方式:POST(HTTPS)
// 请求地址: https://qyapi.weixin.qq.com/cgi-bin/service/get_customized_auth_url?provider_access_token=PROVIDER_ACCESS_TOKEN
func GetCustomizedAuthUrl(api *token.Api, state string, templateId []string) (*CustomizedAuthUrl, error) {
url := fmt.Sprintf("%s/get_customized_auth_url?", consts.WorkServiceApiPrefixUrl)
var req = struct {
State string `json:"state"`
TemplateidList []string `json:"templateid_list"`
}{
State: state,
TemplateidList: templateId,
}
buf, _ := json.Marshal(&req)
var res = struct {
response.Response
CustomizedAuthUrl
}{}
err := api.Request("POST", url, buf, func(hp *http.Http, body []byte) error {
if er := json.Unmarshal(body, &res); er != nil {
return er
}
return res.ReturnIf(api)
})
if err != nil {
return nil, err
}
if res.ErrCode != 0 {
return nil, res
}
return &res.CustomizedAuthUrl, nil
}
// GetuserInfo3rd 获取访问用户身份
// 请求方式:GET(HTTPS)
// 请求地址:https://qyapi.weixin.qq.com/cgi-bin/service/auth/getuserinfo3rd?suite_access_token=SUITE_ACCESS_TOKEN&code=CODE
func GetuserInfo3rd(api *token.Api, code string) (*UserInfo3rd, error) {
url := fmt.Sprintf("%s/auth/getuserinfo3rd?", consts.WorkServiceApiPrefixUrl)
var res = struct {
response.Response
UserInfo3rd
}{}
err := api.Request("GET", url, nil, func(hp *http.Http, body []byte) error {
if er := json.Unmarshal(body, &res); er != nil {
return er
}
return res.ReturnIf(api)
})
if err != nil {
return nil, err
}
if res.ErrCode != 0 {
return nil, res
}
return &res.UserInfo3rd, nil
}
// GetUserDetail3rd 获取访问用户敏感信息
// 请求方式:POST(HTTPS)
// 请求地址:https://qyapi.weixin.qq.com/cgi-bin/service/auth/getuserdetail3rd?suite_access_token=SUITE_ACCESS_TOKEN
func GetUserDetail3rd(api *token.Api, ticket string) (*UserDetail3rd, error) {
url := fmt.Sprintf("%s/get_customized_auth_url?", consts.WorkServiceApiPrefixUrl)
var req = struct {
Ticket string `json:"user_ticket"`
}{
Ticket: ticket,
}
buf, _ := json.Marshal(&req)
var res = struct {
response.Response
UserDetail3rd
}{}
err := api.Request("POST", url, buf, func(hp *http.Http, body []byte) error {
if er := json.Unmarshal(body, &res); er != nil {
return er
}
return res.ReturnIf(api)
})
if err != nil {
return nil, err
}
if res.ErrCode != 0 {
return nil, res
}
return &res.UserDetail3rd, nil
}
// GetLoginInfo 获取登录用户信息 [扫码授权登录]
// 第三方可通过如下接口,获取登录用户的信息。建议用户以返回信息中的corpid及userid为主键匹配用户
// 授权登录服务商的网站时,使用应用提供商的provider_access_token
// 请求方式:POST(HTTPS)
// 请求地址: https://qyapi.weixin.qq.com/cgi-bin/service/get_login_info?access_token=PROVIDER_ACCESS_TOKEN
func GetLoginInfo(api *token.Api, authCode string) (*LoginInfo, error) {
url := fmt.Sprintf("%s/get_login_info?", consts.WorkServiceApiPrefixUrl)
var in = struct {
AuthCode string `json:"auth_code"`
}{
AuthCode: authCode,
}
buf, _ := json.Marshal(&in)
var res = struct {
response.Response
LoginInfo
}{}
err := api.Request("POST", url, buf, func(hp *http.Http, body []byte) error {
if er := json.Unmarshal(body, &res); er != nil {
return er
}
return res.ReturnIf(api)
})
if err != nil {
return nil, err
}
if res.ErrCode != 0 {
return nil, res
}
return &res.LoginInfo, nil
}
type authCorp struct {
AuthCorpId string `json:"auth_corpid"`
PermanentCode string `json:"permanent_code"`
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/h79/gothird.git
git@gitee.com:h79/gothird.git
h79
gothird
gothird
v1.2.0

搜索帮助