Skip to content

Commit b89a82e

Browse files
Matrix-XWalleMatrix-X
authored
Develop (#34)
* Feature/group robot (#33) * Update go.mod * fix(go-libs): update version v1.1.4 * refactor(wecom): add group robot message struct * docs(project): readme and license Co-authored-by: Walle <walle@artisan-cloud.com> Co-authored-by: Matrix-X <matrix-x@aritsancloud.com>
1 parent f5dc216 commit b89a82e

File tree

14 files changed

+404
-27
lines changed

14 files changed

+404
-27
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021-present, 元匠信息科技(上海)有限公司
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
13+
all 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
21+
THE SOFTWARE

README.md

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,119 @@
1-
# PowerWechat
1+
# PowerWeChat SDK 介绍
22

33
[![Go Build](https://github.com/ArtisanCloud/power-wechat/actions/workflows/go-build.yml/badge.svg?branch=release%2F1.0.0)](https://github.com/ArtisanCloud/power-wechat/actions/workflows/go-build.yml)
44

5-
[![Go Test](https://github.com/ArtisanCloud/power-wechat/actions/workflows/go-test.yml/badge.svg?branch=release%2F1.0.0)](https://github.com/ArtisanCloud/power-wechat/actions/workflows/go-test.yml)
5+
[![Go Test](https://github.com/ArtisanCloud/power-wechat/actions/workflows/go-test.yml/badge.svg?branch=release%2F1.0.0)](https://github.com/ArtisanCloud/power-wechat/actions/workflows/go-test.yml)
6+
7+
8+
## 产品介绍
9+
10+
11+
PowerWechat是一款全覆盖微信开发接口,基于Golang的开源项目。您只需安装一次Power WeChat SDK,就可以对接企业微信,小程序,公众号,支付等,微信的开发功能接口。同时我们提供了丰富的文档教程和辅助工具,帮助您轻松使用微信的接口功能。
12+
13+
14+
---
15+
16+
## 产品概述
17+
![Image of Main Page]
18+
(blob:null/ff591363-1799-4516-9f8b-8bb81303fe4f)
19+
20+
21+
### 核心产品
22+
[PowerWeChat SDK](https://github.com/ArtisanCloud/power-wechat) :是核心的SDK产品,安装后即可开箱即用。
23+
在github上,长期维护的开源项目,可以提Issue在讨论版块。也可以在ArtisanCloud官网上,扫企业微信讨论群,方便用户提问,给宝贵的意见。
24+
25+
26+
#### 简易安装,开箱即用
27+
下载安装
28+
```go
29+
go get github.com/ArtisanCloud/power-wechat
30+
```
31+
32+
33+
示范:初始化实例对象,调用小程序的授权登陆接口
34+
```go
35+
import (
36+
"github.com/ArtisanCloud/power-wechat/src/miniProgram"
37+
"os"
38+
)
39+
40+
// 1. 初始化小程序应用实例
41+
app, err := miniProgram.NewMiniProgram(&miniProgram.UserConfig{
42+
AppID: os.Getenv("miniprogram_app_id"), // 小程序、公众号或者企业微信的appid
43+
Secret: os.Getenv("miniprogram_secret"), // 商户号 appID
44+
45+
ResponseType: os.Getenv("array"),
46+
HttpDebug: true,
47+
Debug: false,
48+
})
49+
50+
51+
// 2. 调用小程序的授权登陆接口
52+
var code string = "CODE" // 前端小程序登录时,从微信获取的code
53+
rs, err := services.MiniProgramApp.Auth.Session(code)
54+
55+
56+
// 查看获取强类型对象的属性
57+
// 请参考官方文档的返回值
58+
printf(rs.OpenID)
59+
printf(rs.SessionKey)
60+
printf(rs.UnionID)
61+
62+
```
63+
64+
更多实例接口,请打[开官方文档](https://powerwechat.artisan-cloud.com/zh/start/)
65+
66+
---
67+
68+
### 辅助产品
69+
70+
[PowerWeChat Document](https://powerwechat.artisan-cloud.com/zh/start/) :全面的接口文档,方便用户查找,使用我们开发的sdk功能
71+
72+
![Image of Document Page]
73+
(blob:null/ff591363-1799-4516-9f8b-8bb81303fe4f)
74+
75+
76+
77+
[PowerWeChat Tutorial](https://github.com/ArtisanCloud/power-wechat-tutorial) :独立的golang项目,提供完整的web接口,让开发者方便调试PowerWeChat 接口实例
78+
79+
80+
PowerWeChat 配置中心客户端/SAAS:如果您有多个微信的开发环境,或者多个应用,可以使用这个配置中心来方便切换账号(此应用暂时内部使用,如需体验,可以联系我们)
81+
82+
![Image of Products]
83+
(blob:null/ff591363-1799-4516-9f8b-8bb81303fe4f)
84+
85+
86+
---
87+
88+
89+
# 产品诞生背景
90+
[ArtisanCloud](https://github.com/ArtisanCloud) 团队也是很多同学一样,从PHP转向Golang,具体为什么,有什么好处,就不用我这里多介绍了吧。 但是现在因为微信的生态做私域化管理是得天独厚,所以我们公司也开发了蛮多企业微信的功能。只是在转型golang的过程中,没有找到像 [Easy Wechat](https://www.easywechat.com)(PHP语言)这样好用的sdk。所以我们就自己想为golang的同学们做一点贡献。产品会长期维护,迭代,希望同学们有兴趣在使用的过程中,多给意见。
91+
92+
93+
---
94+
95+
# 产品特性
96+
97+
## 简易上手,安装一次,全覆盖微信功能接口
98+
## 开源项目,丰富的文档内容,长期维护
99+
## 新增群机器接口和文档
100+
## Golang特性,强类型覆盖
101+
## 完整的测试项目,支持web API测试
102+
103+
---
104+
105+
# 相关资源
106+
107+
## 阅览教程文档
108+
### [官网介绍](https://powerwechat.artisan-cloud.com)
109+
### [使用手册](https://powerwechat.artisan-cloud.com/zh/start/)
110+
### (企业微信群,即将提供)
111+
112+
113+
## Github开源代码
114+
### [SDK源代码](https://github.com/ArtisanCloud/power-wechat)
115+
### [SDK调试项目](https://github.com/ArtisanCloud/power-wechat-tutorial)
116+
117+
118+
## 视频教程
119+
### (策划制作中...)

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ go 1.16
66
// replace github.com/ArtisanCloud/go-libs => ../go-libs
77
// replace github.com/ArtisanCloud/go-socialite => ../go-socialite
88

9+
910
require (
1011
github.com/ArtisanCloud/go-libs v1.1.4
1112
github.com/ArtisanCloud/go-socialite v1.0.8

src/work/agent/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"github.com/ArtisanCloud/power-wechat/src/kernel"
66
"github.com/ArtisanCloud/power-wechat/src/kernel/power"
7+
"github.com/ArtisanCloud/power-wechat/src/work/agent/request"
78
"github.com/ArtisanCloud/power-wechat/src/work/agent/response"
89
)
910

@@ -30,11 +31,10 @@ func (comp *Client) Get(agentID int) (*response.ResponseAgentGet, error) {
3031
}
3132

3233
// https://open.work.weixin.qq.com/api/doc/90000/90135/90228
33-
func (comp *Client) Set(agentID int, data *power.HashMap) (*response.ResponseAgentSet, error) {
34+
func (comp *Client) Set(data *request.RequestAgentSet) (*response.ResponseAgentSet, error) {
3435

3536
result := &response.ResponseAgentSet{}
3637

37-
(*data)["agentid"] = agentID
3838
_, err := comp.HttpPostJson("cgi-bin/agent/set", data, nil, nil, result)
3939

4040
return result, err
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package request
2+
3+
type RequestAgentSet struct {
4+
AgentID int `json:"agentid"`
5+
ReportLocationFlag int `json:"report_location_flag"`
6+
LogoMediaID string `json:"logo_mediaid"`
7+
Name string `json:"name"`
8+
Description string `json:"description"`
9+
RedirectDomain string `json:"redirect_domain"`
10+
IsReportEnter int `json:"isreportenter"`
11+
HomeUrl string `json:"home_url"`
12+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package request
2+
3+
type RequestSetWorkbenchTemplate struct {
4+
AgentID int `json:"agentid"`
5+
Type string `json:"type"`
6+
KeyData WorkBenchKeyData `json:"keydata"`
7+
Image WorkBenchImage `json:"image,omitempty"`
8+
List WorkBenchListItem `json:"list,omitempty"`
9+
WebView WorkBenchWebView `json:"webview,omitempty"`
10+
ReplaceUserData bool `json:"replace_user_data"`
11+
}
12+
13+
type RequestSetWorkBenchData struct {
14+
AgentID int `json:"agentid"`
15+
UserID string `json:"userid"`
16+
Type string `json:"type"`
17+
KeyData WorkBenchKeyData `json:"keydata,omitempty"`
18+
Image WorkBenchImage `json:"image,omitempty"`
19+
List WorkBenchListData `json:"list,omitempty"`
20+
WebView WorkBenchWebView `json:"webview,omitempty"`
21+
}
22+
23+
type WorkBenchKeyData struct {
24+
Items []WorkBenchKeyDataItem `json:"items"`
25+
}
26+
type WorkBenchKeyDataItem struct {
27+
Key string `json:"key"`
28+
Data string `json:"data"`
29+
JumpUrl string `json:"jump_url"`
30+
PagePath string `json:"pagepath"`
31+
}
32+
33+
type WorkBenchImage struct {
34+
Url string `json:"url"`
35+
JumpUrl string `json:"jump_url"`
36+
PagePath string `json:"pagepath"`
37+
}
38+
39+
type WorkBenchListData struct {
40+
Items []WorkBenchListItem `json:"items"`
41+
}
42+
type WorkBenchListItem struct {
43+
Title string `json:"title"`
44+
JumpUrl string `json:"jump_url"`
45+
PagePath string `json:"pagepath"`
46+
}
47+
48+
type WorkBenchWebView struct {
49+
Url string `json:"url"`
50+
JumpUrl string `json:"jump_url"`
51+
PagePath string `json:"pagepath"`
52+
}
Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
package response
22

33
import (
4-
"github.com/ArtisanCloud/power-wechat/src/kernel/power"
54
"github.com/ArtisanCloud/power-wechat/src/kernel/response"
65
)
76

87
type ResponseAgentGet struct {
98
*response.ResponseWork
9+
AgentID int16 `json:"agentid"` // "agentid": 1000005,
10+
Name string `json:"name"` // "name": "HR助手",
11+
SquareLogoURL string `json:"square_logo_url"` // "square_logo_url": "https://p.qlogo.cn/bizmail/FicwmI50icF8GH9ib7rUAYR5kicLTgP265naVFQKnleqSlRhiaBx7QA9u7Q/0",
12+
Description string `json:"description"` // "description": "HR服务与员工自助平台",
13+
AllowUserInfos ResponseAgentAllowUserInfos `json:"allow_userinfos"` // "allow_userinfos": {
14+
AllowParty ResponseAgentAllowParty `json:"allow_partys"` // "allow_partys": {
15+
AllowTags ResponseAgentAllowTags `json:"allow_tags"` // "allow_tags": {
16+
Close int8 `json:"close"`
17+
RedirectDomain string `json:"redirect_domain"`
18+
ReportLocationFlag int8 `json:"report_location_flag"`
19+
IsReportEnter int8 `json:"isreportenter"`
20+
HomeURL string `json:"home_url"`
21+
}
22+
23+
type ResponseAgentAllowUserInfos struct {
24+
User ResponseAgentAllowUser `json:"user"`
25+
}
1026

11-
AgentID int16 `json:"agentid"` // "agentid": 1000005,
12-
Name string `json:"name"` // "name": "HR助手",
13-
SquareLogoURL string `json:"square_logo_url"` // "square_logo_url": "https://p.qlogo.cn/bizmail/FicwmI50icF8GH9ib7rUAYR5kicLTgP265naVFQKnleqSlRhiaBx7QA9u7Q/0",
14-
Description string `json:"description"` // "description": "HR服务与员工自助平台",
15-
AllowUserInfo power.HashMap `json:"allow_userinfos"` // "allow_userinfos": {
16-
AllowParty power.HashMap `json:"allow_partys"` // "allow_partys": {
17-
AllowTags power.HashMap `json:"allow_tags"` // "allow_tags": {
27+
type ResponseAgentAllowUser struct {
28+
UserID string `json:"userid"`
29+
}
30+
31+
type ResponseAgentAllowParty struct {
32+
PartyID []int `json:"partyid"`
33+
}
1834

19-
Close int8 `json:"close"`
20-
RedirectDomain string `json:"redirect_domai`
21-
ReportLocationFlag int8 `json:"report_location_flag"`
22-
IsReportEnter int8 `json:"isreportente`
23-
HomeURL string `json:"home_url"`
35+
type ResponseAgentAllowTags struct {
36+
TagID []int `json:"tagid"`
2437
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package response
22

33
import (
4-
"github.com/ArtisanCloud/power-wechat/src/kernel/power"
54
"github.com/ArtisanCloud/power-wechat/src/kernel/response"
5+
"github.com/ArtisanCloud/power-wechat/src/work/agent/request"
66
)
77

88
type ResponseAgentGetWorkbenchTemplate struct {
99
*response.ResponseWork
1010

11-
TemplateType string `json:"type"`
12-
Image power.StringMap `json:"image"`
13-
ReplaceUserData bool `json:"replace_user_data"`
11+
TemplateType string `json:"type"`
12+
Image request.WorkBenchImage `json:"image"`
13+
ReplaceUserData bool `json:"replace_user_data"`
1414
}

src/work/agent/workbench/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
"github.com/ArtisanCloud/go-libs/object"
66
"github.com/ArtisanCloud/power-wechat/src/kernel"
7-
"github.com/ArtisanCloud/power-wechat/src/kernel/power"
7+
"github.com/ArtisanCloud/power-wechat/src/work/agent/request"
88
"github.com/ArtisanCloud/power-wechat/src/work/agent/response"
99
)
1010

@@ -19,7 +19,7 @@ func NewClient(app kernel.ApplicationInterface) *Client {
1919
}
2020

2121
// https://open.work.weixin.qq.com/api/doc/90000/90135/90205
22-
func (comp *Client) SetWorkbenchTemplate(data *power.HashMap) (*response.ResponseAgentSetWorkbenchTemplate, error) {
22+
func (comp *Client) SetWorkbenchTemplate(data *request.RequestSetWorkbenchTemplate) (*response.ResponseAgentSetWorkbenchTemplate, error) {
2323

2424
result := &response.ResponseAgentSetWorkbenchTemplate{}
2525

@@ -41,7 +41,7 @@ func (comp Client) GetWorkbenchTemplate(agentID int) (*response.ResponseAgentGet
4141
}
4242

4343
// https://open.work.weixin.qq.com/api/doc/90000/90135/90207
44-
func (comp Client) SetWorkbenchData(data *power.HashMap) (*response.ResponseAgentSetWorkbenchData, error) {
44+
func (comp Client) SetWorkbenchData(data *request.RequestSetWorkBenchData) (*response.ResponseAgentSetWorkbenchData, error) {
4545

4646
result := &response.ResponseAgentSetWorkbenchData{}
4747

0 commit comments

Comments
 (0)