Skip to content

Commit 4ba8054

Browse files
committed
添加v0.1版本SDK
0 parents  commit 4ba8054

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3220
-0
lines changed

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.dll
4+
*.so
5+
*.dylib
6+
7+
# Test binary, build with `go test -c`
8+
*.test
9+
10+
# Output of the go coverage tool, specifically when used with LiteIDE
11+
*.out
12+
13+
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
14+
.glide/
15+
.company_access_token_file
16+
.company_ticket_file
17+
debug
18+
debug.test

.vscode/launch.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
// 使用 IntelliSense 了解相关属性。
3+
// 悬停以查看现有属性的描述。
4+
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Connect to server",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "remote",
12+
"remotePath": "${workspaceRoot}",
13+
"port": 2345,
14+
"host": "127.0.0.1",
15+
"program": "${workspaceRoot}",
16+
"env": {},
17+
"args": []
18+
},
19+
{
20+
"name": "Launch",
21+
"type": "go",
22+
"request": "launch",
23+
"mode": "debug",
24+
"remotePath": "",
25+
"port": 2345,
26+
"host": "127.0.0.1",
27+
"program": "${fileDirname}",
28+
"env": {},
29+
"args": [],
30+
"showLog": true
31+
}
32+
]
33+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# DingTalk Golang SDK
2+
3+
DingTalk Golang SDK https://github.com/icepy
4+
5+
# Feature Overview
6+
7+
- 支持企业,SSO,SNS免登
8+
- 支持对access_token自动续期过期管理
9+
- 支持注册钉钉事件回调
10+
- 支持对钉钉事件回调消息签名的加解密
11+
- 支持全部 Open api
12+
- 支持全部 Top api,并且自动处理生成加密签名
13+
14+
# Test
15+
16+
- Test get auth scopes
17+
- Test get company acess_token
18+
- Test get company ticket
19+
- Test upload file
20+
- Test download file
21+
22+
```bash
23+
$ cd __test__
24+
$ go test
25+
```
26+
27+
# Install
28+
29+
```bash
30+
$ go get -u github.com/icepy/go-dingtalk
31+
```
32+
33+
# Guide
34+
35+
[Document]()
36+
37+
# Example
38+
39+
```go
40+
package main
41+
42+
import (
43+
"os"
44+
"github.com/icepy/go-dingtalk/src"
45+
)
46+
47+
func main() {
48+
c := getCompanyDingTalkClient()
49+
c.RefreshCompanyAccessToken()
50+
}
51+
52+
func getCompanyDingTalkClient() *dingtalk.DingTalkClient {
53+
CorpID := os.Getenv("CorpId")
54+
CorpSecret := os.Getenv("CorpSecret")
55+
config := &dingtalk.DTCompanyConfig{
56+
CorpID: CorpID,
57+
CorpSecret: CorpSecret,
58+
}
59+
c := dingtalk.NewDingTalkCompanyClient(config)
60+
return c
61+
}
62+
63+
```
64+
65+
# Help
66+
67+
68+
69+
# Contribute
70+
71+
- For a small change, just send a PR.
72+
- For bigger changes open an issue for discussion before sending a PR.
73+
- PR should have:
74+
- Test case
75+
- Documentation
76+
- Example (If it makes sense)
77+
- You can also contribute by:
78+
- Reporting issues
79+
- Suggesting new features or enhancements
80+
- Improve/fix documentation
81+
82+
# 打赏
83+
84+
<div align="left">
85+
<img width="100" heigth="100" src="docs/weixin.png" style="margin-right:10px">
86+
<img width="100" heigth="100" src="docs/ali.png">
87+
</div>
88+
89+
# License
90+
91+
MIT License
92+
93+
Copyright (c) 2018
94+
95+
Permission is hereby granted, free of charge, to any person obtaining a copy
96+
of this software and associated documentation files (the "Software"), to deal
97+
in the Software without restriction, including without limitation the rights
98+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+
copies of the Software, and to permit persons to whom the Software is
100+
furnished to do so, subject to the following conditions:
101+
102+
The above copyright notice and this permission notice shall be included in all
103+
copies or substantial portions of the Software.
104+
105+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
106+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
107+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
108+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
109+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
110+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
111+
SOFTWARE.

__test__/.dingtalkMain.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"os"
5+
)
6+
7+
func main() {
8+
c := getCompanyDingTalkClient()
9+
c.RefreshCompanyAccessToken()
10+
}
11+
12+
func getCompanyDingTalkClient() *dingtalk.DingTalkClient {
13+
CorpID := os.Getenv("CorpId")
14+
CorpSecret := os.Getenv("CorpSecret")
15+
config := &dingtalk.DTCompanyConfig{
16+
CorpID: CorpID,
17+
CorpSecret: CorpSecret,
18+
}
19+
c := dingtalk.NewDingTalkCompanyClient(config)
20+
return c
21+
}

__test__/GetCompanyDingTalkClient.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package dingtalkTest
2+
3+
import (
4+
"os"
5+
6+
"../src"
7+
)
8+
9+
func GetCompanyDingTalkClient() *dingtalk.DingTalkClient {
10+
CorpID := os.Getenv("CorpId")
11+
CorpSecret := os.Getenv("CorpSecret")
12+
AgentID := os.Getenv("AgentID")
13+
SSOSecret := os.Getenv("SSOSecret")
14+
SNSAppID := os.Getenv("SNSAppID")
15+
SNSSecret := os.Getenv("SNSSecret")
16+
config := &dingtalk.DTCompanyConfig{
17+
CorpID: CorpID,
18+
CorpSecret: CorpSecret,
19+
AgentID: AgentID,
20+
SSOSecret: SSOSecret,
21+
SNSAppID: SNSAppID,
22+
SNSSecret: SNSSecret,
23+
}
24+
c := dingtalk.NewDingTalkCompanyClient(config)
25+
return c
26+
}

__test__/getAuthScopes_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package dingtalkTest
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func Test_GetAuthScopes(t *testing.T) {
8+
c := GetCompanyDingTalkClient()
9+
c.RefreshCompanyAccessToken()
10+
data, err := c.GetAuthScopes()
11+
if err != nil {
12+
t.Error("测试获取Auth Scopes 未通过", err)
13+
} else {
14+
t.Log("测试获取Auth Scopes 通过", data)
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package dingtalkTest
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func Test_GetCompanyAccessToken(t *testing.T) {
8+
c := GetCompanyDingTalkClient()
9+
c.RefreshCompanyAccessToken()
10+
if c.AccessToken != "" {
11+
t.Log("测试获取access_token通过")
12+
} else {
13+
t.Error("测试获取access_token未通过")
14+
}
15+
}

__test__/getCompanyTicket_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package dingtalkTest
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func Test_GetCompanyTicket(t *testing.T) {
8+
c := GetCompanyDingTalkClient()
9+
c.RefreshCompanyAccessToken()
10+
ticket, err := c.GetJSAPITicket()
11+
if err != nil {
12+
t.Error("测试未能获取JSAPI Ticket")
13+
} else {
14+
t.Log("测试获取JSAPI Ticket通过", ticket)
15+
}
16+
}

__test__/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
<script src="//g.alicdn.com/dingding/open-develop/1.9.0/dingtalk.js"></script>
9+
</head>
10+
<body>
11+
12+
</body>
13+
</html>

__test__/mediaDownloadFile_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package dingtalkTest
2+
3+
import (
4+
"crypto/md5"
5+
"fmt"
6+
"io"
7+
"os"
8+
"testing"
9+
"time"
10+
)
11+
12+
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
13+
14+
func Test_MediaDownloadFile(t *testing.T) {
15+
mediaID := "@lADPBY0V4zNROQfNBUbNCWA" //填写你刚刚上传的mediaID
16+
name := randStringBytesRmndr()
17+
c := GetCompanyDingTalkClient()
18+
c.RefreshCompanyAccessToken()
19+
ce, ok := os.Create(name + ".jpg")
20+
if ok == nil {
21+
err := c.MediaDownloadFile(mediaID, ce)
22+
if err == nil {
23+
t.Log("测试下载图片通过")
24+
} else {
25+
t.Error("测试下载图片未通过", err)
26+
}
27+
} else {
28+
t.Error("创建图片未通过", ok)
29+
}
30+
}
31+
32+
func randStringBytesRmndr() string {
33+
t := time.Now()
34+
h := md5.New()
35+
io.WriteString(h, "crazyof.me")
36+
io.WriteString(h, t.String())
37+
passwd := fmt.Sprintf("%x", h.Sum(nil))
38+
return passwd
39+
}

__test__/mediaUpload_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package dingtalkTest
2+
3+
import (
4+
"os"
5+
"testing"
6+
)
7+
8+
func Test_MediaUpload(t *testing.T) {
9+
c := GetCompanyDingTalkClient()
10+
c.RefreshCompanyAccessToken()
11+
o, ok := os.Open("wow.jpg")
12+
if ok == nil {
13+
data, err := c.MediaUpload("image", "wow.jpg", o)
14+
if err != nil {
15+
t.Error("测试图片上传未通过", err)
16+
} else {
17+
if data.MediaID != "" {
18+
t.Log("测试图片上传通过", data)
19+
} else {
20+
t.Error("测试图片上传未能获取到media_id")
21+
}
22+
}
23+
} else {
24+
t.Error("os.Open文件错误", ok)
25+
}
26+
27+
}

__test__/wow.jpg

470 KB
Loading

docs/.vuepress/config.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = {
2+
title: 'DingTalk Golang SDK',
3+
description: '简单,易用,稳定',
4+
themeConfig: {
5+
sidebar: [
6+
['/guide/', '介绍'],
7+
['/guide/getting_started', '起步'],
8+
['/guide/open_api_auth', '授权'],
9+
['/guide/open_api_user', '用户相关'],
10+
['guide/top_api', 'TOP']
11+
],
12+
// 假定 GitHub。也可以是一个完整的 GitLab 网址
13+
repo: 'icepy/go-dingtalk',
14+
// 如果你的文档不在仓库的根部
15+
docsDir: 'docs',
16+
// 可选,默认为 master
17+
docsBranch: 'master',
18+
// 默认为 true,设置为 false 来禁用
19+
editLinks: true
20+
}
21+
}

0 commit comments

Comments
 (0)