-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9529a72
Showing
75 changed files
with
15,779 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
on: push | ||
name: golang-ci | ||
jobs: | ||
checks: | ||
name: run | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@main | ||
- name: run | ||
uses: cedrickring/[email protected] | ||
env: | ||
GO111MODULE: "on" | ||
- name: Use Go 1.13 | ||
uses: cedrickring/golang-action/[email protected] | ||
env: | ||
GO111MODULE: "on" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
.idea/ | ||
book/ | ||
*tmp.go | ||
TODO | ||
demo | ||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2020 FastWeGo | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# fastwego/feishu | ||
|
||
A fast feishu development sdk written in Golang | ||
|
||
## 快速开始 & demo | ||
|
||
```shell script | ||
go get github.com/fastwego/feishu | ||
``` | ||
```go | ||
App = feishu.NewApp(feishu.AppConfig{ | ||
AppId: "APPID", | ||
AppSecret: "SECRET", | ||
}) | ||
|
||
// 调用 api 接口 | ||
params = url.Values{} | ||
params.Add("calendarId", "10086") | ||
resp, err := calendar.GetCalendarById(App, params) | ||
fmt.Println(string(resp), err) | ||
``` | ||
|
||
完整演示项目: | ||
|
||
[https://github.com/fastwego/feishu-demo](https://github.com/fastwego/feishu-demo) | ||
|
||
API 列表: | ||
|
||
[doc/apilist.md](doc/apilist.md) | ||
|
||
## 架构设计 | ||
|
||
![sdk](./doc/img/sdk.jpg) | ||
|
||
## 框架特点 | ||
|
||
### 快速 | ||
|
||
「快」作为框架设计的核心理念,体现在方方面面: | ||
|
||
- 使用 Go 语言,开发快、编译快、部署快、运行快,轻松服务海量用户 | ||
- 丰富的[文档](https://pkg.go.dev/github.com/fastwego/feishu) 和 [演示代码](https://github.com/fastwego/feishu-demo) ,快速上手,5 分钟即可搭建一个完整地飞书 App | ||
- 独立清晰的模块划分,快速熟悉整个框架,没有意外,一切都是你期望的样子 | ||
- 甚至连框架自身的大部分代码也是自动生成的,维护更新快到超乎想象 | ||
|
||
### 符合直觉 | ||
|
||
作为第三方开发框架,尽可能贴合官方文档和设计,不引入新的概念,不给开发者添加学习负担 | ||
|
||
### 简洁而不过度封装 | ||
|
||
作为具体业务和飞书服务的中间层,专注于通道的角色:帮业务把配置/材料投递到飞书,将飞书响应/推送透传回业务 | ||
|
||
至于 AccessToken 管理 和 消息加解密处理,框架内部完成得干净利落,开发者甚至觉察不到存在 | ||
|
||
### 官方文档就是最好的文档 | ||
|
||
每个接口的注释都附带官方文档的链接,让你随时翻阅,省时省心 | ||
|
||
### 完备的单元测试 | ||
|
||
100% 覆盖每一个接口,让你每一次调用都信心满满 | ||
|
||
### 详细的日志 | ||
|
||
每个关键环节都为你完整记录,Debug 倍轻松,你可以自由定义日志输出,甚至可以关闭日志 | ||
|
||
### 活跃的开发者社区 | ||
|
||
FastWeGo 是一套丰富的 Go 服务开发框架,支持飞书、微信等服务,拥有庞大的开发者用户群体 | ||
|
||
你遇到的所有问题几乎都可以在社区找到解决方案 | ||
|
||
## 参与贡献 | ||
|
||
欢迎提交 pull request / issue / 文档,一起让微信开发更快更好! | ||
|
||
Faster we go together! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
// Copyright 2020 FastWeGo | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package app_manage 应用信息/应用管理 | ||
package app_manage | ||
|
||
import ( | ||
"bytes" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/fastwego/feishu" | ||
) | ||
|
||
const ( | ||
apiIsUserAdmin = "/open-apis/application/v3/is_user_admin" | ||
apiAdminScopeGet = "/open-apis/contact/v1/user/admin_scope/get" | ||
apiAppVisibility = "/open-apis/application/v2/app/visibility" | ||
apiVisibleApps = "/open-apis/application/v1/user/visible_apps" | ||
apiAppList = "/open-apis/application/v3/app/list" | ||
apiUpdateVisibility = "/open-apis/application/v3/app/update_visibility" | ||
apiAppAdminUserList = "/open-apis/user/v4/app_admin_user/list" | ||
) | ||
|
||
/* | ||
校验应用管理员 | ||
该接口用于查询用户是否为应用管理员,需要申请 校验用户是否为应用管理员 权限。 | ||
See: https://open.feishu.cn/document/ukTMukTMukTM/uITN1EjLyUTNx4iM1UTM | ||
GET https://open.feishu.cn/open-apis/application/v3/is_user_admin | ||
*/ | ||
func IsUserAdmin(ctx *feishu.App) (resp []byte, err error) { | ||
|
||
accessToken, err := ctx.GetTenantAccessTokenHandler() | ||
if err != nil { | ||
return | ||
} | ||
header := http.Header{} | ||
header.Set("Authorization", "Bearer "+accessToken) | ||
header.Set("Content-appType", "application/json") | ||
|
||
return ctx.Client.HTTPGet(apiIsUserAdmin, header) | ||
} | ||
|
||
/* | ||
获取应用管理员管理范围 | ||
该接口用于获取应用管理员的管理范围,即该应用管理员能够管理哪些部门。 | ||
See: https://open.feishu.cn/document/ukTMukTMukTM/uMzN3QjLzczN04yM3cDN | ||
GET https://open.feishu.cn/open-apis/contact/v1/user/admin_scope/get?employee_id=2fab1234 | ||
*/ | ||
func AdminScopeGet(ctx *feishu.App, params url.Values) (resp []byte, err error) { | ||
|
||
accessToken, err := ctx.GetTenantAccessTokenHandler() | ||
if err != nil { | ||
return | ||
} | ||
header := http.Header{} | ||
header.Set("Authorization", "Bearer "+accessToken) | ||
header.Set("Content-appType", "application/json") | ||
|
||
return ctx.Client.HTTPGet(apiAdminScopeGet+"?"+params.Encode(), header) | ||
} | ||
|
||
/* | ||
获取应用在企业内的可用范围 | ||
该接口用于查询应用在该企业内可以被使用的范围,只能被企业自建应用调用且需要“获取应用信息”权限。 | ||
See: https://open.feishu.cn/document/ukTMukTMukTM/uIjM3UjLyIzN14iMycTN | ||
GET https://open.feishu.cn/open-apis/application/v2/app/visibility?app_id=cli_9db45f86b7799104&user_page_token=0&user_page_size=100 | ||
*/ | ||
func AppVisibility(ctx *feishu.App, params url.Values) (resp []byte, err error) { | ||
|
||
accessToken, err := ctx.GetTenantAccessTokenHandler() | ||
if err != nil { | ||
return | ||
} | ||
header := http.Header{} | ||
header.Set("Authorization", "Bearer "+accessToken) | ||
header.Set("Content-appType", "application/json") | ||
|
||
return ctx.Client.HTTPGet(apiAppVisibility+"?"+params.Encode(), header) | ||
} | ||
|
||
/* | ||
获取用户可用的应用 | ||
该接口用于查询用户可用的应用列表,只能被企业自建应用调用且需要“获取用户可用的应用”权限。 | ||
See: https://open.feishu.cn/document/ukTMukTMukTM/uMjM3UjLzIzN14yMycTN | ||
GET https://open.feishu.cn/open-apis/application/v1/user/visible_apps?user_id=79affdge&page_token=0&lang=zh_cn&page_size=5 | ||
*/ | ||
func VisibleApps(ctx *feishu.App, params url.Values) (resp []byte, err error) { | ||
|
||
accessToken, err := ctx.GetTenantAccessTokenHandler() | ||
if err != nil { | ||
return | ||
} | ||
header := http.Header{} | ||
header.Set("Authorization", "Bearer "+accessToken) | ||
header.Set("Content-appType", "application/json") | ||
|
||
return ctx.Client.HTTPGet(apiVisibleApps+"?"+params.Encode(), header) | ||
} | ||
|
||
/* | ||
获取企业安装的应用 | ||
该接口用于查询企业安装的应用列表,只能被企业自建应用调用且需要“获取应用信息”权限。 | ||
See: https://open.feishu.cn/document/ukTMukTMukTM/uYDN3UjL2QzN14iN0cTN | ||
GET https://open.feishu.cn/open-apis/application/v3/app/list?page_size=5&page_token=0&lang=zh_cn&status=1 | ||
*/ | ||
func AppList(ctx *feishu.App, params url.Values) (resp []byte, err error) { | ||
|
||
accessToken, err := ctx.GetTenantAccessTokenHandler() | ||
if err != nil { | ||
return | ||
} | ||
header := http.Header{} | ||
header.Set("Authorization", "Bearer "+accessToken) | ||
header.Set("Content-appType", "application/json") | ||
|
||
return ctx.Client.HTTPGet(apiAppList+"?"+params.Encode(), header) | ||
} | ||
|
||
/* | ||
更新应用可用范围 | ||
该接口用于增加或者删除指定应用被哪些人可用,只能被企业自建应用调用且需要“管理应用可见范围”权限。 | ||
See: https://open.feishu.cn/document/ukTMukTMukTM/ucDN3UjL3QzN14yN0cTN | ||
POST https://open.feishu.cn/open-apis/application/v3/app/update_visibility | ||
*/ | ||
func UpdateVisibility(ctx *feishu.App, payload []byte) (resp []byte, err error) { | ||
|
||
accessToken, err := ctx.GetTenantAccessTokenHandler() | ||
if err != nil { | ||
return | ||
} | ||
header := http.Header{} | ||
header.Set("Authorization", "Bearer "+accessToken) | ||
header.Set("Content-appType", "application/json") | ||
|
||
return ctx.Client.HTTPPost(apiUpdateVisibility, bytes.NewReader(payload), header) | ||
} | ||
|
||
/* | ||
查询应用管理员列表 | ||
查询应用管理员列表,返回应用的最新10个管理员账户id列表。 | ||
**权限说明** : | ||
本接口需要申请 获取应用管理员ID 权限才能访问。 | ||
回包数据中的user_id 需要申请 获取用户 userid 权限才会返回 | ||
回包数据中的union_id 需要申请 获取用户统一ID 权限才会返回 | ||
See: https://open.feishu.cn/document/ukTMukTMukTM/ucDOwYjL3gDM24yN4AjN | ||
GET https://open.feishu.cn/open-apis/user/v4/app_admin_user/list | ||
*/ | ||
func AppAdminUserList(ctx *feishu.App) (resp []byte, err error) { | ||
|
||
accessToken, err := ctx.GetTenantAccessTokenHandler() | ||
if err != nil { | ||
return | ||
} | ||
header := http.Header{} | ||
header.Set("Authorization", "Bearer "+accessToken) | ||
header.Set("Content-appType", "application/json") | ||
|
||
return ctx.Client.HTTPGet(apiAppAdminUserList, header) | ||
} |
Oops, something went wrong.