Skip to content

Commit

Permalink
添加v0.1版本SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
icepy committed Apr 20, 2018
0 parents commit 4ba8054
Show file tree
Hide file tree
Showing 42 changed files with 3,220 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
.company_access_token_file
.company_ticket_file
debug
debug.test
33 changes: 33 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Connect to server",
"type": "go",
"request": "launch",
"mode": "remote",
"remotePath": "${workspaceRoot}",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": []
},
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {},
"args": [],
"showLog": true
}
]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
111 changes: 111 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# DingTalk Golang SDK

DingTalk Golang SDK https://github.com/icepy

# Feature Overview

- 支持企业,SSO,SNS免登
- 支持对access_token自动续期过期管理
- 支持注册钉钉事件回调
- 支持对钉钉事件回调消息签名的加解密
- 支持全部 Open api
- 支持全部 Top api,并且自动处理生成加密签名

# Test

- Test get auth scopes
- Test get company acess_token
- Test get company ticket
- Test upload file
- Test download file

```bash
$ cd __test__
$ go test
```

# Install

```bash
$ go get -u github.com/icepy/go-dingtalk
```

# Guide

[Document]()

# Example

```go
package main

import (
"os"
"github.com/icepy/go-dingtalk/src"
)

func main() {
c := getCompanyDingTalkClient()
c.RefreshCompanyAccessToken()
}

func getCompanyDingTalkClient() *dingtalk.DingTalkClient {
CorpID := os.Getenv("CorpId")
CorpSecret := os.Getenv("CorpSecret")
config := &dingtalk.DTCompanyConfig{
CorpID: CorpID,
CorpSecret: CorpSecret,
}
c := dingtalk.NewDingTalkCompanyClient(config)
return c
}

```

# Help



# Contribute

- For a small change, just send a PR.
- For bigger changes open an issue for discussion before sending a PR.
- PR should have:
- Test case
- Documentation
- Example (If it makes sense)
- You can also contribute by:
- Reporting issues
- Suggesting new features or enhancements
- Improve/fix documentation

# 打赏

<div align="left">
<img width="100" heigth="100" src="docs/weixin.png" style="margin-right:10px">
<img width="100" heigth="100" src="docs/ali.png">
</div>

# License

MIT License

Copyright (c) 2018

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 21 additions & 0 deletions __test__/.dingtalkMain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"os"
)

func main() {
c := getCompanyDingTalkClient()
c.RefreshCompanyAccessToken()
}

func getCompanyDingTalkClient() *dingtalk.DingTalkClient {
CorpID := os.Getenv("CorpId")
CorpSecret := os.Getenv("CorpSecret")
config := &dingtalk.DTCompanyConfig{
CorpID: CorpID,
CorpSecret: CorpSecret,
}
c := dingtalk.NewDingTalkCompanyClient(config)
return c
}
26 changes: 26 additions & 0 deletions __test__/GetCompanyDingTalkClient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dingtalkTest

import (
"os"

"../src"
)

func GetCompanyDingTalkClient() *dingtalk.DingTalkClient {
CorpID := os.Getenv("CorpId")
CorpSecret := os.Getenv("CorpSecret")
AgentID := os.Getenv("AgentID")
SSOSecret := os.Getenv("SSOSecret")
SNSAppID := os.Getenv("SNSAppID")
SNSSecret := os.Getenv("SNSSecret")
config := &dingtalk.DTCompanyConfig{
CorpID: CorpID,
CorpSecret: CorpSecret,
AgentID: AgentID,
SSOSecret: SSOSecret,
SNSAppID: SNSAppID,
SNSSecret: SNSSecret,
}
c := dingtalk.NewDingTalkCompanyClient(config)
return c
}
16 changes: 16 additions & 0 deletions __test__/getAuthScopes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dingtalkTest

import (
"testing"
)

func Test_GetAuthScopes(t *testing.T) {
c := GetCompanyDingTalkClient()
c.RefreshCompanyAccessToken()
data, err := c.GetAuthScopes()
if err != nil {
t.Error("测试获取Auth Scopes 未通过", err)
} else {
t.Log("测试获取Auth Scopes 通过", data)
}
}
15 changes: 15 additions & 0 deletions __test__/getCompanyAccessToken_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dingtalkTest

import (
"testing"
)

func Test_GetCompanyAccessToken(t *testing.T) {
c := GetCompanyDingTalkClient()
c.RefreshCompanyAccessToken()
if c.AccessToken != "" {
t.Log("测试获取access_token通过")
} else {
t.Error("测试获取access_token未通过")
}
}
16 changes: 16 additions & 0 deletions __test__/getCompanyTicket_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dingtalkTest

import (
"testing"
)

func Test_GetCompanyTicket(t *testing.T) {
c := GetCompanyDingTalkClient()
c.RefreshCompanyAccessToken()
ticket, err := c.GetJSAPITicket()
if err != nil {
t.Error("测试未能获取JSAPI Ticket")
} else {
t.Log("测试获取JSAPI Ticket通过", ticket)
}
}
13 changes: 13 additions & 0 deletions __test__/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="//g.alicdn.com/dingding/open-develop/1.9.0/dingtalk.js"></script>
</head>
<body>

</body>
</html>
39 changes: 39 additions & 0 deletions __test__/mediaDownloadFile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package dingtalkTest

import (
"crypto/md5"
"fmt"
"io"
"os"
"testing"
"time"
)

const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

func Test_MediaDownloadFile(t *testing.T) {
mediaID := "@lADPBY0V4zNROQfNBUbNCWA" //填写你刚刚上传的mediaID
name := randStringBytesRmndr()
c := GetCompanyDingTalkClient()
c.RefreshCompanyAccessToken()
ce, ok := os.Create(name + ".jpg")
if ok == nil {
err := c.MediaDownloadFile(mediaID, ce)
if err == nil {
t.Log("测试下载图片通过")
} else {
t.Error("测试下载图片未通过", err)
}
} else {
t.Error("创建图片未通过", ok)
}
}

func randStringBytesRmndr() string {
t := time.Now()
h := md5.New()
io.WriteString(h, "crazyof.me")
io.WriteString(h, t.String())
passwd := fmt.Sprintf("%x", h.Sum(nil))
return passwd
}
27 changes: 27 additions & 0 deletions __test__/mediaUpload_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dingtalkTest

import (
"os"
"testing"
)

func Test_MediaUpload(t *testing.T) {
c := GetCompanyDingTalkClient()
c.RefreshCompanyAccessToken()
o, ok := os.Open("wow.jpg")
if ok == nil {
data, err := c.MediaUpload("image", "wow.jpg", o)
if err != nil {
t.Error("测试图片上传未通过", err)
} else {
if data.MediaID != "" {
t.Log("测试图片上传通过", data)
} else {
t.Error("测试图片上传未能获取到media_id")
}
}
} else {
t.Error("os.Open文件错误", ok)
}

}
Binary file added __test__/wow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
title: 'DingTalk Golang SDK',
description: '简单,易用,稳定',
themeConfig: {
sidebar: [
['/guide/', '介绍'],
['/guide/getting_started', '起步'],
['/guide/open_api_auth', '授权'],
['/guide/open_api_user', '用户相关'],
['guide/top_api', 'TOP']
],
// 假定 GitHub。也可以是一个完整的 GitLab 网址
repo: 'icepy/go-dingtalk',
// 如果你的文档不在仓库的根部
docsDir: 'docs',
// 可选,默认为 master
docsBranch: 'master',
// 默认为 true,设置为 false 来禁用
editLinks: true
}
}
Loading

0 comments on commit 4ba8054

Please sign in to comment.