mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 21:02:25 +08:00
Compare commits
39 Commits
v2.1.3-rc.
...
v2.1.5-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3cb741ae1a | ||
|
|
da3859261b | ||
|
|
86ceb6af2f | ||
|
|
243f8198ae | ||
|
|
2bc0536c02 | ||
|
|
bbbada1b44 | ||
|
|
5380d5bee7 | ||
|
|
a03f3f9f32 | ||
|
|
9d8b803b33 | ||
|
|
5e0c31bfa9 | ||
|
|
9ad8981ff0 | ||
|
|
57fd96454c | ||
|
|
d09d706946 | ||
|
|
88fc6465bb | ||
|
|
b3cb101899 | ||
|
|
86e036a55b | ||
|
|
a8f7a24ff6 | ||
|
|
df62164811 | ||
|
|
0160f99045 | ||
|
|
430c60a36e | ||
|
|
cac3072199 | ||
|
|
37f9e981d6 | ||
|
|
a07c50fda7 | ||
|
|
eb3dbf1646 | ||
|
|
27e18b6958 | ||
|
|
252fc4838b | ||
|
|
fdaffb6aa2 | ||
|
|
108a65ecf3 | ||
|
|
cc9be30ed1 | ||
|
|
adf142dac2 | ||
|
|
ded5a10f9f | ||
|
|
e1307648fd | ||
|
|
c6325ace85 | ||
|
|
f2e7979a9f | ||
|
|
890e9fed43 | ||
|
|
3cbc95732a | ||
|
|
182339c00f | ||
|
|
e952b1d55a | ||
|
|
4b972c740f |
12
.github/workflows/go.yml
vendored
12
.github/workflows/go.yml
vendored
@@ -10,17 +10,17 @@ jobs:
|
||||
golangci:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.15.x,1.16.x]
|
||||
go-version: [1.16.x,1.17.x,1.18.x]
|
||||
name: golangci-lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/setup-go@v2
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-go@v3
|
||||
- uses: actions/checkout@v3
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3.1.0
|
||||
uses: golangci/golangci-lint-action@v3.2.0
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.31
|
||||
version: latest
|
||||
build:
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
# strategy set
|
||||
strategy:
|
||||
matrix:
|
||||
go: ["1.14","1.15", "1.16", "1.17", "1.18"]
|
||||
go: ["1.16", "1.17", "1.18"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
@@ -36,8 +36,13 @@ linters:
|
||||
- whitespace
|
||||
|
||||
issues:
|
||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||
include:
|
||||
- EXC0002 # disable excluding of issues about comments from golint
|
||||
exclude-rules:
|
||||
- linters:
|
||||
- stylecheck
|
||||
text: "ST1000:"
|
||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- gomnd
|
||||
@@ -52,10 +57,10 @@ linters-settings:
|
||||
lines: 66
|
||||
statements: 40
|
||||
|
||||
issues:
|
||||
include:
|
||||
- EXC0002 # disable excluding of issues about comments from golint
|
||||
exclude-rules:
|
||||
- linters:
|
||||
- stylecheck
|
||||
text: "ST1000:"
|
||||
#issues:
|
||||
# include:
|
||||
# - EXC0002 # disable excluding of issues about comments from golint
|
||||
# exclude-rules:
|
||||
# - linters:
|
||||
# - stylecheck
|
||||
# text: "ST1000:"
|
||||
|
||||
12
README.md
12
README.md
@@ -25,35 +25,35 @@ import "github.com/silenceper/wechat/v2"
|
||||
以下是一个微信公众号处理消息接收以及回复的例子:
|
||||
|
||||
```go
|
||||
//使用memcache保存access_token,也可选择redis或自定义cache
|
||||
// 使用memcache保存access_token,也可选择redis或自定义cache
|
||||
wc := wechat.NewWechat()
|
||||
memory := cache.NewMemory()
|
||||
cfg := &offConfig.Config{
|
||||
AppID: "xxx",
|
||||
AppSecret: "xxx",
|
||||
Token: "xxx",
|
||||
//EncodingAESKey: "xxxx",
|
||||
// EncodingAESKey: "xxxx",
|
||||
Cache: memory,
|
||||
}
|
||||
officialAccount := wc.GetOfficialAccount(cfg)
|
||||
|
||||
// 传入request和responseWriter
|
||||
server := officialAccount.GetServer(req, rw)
|
||||
//设置接收消息的处理方法
|
||||
// 设置接收消息的处理方法
|
||||
server.SetMessageHandler(func(msg *message.MixMessage) *message.Reply {
|
||||
|
||||
//回复消息:演示回复用户发送的消息
|
||||
// 回复消息:演示回复用户发送的消息
|
||||
text := message.NewText(msg.Content)
|
||||
return &message.Reply{MsgType: message.MsgTypeText, MsgData: text}
|
||||
})
|
||||
|
||||
//处理消息接收以及回复
|
||||
// 处理消息接收以及回复
|
||||
err := server.Serve()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
//发送回复的消息
|
||||
// 发送回复的消息
|
||||
server.Send()
|
||||
|
||||
```
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
package credential
|
||||
|
||||
import "context"
|
||||
|
||||
// AccessTokenHandle AccessToken 接口
|
||||
type AccessTokenHandle interface {
|
||||
GetAccessToken() (accessToken string, err error)
|
||||
}
|
||||
|
||||
// AccessTokenContextHandle AccessToken 接口
|
||||
type AccessTokenContextHandle interface {
|
||||
AccessTokenHandle
|
||||
GetAccessTokenContext(ctx context.Context) (accessToken string, err error)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package credential
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sync"
|
||||
@@ -33,7 +34,7 @@ type DefaultAccessToken struct {
|
||||
}
|
||||
|
||||
// NewDefaultAccessToken new DefaultAccessToken
|
||||
func NewDefaultAccessToken(appID, appSecret, cacheKeyPrefix string, cache cache.Cache) AccessTokenHandle {
|
||||
func NewDefaultAccessToken(appID, appSecret, cacheKeyPrefix string, cache cache.Cache) AccessTokenContextHandle {
|
||||
if cache == nil {
|
||||
panic("cache is ineed")
|
||||
}
|
||||
@@ -56,6 +57,11 @@ type ResAccessToken struct {
|
||||
|
||||
// GetAccessToken 获取access_token,先从cache中获取,没有则从服务端获取
|
||||
func (ak *DefaultAccessToken) GetAccessToken() (accessToken string, err error) {
|
||||
return ak.GetAccessTokenContext(context.Background())
|
||||
}
|
||||
|
||||
// GetAccessTokenContext 获取access_token,先从cache中获取,没有则从服务端获取
|
||||
func (ak *DefaultAccessToken) GetAccessTokenContext(ctx context.Context) (accessToken string, err error) {
|
||||
// 先从cache中取
|
||||
accessTokenCacheKey := fmt.Sprintf("%s_access_token_%s", ak.cacheKeyPrefix, ak.appID)
|
||||
if val := ak.cache.Get(accessTokenCacheKey); val != nil {
|
||||
@@ -73,7 +79,7 @@ func (ak *DefaultAccessToken) GetAccessToken() (accessToken string, err error) {
|
||||
|
||||
// cache失效,从微信服务器获取
|
||||
var resAccessToken ResAccessToken
|
||||
resAccessToken, err = GetTokenFromServer(fmt.Sprintf(accessTokenURL, ak.appID, ak.appSecret))
|
||||
resAccessToken, err = GetTokenFromServerContext(ctx, fmt.Sprintf(accessTokenURL, ak.appID, ak.appSecret))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -97,7 +103,7 @@ type WorkAccessToken struct {
|
||||
}
|
||||
|
||||
// NewWorkAccessToken new WorkAccessToken
|
||||
func NewWorkAccessToken(corpID, corpSecret, cacheKeyPrefix string, cache cache.Cache) AccessTokenHandle {
|
||||
func NewWorkAccessToken(corpID, corpSecret, cacheKeyPrefix string, cache cache.Cache) AccessTokenContextHandle {
|
||||
if cache == nil {
|
||||
panic("cache the not exist")
|
||||
}
|
||||
@@ -112,6 +118,11 @@ func NewWorkAccessToken(corpID, corpSecret, cacheKeyPrefix string, cache cache.C
|
||||
|
||||
// GetAccessToken 企业微信获取access_token,先从cache中获取,没有则从服务端获取
|
||||
func (ak *WorkAccessToken) GetAccessToken() (accessToken string, err error) {
|
||||
return ak.GetAccessTokenContext(context.Background())
|
||||
}
|
||||
|
||||
// GetAccessTokenContext 企业微信获取access_token,先从cache中获取,没有则从服务端获取
|
||||
func (ak *WorkAccessToken) GetAccessTokenContext(ctx context.Context) (accessToken string, err error) {
|
||||
// 加上lock,是为了防止在并发获取token时,cache刚好失效,导致从微信服务器上获取到不同token
|
||||
ak.accessTokenLock.Lock()
|
||||
defer ak.accessTokenLock.Unlock()
|
||||
@@ -124,7 +135,7 @@ func (ak *WorkAccessToken) GetAccessToken() (accessToken string, err error) {
|
||||
|
||||
// cache失效,从微信服务器获取
|
||||
var resAccessToken ResAccessToken
|
||||
resAccessToken, err = GetTokenFromServer(fmt.Sprintf(workAccessTokenURL, ak.CorpID, ak.CorpSecret))
|
||||
resAccessToken, err = GetTokenFromServerContext(ctx, fmt.Sprintf(workAccessTokenURL, ak.CorpID, ak.CorpSecret))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -140,8 +151,13 @@ func (ak *WorkAccessToken) GetAccessToken() (accessToken string, err error) {
|
||||
|
||||
// GetTokenFromServer 强制从微信服务器获取token
|
||||
func GetTokenFromServer(url string) (resAccessToken ResAccessToken, err error) {
|
||||
return GetTokenFromServerContext(context.Background(), url)
|
||||
}
|
||||
|
||||
// GetTokenFromServerContext 强制从微信服务器获取token
|
||||
func GetTokenFromServerContext(ctx context.Context, url string) (resAccessToken ResAccessToken, err error) {
|
||||
var body []byte
|
||||
body, err = util.HTTPGet(url)
|
||||
body, err = util.HTTPGetContext(ctx, url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
2
doc.go
2
doc.go
@@ -7,4 +7,6 @@ Package wechat provide wechat sdk for go
|
||||
更多信息:https://github.com/silenceper/wechat
|
||||
|
||||
*/
|
||||
|
||||
// Package wechat provide wechat sdk for go
|
||||
package wechat
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
# 微信公众号API列表
|
||||
# 微信公众号 API 列表
|
||||
|
||||
## 基础接口
|
||||
|
||||
[官方文档](https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html)
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| :---------------------: | -------- | :------------------------- | ---------- | -------- |
|
||||
| 获取Access token | GET | /cgi-bin/token | YES | |
|
||||
| 获取微信服务器IP地址 | GET | /cgi-bin/get_api_domain_ip | YES | |
|
||||
| 获取微信callback IP地址 | GET | /cgi-bin/getcallbackip | YES | |
|
||||
| 清理接口调用次数 | POST | /cgi-bin/clear_quota | YES | |
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| :-----------------------: | -------- | :------------------------- | ---------- | -------- |
|
||||
| 获取 Access token | GET | /cgi-bin/token | YES | |
|
||||
| 获取微信服务器 IP 地址 | GET | /cgi-bin/get_api_domain_ip | YES | |
|
||||
| 获取微信 callback IP 地址 | GET | /cgi-bin/getcallbackip | YES | |
|
||||
| 清理接口调用次数 | POST | /cgi-bin/clear_quota | YES | |
|
||||
|
||||
## 订阅通知
|
||||
|
||||
[官方文档](https://developers.weixin.qq.com/doc/offiaccount/Subscription_Messages/api.html)
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| -------------------- | -------- | -------------------------------------- | ---------- | ----------------------- |
|
||||
| 选用模板 | POST | /wxaapi/newtmpl/addtemplate | YES | (tpl *Subscribe) Add |
|
||||
| 删除模板 | POST | /wxaapi/newtmpl/deltemplate | YES | (tpl *Subscribe) Delete |
|
||||
| 获取公众号类目 | GET | /wxaapi/newtmpl/getcategory | NO | |
|
||||
| 获取模板中的关键词 | GET | /wxaapi/newtmpl/getpubtemplatekeywords | NO | |
|
||||
| 获取类目下的公共模板 | GET | /wxaapi/newtmpl/getpubtemplatetitles | NO | |
|
||||
| 获取私有模板列表 | GET | /wxaapi/newtmpl/gettemplate | YES | (tpl *Subscribe) List() |
|
||||
| 发送订阅通知 | POST | /cgi-bin/message/subscribe/bizsend | YES | (tpl *Subscribe) Send |
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| -------------------- | -------- | -------------------------------------- | ---------- | -------------------------------------------- |
|
||||
| 选用模板 | POST | /wxaapi/newtmpl/addtemplate | YES | (tpl \*Subscribe) Add |
|
||||
| 删除模板 | POST | /wxaapi/newtmpl/deltemplate | YES | (tpl \*Subscribe) Delete |
|
||||
| 获取公众号类目 | GET | /wxaapi/newtmpl/getcategory | YES | (tpl \*Subscribe) GetCategory |
|
||||
| 获取模板中的关键词 | GET | /wxaapi/newtmpl/getpubtemplatekeywords | YES | (tpl \*Subscribe) GetPubTplKeyWordsByID |
|
||||
| 获取类目下的公共模板 | GET | /wxaapi/newtmpl/getpubtemplatetitles | YES | (tpl \*Subscribe) GetPublicTemplateTitleList |
|
||||
| 获取私有模板列表 | GET | /wxaapi/newtmpl/gettemplate | YES | (tpl \*Subscribe) List() |
|
||||
| 发送订阅通知 | POST | /cgi-bin/message/subscribe/bizsend | YES | (tpl \*Subscribe) Send |
|
||||
|
||||
## 客服消息
|
||||
|
||||
@@ -33,14 +33,16 @@
|
||||
|
||||
[官方文档](https://developers.weixin.qq.com/doc/offiaccount/Customer_Service/Customer_Service_Management.html)
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| ---------------- | --------- | -------------------------------------- | ---------- | -------- |
|
||||
| 获取客服基本信息 | GET | /cgi-bin/customservice/getkflist | NO | |
|
||||
| 添加客服帐号 | POST | /customservice/kfaccount/add | NO | |
|
||||
| 邀请绑定客服帐号 | POST | /customservice/kfaccount/inviteworker | NO | |
|
||||
| 设置客服信息 | POST | /customservice/kfaccount/update | NO | |
|
||||
| 上传客服头像 | POST/FORM | /customservice/kfaccount/uploadheadimg | NO | |
|
||||
| 删除客服帐号 | GET | /customservice/kfaccount/del | NO | |
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| ---------------- | --------- | -------------------------------------- | ---------- | -------------------------------- |
|
||||
| 获取客服基本信息 | GET | /cgi-bin/customservice/getkflist | YES | (csm \*Manager) List |
|
||||
| 添加客服帐号 | POST | /customservice/kfaccount/add | YES | (csm \*Manager) Add |
|
||||
| 邀请绑定客服帐号 | POST | /customservice/kfaccount/inviteworker | YES | (csm \*Manager) InviteBind |
|
||||
| 设置客服信息 | POST | /customservice/kfaccount/update | YES | (csm \*Manager) Update |
|
||||
| 上传客服头像 | POST/FORM | /customservice/kfaccount/uploadheadimg | YES | (csm \*Manager) UploadHeadImg |
|
||||
| 删除客服帐号 | POST | /customservice/kfaccount/del | YES | (csm \*Manager) Delete |
|
||||
| 获取在线客服 | POST | /cgi-bin/customservice/getonlinekflist | YES | (csm \*Manager) OnlineList |
|
||||
| 下发客服输入状态 | POST | /cgi-bin/message/custom/typing | YES | (csm \*Manager) SendTypingStatus |
|
||||
|
||||
#### 会话控制
|
||||
|
||||
@@ -146,15 +148,15 @@
|
||||
|
||||
[官方文档](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html)
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| ------------------------------------------------------------ | -------- | --------------------------------------------------- | ---------- | ----------------------------------- |
|
||||
| 获取跳转的url地址 | GET | https://open.weixin.qq.com/connect/oauth2/authorize | YES | (oauth *Oauth) GetRedirectURL |
|
||||
| 获取网页应用跳转的url地址 | GET | https://open.weixin.qq.com/connect/qrconnect | YES | (oauth *Oauth) GetWebAppRedirectURL |
|
||||
| 通过网页授权的code 换取access_token(区别于context中的access_token) | GET | /sns/oauth2/access_token | YES | (oauth *Oauth) GetUserAccessToken |
|
||||
| 刷新access_token | GET | /sns/oauth2/refresh_token? | YES | (oauth *Oauth) RefreshAccessToken |
|
||||
| 检验access_token是否有效 | GET | /sns/auth | YES | (oauth *Oauth) CheckAccessToken( |
|
||||
| 拉取用户信息(需scope为 snsapi_userinfo) | GET | /sns/userinfo | YES | (oauth *Oauth) GetUserInfo |
|
||||
| 获取jssdk需要的配置参数 | GET | /cgi-bin/ticket/getticket | YES | (js *Js) GetConfig |
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| ----------------------------------------------------------------------- | -------- | --------------------------------------------------- | ---------- | ------------------------------------ |
|
||||
| 获取跳转的 url 地址 | GET | https://open.weixin.qq.com/connect/oauth2/authorize | YES | (oauth \*Oauth) GetRedirectURL |
|
||||
| 获取网页应用跳转的 url 地址 | GET | https://open.weixin.qq.com/connect/qrconnect | YES | (oauth \*Oauth) GetWebAppRedirectURL |
|
||||
| 通过网页授权的 code 换取 access_token(区别于 context 中的 access_token) | GET | /sns/oauth2/access_token | YES | (oauth \*Oauth) GetUserAccessToken |
|
||||
| 刷新 access_token | GET | /sns/oauth2/refresh_token? | YES | (oauth \*Oauth) RefreshAccessToken |
|
||||
| 检验 access_token 是否有效 | GET | /sns/auth | YES | (oauth \*Oauth) CheckAccessToken( |
|
||||
| 拉取用户信息(需 scope 为 snsapi_userinfo) | GET | /sns/userinfo | YES | (oauth \*Oauth) GetUserInfo |
|
||||
| 获取 jssdk 需要的配置参数 | GET | /cgi-bin/ticket/getticket | YES | (js \*Js) GetConfig |
|
||||
|
||||
## 素材管理
|
||||
|
||||
@@ -162,17 +164,15 @@
|
||||
|
||||
[官方文档](https://developers.weixin.qq.com/doc/offiaccount/Draft_Box/Add_draft.html)
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| -------------------------- | -------- | ------------------------------------------------------------ | ---------- | ---------------------------- |
|
||||
| 新建草稿 | POST | /cgi-bin/draft/add | YES | (draft *Draft) AddDraft |
|
||||
| 获取草稿 | POST | /cgi-bin/draft/get | YES | (draft *Draft) GetDraft |
|
||||
| 删除草稿 | POST | /cgi-bin/draft/delete | YES | (draft *Draft) DeleteDraft |
|
||||
| 修改草稿 | POST | /cgi-bin/draft/update | YES | (draft *Draft) UpdateDraft |
|
||||
| 获取草稿总数 | GET | /cgi-bin/draft/count | YES | (draft *Draft) CountDraft |
|
||||
| 获取草稿列表 | POST | /cgi-bin/draft/batchget | YES | (draft *Draft) PaginateDraft |
|
||||
| MP端开关(仅内测期间使用) | POST | /cgi-bin/draft/switch<br />/cgi-bin/draft/switch?checkonly=1 | NO | |
|
||||
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| --------------------------- | -------- | ------------------------------------------------------------ | ---------- | ----------------------------- |
|
||||
| 新建草稿 | POST | /cgi-bin/draft/add | YES | (draft \*Draft) AddDraft |
|
||||
| 获取草稿 | POST | /cgi-bin/draft/get | YES | (draft \*Draft) GetDraft |
|
||||
| 删除草稿 | POST | /cgi-bin/draft/delete | YES | (draft \*Draft) DeleteDraft |
|
||||
| 修改草稿 | POST | /cgi-bin/draft/update | YES | (draft \*Draft) UpdateDraft |
|
||||
| 获取草稿总数 | GET | /cgi-bin/draft/count | YES | (draft \*Draft) CountDraft |
|
||||
| 获取草稿列表 | POST | /cgi-bin/draft/batchget | YES | (draft \*Draft) PaginateDraft |
|
||||
| MP 端开关(仅内测期间使用) | POST | /cgi-bin/draft/switch<br />/cgi-bin/draft/switch?checkonly=1 | NO | |
|
||||
|
||||
## 发布能力
|
||||
|
||||
@@ -185,20 +185,40 @@
|
||||
- 群发:主动推送给粉丝,历史消息可看,被搜一搜收录,可以限定部分的粉丝接收到。
|
||||
- 发布:不会主动推给粉丝,历史消息列表看不到,但是是公开给所有人的文章。也不会占用群发的次数。每天可以发布多篇内容。可以用于自动回复、自定义菜单、页面模板和话题中,发布成功时会生成一个永久链接。
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| ------------------------------ | -------- | ------------------------------- | ---------- | --------------------------------------- |
|
||||
| 发布接口 | POST | /cgi-bin/freepublish/submit | YES | (freePublish *FreePublish) Publish |
|
||||
| 发布状态轮询接口 | POST | /cgi-bin/freepublish/get | YES | (freePublish *FreePublish) SelectStatus |
|
||||
| 事件推送发布结果 | | | YES | EventPublishJobFinish |
|
||||
| 删除发布 | POST | /cgi-bin/freepublish/delete | YES | (freePublish *FreePublish) Delete |
|
||||
| 通过 article_id 获取已发布文章 | POST | /cgi-bin/freepublish/getarticle | YES | (freePublish *FreePublish) First |
|
||||
| 获取成功发布列表 | POST | /cgi-bin/freepublish/batchget | YES | (freePublish *FreePublish) Paginate |
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| ------------------------------ | -------- | ------------------------------- | ---------- | ---------------------------------------- |
|
||||
| 发布接口 | POST | /cgi-bin/freepublish/submit | YES | (freePublish \*FreePublish) Publish |
|
||||
| 发布状态轮询接口 | POST | /cgi-bin/freepublish/get | YES | (freePublish \*FreePublish) SelectStatus |
|
||||
| 事件推送发布结果 | | | YES | EventPublishJobFinish |
|
||||
| 删除发布 | POST | /cgi-bin/freepublish/delete | YES | (freePublish \*FreePublish) Delete |
|
||||
| 通过 article_id 获取已发布文章 | POST | /cgi-bin/freepublish/getarticle | YES | (freePublish \*FreePublish) First |
|
||||
| 获取成功发布列表 | POST | /cgi-bin/freepublish/batchget | YES | (freePublish \*FreePublish) Paginate |
|
||||
|
||||
## 图文消息留言管理
|
||||
|
||||
## 用户管理
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| ------------------------------------------ | -------- | -------------------------------------- | ---------- | ---------------------------------- |
|
||||
| 获取指定 OpenID 变化列表(公众号账号迁移) | POST | /cgi-bin/changeopenid | YES | (user \*User) ListChangeOpenIDs |
|
||||
| 获取所有用户 OpenID 列表(公众号账号迁移) | | | YES | (user \*User) ListAllChangeOpenIDs |
|
||||
| 获取用户基本信息 | GET | /cgi-bin/user/info | YES | (user \*User) GetUserInfo |
|
||||
| 设置用户备注名 | POST | /cgi-bin/user/info/updateremark | YES | (user \*User) UpdateRemark |
|
||||
| 获取用户列表 | GET | /cgi-bin/user/get | YES | (user \*User) ListUserOpenIDs |
|
||||
| 获取所有用户 OpenID 列表 | | | YES | (user \*User) ListAllUserOpenIDs |
|
||||
| 获取公众号的黑名单列表 | POST | /cgi-bin/tags/members/getblacklist | YES | (user \*User) GetBlackList |
|
||||
| 获取公众号的所有黑名单列表 | | | YES | (user \*User) GetAllBlackList |
|
||||
| 拉黑用户 | POST | /cgi-bin/tags/members/batchblacklist | YES | (user \*User) BatchBlackList |
|
||||
| 取消拉黑用户 | POST | /cgi-bin/tags/members/batchunblacklist | YES | (user \*User) BatchUnBlackList |
|
||||
| 创建标签 | POST | /cgi-bin/tags/create | YES | (user \*User) CreateTag |
|
||||
| 删除标签 | POST | /cgi-bin/tags/delete | YES | (user \*User) DeleteTag |
|
||||
| 编辑标签 | POST | /cgi-bin/tags/update | YES | (user \*User) UpdateTag |
|
||||
| 获取公众号已创建的标签 | GET | /cgi-bin/tags/get | YES | (user \*User) GetTag |
|
||||
| 获取标签下粉丝列表 | POST | /cgi-bin/user/tag/get | YES | (user \*User) OpenIDListByTag |
|
||||
| 批量为用户打标签 | POST | /cgi-bin/tags/members/batchtagging | YES | (user \*User) BatchTag |
|
||||
| 批量为用户取消标签 | POST | /cgi-bin/tags/members/batchuntagging | YES | (user \*User) BatchUntag |
|
||||
| 获取用户身上的标签列表 | POST | /cgi-bin/tags/getidlist | YES | (user \*User) UserTidList |
|
||||
|
||||
## 账号管理
|
||||
|
||||
## 数据统计
|
||||
@@ -215,5 +235,4 @@
|
||||
|
||||
## 微信发票
|
||||
|
||||
## 微信非税缴费
|
||||
|
||||
## 微信非税缴费
|
||||
|
||||
@@ -59,7 +59,62 @@ host: https://qyapi.weixin.qq.com/
|
||||
| 获取客户基础信息 | POST | /cgi-bin/kf/customer/batchget | YES | (r *Client) CustomerBatchGet | NICEXAI |
|
||||
| 获取视频号绑定状态 | GET | /cgi-bin/kf/get_corp_qualification | YES | (r *Client) GetCorpQualification | NICEXAI |
|
||||
|
||||
### 客户联系
|
||||
[官方文档](https://developer.work.weixin.qq.com/document/path/92132/92133/92228)
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 |
|
||||
|:------------------------:| -------- |:-------------------------------------------------------------| ---------- | ------------------------------- |----------|
|
||||
| 获取「联系客户统计」数据 | POST | /cgi-bin/externalcontact/get_user_behavior_data | YES | (r *Client) GetUserBehaviorData | MARKWANG |
|
||||
| 获取「群聊数据统计」数据 (按群主聚合的方式) | POST | /cgi-bin/externalcontact/groupchat/statistic | YES | (r *Client) GetGroupChatStat | MARKWANG |
|
||||
| 获取「群聊数据统计」数据 (按自然日聚合的方式) | POST | /cgi-bin/externalcontact/groupchat/statistic_group_by_day | YES | (r *Client) GetGroupChatStatByDay | MARKWANG |
|
||||
| 配置客户联系「联系我」方式 | POST | /cgi-bin/externalcontact/add_contact_way | YES | (r *Client) AddContactWay | MARKWANG |
|
||||
| 获取企业已配置的「联系我」方式 | POST | /cgi-bin/externalcontact/get_contact_way | YES | (r *Client) GetContactWay | MARKWANG |
|
||||
| 更新企业已配置的「联系我」方式 | POST | /cgi-bin/externalcontact/update_contact_way | YES | (r *Client) UpdateContactWay | MARKWANG |
|
||||
| 获取企业已配置的「联系我」列表 | POST | /cgi-bin/externalcontact/list_contact_way | YES | (r *Client) ListContactWay | MARKWANG |
|
||||
| 删除企业已配置的「联系我」方式 | POST | /cgi-bin/externalcontact/del_contact_way | YES | (r *Client) DelContactWay | MARKWANG |
|
||||
| 创建企业群发 | POST | /cgi-bin/externalcontact/add_msg_template | YES | (r *Client) AddMsgTemplate | MARKWANG |
|
||||
| 获取群发记录列表 | POST | /cgi-bin/externalcontact/get_groupmsg_list_v2 | YES | (r *Client) GetGroupMsgListV2 | MARKWANG |
|
||||
| 获取群发成员发送任务列表 | POST | /cgi-bin/externalcontact/get_groupmsg_task | YES | (r *Client) GetGroupMsgTask | MARKWANG |
|
||||
| 获取企业群发成员执行结果 | POST | /cgi-bin/externalcontact/get_groupmsg_send_result | YES | (r *Client) GetGroupMsgSendResult | MARKWANG |
|
||||
| 发送新客户欢迎语 | POST | /cgi-bin/externalcontact/send_welcome_msg | YES | (r *Client) SendWelcomeMsg | MARKWANG |
|
||||
| 添加入群欢迎语素材 | POST | /cgi-bin/externalcontact/group_welcome_template/add | YES | (r *Client) AddGroupWelcomeTemplate | MARKWANG |
|
||||
| 编辑入群欢迎语素材 | POST | /cgi-bin/externalcontact/group_welcome_template/edit | YES | (r *Client) EditGroupWelcomeTemplate | MARKWANG |
|
||||
| 获取入群欢迎语素材 | POST | /cgi-bin/externalcontact/group_welcome_template/get | YES | (r *Client) GetGroupWelcomeTemplate | MARKWANG |
|
||||
| 删除入群欢迎语素材 | POST | /cgi-bin/externalcontact/group_welcome_template/del | YES | (r *Client) DelGroupWelcomeTemplate | MARKWANG |
|
||||
|
||||
## 通讯录管理
|
||||
[官方文档](https://developer.work.weixin.qq.com/document/path/90193)
|
||||
|
||||
### 部门管理
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 |
|
||||
|:---------:|------|:----------------------------------------| ---------- | ------------------------------- |----------|
|
||||
| 获取子部门ID列表 | GET | /cgi-bin/department/simplelist | YES | (r *Client) DepartmentSimpleList| MARKWANG |
|
||||
| 获取部门成员 | GET | /cgi-bin/user/simplelist | YES | (r *Client) UserSimpleList | MARKWANG |
|
||||
| 获取成员ID列表 | Post | /cgi-bin/user/list_id | YES | (r *Client) UserListId | MARKWANG |
|
||||
|
||||
|
||||
## 素材管理
|
||||
[官方文档](https://developer.work.weixin.qq.com/document/path/91054)
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 |
|
||||
|:---------:|------|:----------------------------------------| ---------- | ------------------------------- |----------|
|
||||
| 上传图片 | POST | /cgi-bin/media/uploadimg | YES | (r *Client) UploadImg| MARKWANG |
|
||||
|
||||
### 成员管理
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 |
|
||||
| -------- | -------- | ----------------- | ---------- | ------------------- | -------- |
|
||||
| 读取成员 | GET | /cgi-bin/user/get | YES | (r *Client) UserGet | chcthink |
|
||||
|
||||
|
||||
## 群机器人
|
||||
|
||||
[官方文档](https://developer.work.weixin.qq.com/document/path/91770)
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 |
|
||||
| ---------------- | -------- | --------------------- | ---------- | -------------------------- | -------- |
|
||||
| 群机器人发送消息 | POST | /cgi-bin/webhook/send | YES | (r *Client) RobotBroadcast | chcthink |
|
||||
|
||||
## 应用管理
|
||||
|
||||
TODO
|
||||
|
||||
|
||||
9
go.mod
9
go.mod
@@ -1,14 +1,15 @@
|
||||
module github.com/silenceper/wechat/v2
|
||||
|
||||
go 1.14
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/go-redis/redis/v8 v8.11.6-0.20220405070650-99c79f7041fc
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/spf13/cast v1.4.1
|
||||
github.com/stretchr/testify v1.7.1
|
||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
|
||||
github.com/tidwall/gjson v1.14.1
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
|
||||
gopkg.in/h2non/gock.v1 v1.1.2
|
||||
)
|
||||
|
||||
41
go.sum
41
go.sum
@@ -15,8 +15,8 @@ github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/go-redis/redis/v8 v8.11.6-0.20220405070650-99c79f7041fc h1:jZY+lpZB92nvBo2f31oPC/ivGll6NcsnEOORm8Fkr4M=
|
||||
github.com/go-redis/redis/v8 v8.11.6-0.20220405070650-99c79f7041fc/go.mod h1:25mL1NKxbJhB63ihiK8MnNeTRd+xAizd6bOdydrTLUQ=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
@@ -26,12 +26,10 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
||||
@@ -48,30 +46,36 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108
|
||||
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||
github.com/onsi/ginkgo/v2 v2.1.3 h1:e/3Cwtogj0HA+25nMP1jCMDIf8RtRYbGwGGuBIFztkc=
|
||||
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
||||
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
|
||||
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
|
||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
|
||||
github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
|
||||
github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
|
||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
@@ -79,9 +83,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -90,7 +93,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -99,22 +101,20 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
@@ -123,7 +123,6 @@ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miE
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -190,9 +190,9 @@ func (analysis *Analysis) GetAnalysisWeeklyVisitTrend(beginDate, endDate string)
|
||||
|
||||
// UserPortraitItem 用户画像项目
|
||||
type UserPortraitItem struct {
|
||||
ID int `json:"id"` // 属性值id
|
||||
Name string `json:"name"` // 属性值名称
|
||||
AccessSourceVisitUV int `json:"access_source_visit_uv"` // 该场景访问uv
|
||||
ID int `json:"id"` // 属性值id
|
||||
Name string `json:"name"` // 属性值名称
|
||||
Value int `json:"value"` // 该场景访问uv
|
||||
}
|
||||
|
||||
// UserPortrait 用户画像
|
||||
|
||||
@@ -84,7 +84,9 @@ func (auth *Auth) CheckEncryptedDataContext(ctx context2.Context, encryptedMsgHa
|
||||
if at, err = auth.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
if response, err = util.HTTPPostContext(ctx, fmt.Sprintf(checkEncryptedDataURL, at), "encrypted_msg_hash="+encryptedMsgHash); err != nil {
|
||||
|
||||
// 由于GetPhoneNumberContext需要传入JSON,所以HTTPPostContext入参改为[]byte
|
||||
if response, err = util.HTTPPostContext(ctx, fmt.Sprintf(checkEncryptedDataURL, at), []byte("encrypted_msg_hash="+encryptedMsgHash), nil); err != nil {
|
||||
return
|
||||
}
|
||||
if err = util.DecodeWithError(response, &result, "CheckEncryptedDataAuth"); err != nil {
|
||||
@@ -111,23 +113,38 @@ type PhoneInfo struct {
|
||||
} `json:"watermark"` // 数据水印
|
||||
}
|
||||
|
||||
// GetPhoneNumber 小程序通过code获取用户手机号
|
||||
func (auth *Auth) GetPhoneNumber(code string) (result *GetPhoneNumberResponse, err error) {
|
||||
// GetPhoneNumberContext 小程序通过code获取用户手机号
|
||||
func (auth *Auth) GetPhoneNumberContext(ctx context2.Context, code string) (*GetPhoneNumberResponse, error) {
|
||||
var response []byte
|
||||
var (
|
||||
at string
|
||||
at string
|
||||
err error
|
||||
)
|
||||
if at, err = auth.GetAccessToken(); err != nil {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
body := map[string]interface{}{
|
||||
"code": code,
|
||||
}
|
||||
if response, err = util.PostJSON(fmt.Sprintf(getPhoneNumber, at), body); err != nil {
|
||||
return
|
||||
|
||||
bodyBytes, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
header := map[string]string{"Content-Type": "application/json;charset=utf-8"}
|
||||
if response, err = util.HTTPPostContext(ctx, fmt.Sprintf(getPhoneNumber, at), bodyBytes, header); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result GetPhoneNumberResponse
|
||||
if err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber"); err != nil {
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// GetPhoneNumber 小程序通过code获取用户手机号
|
||||
func (auth *Auth) GetPhoneNumber(code string) (*GetPhoneNumberResponse, error) {
|
||||
return auth.GetPhoneNumberContext(context2.Background(), code)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@ import (
|
||||
// Config .config for 小程序
|
||||
type Config struct {
|
||||
AppID string `json:"app_id"` // appid
|
||||
AppSecret string `json:"app_secret"` // appsecret
|
||||
AppSecret string `json:"app_secret"` // appSecret
|
||||
Cache cache.Cache
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ type UniformMessage struct {
|
||||
URL string `json:"url"`
|
||||
Miniprogram struct {
|
||||
Appid string `json:"appid"`
|
||||
Pagepath string `json:"page"`
|
||||
Pagepath string `json:"pagepath"`
|
||||
} `json:"miniprogram"`
|
||||
Data map[string]*DataItem `json:"data"`
|
||||
} `json:"mp_template_msg"`
|
||||
|
||||
@@ -18,6 +18,7 @@ type InvokeCloudFunctionRes struct {
|
||||
}
|
||||
|
||||
// InvokeCloudFunction 云函数调用
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/functions/invokeCloudFunction.html
|
||||
func (tcb *Tcb) InvokeCloudFunction(env, name, args string) (*InvokeCloudFunctionRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
|
||||
@@ -192,6 +192,7 @@ type DatabaseCountRes struct {
|
||||
}
|
||||
|
||||
// DatabaseMigrateImport 数据库导入
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateImport.html
|
||||
func (tcb *Tcb) DatabaseMigrateImport(req *DatabaseMigrateImportReq) (*DatabaseMigrateImportRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
@@ -209,6 +210,7 @@ func (tcb *Tcb) DatabaseMigrateImport(req *DatabaseMigrateImportReq) (*DatabaseM
|
||||
}
|
||||
|
||||
// DatabaseMigrateExport 数据库导出
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateExport.html
|
||||
func (tcb *Tcb) DatabaseMigrateExport(req *DatabaseMigrateExportReq) (*DatabaseMigrateExportRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
@@ -226,6 +228,7 @@ func (tcb *Tcb) DatabaseMigrateExport(req *DatabaseMigrateExportReq) (*DatabaseM
|
||||
}
|
||||
|
||||
// DatabaseMigrateQueryInfo 数据库迁移状态查询
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateQueryInfo.html
|
||||
func (tcb *Tcb) DatabaseMigrateQueryInfo(env string, jobID int64) (*DatabaseMigrateQueryInfoRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
@@ -261,6 +264,7 @@ func (tcb *Tcb) UpdateIndex(req *UpdateIndexReq) error {
|
||||
}
|
||||
|
||||
// DatabaseCollectionAdd 新增集合
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionAdd.html
|
||||
func (tcb *Tcb) DatabaseCollectionAdd(env, collectionName string) error {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
@@ -279,6 +283,7 @@ func (tcb *Tcb) DatabaseCollectionAdd(env, collectionName string) error {
|
||||
}
|
||||
|
||||
// DatabaseCollectionDelete 删除集合
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionDelete.html
|
||||
func (tcb *Tcb) DatabaseCollectionDelete(env, collectionName string) error {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
@@ -297,6 +302,7 @@ func (tcb *Tcb) DatabaseCollectionDelete(env, collectionName string) error {
|
||||
}
|
||||
|
||||
// DatabaseCollectionGet 获取特定云环境下集合信息
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionGet.html
|
||||
func (tcb *Tcb) DatabaseCollectionGet(env string, limit, offset int64) (*DatabaseCollectionGetRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
@@ -318,6 +324,7 @@ func (tcb *Tcb) DatabaseCollectionGet(env string, limit, offset int64) (*Databas
|
||||
}
|
||||
|
||||
// DatabaseAdd 数据库插入记录
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseAdd.html
|
||||
func (tcb *Tcb) DatabaseAdd(env, query string) (*DatabaseAddRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
@@ -338,6 +345,7 @@ func (tcb *Tcb) DatabaseAdd(env, query string) (*DatabaseAddRes, error) {
|
||||
}
|
||||
|
||||
// DatabaseDelete 数据库插入记录
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseDelete.html
|
||||
func (tcb *Tcb) DatabaseDelete(env, query string) (*DatabaseDeleteRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
@@ -358,6 +366,7 @@ func (tcb *Tcb) DatabaseDelete(env, query string) (*DatabaseDeleteRes, error) {
|
||||
}
|
||||
|
||||
// DatabaseUpdate 数据库插入记录
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseUpdate.html
|
||||
func (tcb *Tcb) DatabaseUpdate(env, query string) (*DatabaseUpdateRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
@@ -378,6 +387,7 @@ func (tcb *Tcb) DatabaseUpdate(env, query string) (*DatabaseUpdateRes, error) {
|
||||
}
|
||||
|
||||
// DatabaseQuery 数据库查询记录
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseQuery.html
|
||||
func (tcb *Tcb) DatabaseQuery(env, query string) (*DatabaseQueryRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
@@ -398,6 +408,7 @@ func (tcb *Tcb) DatabaseQuery(env, query string) (*DatabaseQueryRes, error) {
|
||||
}
|
||||
|
||||
// DatabaseCount 统计集合记录数或统计查询语句对应的结果记录数
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCount.html
|
||||
func (tcb *Tcb) DatabaseCount(env, query string) (*DatabaseCountRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
|
||||
@@ -71,6 +71,7 @@ type BatchDeleteFileRes struct {
|
||||
}
|
||||
|
||||
// UploadFile 上传文件
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/uploadFile.html
|
||||
func (tcb *Tcb) UploadFile(env, path string) (*UploadFileRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
@@ -92,6 +93,7 @@ func (tcb *Tcb) UploadFile(env, path string) (*UploadFileRes, error) {
|
||||
}
|
||||
|
||||
// BatchDownloadFile 获取文件下载链接
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/batchDownloadFile.html
|
||||
func (tcb *Tcb) BatchDownloadFile(env string, fileList []*DownloadFile) (*BatchDownloadFileRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
@@ -113,6 +115,7 @@ func (tcb *Tcb) BatchDownloadFile(env string, fileList []*DownloadFile) (*BatchD
|
||||
}
|
||||
|
||||
// BatchDeleteFile 批量删除文件
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/batchDeleteFile.html
|
||||
func (tcb *Tcb) BatchDeleteFile(env string, fileIDList []string) (*BatchDeleteFileRes, error) {
|
||||
accessToken, err := tcb.GetAccessToken()
|
||||
|
||||
52
miniprogram/urllink/query.go
Normal file
52
miniprogram/urllink/query.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package urllink
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const queryURL = "https://api.weixin.qq.com/wxa/query_urllink"
|
||||
|
||||
// ULQueryResult 返回的结果
|
||||
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-link/urllink.query.html 返回值
|
||||
type ULQueryResult struct {
|
||||
util.CommonError
|
||||
|
||||
URLLinkInfo struct {
|
||||
Appid string `json:"appid"`
|
||||
Path string `json:"path"`
|
||||
Query string `json:"query"`
|
||||
CreateTime int64 `json:"create_time"`
|
||||
ExpireTime int64 `json:"expire_time"`
|
||||
EnvVersion string `json:"env_version"`
|
||||
CloudBase struct {
|
||||
Env string `json:"env"`
|
||||
Domain string `json:"domain"`
|
||||
Path string `json:"path"`
|
||||
Query string `json:"query"`
|
||||
ResourceAppid string `json:"resource_appid"`
|
||||
} `json:"cloud_base"`
|
||||
} `json:"url_link_info"`
|
||||
VisitOpenid string `json:"visit_openid"`
|
||||
}
|
||||
|
||||
// Query 查询小程序 url_link 配置。
|
||||
func (u *URLLink) Query(urlLink string) (*ULQueryResult, error) {
|
||||
accessToken, err := u.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uri := fmt.Sprintf("%s?access_token=%s", queryURL, accessToken)
|
||||
response, err := util.PostJSON(uri, map[string]string{"url_link": urlLink})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var resp ULQueryResult
|
||||
err = util.DecodeWithError(response, &resp, "URLLink.Query")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
253
officialaccount/customerservice/manager.go
Normal file
253
officialaccount/customerservice/manager.go
Normal file
@@ -0,0 +1,253 @@
|
||||
package customerservice
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
// TypingStatus 输入状态类型
|
||||
type TypingStatus string
|
||||
|
||||
const (
|
||||
customerServiceListURL = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist"
|
||||
customerServiceOnlineListURL = "https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist"
|
||||
customerServiceAddURL = "https://api.weixin.qq.com/customservice/kfaccount/add"
|
||||
customerServiceUpdateURL = "https://api.weixin.qq.com/customservice/kfaccount/update"
|
||||
customerServiceDeleteURL = "https://api.weixin.qq.com/customservice/kfaccount/del"
|
||||
customerServiceInviteURL = "https://api.weixin.qq.com/customservice/kfaccount/inviteworker"
|
||||
customerServiceUploadHeadImg = "https://api.weixin.qq.com/customservice/kfaccount/uploadheadimg"
|
||||
customerServiceTypingURL = "https://api.weixin.qq.com/cgi-bin/message/custom/typing"
|
||||
)
|
||||
|
||||
const (
|
||||
// Typing 表示正在输入状态
|
||||
Typing TypingStatus = "Typing"
|
||||
// CancelTyping 表示取消正在输入状态
|
||||
CancelTyping TypingStatus = "CancelTyping"
|
||||
)
|
||||
|
||||
// Manager 客服管理者,可以管理客服
|
||||
type Manager struct {
|
||||
*context.Context
|
||||
}
|
||||
|
||||
// NewCustomerServiceManager 实例化客服管理
|
||||
func NewCustomerServiceManager(ctx *context.Context) *Manager {
|
||||
csm := new(Manager)
|
||||
csm.Context = ctx
|
||||
return csm
|
||||
}
|
||||
|
||||
// KeFuInfo 客服基本信息
|
||||
type KeFuInfo struct {
|
||||
KfAccount string `json:"kf_account"` // 完整客服帐号,格式为:帐号前缀@公众号微信号
|
||||
KfNick string `json:"kf_nick"` // 客服昵称
|
||||
KfID int `json:"kf_id"` // 客服编号
|
||||
KfHeadImgURL string `json:"kf_headimgurl"` // 客服头像
|
||||
KfWX string `json:"kf_wx"` // 如果客服帐号已绑定了客服人员微信号, 则此处显示微信号
|
||||
InviteWX string `json:"invite_wx"` // 如果客服帐号尚未绑定微信号,但是已经发起了一个绑定邀请, 则此处显示绑定邀请的微信号
|
||||
InviteExpTime int `json:"invite_expire_time"` // 如果客服帐号尚未绑定微信号,但是已经发起过一个绑定邀请, 邀请的过期时间,为unix 时间戳
|
||||
InviteStatus string `json:"invite_status"` // 邀请的状态,有等待确认“waiting”,被拒绝“rejected”, 过期“expired”
|
||||
}
|
||||
|
||||
type resKeFuList struct {
|
||||
util.CommonError
|
||||
KfList []*KeFuInfo `json:"kf_list"`
|
||||
}
|
||||
|
||||
// List 获取所有客服基本信息
|
||||
func (csm *Manager) List() (customerServiceList []*KeFuInfo, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = csm.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", customerServiceListURL, accessToken)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var res resKeFuList
|
||||
err = util.DecodeWithError(response, &res, "ListCustomerService")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
customerServiceList = res.KfList
|
||||
return
|
||||
}
|
||||
|
||||
// KeFuOnlineInfo 客服在线信息
|
||||
type KeFuOnlineInfo struct {
|
||||
KfAccount string `json:"kf_account"`
|
||||
Status int `json:"status"`
|
||||
KfID int `json:"kf_id"`
|
||||
AcceptedCase int `json:"accepted_case"`
|
||||
}
|
||||
|
||||
type resKeFuOnlineList struct {
|
||||
util.CommonError
|
||||
KfOnlineList []*KeFuOnlineInfo `json:"kf_online_list"`
|
||||
}
|
||||
|
||||
// OnlineList 获取在线客服列表
|
||||
func (csm *Manager) OnlineList() (customerServiceOnlineList []*KeFuOnlineInfo, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = csm.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", customerServiceOnlineListURL, accessToken)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var res resKeFuOnlineList
|
||||
err = util.DecodeWithError(response, &res, "ListOnlineCustomerService")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
customerServiceOnlineList = res.KfOnlineList
|
||||
return
|
||||
}
|
||||
|
||||
// Add 添加客服账号
|
||||
func (csm *Manager) Add(kfAccount, nickName string) (err error) {
|
||||
// kfAccount:完整客服帐号,格式为:帐号前缀@公众号微信号,帐号前缀最多10个字符,必须是英文、数字字符或者下划线,后缀为公众号微信号,长度不超过30个字符
|
||||
// nickName:客服昵称,最长16个字
|
||||
// 参数此处均不做校验
|
||||
var accessToken string
|
||||
accessToken, err = csm.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", customerServiceAddURL, accessToken)
|
||||
data := struct {
|
||||
KfAccount string `json:"kf_account"`
|
||||
NickName string `json:"nickname"`
|
||||
}{
|
||||
KfAccount: kfAccount,
|
||||
NickName: nickName,
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.PostJSON(uri, data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = util.DecodeWithCommonError(response, "AddCustomerService")
|
||||
return
|
||||
}
|
||||
|
||||
// Update 修改客服账号
|
||||
func (csm *Manager) Update(kfAccount, nickName string) (err error) {
|
||||
var accessToken string
|
||||
accessToken, err = csm.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", customerServiceUpdateURL, accessToken)
|
||||
data := struct {
|
||||
KfAccount string `json:"kf_account"`
|
||||
NickName string `json:"nickname"`
|
||||
}{
|
||||
KfAccount: kfAccount,
|
||||
NickName: nickName,
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.PostJSON(uri, data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = util.DecodeWithCommonError(response, "UpdateCustomerService")
|
||||
return
|
||||
}
|
||||
|
||||
// Delete 删除客服帐号
|
||||
func (csm *Manager) Delete(kfAccount string) (err error) {
|
||||
var accessToken string
|
||||
accessToken, err = csm.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", customerServiceDeleteURL, accessToken)
|
||||
data := struct {
|
||||
KfAccount string `json:"kf_account"`
|
||||
}{
|
||||
KfAccount: kfAccount,
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.PostJSON(uri, data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = util.DecodeWithCommonError(response, "DeleteCustomerService")
|
||||
return
|
||||
}
|
||||
|
||||
// InviteBind 邀请绑定客服帐号和微信号
|
||||
func (csm *Manager) InviteBind(kfAccount, inviteWX string) (err error) {
|
||||
var accessToken string
|
||||
accessToken, err = csm.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", customerServiceInviteURL, accessToken)
|
||||
data := struct {
|
||||
KfAccount string `json:"kf_account"`
|
||||
InviteWX string `json:"invite_wx"`
|
||||
}{
|
||||
KfAccount: kfAccount,
|
||||
InviteWX: inviteWX,
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.PostJSON(uri, data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = util.DecodeWithCommonError(response, "InviteBindCustomerService")
|
||||
return
|
||||
}
|
||||
|
||||
// UploadHeadImg 上传客服头像
|
||||
func (csm *Manager) UploadHeadImg(kfAccount, fileName string) (err error) {
|
||||
var accessToken string
|
||||
accessToken, err = csm.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s&kf_account=%s", customerServiceUploadHeadImg, accessToken, kfAccount)
|
||||
var response []byte
|
||||
response, err = util.PostFile("media", fileName, uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = util.DecodeWithCommonError(response, "UploadCustomerServiceHeadImg")
|
||||
return
|
||||
}
|
||||
|
||||
// SendTypingStatus 下发客服输入状态给用户
|
||||
func (csm *Manager) SendTypingStatus(openid string, cmd TypingStatus) (err error) {
|
||||
var accessToken string
|
||||
accessToken, err = csm.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", customerServiceTypingURL, accessToken)
|
||||
data := struct {
|
||||
ToUser string `json:"touser"`
|
||||
Command string `json:"command"`
|
||||
}{
|
||||
ToUser: openid,
|
||||
Command: string(cmd),
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.PostJSON(uri, data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = util.DecodeWithCommonError(response, "SendTypingStatus")
|
||||
return
|
||||
}
|
||||
@@ -302,6 +302,7 @@ type reqBatchGetMaterial struct {
|
||||
}
|
||||
|
||||
// BatchGetMaterial 批量获取永久素材
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html
|
||||
func (material *Material) BatchGetMaterial(permanentMaterialType PermanentMaterialType, offset, count int64) (list ArticleList, err error) {
|
||||
var accessToken string
|
||||
|
||||
@@ -68,6 +68,8 @@ const (
|
||||
EventPicWeixin EventType = "pic_weixin"
|
||||
// EventLocationSelect 弹出地理位置选择器的事件推送
|
||||
EventLocationSelect EventType = "location_select"
|
||||
// EventViewMiniprogram 点击菜单跳转小程序的事件推送
|
||||
EventViewMiniprogram EventType = "view_miniprogram"
|
||||
// EventTemplateSendJobFinish 发送模板消息推送通知
|
||||
EventTemplateSendJobFinish EventType = "TEMPLATESENDJOBFINISH"
|
||||
// EventMassSendJobFinish 群发消息推送通知
|
||||
@@ -78,6 +80,12 @@ const (
|
||||
EventSubscribeMsgPopupEvent EventType = "subscribe_msg_popup_event"
|
||||
// EventPublishJobFinish 发布任务完成
|
||||
EventPublishJobFinish EventType = "PUBLISHJOBFINISH"
|
||||
// EventWeappAuditSuccess 审核通过
|
||||
EventWeappAuditSuccess EventType = "weapp_audit_success"
|
||||
// EventWeappAuditFail 审核不通过
|
||||
EventWeappAuditFail EventType = "weapp_audit_fail"
|
||||
// EventWeappAuditDelay 审核延后
|
||||
EventWeappAuditDelay EventType = "weapp_audit_delay"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -117,7 +125,7 @@ type MixMessage struct {
|
||||
URL string `xml:"Url"`
|
||||
|
||||
// 事件相关
|
||||
Event EventType `xml:"Event"`
|
||||
Event EventType `xml:"Event" json:"Event"`
|
||||
EventKey string `xml:"EventKey"`
|
||||
Ticket string `xml:"Ticket"`
|
||||
Latitude string `xml:"Latitude"`
|
||||
@@ -149,6 +157,8 @@ type MixMessage struct {
|
||||
Poiname string `xml:"Poiname"`
|
||||
}
|
||||
|
||||
subscribeMsgPopupEventList []SubscribeMsgPopupEvent `json:"-"`
|
||||
|
||||
SubscribeMsgPopupEvent []struct {
|
||||
List SubscribeMsgPopupEvent `xml:"List"`
|
||||
} `xml:"SubscribeMsgPopupEvent"`
|
||||
@@ -205,13 +215,37 @@ type MixMessage struct {
|
||||
|
||||
// 设备相关
|
||||
device.MsgDevice
|
||||
|
||||
//小程序审核通知
|
||||
SuccTime int `xml:"SuccTime"` //审核成功时的时间戳
|
||||
FailTime int `xml:"FailTime"` //审核不通过的时间戳
|
||||
DelayTime int `xml:"DelayTime"` //审核延后时的时间戳
|
||||
Reason string `xml:"Reason"` //审核不通过的原因
|
||||
ScreenShot string `xml:"ScreenShot"` //审核不通过的截图示例。用 | 分隔的 media_id 的列表,可通过获取永久素材接口拉取截图内容
|
||||
}
|
||||
|
||||
// SubscribeMsgPopupEvent 订阅通知事件推送的消息体
|
||||
type SubscribeMsgPopupEvent struct {
|
||||
TemplateID string `xml:"TemplateId"`
|
||||
SubscribeStatusString string `xml:"SubscribeStatusString"`
|
||||
PopupScene int `xml:"PopupScene"`
|
||||
TemplateID string `xml:"TemplateId" json:"TemplateId"`
|
||||
SubscribeStatusString string `xml:"SubscribeStatusString" json:"SubscribeStatusString"`
|
||||
PopupScene int `xml:"PopupScene" json:"PopupScene,string"`
|
||||
}
|
||||
|
||||
// SetSubscribeMsgPopupEvents 设置订阅消息事件
|
||||
func (s *MixMessage) SetSubscribeMsgPopupEvents(list []SubscribeMsgPopupEvent) {
|
||||
s.subscribeMsgPopupEventList = list
|
||||
}
|
||||
|
||||
// GetSubscribeMsgPopupEvents 获取订阅消息事件数据
|
||||
func (s *MixMessage) GetSubscribeMsgPopupEvents() []SubscribeMsgPopupEvent {
|
||||
if s.subscribeMsgPopupEventList != nil {
|
||||
return s.subscribeMsgPopupEventList
|
||||
}
|
||||
list := make([]SubscribeMsgPopupEvent, len(s.SubscribeMsgPopupEvent))
|
||||
for i, item := range s.SubscribeMsgPopupEvent {
|
||||
list[i] = item.List
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// EventPic 发图事件推送
|
||||
@@ -248,10 +282,10 @@ func (c CDATA) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||
// CommonToken 消息中通用的结构
|
||||
type CommonToken struct {
|
||||
XMLName xml.Name `xml:"xml"`
|
||||
ToUserName CDATA `xml:"ToUserName"`
|
||||
FromUserName CDATA `xml:"FromUserName"`
|
||||
CreateTime int64 `xml:"CreateTime"`
|
||||
MsgType MsgType `xml:"MsgType"`
|
||||
ToUserName CDATA `xml:"ToUserName" json:"ToUserName"`
|
||||
FromUserName CDATA `xml:"FromUserName" json:"FromUserName"`
|
||||
CreateTime int64 `xml:"CreateTime" json:"CreateTime"`
|
||||
MsgType MsgType `xml:"MsgType" json:"MsgType"`
|
||||
}
|
||||
|
||||
// SetToUserName set ToUserName
|
||||
|
||||
@@ -8,10 +8,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
subscribeSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend"
|
||||
subscribeTemplateListURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
||||
subscribeTemplateAddURL = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate"
|
||||
subscribeTemplateDelURL = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate"
|
||||
subscribeSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend"
|
||||
subscribeTemplateListURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
||||
subscribeTemplateAddURL = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate"
|
||||
subscribeTemplateDelURL = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate"
|
||||
subscribeTemplateGetCategoryURL = "https://api.weixin.qq.com/wxaapi/newtmpl/getcategory"
|
||||
subscribeTemplateGetPubTplKeyWorksURL = "https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords"
|
||||
subscribeTemplateGetPubTplTitles = "https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles"
|
||||
)
|
||||
|
||||
// Subscribe 订阅消息
|
||||
@@ -145,3 +148,108 @@ func (tpl *Subscribe) Delete(templateID string) (err error) {
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "DeleteSubscribe")
|
||||
}
|
||||
|
||||
// PublicTemplateCategory 公众号类目
|
||||
type PublicTemplateCategory struct {
|
||||
ID int `json:"id"` // 类目ID
|
||||
Name string `json:"name"` // 类目的中文名
|
||||
}
|
||||
|
||||
type resSubscribeCategoryList struct {
|
||||
util.CommonError
|
||||
CategoryList []*PublicTemplateCategory `json:"data"`
|
||||
}
|
||||
|
||||
// GetCategory 获取公众号类目
|
||||
func (tpl *Subscribe) GetCategory() (categoryList []*PublicTemplateCategory, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = tpl.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", subscribeTemplateGetCategoryURL, accessToken)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var result resSubscribeCategoryList
|
||||
err = util.DecodeWithError(response, &result, "GetCategory")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
categoryList = result.CategoryList
|
||||
return
|
||||
}
|
||||
|
||||
// PublicTemplateKeyWords 模板中的关键词
|
||||
type PublicTemplateKeyWords struct {
|
||||
KeyWordsID int `json:"kid"` // 关键词 id
|
||||
Name string `json:"name"` // 关键词内容
|
||||
Example string `json:"example"` // 关键词内容对应的示例
|
||||
Rule string `json:"rule"` // 参数类型
|
||||
}
|
||||
|
||||
type resPublicTemplateKeyWordsList struct {
|
||||
util.CommonError
|
||||
KeyWordsList []*PublicTemplateKeyWords `json:"data"` // 关键词列表
|
||||
}
|
||||
|
||||
// GetPubTplKeyWordsByID 获取模板中的关键词
|
||||
func (tpl *Subscribe) GetPubTplKeyWordsByID(titleID string) (keyWordsList []*PublicTemplateKeyWords, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = tpl.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s&tid=%s", subscribeTemplateGetPubTplKeyWorksURL, accessToken, titleID)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var result resPublicTemplateKeyWordsList
|
||||
err = util.DecodeWithError(response, &result, "GetPublicTemplateKeyWords")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
keyWordsList = result.KeyWordsList
|
||||
return
|
||||
}
|
||||
|
||||
// PublicTemplateTitle 类目下的公共模板
|
||||
type PublicTemplateTitle struct {
|
||||
TitleID int `json:"tid"` // 模版标题 id
|
||||
Title string `json:"title"` // 模版标题
|
||||
Type int `json:"type"` // 模版类型,2 为一次性订阅,3 为长期订阅
|
||||
CategoryID string `json:"categoryId"` // 模版所属类目 id
|
||||
}
|
||||
|
||||
type resPublicTemplateTitleList struct {
|
||||
util.CommonError
|
||||
Count int `json:"count"` // 公共模板列表总数
|
||||
TemplateTitleList []*PublicTemplateTitle `json:"data"` // 模板标题列表
|
||||
}
|
||||
|
||||
// GetPublicTemplateTitleList 获取类目下的公共模板
|
||||
func (tpl *Subscribe) GetPublicTemplateTitleList(ids string, start int, limit int) (count int, templateTitleList []*PublicTemplateTitle, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = tpl.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s&ids=%s&start=%d&limit=%d", subscribeTemplateGetPubTplTitles, accessToken, ids, start, limit)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var result resPublicTemplateTitleList
|
||||
err = util.DecodeWithError(response, &result, "GetPublicTemplateTitle")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = result.Count
|
||||
templateTitleList = result.TemplateTitleList
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package officialaccount
|
||||
|
||||
import (
|
||||
stdcontext "context"
|
||||
"net/http"
|
||||
|
||||
"github.com/silenceper/wechat/v2/officialaccount/draft"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
"github.com/silenceper/wechat/v2/officialaccount/broadcast"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/config"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/customerservice"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/device"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/js"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/material"
|
||||
@@ -26,7 +28,22 @@ import (
|
||||
|
||||
// OfficialAccount 微信公众号相关API
|
||||
type OfficialAccount struct {
|
||||
ctx *context.Context
|
||||
ctx *context.Context
|
||||
basic *basic.Basic
|
||||
menu *menu.Menu
|
||||
oauth *oauth.Oauth
|
||||
material *material.Material
|
||||
draft *draft.Draft
|
||||
freepublish *freepublish.FreePublish
|
||||
js *js.Js
|
||||
user *user.User
|
||||
templateMsg *message.Template
|
||||
managerMsg *message.Manager
|
||||
device *device.Device
|
||||
broadcast *broadcast.Broadcast
|
||||
datacube *datacube.DataCube
|
||||
ocr *ocr.OCR
|
||||
subscribeMsg *message.Subscribe
|
||||
}
|
||||
|
||||
// NewOfficialAccount 实例化公众号API
|
||||
@@ -51,12 +68,18 @@ func (officialAccount *OfficialAccount) GetContext() *context.Context {
|
||||
|
||||
// GetBasic qr/url 相关配置
|
||||
func (officialAccount *OfficialAccount) GetBasic() *basic.Basic {
|
||||
return basic.NewBasic(officialAccount.ctx)
|
||||
if officialAccount.basic == nil {
|
||||
officialAccount.basic = basic.NewBasic(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.basic
|
||||
}
|
||||
|
||||
// GetMenu 菜单管理接口
|
||||
func (officialAccount *OfficialAccount) GetMenu() *menu.Menu {
|
||||
return menu.NewMenu(officialAccount.ctx)
|
||||
if officialAccount.menu == nil {
|
||||
officialAccount.menu = menu.NewMenu(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.menu
|
||||
}
|
||||
|
||||
// GetServer 消息管理:接收事件,被动回复消息管理
|
||||
@@ -72,68 +95,120 @@ func (officialAccount *OfficialAccount) GetAccessToken() (string, error) {
|
||||
return officialAccount.ctx.GetAccessToken()
|
||||
}
|
||||
|
||||
// GetAccessTokenContext 获取access_token
|
||||
func (officialAccount *OfficialAccount) GetAccessTokenContext(ctx stdcontext.Context) (string, error) {
|
||||
if c, ok := officialAccount.ctx.AccessTokenHandle.(credential.AccessTokenContextHandle); ok {
|
||||
return c.GetAccessTokenContext(ctx)
|
||||
}
|
||||
return officialAccount.ctx.GetAccessToken()
|
||||
}
|
||||
|
||||
// GetOauth oauth2网页授权
|
||||
func (officialAccount *OfficialAccount) GetOauth() *oauth.Oauth {
|
||||
return oauth.NewOauth(officialAccount.ctx)
|
||||
if officialAccount.oauth == nil {
|
||||
officialAccount.oauth = oauth.NewOauth(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.oauth
|
||||
}
|
||||
|
||||
// GetMaterial 素材管理
|
||||
func (officialAccount *OfficialAccount) GetMaterial() *material.Material {
|
||||
return material.NewMaterial(officialAccount.ctx)
|
||||
if officialAccount.material == nil {
|
||||
officialAccount.material = material.NewMaterial(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.material
|
||||
}
|
||||
|
||||
// GetDraft 草稿箱
|
||||
func (officialAccount *OfficialAccount) GetDraft() *draft.Draft {
|
||||
return draft.NewDraft(officialAccount.ctx)
|
||||
if officialAccount.draft == nil {
|
||||
officialAccount.draft = draft.NewDraft(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.draft
|
||||
}
|
||||
|
||||
// GetFreePublish 发布能力
|
||||
func (officialAccount *OfficialAccount) GetFreePublish() *freepublish.FreePublish {
|
||||
return freepublish.NewFreePublish(officialAccount.ctx)
|
||||
if officialAccount.freepublish == nil {
|
||||
officialAccount.freepublish = freepublish.NewFreePublish(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.freepublish
|
||||
}
|
||||
|
||||
// GetJs js-sdk配置
|
||||
func (officialAccount *OfficialAccount) GetJs() *js.Js {
|
||||
return js.NewJs(officialAccount.ctx)
|
||||
if officialAccount.js == nil {
|
||||
officialAccount.js = js.NewJs(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.js
|
||||
}
|
||||
|
||||
// GetUser 用户管理接口
|
||||
func (officialAccount *OfficialAccount) GetUser() *user.User {
|
||||
return user.NewUser(officialAccount.ctx)
|
||||
if officialAccount.user == nil {
|
||||
officialAccount.user = user.NewUser(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.user
|
||||
}
|
||||
|
||||
// GetTemplate 模板消息接口
|
||||
func (officialAccount *OfficialAccount) GetTemplate() *message.Template {
|
||||
return message.NewTemplate(officialAccount.ctx)
|
||||
if officialAccount.templateMsg == nil {
|
||||
officialAccount.templateMsg = message.NewTemplate(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.templateMsg
|
||||
}
|
||||
|
||||
// GetCustomerMessageManager 客服消息接口
|
||||
func (officialAccount *OfficialAccount) GetCustomerMessageManager() *message.Manager {
|
||||
return message.NewMessageManager(officialAccount.ctx)
|
||||
if officialAccount.managerMsg == nil {
|
||||
officialAccount.managerMsg = message.NewMessageManager(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.managerMsg
|
||||
}
|
||||
|
||||
// GetDevice 获取智能设备的实例
|
||||
func (officialAccount *OfficialAccount) GetDevice() *device.Device {
|
||||
return device.NewDevice(officialAccount.ctx)
|
||||
if officialAccount.device == nil {
|
||||
officialAccount.device = device.NewDevice(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.device
|
||||
}
|
||||
|
||||
// GetBroadcast 群发消息
|
||||
// TODO 待完善
|
||||
func (officialAccount *OfficialAccount) GetBroadcast() *broadcast.Broadcast {
|
||||
return broadcast.NewBroadcast(officialAccount.ctx)
|
||||
if officialAccount.broadcast == nil {
|
||||
officialAccount.broadcast = broadcast.NewBroadcast(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.broadcast
|
||||
}
|
||||
|
||||
// GetDataCube 数据统计
|
||||
func (officialAccount *OfficialAccount) GetDataCube() *datacube.DataCube {
|
||||
return datacube.NewCube(officialAccount.ctx)
|
||||
if officialAccount.datacube == nil {
|
||||
officialAccount.datacube = datacube.NewCube(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.datacube
|
||||
}
|
||||
|
||||
// GetOCR OCR接口
|
||||
func (officialAccount *OfficialAccount) GetOCR() *ocr.OCR {
|
||||
return ocr.NewOCR(officialAccount.ctx)
|
||||
if officialAccount.ocr == nil {
|
||||
officialAccount.ocr = ocr.NewOCR(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.ocr
|
||||
}
|
||||
|
||||
// GetSubscribe 公众号订阅消息
|
||||
func (officialAccount *OfficialAccount) GetSubscribe() *message.Subscribe {
|
||||
return message.NewSubscribe(officialAccount.ctx)
|
||||
if officialAccount.subscribeMsg == nil {
|
||||
officialAccount.subscribeMsg = message.NewSubscribe(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.subscribeMsg
|
||||
}
|
||||
|
||||
// GetCustomerServiceManager 客服管理
|
||||
func (officialAccount *OfficialAccount) GetCustomerServiceManager() *customerservice.Manager {
|
||||
return customerservice.NewCustomerServiceManager(officialAccount.ctx)
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/message"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
@@ -35,10 +37,11 @@ type Server struct {
|
||||
ResponseRawXMLMsg []byte
|
||||
ResponseMsg interface{}
|
||||
|
||||
isSafeMode bool
|
||||
random []byte
|
||||
nonce string
|
||||
timestamp int64
|
||||
isSafeMode bool
|
||||
isJSONContent bool
|
||||
random []byte
|
||||
nonce string
|
||||
timestamp int64
|
||||
}
|
||||
|
||||
// NewServer init
|
||||
@@ -70,6 +73,11 @@ func (srv *Server) Serve() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 非安全模式下,请求处理方法返回为nil则直接回复success给微信服务器
|
||||
if response == nil && !srv.isSafeMode {
|
||||
srv.String("success")
|
||||
return nil
|
||||
}
|
||||
|
||||
// debug print request msg
|
||||
log.Debugf("request msg =%s", string(srv.RequestRawXMLMsg))
|
||||
@@ -98,6 +106,10 @@ func (srv *Server) handleRequest() (reply *message.Reply, err error) {
|
||||
srv.isSafeMode = true
|
||||
}
|
||||
|
||||
// set request contentType
|
||||
contentType := srv.Request.Header.Get("Content-Type")
|
||||
srv.isJSONContent = strings.Contains(contentType, "application/json")
|
||||
|
||||
// set openID
|
||||
srv.openID = srv.Query("openid")
|
||||
|
||||
@@ -125,9 +137,9 @@ func (srv *Server) getMessage() (interface{}, error) {
|
||||
var rawXMLMsgBytes []byte
|
||||
var err error
|
||||
if srv.isSafeMode {
|
||||
var encryptedXMLMsg message.EncryptedXMLMsg
|
||||
if err := xml.NewDecoder(srv.Request.Body).Decode(&encryptedXMLMsg); err != nil {
|
||||
return nil, fmt.Errorf("从body中解析xml失败,err=%v", err)
|
||||
encryptedXMLMsg, dataErr := srv.getEncryptBody()
|
||||
if dataErr != nil {
|
||||
return nil, dataErr
|
||||
}
|
||||
|
||||
// 验证消息签名
|
||||
@@ -150,7 +162,7 @@ func (srv *Server) getMessage() (interface{}, error) {
|
||||
return nil, fmt.Errorf("消息解密失败, err=%v", err)
|
||||
}
|
||||
} else {
|
||||
rawXMLMsgBytes, err = ioutil.ReadAll(srv.Request.Body)
|
||||
rawXMLMsgBytes, err = io.ReadAll(srv.Request.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("从body中解析xml失败, err=%v", err)
|
||||
}
|
||||
@@ -161,9 +173,48 @@ func (srv *Server) getMessage() (interface{}, error) {
|
||||
return srv.parseRequestMessage(rawXMLMsgBytes)
|
||||
}
|
||||
|
||||
func (srv *Server) getEncryptBody() (*message.EncryptedXMLMsg, error) {
|
||||
var encryptedXMLMsg = &message.EncryptedXMLMsg{}
|
||||
if srv.isJSONContent {
|
||||
if err := json.NewDecoder(srv.Request.Body).Decode(encryptedXMLMsg); err != nil {
|
||||
return nil, fmt.Errorf("从body中解析json失败,err=%v", err)
|
||||
}
|
||||
} else {
|
||||
if err := xml.NewDecoder(srv.Request.Body).Decode(encryptedXMLMsg); err != nil {
|
||||
return nil, fmt.Errorf("从body中解析xml失败,err=%v", err)
|
||||
}
|
||||
}
|
||||
return encryptedXMLMsg, nil
|
||||
}
|
||||
|
||||
func (srv *Server) parseRequestMessage(rawXMLMsgBytes []byte) (msg *message.MixMessage, err error) {
|
||||
msg = &message.MixMessage{}
|
||||
err = xml.Unmarshal(rawXMLMsgBytes, msg)
|
||||
if !srv.isJSONContent {
|
||||
err = xml.Unmarshal(rawXMLMsgBytes, msg)
|
||||
return
|
||||
}
|
||||
// parse json
|
||||
err = json.Unmarshal(rawXMLMsgBytes, msg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// nonstandard json, 目前小程序订阅消息返回数据格式不标准,订阅消息模板单个List返回是对象,多个List返回是数组。
|
||||
if msg.MsgType == message.MsgTypeEvent {
|
||||
listData := gjson.Get(string(rawXMLMsgBytes), "List")
|
||||
if listData.IsObject() {
|
||||
listItem := message.SubscribeMsgPopupEvent{}
|
||||
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItem); parseErr != nil {
|
||||
return msg, parseErr
|
||||
}
|
||||
msg.SetSubscribeMsgPopupEvents([]message.SubscribeMsgPopupEvent{listItem})
|
||||
} else if listData.IsArray() {
|
||||
listItems := make([]message.SubscribeMsgPopupEvent, 0)
|
||||
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItems); parseErr != nil {
|
||||
return msg, parseErr
|
||||
}
|
||||
msg.SetSubscribeMsgPopupEvents(listItems)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
116
officialaccount/user/blacklist.go
Normal file
116
officialaccount/user/blacklist.go
Normal file
@@ -0,0 +1,116 @@
|
||||
// Package user blacklist 公众号用户黑名单管理
|
||||
// 参考文档:https://developers.weixin.qq.com/doc/offiaccount/User_Management/Manage_blacklist.html
|
||||
package user
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// 获取公众号的黑名单列表
|
||||
getblacklistURL = "https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist?access_token=%s"
|
||||
// 拉黑用户
|
||||
batchblacklistURL = "https://api.weixin.qq.com/cgi-bin/tags/members/batchblacklist?access_token=%s"
|
||||
// 取消拉黑用户
|
||||
batchunblacklistURL = "https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist?access_token=%s"
|
||||
)
|
||||
|
||||
// GetBlackList 获取公众号的黑名单列表
|
||||
// 该接口每次调用最多可拉取 1000 个OpenID,当列表数较多时,可以通过多次拉取的方式来满足需求。
|
||||
// 参数 beginOpenid:当 begin_openid 为空时,默认从开头拉取。
|
||||
func (user *User) GetBlackList(beginOpenid ...string) (userlist *OpenidList, err error) {
|
||||
if len(beginOpenid) > 1 {
|
||||
return nil, errors.New("参数 beginOpenid 错误:请传递 1 个openID,若需要从头开始拉取列表请留空。")
|
||||
}
|
||||
// 获取 AccessToken
|
||||
var accessToken string
|
||||
if accessToken, err = user.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 处理 request 内容
|
||||
request := map[string]string{"begin_openid": ""}
|
||||
if len(beginOpenid) == 1 {
|
||||
request["begin_openid"] = beginOpenid[0]
|
||||
}
|
||||
|
||||
// 调用接口
|
||||
var resp []byte
|
||||
url := fmt.Sprintf(getblacklistURL, accessToken)
|
||||
if resp, err = util.PostJSON(url, &request); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 处理返回
|
||||
userlist = &OpenidList{}
|
||||
if err = util.DecodeWithError(resp, userlist, "GetBlackList"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetAllBlackList 获取公众号的所有黑名单列表
|
||||
func (user *User) GetAllBlackList() (openIDList []string, err error) {
|
||||
var (
|
||||
beginOpenid string
|
||||
count int
|
||||
userlist *OpenidList
|
||||
)
|
||||
|
||||
for {
|
||||
// 获取列表(每次1k条)
|
||||
if userlist, err = user.GetBlackList(beginOpenid); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
openIDList = append(openIDList, userlist.Data.OpenIDs...) // 存储本次获得的OpenIDs
|
||||
count += userlist.Count // 记录获得的总数量
|
||||
beginOpenid = userlist.NextOpenID // 记录下次循环的起始openID
|
||||
if count >= userlist.Total {
|
||||
break // 获得的数量=total,结束循环
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// BatchBlackList 拉黑用户
|
||||
// 参数 openidList:需要拉入黑名单的用户的openid,每次拉黑最多允许20个
|
||||
func (user *User) BatchBlackList(openidList ...string) (err error) {
|
||||
return user.batch(batchblacklistURL, "BatchBlackList", openidList...)
|
||||
}
|
||||
|
||||
// BatchUnBlackList 取消拉黑用户
|
||||
// 参数 openidList:需要取消拉入黑名单的用户的openid,每次拉黑最多允许20个
|
||||
func (user *User) BatchUnBlackList(openidList ...string) (err error) {
|
||||
return user.batch(batchunblacklistURL, "BatchUnBlackList", openidList...)
|
||||
}
|
||||
|
||||
// batch 公共方法
|
||||
func (user *User) batch(url, apiName string, openidList ...string) (err error) {
|
||||
// 检查参数
|
||||
if len(openidList) == 0 || len(openidList) > 20 {
|
||||
return errors.New("参数 openidList 错误:每次操作黑名单用户数量为1-20个。")
|
||||
}
|
||||
|
||||
// 获取 AccessToken
|
||||
var accessToken string
|
||||
if accessToken, err = user.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 处理 request 内容
|
||||
request := map[string][]string{"openid_list": openidList}
|
||||
|
||||
// 调用接口
|
||||
var resp []byte
|
||||
url = fmt.Sprintf(url, accessToken)
|
||||
if resp, err = util.PostJSON(url, &request); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return util.DecodeWithCommonError(resp, apiName)
|
||||
}
|
||||
@@ -226,6 +226,36 @@ type AuthorizerInfo struct {
|
||||
}
|
||||
Alias string `json:"alias"`
|
||||
QrcodeURL string `json:"qrcode_url"`
|
||||
|
||||
MiniProgramInfo *MiniProgramInfo `json:"MiniProgramInfo"`
|
||||
RegisterType int `json:"register_type"`
|
||||
AccountStatus int `json:"account_status"`
|
||||
BasicConfig *AuthorizerBasicConfig `json:"basic_config"`
|
||||
}
|
||||
|
||||
// AuthorizerBasicConfig 授权账号的基础配置结构体
|
||||
type AuthorizerBasicConfig struct {
|
||||
IsPhoneConfigured bool `json:"isPhoneConfigured"`
|
||||
IsEmailConfigured bool `json:"isEmailConfigured"`
|
||||
}
|
||||
|
||||
// MiniProgramInfo 授权账号小程序配置 授权账号为小程序时存在
|
||||
type MiniProgramInfo struct {
|
||||
Network struct {
|
||||
RequestDomain []string `json:"RequestDomain"`
|
||||
WsRequestDomain []string `json:"WsRequestDomain"`
|
||||
UploadDomain []string `json:"UploadDomain"`
|
||||
DownloadDomain []string `json:"DownloadDomain"`
|
||||
BizDomain []string `json:"BizDomain"`
|
||||
UDPDomain []string `json:"UDPDomain"`
|
||||
} `json:"network"`
|
||||
Categories []CategoriesInfo `json:"categories"`
|
||||
}
|
||||
|
||||
// CategoriesInfo 授权账号小程序配置的类目信息
|
||||
type CategoriesInfo struct {
|
||||
First string `wx:"first"`
|
||||
Second string `wx:"second"`
|
||||
}
|
||||
|
||||
// GetAuthrInfo 获取授权方的帐号基本信息
|
||||
|
||||
@@ -28,6 +28,7 @@ type AccountBasicInfo struct {
|
||||
}
|
||||
|
||||
// GetAccountBasicInfo 获取小程序基础信息
|
||||
//
|
||||
//reference:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/Mini_Program_Information_Settings.html
|
||||
func (basic *Basic) GetAccountBasicInfo() (*AccountBasicInfo, error) {
|
||||
ak, err := basic.GetAuthrAccessToken(basic.AppID)
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
package miniprogram
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/credential"
|
||||
"github.com/silenceper/wechat/v2/miniprogram"
|
||||
miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
|
||||
miniContext "github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/urllink"
|
||||
openContext "github.com/silenceper/wechat/v2/openplatform/context"
|
||||
"github.com/silenceper/wechat/v2/openplatform/miniprogram/basic"
|
||||
"github.com/silenceper/wechat/v2/openplatform/miniprogram/component"
|
||||
@@ -10,14 +17,41 @@ import (
|
||||
type MiniProgram struct {
|
||||
AppID string
|
||||
openContext *openContext.Context
|
||||
*miniprogram.MiniProgram
|
||||
authorizerRefreshToken string
|
||||
}
|
||||
|
||||
// GetAccessToken 获取ak
|
||||
func (miniProgram *MiniProgram) GetAccessToken() (string, error) {
|
||||
ak, akErr := miniProgram.openContext.GetAuthrAccessToken(miniProgram.AppID)
|
||||
if akErr == nil {
|
||||
return ak, nil
|
||||
}
|
||||
if miniProgram.authorizerRefreshToken == "" {
|
||||
return "", fmt.Errorf("please set the authorizer_refresh_token first")
|
||||
}
|
||||
akRes, akResErr := miniProgram.GetComponent().RefreshAuthrToken(miniProgram.AppID, miniProgram.authorizerRefreshToken)
|
||||
if akResErr != nil {
|
||||
return "", akResErr
|
||||
}
|
||||
return akRes.AccessToken, nil
|
||||
}
|
||||
|
||||
// SetAuthorizerRefreshToken 设置代执操作业务授权账号authorizer_refresh_token
|
||||
func (miniProgram *MiniProgram) SetAuthorizerRefreshToken(authorizerRefreshToken string) *MiniProgram {
|
||||
miniProgram.authorizerRefreshToken = authorizerRefreshToken
|
||||
return miniProgram
|
||||
}
|
||||
|
||||
// NewMiniProgram 实例化
|
||||
func NewMiniProgram(opCtx *openContext.Context, appID string) *MiniProgram {
|
||||
return &MiniProgram{
|
||||
openContext: opCtx,
|
||||
AppID: appID,
|
||||
}
|
||||
miniProgram := miniprogram.NewMiniProgram(&miniConfig.Config{
|
||||
AppID: opCtx.AppID,
|
||||
Cache: opCtx.Cache,
|
||||
})
|
||||
// 设置获取access_token的函数
|
||||
miniProgram.SetAccessTokenHandle(NewDefaultAuthrAccessToken(opCtx, appID))
|
||||
return &MiniProgram{AppID: appID, MiniProgram: miniProgram, openContext: opCtx}
|
||||
}
|
||||
|
||||
// GetComponent get component
|
||||
@@ -30,3 +64,29 @@ func (miniProgram *MiniProgram) GetComponent() *component.Component {
|
||||
func (miniProgram *MiniProgram) GetBasic() *basic.Basic {
|
||||
return basic.NewBasic(miniProgram.openContext, miniProgram.AppID)
|
||||
}
|
||||
|
||||
// GetURLLink 小程序URL Link接口 调用前需确认已调用 SetAuthorizerRefreshToken 避免由于缓存中 authorizer_access_token 过期执行中断
|
||||
func (miniProgram *MiniProgram) GetURLLink() *urllink.URLLink {
|
||||
return urllink.NewURLLink(&miniContext.Context{
|
||||
AccessTokenHandle: miniProgram,
|
||||
})
|
||||
}
|
||||
|
||||
// DefaultAuthrAccessToken 默认获取授权ak的方法
|
||||
type DefaultAuthrAccessToken struct {
|
||||
opCtx *openContext.Context
|
||||
appID string
|
||||
}
|
||||
|
||||
// NewDefaultAuthrAccessToken 设置access_token
|
||||
func NewDefaultAuthrAccessToken(opCtx *openContext.Context, appID string) credential.AccessTokenHandle {
|
||||
return &DefaultAuthrAccessToken{
|
||||
opCtx: opCtx,
|
||||
appID: appID,
|
||||
}
|
||||
}
|
||||
|
||||
// GetAccessToken 获取ak
|
||||
func (ak *DefaultAuthrAccessToken) GetAccessToken() (string, error) {
|
||||
return ak.opCtx.GetAuthrAccessToken(ak.appID)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ type RefundedResp struct {
|
||||
|
||||
// DecryptReqInfo 对退款结果进行解密
|
||||
func (notify *Notify) DecryptReqInfo(result *RefundedResult) (*RefundedReqInfo, error) {
|
||||
var err error
|
||||
if result == nil || result.ReqInfo == nil {
|
||||
return nil, errors.New("empty refunded_result or req_info")
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ func (o *Order) BridgeConfig(p *Params) (cfg Config, err error) {
|
||||
// BridgeAppConfig get app bridge config
|
||||
func (o *Order) BridgeAppConfig(p *Params) (cfg ConfigForApp, err error) {
|
||||
var (
|
||||
timestamp = strconv.FormatInt(time.Now().Unix(), 10)
|
||||
timestamp = strconv.FormatInt(util.GetCurrTS(), 10)
|
||||
noncestr = util.RandomStr(32)
|
||||
_package = "Sign=WXPay"
|
||||
)
|
||||
@@ -273,7 +273,7 @@ func (o *Order) PrePayOrder(p *Params) (payOrder PreOrder, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// PrePayID will request wechat merchant api and request for a pre payment order id
|
||||
// PrePayID will request wechat merchant api and request for a pre-payment order id
|
||||
func (o *Order) PrePayID(p *Params) (prePayID string, err error) {
|
||||
order, err := o.PrePayOrder(p)
|
||||
if err != nil {
|
||||
|
||||
@@ -23,12 +23,12 @@ func (pay *Pay) GetOrder() *order.Order {
|
||||
return order.NewOrder(pay.cfg)
|
||||
}
|
||||
|
||||
// GetNotify 通知
|
||||
// GetNotify 通知
|
||||
func (pay *Pay) GetNotify() *notify.Notify {
|
||||
return notify.NewNotify(pay.cfg)
|
||||
}
|
||||
|
||||
// GetRefund 退款
|
||||
// GetRefund 退款
|
||||
func (pay *Pay) GetRefund() *refund.Refund {
|
||||
return refund.NewRefund(pay.cfg)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
// 付款到零钱
|
||||
// walletTransferGateway 付款到零钱
|
||||
// https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
|
||||
var walletTransferGateway = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"
|
||||
|
||||
@@ -20,8 +20,7 @@ type Transfer struct {
|
||||
|
||||
// NewTransfer return an instance of Transfer package
|
||||
func NewTransfer(cfg *config.Config) *Transfer {
|
||||
transfer := Transfer{cfg}
|
||||
return &transfer
|
||||
return &Transfer{cfg}
|
||||
}
|
||||
|
||||
// Params 调用参数
|
||||
|
||||
@@ -8,10 +8,24 @@ import (
|
||||
|
||||
// CommonError 微信返回的通用错误json
|
||||
type CommonError struct {
|
||||
apiName string
|
||||
ErrCode int64 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
}
|
||||
|
||||
func (c *CommonError) Error() string {
|
||||
return fmt.Sprintf("%s Error , errcode=%d , errmsg=%s", c.apiName, c.ErrCode, c.ErrMsg)
|
||||
}
|
||||
|
||||
// NewCommonError 新建CommonError错误,对于无errcode和errmsg的返回也可以返回该通用错误
|
||||
func NewCommonError(apiName string, code int64, msg string) *CommonError {
|
||||
return &CommonError{
|
||||
apiName: apiName,
|
||||
ErrCode: code,
|
||||
ErrMsg: msg,
|
||||
}
|
||||
}
|
||||
|
||||
// DecodeWithCommonError 将返回值按照CommonError解析
|
||||
func DecodeWithCommonError(response []byte, apiName string) (err error) {
|
||||
var commError CommonError
|
||||
@@ -19,8 +33,9 @@ func DecodeWithCommonError(response []byte, apiName string) (err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
commError.apiName = apiName
|
||||
if commError.ErrCode != 0 {
|
||||
return fmt.Errorf("%s Error , errcode=%d , errmsg=%s", apiName, commError.ErrCode, commError.ErrMsg)
|
||||
return &commError
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -45,7 +60,11 @@ func DecodeWithError(response []byte, obj interface{}, apiName string) error {
|
||||
return fmt.Errorf("errcode or errmsg is invalid")
|
||||
}
|
||||
if errCode.Int() != 0 {
|
||||
return fmt.Errorf("%s Error , errcode=%d , errmsg=%s", apiName, errCode.Int(), errMsg.String())
|
||||
return &CommonError{
|
||||
apiName: apiName,
|
||||
ErrCode: errCode.Int(),
|
||||
ErrMsg: errMsg.String(),
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
55
util/error_test.go
Normal file
55
util/error_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package util
|
||||
|
||||
import "testing"
|
||||
|
||||
var okErrData string = `{"errcode": 0}`
|
||||
var errData string = `{"errcode": 43101, "errmsg": "user refuse to accept the msg"}`
|
||||
var expectError string = "Send Error , errcode=43101 , errmsg=user refuse to accept the msg"
|
||||
|
||||
func TestDecodeWithCommonErrorNoError(t *testing.T) {
|
||||
err := DecodeWithCommonError([]byte(okErrData), "Send")
|
||||
if err != nil {
|
||||
t.Error("DecodeWithCommonError should not return error")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeWithCommonError(t *testing.T) {
|
||||
err := DecodeWithCommonError([]byte(errData), "Send")
|
||||
if err == nil {
|
||||
t.Error("DecodeWithCommonError should return error")
|
||||
return
|
||||
}
|
||||
|
||||
cErr, ok := err.(*CommonError)
|
||||
if !ok {
|
||||
t.Errorf("DecodeWithCommonError should return *CommonError but %T", err)
|
||||
return
|
||||
}
|
||||
if !(cErr.ErrCode == 43101 && cErr.ErrMsg == "user refuse to accept the msg" && cErr.Error() == expectError) {
|
||||
t.Error("DecodeWithCommonError return bad *CommonError")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeWithError(t *testing.T) {
|
||||
type DE struct {
|
||||
CommonError
|
||||
}
|
||||
var obj DE
|
||||
err := DecodeWithError([]byte(errData), &obj, "Send")
|
||||
if err == nil {
|
||||
t.Error("DecodeWithError should return error")
|
||||
return
|
||||
}
|
||||
|
||||
cErr, ok := err.(*CommonError)
|
||||
if !ok {
|
||||
t.Errorf("DecodeWithError should return *CommonError but %T", err)
|
||||
return
|
||||
}
|
||||
if !(cErr.ErrCode == 43101 && cErr.ErrMsg == "user refuse to accept the msg" && cErr.Error() == expectError) {
|
||||
t.Error("DecodeWithError return bad *CommonError")
|
||||
return
|
||||
}
|
||||
}
|
||||
34
util/http.go
34
util/http.go
@@ -9,7 +9,6 @@ import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
@@ -38,21 +37,26 @@ func HTTPGetContext(ctx context.Context, uri string) ([]byte, error) {
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
||||
}
|
||||
return ioutil.ReadAll(response.Body)
|
||||
return io.ReadAll(response.Body)
|
||||
}
|
||||
|
||||
// HTTPPost post 请求
|
||||
func HTTPPost(uri string, data string) ([]byte, error) {
|
||||
return HTTPPostContext(context.Background(), uri, data)
|
||||
return HTTPPostContext(context.Background(), uri, []byte(data), nil)
|
||||
}
|
||||
|
||||
// HTTPPostContext post 请求
|
||||
func HTTPPostContext(ctx context.Context, uri string, data string) ([]byte, error) {
|
||||
body := bytes.NewBuffer([]byte(data))
|
||||
func HTTPPostContext(ctx context.Context, uri string, data []byte, header map[string]string) ([]byte, error) {
|
||||
body := bytes.NewBuffer(data)
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for key, value := range header {
|
||||
request.Header.Set(key, value)
|
||||
}
|
||||
|
||||
response, err := http.DefaultClient.Do(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -60,9 +64,9 @@ func HTTPPostContext(ctx context.Context, uri string, data string) ([]byte, erro
|
||||
|
||||
defer response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
||||
return nil, fmt.Errorf("http post error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
||||
}
|
||||
return ioutil.ReadAll(response.Body)
|
||||
return io.ReadAll(response.Body)
|
||||
}
|
||||
|
||||
// PostJSON post json 数据请求
|
||||
@@ -83,7 +87,7 @@ func PostJSON(uri string, obj interface{}) ([]byte, error) {
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
||||
}
|
||||
return ioutil.ReadAll(response.Body)
|
||||
return io.ReadAll(response.Body)
|
||||
}
|
||||
|
||||
// PostJSONWithRespContentType post json数据请求,且返回数据类型
|
||||
@@ -105,17 +109,17 @@ func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, e
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return nil, "", fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
||||
}
|
||||
responseData, err := ioutil.ReadAll(response.Body)
|
||||
responseData, err := io.ReadAll(response.Body)
|
||||
contentType := response.Header.Get("Content-Type")
|
||||
return responseData, contentType, err
|
||||
}
|
||||
|
||||
// PostFile 上传文件
|
||||
func PostFile(fieldname, filename, uri string) ([]byte, error) {
|
||||
func PostFile(fieldName, filename, uri string) ([]byte, error) {
|
||||
fields := []MultipartFormField{
|
||||
{
|
||||
IsFile: true,
|
||||
Fieldname: fieldname,
|
||||
Fieldname: fieldName,
|
||||
Filename: filename,
|
||||
},
|
||||
}
|
||||
@@ -178,7 +182,7 @@ func PostMultipartForm(fields []MultipartFormField, uri string) (respBody []byte
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, err
|
||||
}
|
||||
respBody, err = ioutil.ReadAll(resp.Body)
|
||||
respBody, err = io.ReadAll(resp.Body)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -199,13 +203,13 @@ func PostXML(uri string, obj interface{}) ([]byte, error) {
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("http code error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
||||
}
|
||||
return ioutil.ReadAll(response.Body)
|
||||
return io.ReadAll(response.Body)
|
||||
}
|
||||
|
||||
// httpWithTLS CA证书
|
||||
func httpWithTLS(rootCa, key string) (*http.Client, error) {
|
||||
var client *http.Client
|
||||
certData, err := ioutil.ReadFile(rootCa)
|
||||
certData, err := os.ReadFile(rootCa)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to find cert path=%s, error=%v", rootCa, err)
|
||||
}
|
||||
@@ -264,5 +268,5 @@ func PostXMLWithTLS(uri string, obj interface{}, ca, key string) ([]byte, error)
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("http code error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
||||
}
|
||||
return ioutil.ReadAll(response.Body)
|
||||
return io.ReadAll(response.Body)
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ func NewWechat() *Wechat {
|
||||
}
|
||||
|
||||
// SetCache 设置cache
|
||||
func (wc *Wechat) SetCache(cahce cache.Cache) {
|
||||
wc.cache = cahce
|
||||
func (wc *Wechat) SetCache(cache cache.Cache) {
|
||||
wc.cache = cache
|
||||
}
|
||||
|
||||
// GetOfficialAccount 获取微信公众号实例
|
||||
|
||||
17
work/addresslist/client.go
Normal file
17
work/addresslist/client.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package addresslist
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/v2/work/context"
|
||||
)
|
||||
|
||||
// Client 通讯录管理接口实例
|
||||
type Client struct {
|
||||
*context.Context
|
||||
}
|
||||
|
||||
// NewClient 初始化实例
|
||||
func NewClient(ctx *context.Context) *Client {
|
||||
return &Client{
|
||||
ctx,
|
||||
}
|
||||
}
|
||||
47
work/addresslist/department.go
Normal file
47
work/addresslist/department.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package addresslist
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// DepartmentSimpleListURL 获取子部门ID列表
|
||||
DepartmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d"
|
||||
)
|
||||
|
||||
type (
|
||||
// DepartmentSimpleListResponse 获取子部门ID列表响应
|
||||
DepartmentSimpleListResponse struct {
|
||||
util.CommonError
|
||||
DepartmentID []*DepartmentID `json:"department_id"`
|
||||
}
|
||||
// DepartmentID 子部门ID
|
||||
DepartmentID struct {
|
||||
ID int `json:"id"`
|
||||
ParentID int `json:"parentid"`
|
||||
Order int `json:"order"`
|
||||
}
|
||||
)
|
||||
|
||||
// DepartmentSimpleList 获取子部门ID列表
|
||||
// see https://developer.work.weixin.qq.com/document/path/95350
|
||||
func (r *Client) DepartmentSimpleList(departmentID int) ([]*DepartmentID, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.HTTPGet(fmt.Sprintf(DepartmentSimpleListURL, accessToken, departmentID)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &DepartmentSimpleListResponse{}
|
||||
if err = util.DecodeWithError(response, result, "DepartmentSimpleList"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.DepartmentID, nil
|
||||
}
|
||||
177
work/addresslist/user.go
Normal file
177
work/addresslist/user.go
Normal file
@@ -0,0 +1,177 @@
|
||||
package addresslist
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// UserSimpleListURL 获取部门成员
|
||||
UserSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=%s&department_id=%d"
|
||||
// UserGetURL 读取成员
|
||||
UserGetURL = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=%s&userid=%s"
|
||||
// UserListIDURL 获取成员ID列表
|
||||
UserListIDURL = "https://qyapi.weixin.qq.com/cgi-bin/user/list_id?access_token=%s"
|
||||
)
|
||||
|
||||
type (
|
||||
// UserSimpleListResponse 获取部门成员响应
|
||||
UserSimpleListResponse struct {
|
||||
util.CommonError
|
||||
UserList []*UserList
|
||||
}
|
||||
// UserList 部门成员
|
||||
UserList struct {
|
||||
UserID string `json:"userid"`
|
||||
Name string `json:"name"`
|
||||
Department []int `json:"department"`
|
||||
OpenUserID string `json:"open_userid"`
|
||||
}
|
||||
)
|
||||
|
||||
// UserSimpleList 获取部门成员
|
||||
// @see https://developer.work.weixin.qq.com/document/path/90200
|
||||
func (r *Client) UserSimpleList(departmentID int) ([]*UserList, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.HTTPGet(fmt.Sprintf(UserSimpleListURL, accessToken, departmentID)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &UserSimpleListResponse{}
|
||||
err = util.DecodeWithError(response, result, "UserSimpleList")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.UserList, nil
|
||||
}
|
||||
|
||||
// UserGetResponse 获取部门成员响应
|
||||
type UserGetResponse struct {
|
||||
util.CommonError
|
||||
UserID string `json:"userid"` // 成员UserID。对应管理端的帐号,企业内必须唯一。不区分大小写,长度为1~64个字节;第三方应用返回的值为open_userid
|
||||
Name string `json:"name"` // 成员名称;第三方不可获取,调用时返回userid以代替name;代开发自建应用需要管理员授权才返回;对于非第三方创建的成员,第三方通讯录应用也不可获取;未返回name的情况需要通过通讯录展示组件来展示名字
|
||||
Department []int `json:"department"` // 成员所属部门id列表,仅返回该应用有查看权限的部门id;成员授权模式下,固定返回根部门id,即固定为1。对授权了“组织架构信息”权限的第三方应用,返回成员所属的全部部门id
|
||||
Order []int `json:"order"` // 部门内的排序值,默认为0。数量必须和department一致,数值越大排序越前面。值范围是[0, 2^32)。成员授权模式下不返回该字段
|
||||
Position string `json:"position"` // 职务信息;代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
Mobile string `json:"mobile"` // 手机号码,代开发自建应用需要管理员授权且成员oauth2授权获取;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
Gender string `json:"gender"` // 性别。0表示未定义,1表示男性,2表示女性。代开发自建应用需要管理员授权且成员oauth2授权获取;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段。注:不可获取指返回值0
|
||||
Email string `json:"email"` // 邮箱,代开发自建应用需要管理员授权且成员oauth2授权获取;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
BizMail string `json:"biz_mail"` // 企业邮箱,代开发自建应用需要管理员授权且成员oauth2授权获取;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
IsLeaderInDept []int `json:"is_leader_in_dept"` // 表示在所在的部门内是否为部门负责人,数量与department一致;第三方通讯录应用或者授权了“组织架构信息-应用可获取企业的部门组织架构信息-部门负责人”权限的第三方应用可获取;对于非第三方创建的成员,第三方通讯录应用不可获取;上游企业不可获取下游企业成员该字段
|
||||
DirectLeader []string `json:"direct_leader"` // 直属上级UserID,返回在应用可见范围内的直属上级列表,最多有五个直属上级;第三方通讯录应用或者授权了“组织架构信息-应用可获取可见范围内成员组织架构信息-直属上级”权限的第三方应用可获取;对于非第三方创建的成员,第三方通讯录应用不可获取;上游企业不可获取下游企业成员该字段;代开发自建应用不可获取该字段
|
||||
Avatar string `json:"avatar"` // 头像url。 代开发自建应用需要管理员授权且成员oauth2授权获取;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
ThumbAvatar string `json:"thumb_avatar"` // 头像缩略图url。第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
Telephone string `json:"telephone"` // 座机。代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
Alias string `json:"alias"` // 别名;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
Address string `json:"address"` // 地址。代开发自建应用需要管理员授权且成员oauth2授权获取;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
OpenUserid string `json:"open_userid"` // 全局唯一。对于同一个服务商,不同应用获取到企业内同一个成员的open_userid是相同的,最多64个字节。仅第三方应用可获取
|
||||
MainDepartment int `json:"main_department"` // 主部门,仅当应用对主部门有查看权限时返回。
|
||||
Extattr struct {
|
||||
Attrs []struct {
|
||||
Type int `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Text struct {
|
||||
Value string `json:"value"`
|
||||
} `json:"text,omitempty"`
|
||||
Web struct {
|
||||
URL string `json:"url"`
|
||||
Title string `json:"title"`
|
||||
} `json:"web,omitempty"`
|
||||
} `json:"attrs"`
|
||||
} `json:"extattr"` // 扩展属性,代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
Status int `json:"status"` // 激活状态: 1=已激活,2=已禁用,4=未激活,5=退出企业。 已激活代表已激活企业微信或已关注微信插件(原企业号)。未激活代表既未激活企业微信又未关注微信插件(原企业号)。
|
||||
QrCode string `json:"qr_code"` // 员工个人二维码,扫描可添加为外部联系人(注意返回的是一个url,可在浏览器上打开该url以展示二维码);代开发自建应用需要管理员授权且成员oauth2授权获取;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
ExternalPosition string `json:"external_position"` // 对外职务,如果设置了该值,则以此作为对外展示的职务,否则以position来展示。代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
ExternalProfile struct {
|
||||
ExternalCorpName string `json:"external_corp_name"`
|
||||
WechatChannels struct {
|
||||
Nickname string `json:"nickname"`
|
||||
Status int `json:"status"`
|
||||
} `json:"wechat_channels"`
|
||||
ExternalAttr []struct {
|
||||
Type int `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Text struct {
|
||||
Value string `json:"value"`
|
||||
} `json:"text,omitempty"`
|
||||
Web struct {
|
||||
URL string `json:"url"`
|
||||
Title string `json:"title"`
|
||||
} `json:"web,omitempty"`
|
||||
Miniprogram struct {
|
||||
Appid string `json:"appid"`
|
||||
Pagepath string `json:"pagepath"`
|
||||
Title string `json:"title"`
|
||||
} `json:"miniprogram,omitempty"`
|
||||
} `json:"external_attr"`
|
||||
} `json:"external_profile"` // 成员对外属性,字段详情见对外属性;代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
|
||||
}
|
||||
|
||||
// UserGet 获取部门成员
|
||||
// @see https://developer.work.weixin.qq.com/document/path/90196
|
||||
func (r *Client) UserGet(UserID string) (*UserGetResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.HTTPGet(fmt.Sprintf(UserGetURL, accessToken, UserID)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &UserGetResponse{}
|
||||
err = util.DecodeWithError(response, result, "UserGet")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// UserListIDRequest 获取成员ID列表请求
|
||||
type UserListIDRequest struct {
|
||||
Cursor string `json:"cursor"`
|
||||
Limit int `json:"limit"`
|
||||
}
|
||||
|
||||
// UserListIDResponse 获取成员ID列表响应
|
||||
type UserListIDResponse struct {
|
||||
util.CommonError
|
||||
NextCursor string `json:"next_cursor"`
|
||||
DeptUser []*DeptUser `json:"dept_user"`
|
||||
}
|
||||
|
||||
// DeptUser 用户-部门关系
|
||||
type DeptUser struct {
|
||||
UserID string `json:"userid"`
|
||||
Department int `json:"department"`
|
||||
}
|
||||
|
||||
// UserListID 获取成员ID列表
|
||||
// see https://developer.work.weixin.qq.com/document/path/96067
|
||||
func (r *Client) UserListID(req *UserListIDRequest) (*UserListIDResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(UserListIDURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &UserListIDResponse{}
|
||||
if err = util.DecodeWithError(response, result, "UserListID"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
3
work/externalcontact/README.md
Normal file
3
work/externalcontact/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
### 企业微信 客户联系部分
|
||||
|
||||
相关文档正在梳理中...
|
||||
17
work/externalcontact/client.go
Normal file
17
work/externalcontact/client.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package externalcontact
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/v2/work/context"
|
||||
)
|
||||
|
||||
// Client 外部联系接口实例
|
||||
type Client struct {
|
||||
*context.Context
|
||||
}
|
||||
|
||||
// NewClient 初始化实例
|
||||
func NewClient(ctx *context.Context) *Client {
|
||||
return &Client{
|
||||
ctx,
|
||||
}
|
||||
}
|
||||
275
work/externalcontact/contact_way.go
Normal file
275
work/externalcontact/contact_way.go
Normal file
@@ -0,0 +1,275 @@
|
||||
package externalcontact
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// AddContactWayURL 配置客户联系「联系我」方式
|
||||
AddContactWayURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_contact_way?access_token=%s"
|
||||
// GetContactWayURL 获取企业已配置的「联系我」方式
|
||||
GetContactWayURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_contact_way?access_token=%s"
|
||||
// UpdateContactWayURL 更新企业已配置的「联系我」方式
|
||||
UpdateContactWayURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/update_contact_way?access_token=%s"
|
||||
// ListContactWayURL 获取企业已配置的「联系我」列表
|
||||
ListContactWayURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list_contact_way?access_token=%s"
|
||||
// DelContactWayURL 删除企业已配置的「联系我」方式
|
||||
DelContactWayURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_contact_way?access_token=%s"
|
||||
)
|
||||
|
||||
type (
|
||||
// ConclusionsRequest 结束语请求
|
||||
ConclusionsRequest struct {
|
||||
Text ConclusionsText `json:"text"`
|
||||
Image ConclusionsImageRequest `json:"image"`
|
||||
Link ConclusionsLink `json:"link"`
|
||||
MiniProgram ConclusionsMiniProgram `json:"miniprogram"`
|
||||
}
|
||||
// ConclusionsText 文本格式结束语
|
||||
ConclusionsText struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
// ConclusionsImageRequest 图片格式结束语请求
|
||||
ConclusionsImageRequest struct {
|
||||
MediaID string `json:"media_id"`
|
||||
}
|
||||
// ConclusionsLink 链接格式结束语
|
||||
ConclusionsLink struct {
|
||||
Title string `json:"title"`
|
||||
PicURL string `json:"picurl"`
|
||||
Desc string `json:"desc"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
// ConclusionsMiniProgram 小程序格式结束语
|
||||
ConclusionsMiniProgram struct {
|
||||
Title string `json:"title"`
|
||||
PicMediaID string `json:"pic_media_id"`
|
||||
AppID string `json:"appid"`
|
||||
Page string `json:"page"`
|
||||
}
|
||||
// ConclusionsResponse 结束语响应
|
||||
ConclusionsResponse struct {
|
||||
Text ConclusionsText `json:"text"`
|
||||
Image ConclusionsImageResponse `json:"image"`
|
||||
Link ConclusionsLink `json:"link"`
|
||||
MiniProgram ConclusionsMiniProgram `json:"miniprogram"`
|
||||
}
|
||||
// ConclusionsImageResponse 图片格式结束语响应
|
||||
ConclusionsImageResponse struct {
|
||||
PicURL string `json:"pic_url"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
// AddContactWayRequest 配置客户联系「联系我」方式请求
|
||||
AddContactWayRequest struct {
|
||||
Type int `json:"type"`
|
||||
Scene int `json:"scene"`
|
||||
Style int `json:"style"`
|
||||
Remark string `json:"remark"`
|
||||
SkipVerify bool `json:"skip_verify"`
|
||||
State string `json:"state"`
|
||||
User []string `json:"user"`
|
||||
Party []int `json:"party"`
|
||||
IsTemp bool `json:"is_temp"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
ChatExpiresIn int `json:"chat_expires_in"`
|
||||
UnionID string `json:"unionid"`
|
||||
Conclusions ConclusionsRequest `json:"conclusions"`
|
||||
}
|
||||
// AddContactWayResponse 配置客户联系「联系我」方式响应
|
||||
AddContactWayResponse struct {
|
||||
util.CommonError
|
||||
ConfigID string `json:"config_id"`
|
||||
QrCode string `json:"qr_code"`
|
||||
}
|
||||
)
|
||||
|
||||
// AddContactWay 配置客户联系「联系我」方式
|
||||
// see https://developer.work.weixin.qq.com/document/path/92228
|
||||
func (r *Client) AddContactWay(req *AddContactWayRequest) (*AddContactWayResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(AddContactWayURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &AddContactWayResponse{}
|
||||
if err = util.DecodeWithError(response, result, "AddContactWay"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type (
|
||||
// GetContactWayRequest 获取企业已配置的「联系我」方式请求
|
||||
GetContactWayRequest struct {
|
||||
ConfigID string `json:"config_id"`
|
||||
}
|
||||
// GetContactWayResponse 获取企业已配置的「联系我」方式响应
|
||||
GetContactWayResponse struct {
|
||||
util.CommonError
|
||||
ContactWay ContactWay `json:"contact_way"`
|
||||
}
|
||||
// ContactWay 「联系我」配置
|
||||
ContactWay struct {
|
||||
ConfigID string `json:"config_id"`
|
||||
Type int `json:"type"`
|
||||
Scene int `json:"scene"`
|
||||
Style int `json:"style"`
|
||||
Remark string `json:"remark"`
|
||||
SkipVerify bool `json:"skip_verify"`
|
||||
State string `json:"state"`
|
||||
QrCode string `json:"qr_code"`
|
||||
User []string `json:"user"`
|
||||
Party []int `json:"party"`
|
||||
IsTemp bool `json:"is_temp"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
ChatExpiresIn int `json:"chat_expires_in"`
|
||||
UnionID string `json:"unionid"`
|
||||
Conclusions ConclusionsResponse `json:"conclusions"`
|
||||
}
|
||||
)
|
||||
|
||||
// GetContactWay 获取企业已配置的「联系我」方式
|
||||
// see https://developer.work.weixin.qq.com/document/path/92228
|
||||
func (r *Client) GetContactWay(req *GetContactWayRequest) (*GetContactWayResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(GetContactWayURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GetContactWayResponse{}
|
||||
if err = util.DecodeWithError(response, result, "GetContactWay"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type (
|
||||
// UpdateContactWayRequest 更新企业已配置的「联系我」方式请求
|
||||
UpdateContactWayRequest struct {
|
||||
ConfigID string `json:"config_id"`
|
||||
Remark string `json:"remark"`
|
||||
SkipVerify bool `json:"skip_verify"`
|
||||
Style int `json:"style"`
|
||||
State string `json:"state"`
|
||||
User []string `json:"user"`
|
||||
Party []int `json:"party"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
ChatExpiresIn int `json:"chat_expires_in"`
|
||||
UnionID string `json:"unionid"`
|
||||
Conclusions ConclusionsRequest `json:"conclusions"`
|
||||
}
|
||||
// UpdateContactWayResponse 更新企业已配置的「联系我」方式响应
|
||||
UpdateContactWayResponse struct {
|
||||
util.CommonError
|
||||
}
|
||||
)
|
||||
|
||||
// UpdateContactWay 更新企业已配置的「联系我」方式
|
||||
// see https://developer.work.weixin.qq.com/document/path/92228
|
||||
func (r *Client) UpdateContactWay(req *UpdateContactWayRequest) (*UpdateContactWayResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(UpdateContactWayURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &UpdateContactWayResponse{}
|
||||
if err = util.DecodeWithError(response, result, "UpdateContactWay"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type (
|
||||
//ListContactWayRequest 获取企业已配置的「联系我」列表请求
|
||||
ListContactWayRequest struct {
|
||||
StartTime int `json:"start_time"`
|
||||
EndTime int `json:"end_time"`
|
||||
Cursor string `json:"cursor"`
|
||||
Limit int `json:"limit"`
|
||||
}
|
||||
//ListContactWayResponse 获取企业已配置的「联系我」列表响应
|
||||
ListContactWayResponse struct {
|
||||
util.CommonError
|
||||
ContactWay []*ContactWayForList `json:"contact_way"`
|
||||
NextCursor string `json:"next_cursor"`
|
||||
}
|
||||
// ContactWayForList 「联系我」配置
|
||||
ContactWayForList struct {
|
||||
ConfigID string `json:"config_id"`
|
||||
}
|
||||
)
|
||||
|
||||
// ListContactWay 获取企业已配置的「联系我」列表
|
||||
// see https://developer.work.weixin.qq.com/document/path/92228
|
||||
func (r *Client) ListContactWay(req *ListContactWayRequest) (*ListContactWayResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(ListContactWayURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &ListContactWayResponse{}
|
||||
if err = util.DecodeWithError(response, result, "ListContactWay"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type (
|
||||
// DelContactWayRequest 删除企业已配置的「联系我」方式请求
|
||||
DelContactWayRequest struct {
|
||||
ConfigID string `json:"config_id"`
|
||||
}
|
||||
// DelContactWayResponse 删除企业已配置的「联系我」方式响应
|
||||
DelContactWayResponse struct {
|
||||
util.CommonError
|
||||
}
|
||||
)
|
||||
|
||||
// DelContactWay 删除企业已配置的「联系我」方式
|
||||
// see https://developer.work.weixin.qq.com/document/path/92228
|
||||
func (r *Client) DelContactWay(req *DelContactWayRequest) (*DelContactWayResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(DelContactWayURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &DelContactWayResponse{}
|
||||
if err = util.DecodeWithError(response, result, "DelContactWay"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
216
work/externalcontact/external_user.go
Normal file
216
work/externalcontact/external_user.go
Normal file
@@ -0,0 +1,216 @@
|
||||
package externalcontact
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// FetchExternalContactUserListURL 获取客户列表
|
||||
FetchExternalContactUserListURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list"
|
||||
// FetchExternalContactUserDetailURL 获取客户详情
|
||||
FetchExternalContactUserDetailURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get"
|
||||
// FetchBatchExternalContactUserDetailURL 批量获取客户详情
|
||||
FetchBatchExternalContactUserDetailURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/batch/get_by_user"
|
||||
// UpdateUserRemarkURL 更新客户备注信息
|
||||
UpdateUserRemarkURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/remark"
|
||||
)
|
||||
|
||||
// ExternalUserListResponse 外部联系人列表响应
|
||||
type ExternalUserListResponse struct {
|
||||
util.CommonError
|
||||
ExternalUserID []string `json:"external_userid"`
|
||||
}
|
||||
|
||||
// GetExternalUserList 获取客户列表
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92113
|
||||
func (r *Client) GetExternalUserList(userID string) ([]string, error) {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(fmt.Sprintf("%s?access_token=%v&userid=%v", FetchExternalContactUserListURL, accessToken, userID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result ExternalUserListResponse
|
||||
err = util.DecodeWithError(response, &result, "GetExternalUserList")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.ExternalUserID, nil
|
||||
}
|
||||
|
||||
// ExternalUserDetailResponse 外部联系人详情响应
|
||||
type ExternalUserDetailResponse struct {
|
||||
util.CommonError
|
||||
ExternalContact ExternalUser `json:"external_contact"`
|
||||
FollowUser []FollowUser `json:"follow_user"`
|
||||
NextCursor string `json:"next_cursor"`
|
||||
}
|
||||
|
||||
// ExternalUser 外部联系人
|
||||
type ExternalUser struct {
|
||||
ExternalUserID string `json:"external_userid"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"avatar"`
|
||||
Type int64 `json:"type"`
|
||||
Gender int64 `json:"gender"`
|
||||
UnionID string `json:"unionid"`
|
||||
Position string `json:"position"`
|
||||
CorpName string `json:"corp_name"`
|
||||
CorpFullName string `json:"corp_full_name"`
|
||||
ExternalProfile string `json:"external_profile"`
|
||||
}
|
||||
|
||||
// FollowUser 跟进用户(指企业内部用户)
|
||||
type FollowUser struct {
|
||||
UserID string `json:"userid"`
|
||||
Remark string `json:"remark"`
|
||||
Description string `json:"description"`
|
||||
CreateTime string `json:"create_time"`
|
||||
Tags []Tag `json:"tags"`
|
||||
RemarkCorpName string `json:"remark_corp_name"`
|
||||
RemarkMobiles []string `json:"remark_mobiles"`
|
||||
OperUserID string `json:"oper_userid"`
|
||||
AddWay int64 `json:"add_way"`
|
||||
WeChatChannels WechatChannel `json:"wechat_channels"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
// Tag 已绑定在外部联系人的标签
|
||||
type Tag struct {
|
||||
GroupName string `json:"group_name"`
|
||||
TagName string `json:"tag_name"`
|
||||
Type int64 `json:"type"`
|
||||
TagID string `json:"tag_id"`
|
||||
}
|
||||
|
||||
// WechatChannel 视频号添加的场景
|
||||
type WechatChannel struct {
|
||||
NickName string `json:"nickname"`
|
||||
Source string `json:"source"`
|
||||
}
|
||||
|
||||
// GetExternalUserDetail 获取外部联系人详情
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92114
|
||||
func (r *Client) GetExternalUserDetail(externalUserID string, nextCursor ...string) (*ExternalUserDetailResponse, error) {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(fmt.Sprintf("%s?access_token=%v&external_userid=%v&cursor=%v", FetchExternalContactUserDetailURL, accessToken, externalUserID, nextCursor))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &ExternalUserDetailResponse{}
|
||||
err = util.DecodeWithError(response, result, "get_external_user_detail")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// BatchGetExternalUserDetailsRequest 批量获取外部联系人详情请求
|
||||
type BatchGetExternalUserDetailsRequest struct {
|
||||
UserIDList []string `json:"userid_list"`
|
||||
Cursor string `json:"cursor"`
|
||||
}
|
||||
|
||||
// ExternalUserDetailListResponse 批量获取外部联系人详情响应
|
||||
type ExternalUserDetailListResponse struct {
|
||||
util.CommonError
|
||||
ExternalContactList []ExternalUserForBatch `json:"external_contact_list"`
|
||||
}
|
||||
|
||||
// ExternalUserForBatch 批量获取外部联系人客户列表
|
||||
type ExternalUserForBatch struct {
|
||||
ExternalContact ExternalContact `json:"external_contact"`
|
||||
FollowInfo FollowInfo `json:"follow_info"`
|
||||
}
|
||||
|
||||
// ExternalContact 批量获取外部联系人用户信息
|
||||
type ExternalContact struct {
|
||||
ExternalUserID string `json:"external_userid"`
|
||||
Name string `json:"name"`
|
||||
Position string `json:"position"`
|
||||
Avatar string `json:"avatar"`
|
||||
CorpName string `json:"corp_name"`
|
||||
CorpFullName string `json:"corp_full_name"`
|
||||
Type int64 `json:"type"`
|
||||
Gender int64 `json:"gender"`
|
||||
UnionID string `json:"unionid"`
|
||||
ExternalProfile string `json:"external_profile"`
|
||||
}
|
||||
|
||||
// FollowInfo 批量获取外部联系人跟进人信息
|
||||
type FollowInfo struct {
|
||||
UserID string `json:"userid"`
|
||||
Remark string `json:"remark"`
|
||||
Description string `json:"description"`
|
||||
CreateTime int `json:"create_time"`
|
||||
TagID []string `json:"tag_id"`
|
||||
RemarkCorpName string `json:"remark_corp_name"`
|
||||
RemarkMobiles []string `json:"remark_mobiles"`
|
||||
OperUserID string `json:"oper_userid"`
|
||||
AddWay int64 `json:"add_way"`
|
||||
WeChatChannels WechatChannel `json:"wechat_channels"`
|
||||
}
|
||||
|
||||
// BatchGetExternalUserDetails 批量获取外部联系人详情
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92994
|
||||
func (r *Client) BatchGetExternalUserDetails(request BatchGetExternalUserDetailsRequest) ([]ExternalUserForBatch, error) {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
jsonData, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", FetchBatchExternalContactUserDetailURL, accessToken), string(jsonData))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result ExternalUserDetailListResponse
|
||||
err = util.DecodeWithError(response, &result, "BatchGetExternalUserDetails")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.ExternalContactList, nil
|
||||
}
|
||||
|
||||
// UpdateUserRemarkRequest 修改客户备注信息请求体
|
||||
type UpdateUserRemarkRequest struct {
|
||||
UserID string `json:"userid"`
|
||||
ExternalUserID string `json:"external_userid"`
|
||||
Remark string `json:"remark"`
|
||||
Description string `json:"description"`
|
||||
RemarkCompany string `json:"remark_company"`
|
||||
RemarkMobiles []string `json:"remark_mobiles"`
|
||||
RemarkPicMediaID string `json:"remark_pic_mediaid"`
|
||||
}
|
||||
|
||||
// UpdateUserRemark 修改客户备注信息
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92115
|
||||
func (r *Client) UpdateUserRemark(request UpdateUserRemarkRequest) error {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var response []byte
|
||||
jsonData, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", UpdateUserRemarkURL, accessToken), string(jsonData))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "UpdateUserRemark")
|
||||
}
|
||||
38
work/externalcontact/follow_user.go
Normal file
38
work/externalcontact/follow_user.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package externalcontact
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// FetchFollowUserListURL 获取配置了客户联系功能的成员列表
|
||||
FetchFollowUserListURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_follow_user_list"
|
||||
)
|
||||
|
||||
// followerUserResponse 客户联系功能的成员列表响应
|
||||
type followerUserResponse struct {
|
||||
util.CommonError
|
||||
FollowUser []string `json:"follow_user"`
|
||||
}
|
||||
|
||||
// GetFollowUserList 获取配置了客户联系功能的成员列表
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92571
|
||||
func (r *Client) GetFollowUserList() ([]string, error) {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(fmt.Sprintf("%s?access_token=%s", FetchFollowUserListURL, accessToken))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result followerUserResponse
|
||||
err = util.DecodeWithError(response, &result, "GetFollowUserList")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.FollowUser, nil
|
||||
}
|
||||
143
work/externalcontact/groupchat.go
Normal file
143
work/externalcontact/groupchat.go
Normal file
@@ -0,0 +1,143 @@
|
||||
package externalcontact
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
// OpengIDToChatIDURL 客户群opengid转换URL
|
||||
const OpengIDToChatIDURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/opengid_to_chatid"
|
||||
|
||||
type (
|
||||
//GroupChatListRequest 获取客户群列表的请求参数
|
||||
GroupChatListRequest struct {
|
||||
StatusFilter int `json:"status_filter"` // 非必填 客户群跟进状态过滤。0 - 所有列表(即不过滤) 1 - 离职待继承 2 - 离职继承中 3 - 离职继承完成
|
||||
OwnerFilter OwnerFilter `json:"owner_filter"` //非必填 群主过滤。如果不填,表示获取应用可见范围内全部群主的数据(但是不建议这么用,如果可见范围人数超过1000人,为了防止数据包过大,会报错 81017)
|
||||
Cursor string `json:"cursor"` //非必填 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用不填
|
||||
Limit int `json:"limit"` //必填 分页,预期请求的数据量,取值范围 1 ~ 1000
|
||||
}
|
||||
|
||||
//GroupChatList 客户群列表
|
||||
GroupChatList struct {
|
||||
ChatID string `json:"chat_id"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
//GroupChatListResponse 获取客户群列表的返回值
|
||||
GroupChatListResponse struct {
|
||||
util.CommonError
|
||||
GroupChatList []GroupChatList `json:"group_chat_list"`
|
||||
NextCursor string `json:"next_cursor"` //游标
|
||||
}
|
||||
)
|
||||
|
||||
// GetGroupChatList 获取客户群列表
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92120
|
||||
func (r *Client) GetGroupChatList(req *GroupChatListRequest) (*GroupChatListResponse, error) {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.PostJSON(fmt.Sprintf("%s/list?access_token=%s", GroupChatURL, accessToken), req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GroupChatListResponse{}
|
||||
if err = util.DecodeWithError(response, result, "GetGroupChatList"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type (
|
||||
//GroupChatDetailRequest 客户群详情 请求参数
|
||||
GroupChatDetailRequest struct {
|
||||
ChatID string `json:"chat_id"`
|
||||
NeedName int `json:"need_name"`
|
||||
}
|
||||
//Invitor 邀请者
|
||||
Invitor struct {
|
||||
UserID string `json:"userid"` //邀请者的userid
|
||||
}
|
||||
//GroupChatMember 群成员
|
||||
GroupChatMember struct {
|
||||
UserID string `json:"userid"` //群成员id
|
||||
Type int `json:"type"` //成员类型。 1 - 企业成员 2 - 外部联系人
|
||||
JoinTime int `json:"join_time"` //入群时间
|
||||
JoinScene int `json:"join_scene"` //入群方式 1 - 由群成员邀请入群(直接邀请入群) 2 - 由群成员邀请入群(通过邀请链接入群) 3 - 通过扫描群二维码入群
|
||||
Invitor Invitor `json:"invitor,omitempty"` //邀请者。目前仅当是由本企业内部成员邀请入群时会返回该值
|
||||
GroupNickname string `json:"group_nickname"` //在群里的昵称
|
||||
Name string `json:"name"` //名字。仅当 need_name = 1 时返回 如果是微信用户,则返回其在微信中设置的名字 如果是企业微信联系人,则返回其设置对外展示的别名或实名
|
||||
UnionID string `json:"unionid,omitempty"` //外部联系人在微信开放平台的唯一身份标识(微信unionid),通过此字段企业可将外部联系人与公众号/小程序用户关联起来。仅当群成员类型是微信用户(包括企业成员未添加好友),且企业绑定了微信开发者ID有此字段(查看绑定方法)。第三方不可获取,上游企业不可获取下游企业客户的unionid字段
|
||||
}
|
||||
//GroupChatAdmin 群管理员
|
||||
GroupChatAdmin struct {
|
||||
UserID string `json:"userid"` //群管理员userid
|
||||
}
|
||||
//GroupChat 客户群详情
|
||||
GroupChat struct {
|
||||
ChatID string `json:"chat_id"` //客户群ID
|
||||
Name string `json:"name"` //群名
|
||||
Owner string `json:"owner"` //群主ID
|
||||
CreateTime int `json:"create_time"` //群的创建时间
|
||||
Notice string `json:"notice"` //群公告
|
||||
MemberList []GroupChatMember `json:"member_list"` //群成员列表
|
||||
AdminList []GroupChatAdmin `json:"admin_list"` //群管理员列表
|
||||
}
|
||||
//GroupChatDetailResponse 客户群详情 返回值
|
||||
GroupChatDetailResponse struct {
|
||||
util.CommonError
|
||||
GroupChat GroupChat `json:"group_chat"` //客户群详情
|
||||
}
|
||||
)
|
||||
|
||||
// GetGroupChatDetail 获取客户群详情
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92122
|
||||
func (r *Client) GetGroupChatDetail(req *GroupChatDetailRequest) (*GroupChatDetailResponse, error) {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.PostJSON(fmt.Sprintf("%s/get?access_token=%s", GroupChatURL, accessToken), req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GroupChatDetailResponse{}
|
||||
if err = util.DecodeWithError(response, result, "GetGroupChatDetail"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type (
|
||||
//OpengIDToChatIDRequest 客户群opengid转换 请求参数
|
||||
OpengIDToChatIDRequest struct {
|
||||
OpengID string `json:"opengid"`
|
||||
}
|
||||
//OpengIDToChatIDResponse 客户群opengid转换 返回值
|
||||
OpengIDToChatIDResponse struct {
|
||||
util.CommonError
|
||||
ChatID string `json:"chat_id"` //客户群ID
|
||||
}
|
||||
)
|
||||
|
||||
// OpengIDToChatID 客户群opengid转换
|
||||
// @see https://developer.work.weixin.qq.com/document/path/94828
|
||||
func (r *Client) OpengIDToChatID(req *OpengIDToChatIDRequest) (*OpengIDToChatIDResponse, error) {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.PostJSON(fmt.Sprintf("%s?access_token=%s", OpengIDToChatIDURL, accessToken), req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &OpengIDToChatIDResponse{}
|
||||
if err = util.DecodeWithError(response, result, "GetGroupChatDetail"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
146
work/externalcontact/join_way.go
Normal file
146
work/externalcontact/join_way.go
Normal file
@@ -0,0 +1,146 @@
|
||||
package externalcontact
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
// GroupChatURL 客户群
|
||||
const GroupChatURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat"
|
||||
|
||||
type (
|
||||
// AddJoinWayRequest 添加群配置请求参数
|
||||
AddJoinWayRequest struct {
|
||||
Scene int `json:"scene"` // 必填 1 - 群的小程序插件,2 - 群的二维码插件
|
||||
Remark string `json:"remark"` //非必填 联系方式的备注信息,用于助记,超过30个字符将被截断
|
||||
AutoCreateRoom int `json:"auto_create_room"` //非必填 当群满了后,是否自动新建群。0-否;1-是。 默认为1
|
||||
RoomBaseName string `json:"room_base_name"` //非必填 自动建群的群名前缀,当auto_create_room为1时有效。最长40个utf8字符
|
||||
RoomBaseID int `json:"room_base_id"` //非必填 自动建群的群起始序号,当auto_create_room为1时有效
|
||||
ChatIDList []string `json:"chat_id_list"` //必填 使用该配置的客户群ID列表,支持5个。见客户群ID获取方法
|
||||
State string `json:"state"` //非必填 企业自定义的state参数,用于区分不同的入群渠道。不超过30个UTF-8字符
|
||||
}
|
||||
|
||||
// AddJoinWayResponse 添加群配置返回值
|
||||
AddJoinWayResponse struct {
|
||||
util.CommonError
|
||||
ConfigID string `json:"config_id"`
|
||||
}
|
||||
)
|
||||
|
||||
// AddJoinWay 加入群聊
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92229
|
||||
func (r *Client) AddJoinWay(req *AddJoinWayRequest) (*AddJoinWayResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
response []byte
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err = util.PostJSON(fmt.Sprintf("%s/add_join_way?access_token=%s", GroupChatURL, accessToken), req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &AddJoinWayResponse{}
|
||||
if err = util.DecodeWithError(response, result, "AddJoinWay"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type (
|
||||
//JoinWayConfigRequest 获取或删除群配置的请求参数
|
||||
JoinWayConfigRequest struct {
|
||||
ConfigID string `json:"config_id"`
|
||||
}
|
||||
|
||||
//JoinWay 群配置
|
||||
JoinWay struct {
|
||||
ConfigID string `json:"config_id"`
|
||||
Scene int `json:"scene"`
|
||||
Remark string `json:"remark"`
|
||||
AutoCreateRoom int `json:"auto_create_room"`
|
||||
RoomBaseName string `json:"room_base_name"`
|
||||
RoomBaseID int `json:"room_base_id"`
|
||||
ChatIDList []string `json:"chat_id_list"`
|
||||
QrCode string `json:"qr_code"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
//GetJoinWayResponse 获取群配置的返回值
|
||||
GetJoinWayResponse struct {
|
||||
util.CommonError
|
||||
JoinWay JoinWay `json:"join_way"`
|
||||
}
|
||||
)
|
||||
|
||||
// GetJoinWay 获取客户群进群方式配置
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92229
|
||||
func (r *Client) GetJoinWay(req *JoinWayConfigRequest) (*GetJoinWayResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
response []byte
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err = util.PostJSON(fmt.Sprintf("%s/get_join_way?access_token=%s", GroupChatURL, accessToken), req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GetJoinWayResponse{}
|
||||
if err = util.DecodeWithError(response, result, "GetJoinWay"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// UpdateJoinWayRequest 更新群配置的请求参数
|
||||
type UpdateJoinWayRequest struct {
|
||||
ConfigID string `json:"config_id"`
|
||||
Scene int `json:"scene"` // 必填 1 - 群的小程序插件,2 - 群的二维码插件
|
||||
Remark string `json:"remark"` //非必填 联系方式的备注信息,用于助记,超过30个字符将被截断
|
||||
AutoCreateRoom int `json:"auto_create_room"` //非必填 当群满了后,是否自动新建群。0-否;1-是。 默认为1
|
||||
RoomBaseName string `json:"room_base_name"` //非必填 自动建群的群名前缀,当auto_create_room为1时有效。最长40个utf8字符
|
||||
RoomBaseID int `json:"room_base_id"` //非必填 自动建群的群起始序号,当auto_create_room为1时有效
|
||||
ChatIDList []string `json:"chat_id_list"` //必填 使用该配置的客户群ID列表,支持5个。见客户群ID获取方法
|
||||
State string `json:"state"` //非必填 企业自定义的state参数,用于区分不同的入群渠道。不超过30个UTF-8字符
|
||||
}
|
||||
|
||||
// UpdateJoinWay 更新客户群进群方式配置
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92229
|
||||
func (r *Client) UpdateJoinWay(req *UpdateJoinWayRequest) error {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
response []byte
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return err
|
||||
}
|
||||
response, err = util.PostJSON(fmt.Sprintf("%s/update_join_way?access_token=%s", GroupChatURL, accessToken), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "UpdateJoinWay")
|
||||
}
|
||||
|
||||
// DelJoinWay 删除客户群进群方式配置
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92229
|
||||
func (r *Client) DelJoinWay(req *JoinWayConfigRequest) error {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
response []byte
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return err
|
||||
}
|
||||
response, err = util.PostJSON(fmt.Sprintf("%s/del_join_way?access_token=%s", GroupChatURL, accessToken), req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "DelJoinWay")
|
||||
}
|
||||
424
work/externalcontact/msg.go
Normal file
424
work/externalcontact/msg.go
Normal file
@@ -0,0 +1,424 @@
|
||||
package externalcontact
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// AddMsgTemplateURL 创建企业群发
|
||||
AddMsgTemplateURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_msg_template?access_token=%s"
|
||||
// GetGroupMsgListV2URL 获取群发记录列表
|
||||
GetGroupMsgListV2URL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_list_v2?access_token=%s"
|
||||
// GetGroupMsgTaskURL 获取群发成员发送任务列表
|
||||
GetGroupMsgTaskURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_task?access_token=%s"
|
||||
// GetGroupMsgSendResultURL 获取企业群发成员执行结果
|
||||
GetGroupMsgSendResultURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_groupmsg_send_result?access_token=%s"
|
||||
// SendWelcomeMsgURL 发送新客户欢迎语
|
||||
SendWelcomeMsgURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/send_welcome_msg?access_token=%s"
|
||||
// AddGroupWelcomeTemplateURL 添加入群欢迎语素材
|
||||
AddGroupWelcomeTemplateURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/add?access_token=%s"
|
||||
// EditGroupWelcomeTemplateURL 编辑入群欢迎语素材
|
||||
EditGroupWelcomeTemplateURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/edit?access_token=%s"
|
||||
// GetGroupWelcomeTemplateURL 获取入群欢迎语素材
|
||||
GetGroupWelcomeTemplateURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/get?access_token=%s"
|
||||
// DelGroupWelcomeTemplateURL 删除入群欢迎语素材
|
||||
DelGroupWelcomeTemplateURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/group_welcome_template/del?access_token=%s"
|
||||
)
|
||||
|
||||
// AddMsgTemplateRequest 创建企业群发请求
|
||||
type AddMsgTemplateRequest struct {
|
||||
ChatType string `json:"chat_type"`
|
||||
ExternalUserID []string `json:"external_userid"`
|
||||
Sender string `json:"sender,omitempty"`
|
||||
Text MsgText `json:"text"`
|
||||
Attachments []*Attachment `json:"attachments"`
|
||||
}
|
||||
|
||||
// MsgText 文本消息
|
||||
type MsgText struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
type (
|
||||
// Attachment 附件
|
||||
Attachment struct {
|
||||
MsgType string `json:"msgtype"`
|
||||
Image AttachmentImg `json:"image,omitempty"`
|
||||
Link AttachmentLink `json:"link,omitempty"`
|
||||
MiniProgram AttachmentMiniProgram `json:"miniprogram,omitempty"`
|
||||
Video AttachmentVideo `json:"video,omitempty"`
|
||||
File AttachmentFile `json:"file,omitempty"`
|
||||
}
|
||||
// AttachmentImg 图片消息
|
||||
AttachmentImg struct {
|
||||
MediaID string `json:"media_id"`
|
||||
PicURL string `json:"pic_url"`
|
||||
}
|
||||
// AttachmentLink 图文消息
|
||||
AttachmentLink struct {
|
||||
Title string `json:"title"`
|
||||
PicURL string `json:"picurl"`
|
||||
Desc string `json:"desc"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
// AttachmentMiniProgram 小程序消息
|
||||
AttachmentMiniProgram struct {
|
||||
Title string `json:"title"`
|
||||
PicMediaID string `json:"pic_media_id"`
|
||||
AppID string `json:"appid"`
|
||||
Page string `json:"page"`
|
||||
}
|
||||
// AttachmentVideo 视频消息
|
||||
AttachmentVideo struct {
|
||||
MediaID string `json:"media_id"`
|
||||
}
|
||||
// AttachmentFile 文件消息
|
||||
AttachmentFile struct {
|
||||
MediaID string `json:"media_id"`
|
||||
}
|
||||
)
|
||||
|
||||
// AddMsgTemplateResponse 创建企业群发响应
|
||||
type AddMsgTemplateResponse struct {
|
||||
util.CommonError
|
||||
FailList []string `json:"fail_list"`
|
||||
MsgID string `json:"msgid"`
|
||||
}
|
||||
|
||||
// AddMsgTemplate 创建企业群发
|
||||
// see https://developer.work.weixin.qq.com/document/path/92135
|
||||
func (r *Client) AddMsgTemplate(req *AddMsgTemplateRequest) (*AddMsgTemplateResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(AddMsgTemplateURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &AddMsgTemplateResponse{}
|
||||
if err = util.DecodeWithError(response, result, "AddMsgTemplate"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetGroupMsgListV2Request 获取群发记录列表请求
|
||||
type GetGroupMsgListV2Request struct {
|
||||
ChatType string `json:"chat_type"`
|
||||
StartTime int `json:"start_time"`
|
||||
EndTime int `json:"end_time"`
|
||||
Creator string `json:"creator,omitempty"`
|
||||
FilterType int `json:"filter_type"`
|
||||
Limit int `json:"limit"`
|
||||
Cursor string `json:"cursor"`
|
||||
}
|
||||
|
||||
// GetGroupMsgListV2Response 获取群发记录列表响应
|
||||
type GetGroupMsgListV2Response struct {
|
||||
util.CommonError
|
||||
NextCursor string `json:"next_cursor"`
|
||||
GroupMsgList []*GroupMsg `json:"group_msg_list"`
|
||||
}
|
||||
|
||||
// GroupMsg 群发消息
|
||||
type GroupMsg struct {
|
||||
MsgID string `json:"msgid"`
|
||||
Creator string `json:"creator"`
|
||||
CreateTime int `json:"create_time"`
|
||||
CreateType int `json:"create_type"`
|
||||
Text MsgText `json:"text"`
|
||||
Attachments []*Attachment `json:"attachments"`
|
||||
}
|
||||
|
||||
// GetGroupMsgListV2 获取群发记录列表
|
||||
// see https://developer.work.weixin.qq.com/document/path/93338#%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%8F%91%E8%AE%B0%E5%BD%95%E5%88%97%E8%A1%A8
|
||||
func (r *Client) GetGroupMsgListV2(req *GetGroupMsgListV2Request) (*GetGroupMsgListV2Response, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(GetGroupMsgListV2URL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GetGroupMsgListV2Response{}
|
||||
if err = util.DecodeWithError(response, result, "GetGroupMsgListV2"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetGroupMsgTaskRequest 获取群发成员发送任务列表请求
|
||||
type GetGroupMsgTaskRequest struct {
|
||||
MsgID string `json:"msgid"`
|
||||
Limit int `json:"limit"`
|
||||
Cursor string `json:"cursor"`
|
||||
}
|
||||
|
||||
// GetGroupMsgTaskResponse 获取群发成员发送任务列表响应
|
||||
type GetGroupMsgTaskResponse struct {
|
||||
util.CommonError
|
||||
NextCursor string `json:"next_cursor"`
|
||||
TaskList []*Task `json:"task_list"`
|
||||
}
|
||||
|
||||
// Task 获取群发成员发送任务列表任务
|
||||
type Task struct {
|
||||
UserID string `json:"userid"`
|
||||
Status int `json:"status"`
|
||||
SendTime int `json:"send_time"`
|
||||
}
|
||||
|
||||
// GetGroupMsgTask 获取群发成员发送任务列表
|
||||
// see https://developer.work.weixin.qq.com/document/path/93338#%E8%8E%B7%E5%8F%96%E7%BE%A4%E5%8F%91%E6%88%90%E5%91%98%E5%8F%91%E9%80%81%E4%BB%BB%E5%8A%A1%E5%88%97%E8%A1%A8
|
||||
func (r *Client) GetGroupMsgTask(req *GetGroupMsgTaskRequest) (*GetGroupMsgTaskResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(GetGroupMsgTaskURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GetGroupMsgTaskResponse{}
|
||||
if err = util.DecodeWithError(response, result, "GetGroupMsgTask"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetGroupMsgSendResultRequest 获取企业群发成员执行结果请求
|
||||
type GetGroupMsgSendResultRequest struct {
|
||||
MsgID string `json:"msgid"`
|
||||
UserID string `json:"userid"`
|
||||
Limit int `json:"limit"`
|
||||
Cursor string `json:"cursor"`
|
||||
}
|
||||
|
||||
// GetGroupMsgSendResultResponse 获取企业群发成员执行结果响应
|
||||
type GetGroupMsgSendResultResponse struct {
|
||||
util.CommonError
|
||||
NextCursor string `json:"next_cursor"`
|
||||
SendList []*Send `json:"send_list"`
|
||||
}
|
||||
|
||||
// Send 企业群发成员执行结果
|
||||
type Send struct {
|
||||
ExternalUserID string `json:"external_userid"`
|
||||
ChatID string `json:"chat_id"`
|
||||
UserID string `json:"userid"`
|
||||
Status int `json:"status"`
|
||||
SendTime int `json:"send_time"`
|
||||
}
|
||||
|
||||
// GetGroupMsgSendResult 获取企业群发成员执行结果
|
||||
// see https://developer.work.weixin.qq.com/document/path/93338#%E8%8E%B7%E5%8F%96%E4%BC%81%E4%B8%9A%E7%BE%A4%E5%8F%91%E6%88%90%E5%91%98%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9E%9C
|
||||
func (r *Client) GetGroupMsgSendResult(req *GetGroupMsgSendResultRequest) (*GetGroupMsgSendResultResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(GetGroupMsgSendResultURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GetGroupMsgSendResultResponse{}
|
||||
if err = util.DecodeWithError(response, result, "GetGroupMsgSendResult"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// SendWelcomeMsgRequest 发送新客户欢迎语请求
|
||||
type SendWelcomeMsgRequest struct {
|
||||
WelcomeCode string `json:"welcome_code"`
|
||||
Text MsgText `json:"text"`
|
||||
Attachments []*Attachment `json:"attachments"`
|
||||
}
|
||||
|
||||
// SendWelcomeMsgResponse 发送新客户欢迎语响应
|
||||
type SendWelcomeMsgResponse struct {
|
||||
util.CommonError
|
||||
}
|
||||
|
||||
// SendWelcomeMsg 发送新客户欢迎语
|
||||
// see https://developer.work.weixin.qq.com/document/path/92137
|
||||
func (r *Client) SendWelcomeMsg(req *SendWelcomeMsgRequest) error {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(SendWelcomeMsgURL, accessToken), req); err != nil {
|
||||
return err
|
||||
}
|
||||
result := &SendWelcomeMsgResponse{}
|
||||
if err = util.DecodeWithError(response, result, "SendWelcomeMsg"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddGroupWelcomeTemplateRequest 添加入群欢迎语素材请求
|
||||
type AddGroupWelcomeTemplateRequest struct {
|
||||
Text MsgText `json:"text"`
|
||||
Image AttachmentImg `json:"image"`
|
||||
Link AttachmentLink `json:"link"`
|
||||
MiniProgram AttachmentMiniProgram `json:"miniprogram"`
|
||||
File AttachmentFile `json:"file"`
|
||||
Video AttachmentVideo `json:"video"`
|
||||
AgentID int `json:"agentid"`
|
||||
Notify int `json:"notify"`
|
||||
}
|
||||
|
||||
// AddGroupWelcomeTemplateResponse 添加入群欢迎语素材响应
|
||||
type AddGroupWelcomeTemplateResponse struct {
|
||||
util.CommonError
|
||||
TemplateID string `json:"template_id"`
|
||||
}
|
||||
|
||||
// AddGroupWelcomeTemplate 添加入群欢迎语素材
|
||||
// see https://developer.work.weixin.qq.com/document/path/92366#%E6%B7%BB%E5%8A%A0%E5%85%A5%E7%BE%A4%E6%AC%A2%E8%BF%8E%E8%AF%AD%E7%B4%A0%E6%9D%90
|
||||
func (r *Client) AddGroupWelcomeTemplate(req *AddGroupWelcomeTemplateRequest) (*AddGroupWelcomeTemplateResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(AddGroupWelcomeTemplateURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &AddGroupWelcomeTemplateResponse{}
|
||||
if err = util.DecodeWithError(response, result, "AddGroupWelcomeTemplate"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// EditGroupWelcomeTemplateRequest 编辑入群欢迎语素材请求
|
||||
type EditGroupWelcomeTemplateRequest struct {
|
||||
TemplateID string `json:"template_id"`
|
||||
Text MsgText `json:"text"`
|
||||
Image AttachmentImg `json:"image"`
|
||||
Link AttachmentLink `json:"link"`
|
||||
MiniProgram AttachmentMiniProgram `json:"miniprogram"`
|
||||
File AttachmentFile `json:"file"`
|
||||
Video AttachmentVideo `json:"video"`
|
||||
AgentID int `json:"agentid"`
|
||||
}
|
||||
|
||||
// EditGroupWelcomeTemplateResponse 编辑入群欢迎语素材响应
|
||||
type EditGroupWelcomeTemplateResponse struct {
|
||||
util.CommonError
|
||||
}
|
||||
|
||||
// EditGroupWelcomeTemplate 编辑入群欢迎语素材
|
||||
// see https://developer.work.weixin.qq.com/document/path/92366#%E7%BC%96%E8%BE%91%E5%85%A5%E7%BE%A4%E6%AC%A2%E8%BF%8E%E8%AF%AD%E7%B4%A0%E6%9D%90
|
||||
func (r *Client) EditGroupWelcomeTemplate(req *EditGroupWelcomeTemplateRequest) error {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(EditGroupWelcomeTemplateURL, accessToken), req); err != nil {
|
||||
return err
|
||||
}
|
||||
result := &EditGroupWelcomeTemplateResponse{}
|
||||
if err = util.DecodeWithError(response, result, "EditGroupWelcomeTemplate"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetGroupWelcomeTemplateRequest 获取入群欢迎语素材请求
|
||||
type GetGroupWelcomeTemplateRequest struct {
|
||||
TemplateID string `json:"template_id"`
|
||||
}
|
||||
|
||||
// GetGroupWelcomeTemplateResponse 获取入群欢迎语素材响应
|
||||
type GetGroupWelcomeTemplateResponse struct {
|
||||
util.CommonError
|
||||
Text MsgText `json:"text"`
|
||||
Image AttachmentImg `json:"image"`
|
||||
Link AttachmentLink `json:"link"`
|
||||
MiniProgram AttachmentMiniProgram `json:"miniprogram"`
|
||||
File AttachmentFile `json:"file"`
|
||||
Video AttachmentVideo `json:"video"`
|
||||
}
|
||||
|
||||
// GetGroupWelcomeTemplate 获取入群欢迎语素材
|
||||
// see https://developer.work.weixin.qq.com/document/path/92366#%E8%8E%B7%E5%8F%96%E5%85%A5%E7%BE%A4%E6%AC%A2%E8%BF%8E%E8%AF%AD%E7%B4%A0%E6%9D%90
|
||||
func (r *Client) GetGroupWelcomeTemplate(req *GetGroupWelcomeTemplateRequest) (*GetGroupWelcomeTemplateResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(GetGroupWelcomeTemplateURL, accessToken), req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GetGroupWelcomeTemplateResponse{}
|
||||
if err = util.DecodeWithError(response, result, "GetGroupWelcomeTemplate"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// DelGroupWelcomeTemplateRequest 删除入群欢迎语素材请求
|
||||
type DelGroupWelcomeTemplateRequest struct {
|
||||
TemplateID string `json:"template_id"`
|
||||
AgentID int `json:"agentid"`
|
||||
}
|
||||
|
||||
// DelGroupWelcomeTemplateResponse 删除入群欢迎语素材响应
|
||||
type DelGroupWelcomeTemplateResponse struct {
|
||||
util.CommonError
|
||||
}
|
||||
|
||||
// DelGroupWelcomeTemplate 删除入群欢迎语素材
|
||||
// see https://developer.work.weixin.qq.com/document/path/92366#%E5%88%A0%E9%99%A4%E5%85%A5%E7%BE%A4%E6%AC%A2%E8%BF%8E%E8%AF%AD%E7%B4%A0%E6%9D%90
|
||||
func (r *Client) DelGroupWelcomeTemplate(req *DelGroupWelcomeTemplateRequest) error {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostJSON(fmt.Sprintf(DelGroupWelcomeTemplateURL, accessToken), req); err != nil {
|
||||
return err
|
||||
}
|
||||
result := &DelGroupWelcomeTemplateResponse{}
|
||||
if err = util.DecodeWithError(response, result, "DelGroupWelcomeTemplate"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
176
work/externalcontact/statistic.go
Normal file
176
work/externalcontact/statistic.go
Normal file
@@ -0,0 +1,176 @@
|
||||
package externalcontact
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// GetUserBehaviorDataURL 获取「联系客户统计」数据
|
||||
GetUserBehaviorDataURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_user_behavior_data"
|
||||
// GetGroupChatStatURL 获取「群聊数据统计」数据 按群主聚合的方式
|
||||
GetGroupChatStatURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/statistic"
|
||||
// GetGroupChatStatByDayURL 获取「群聊数据统计」数据 按自然日聚合的方式
|
||||
GetGroupChatStatByDayURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/groupchat/statistic_group_by_day"
|
||||
)
|
||||
|
||||
type (
|
||||
// GetUserBehaviorRequest 获取「联系客户统计」数据请求
|
||||
GetUserBehaviorRequest struct {
|
||||
UserID []string `json:"userid"`
|
||||
PartyID []int `json:"partyid"`
|
||||
StartTime int `json:"start_time"`
|
||||
EndTime int `json:"end_time"`
|
||||
}
|
||||
// GetUserBehaviorResponse 获取「联系客户统计」数据响应
|
||||
GetUserBehaviorResponse struct {
|
||||
util.CommonError
|
||||
BehaviorData []BehaviorData `json:"behavior_data"`
|
||||
}
|
||||
// BehaviorData 联系客户统计数据
|
||||
BehaviorData struct {
|
||||
StatTime int `json:"stat_time"`
|
||||
ChatCnt int `json:"chat_cnt"`
|
||||
MessageCnt int `json:"message_cnt"`
|
||||
ReplyPercentage float64 `json:"reply_percentage"`
|
||||
AvgReplyTime int `json:"avg_reply_time"`
|
||||
NegativeFeedbackCnt int `json:"negative_feedback_cnt"`
|
||||
NewApplyCnt int `json:"new_apply_cnt"`
|
||||
NewContactCnt int `json:"new_contact_cnt"`
|
||||
}
|
||||
)
|
||||
|
||||
// GetUserBehaviorData 获取「联系客户统计」数据
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92132
|
||||
func (r *Client) GetUserBehaviorData(req *GetUserBehaviorRequest) ([]BehaviorData, error) {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
jsonData, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", GetUserBehaviorDataURL, accessToken), string(jsonData))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result GetUserBehaviorResponse
|
||||
err = util.DecodeWithError(response, &result, "GetUserBehaviorData")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.BehaviorData, nil
|
||||
}
|
||||
|
||||
type (
|
||||
// GetGroupChatStatRequest 获取「群聊数据统计」数据 按群主聚合的方式 请求
|
||||
GetGroupChatStatRequest struct {
|
||||
DayBeginTime int `json:"day_begin_time"`
|
||||
DayEndTime int `json:"day_end_time"`
|
||||
OwnerFilter OwnerFilter `json:"owner_filter"`
|
||||
OrderBy int `json:"order_by"`
|
||||
OrderAsc int `json:"order_asc"`
|
||||
Offset int `json:"offset"`
|
||||
Limit int `json:"limit"`
|
||||
}
|
||||
// GetGroupChatStatResponse 获取「群聊数据统计」数据 按群主聚合的方式 响应
|
||||
GetGroupChatStatResponse struct {
|
||||
util.CommonError
|
||||
Total int `json:"total"`
|
||||
NextOffset int `json:"next_offset"`
|
||||
Items []GroupChatStatItem `json:"items"`
|
||||
}
|
||||
// GroupChatStatItem 群聊数据统计(按群主聚合)条目
|
||||
GroupChatStatItem struct {
|
||||
Owner string `json:"owner"`
|
||||
Data GroupChatStatItemData `json:"data"`
|
||||
}
|
||||
)
|
||||
|
||||
// OwnerFilter 群主过滤
|
||||
type OwnerFilter struct {
|
||||
UseridList []string `json:"userid_list"`
|
||||
}
|
||||
|
||||
// GroupChatStatItemData 群聊数据统计条目数据
|
||||
type GroupChatStatItemData struct {
|
||||
NewChatCnt int `json:"new_chat_cnt"`
|
||||
ChatTotal int `json:"chat_total"`
|
||||
ChatHasMsg int `json:"chat_has_msg"`
|
||||
NewMemberCnt int `json:"new_member_cnt"`
|
||||
MemberTotal int `json:"member_total"`
|
||||
MemberHasMsg int `json:"member_has_msg"`
|
||||
MsgTotal int `json:"msg_total"`
|
||||
MigrateTraineeChatCnt int `json:"migrate_trainee_chat_cnt"`
|
||||
}
|
||||
|
||||
// GetGroupChatStat 获取「群聊数据统计」数据 按群主聚合的方式
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92133
|
||||
func (r *Client) GetGroupChatStat(req *GetGroupChatStatRequest) (*GetGroupChatStatResponse, error) {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
jsonData, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", GetGroupChatStatURL, accessToken), string(jsonData))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &GetGroupChatStatResponse{}
|
||||
err = util.DecodeWithError(response, result, "GetGroupChatStat")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type (
|
||||
// GetGroupChatStatByDayRequest 获取「群聊数据统计」数据 按自然日聚合的方式 请求
|
||||
GetGroupChatStatByDayRequest struct {
|
||||
DayBeginTime int `json:"day_begin_time"`
|
||||
DayEndTime int `json:"day_end_time"`
|
||||
OwnerFilter OwnerFilter `json:"owner_filter"`
|
||||
}
|
||||
// GetGroupChatStatByDayResponse 获取「群聊数据统计」数据 按自然日聚合的方式 响应
|
||||
GetGroupChatStatByDayResponse struct {
|
||||
util.CommonError
|
||||
Items []GetGroupChatStatByDayItem `json:"items"`
|
||||
}
|
||||
// GetGroupChatStatByDayItem 群聊数据统计(按自然日聚合)条目
|
||||
GetGroupChatStatByDayItem struct {
|
||||
StatTime int `json:"stat_time"`
|
||||
Data GroupChatStatItemData `json:"data"`
|
||||
}
|
||||
)
|
||||
|
||||
// GetGroupChatStatByDay 获取「群聊数据统计」数据 按自然日聚合的方式
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92133
|
||||
func (r *Client) GetGroupChatStatByDay(req *GetGroupChatStatByDayRequest) ([]GetGroupChatStatByDayItem, error) {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
jsonData, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", GetGroupChatStatByDayURL, accessToken), string(jsonData))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result GetGroupChatStatByDayResponse
|
||||
err = util.DecodeWithError(response, &result, "GetGroupChatStatByDay")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.Items, nil
|
||||
}
|
||||
203
work/externalcontact/tag.go
Normal file
203
work/externalcontact/tag.go
Normal file
@@ -0,0 +1,203 @@
|
||||
package externalcontact
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// GetCropTagURL 获取标签列表
|
||||
GetCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list"
|
||||
// AddCropTagURL 添加标签
|
||||
AddCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag"
|
||||
// EditCropTagURL 修改标签
|
||||
EditCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/edit_corp_tag"
|
||||
// DelCropTagURL 删除标签
|
||||
DelCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_corp_tag"
|
||||
// MarkCropTagURL 为客户打上、删除标签
|
||||
MarkCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag"
|
||||
)
|
||||
|
||||
// GetCropTagRequest 获取企业标签请求
|
||||
type GetCropTagRequest struct {
|
||||
TagID []string `json:"tag_id"`
|
||||
GroupID []string `json:"group_id"`
|
||||
}
|
||||
|
||||
// GetCropTagListResponse 获取企业标签列表响应
|
||||
type GetCropTagListResponse struct {
|
||||
util.CommonError
|
||||
TagGroup []TagGroup `json:"tag_group"`
|
||||
}
|
||||
|
||||
// TagGroup 企业标签组
|
||||
type TagGroup struct {
|
||||
GroupID string `json:"group_id"`
|
||||
GroupName string `json:"group_name"`
|
||||
CreateTime int `json:"create_time"`
|
||||
GroupOrder int `json:"group_order"`
|
||||
Deleted bool `json:"deleted"`
|
||||
Tag []TagGroupTagItem `json:"tag"`
|
||||
}
|
||||
|
||||
// TagGroupTagItem 企业标签内的子项
|
||||
type TagGroupTagItem struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
CreateTime int `json:"create_time"`
|
||||
Order int `json:"order"`
|
||||
Deleted bool `json:"deleted"`
|
||||
}
|
||||
|
||||
// GetCropTagList 获取企业标签库
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92117
|
||||
func (r *Client) GetCropTagList(req GetCropTagRequest) ([]TagGroup, error) {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
jsonData, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", GetCropTagURL, accessToken), string(jsonData))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result GetCropTagListResponse
|
||||
err = util.DecodeWithError(response, &result, "GetCropTagList")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.TagGroup, nil
|
||||
}
|
||||
|
||||
// AddCropTagRequest 添加企业标签请求
|
||||
type AddCropTagRequest struct {
|
||||
GroupID string `json:"group_id,omitempty"`
|
||||
GroupName string `json:"group_name"`
|
||||
Order int `json:"order"`
|
||||
Tag []AddCropTagItem `json:"tag"`
|
||||
AgentID int `json:"agentid"`
|
||||
}
|
||||
|
||||
// AddCropTagItem 添加企业标签子项
|
||||
type AddCropTagItem struct {
|
||||
Name string `json:"name"`
|
||||
Order int `json:"order"`
|
||||
}
|
||||
|
||||
// AddCropTagResponse 添加企业标签响应
|
||||
type AddCropTagResponse struct {
|
||||
util.CommonError
|
||||
TagGroup TagGroup `json:"tag_group"`
|
||||
}
|
||||
|
||||
// AddCropTag 添加企业客户标签
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92117
|
||||
func (r *Client) AddCropTag(req AddCropTagRequest) (*TagGroup, error) {
|
||||
var accessToken string
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
jsonData, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", AddCropTagURL, accessToken), string(jsonData))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result AddCropTagResponse
|
||||
err = util.DecodeWithError(response, &result, "AddCropTag")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result.TagGroup, nil
|
||||
}
|
||||
|
||||
// EditCropTagRequest 编辑客户企业标签请求
|
||||
type EditCropTagRequest struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Order int `json:"order"`
|
||||
AgentID string `json:"agent_id"`
|
||||
}
|
||||
|
||||
// EditCropTag 修改企业客户标签
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92117
|
||||
func (r *Client) EditCropTag(req EditCropTagRequest) error {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var response []byte
|
||||
jsonData, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", EditCropTagURL, accessToken), string(jsonData))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "EditCropTag")
|
||||
}
|
||||
|
||||
// DeleteCropTagRequest 删除企业标签请求
|
||||
type DeleteCropTagRequest struct {
|
||||
TagID []string `json:"tag_id"`
|
||||
GroupID []string `json:"group_id"`
|
||||
AgentID string `json:"agent_id"`
|
||||
}
|
||||
|
||||
// DeleteCropTag 删除企业客户标签
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92117
|
||||
func (r *Client) DeleteCropTag(req DeleteCropTagRequest) error {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var response []byte
|
||||
jsonData, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", DelCropTagURL, accessToken), string(jsonData))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "DeleteCropTag")
|
||||
}
|
||||
|
||||
// MarkTagRequest 给客户打标签请求
|
||||
// 相关文档地址:https://developer.work.weixin.qq.com/document/path/92118
|
||||
type MarkTagRequest struct {
|
||||
UserID string `json:"userid"`
|
||||
ExternalUserID string `json:"external_userid"`
|
||||
AddTag []string `json:"add_tag"`
|
||||
RemoveTag []string `json:"remove_tag"`
|
||||
}
|
||||
|
||||
// MarkTag 为客户打上标签
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92118
|
||||
func (r *Client) MarkTag(request MarkTagRequest) error {
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var response []byte
|
||||
jsonData, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", MarkCropTagURL, accessToken), string(jsonData))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "MarkTag")
|
||||
}
|
||||
@@ -38,12 +38,10 @@ func (r *Client) AccountAdd(options AccountAddOptions) (info AccountAddSchema, e
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(accountAddAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(accountAddAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -66,12 +64,10 @@ func (r *Client) AccountDel(options AccountDelOptions) (info util.CommonError, e
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(accountDelAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(accountDelAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -96,12 +92,10 @@ func (r *Client) AccountUpdate(options AccountUpdateOptions) (info util.CommonEr
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(accountUpdateAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(accountUpdateAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -132,12 +126,10 @@ func (r *Client) AccountList() (info AccountListSchema, err error) {
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.HTTPGet(fmt.Sprintf(accountListAddr, accessToken))
|
||||
if err != nil {
|
||||
if data, err = util.HTTPGet(fmt.Sprintf(accountListAddr, accessToken)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -171,12 +163,10 @@ func (r *Client) AddContactWay(options AddContactWayOptions) (info AddContactWay
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(addContactWayAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(addContactWayAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -15,21 +15,22 @@ type SignatureOptions struct {
|
||||
}
|
||||
|
||||
// VerifyURL 验证请求参数是否合法并返回解密后的消息内容
|
||||
// //Gin框架的使用示例
|
||||
// r.GET("/v1/event/callback", func(c *gin.Context) {
|
||||
// options := kf.SignatureOptions{}
|
||||
// //获取回调的的校验参数
|
||||
// if = c.ShouldBindQuery(&options); err != nil {
|
||||
// c.String(http.StatusUnauthorized, "参数解析失败")
|
||||
// }
|
||||
// // 调用VerifyURL方法校验当前请求,如果合法则把解密后的内容作为响应返回给微信服务器
|
||||
// echo, err := kfClient.VerifyURL(options)
|
||||
// if err == nil {
|
||||
// c.String(http.StatusOK, echo)
|
||||
// } else {
|
||||
// c.String(http.StatusUnauthorized, "非法请求来源")
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// //Gin框架的使用示例
|
||||
// r.GET("/v1/event/callback", func(c *gin.Context) {
|
||||
// options := kf.SignatureOptions{}
|
||||
// //获取回调的的校验参数
|
||||
// if = c.ShouldBindQuery(&options); err != nil {
|
||||
// c.String(http.StatusUnauthorized, "参数解析失败")
|
||||
// }
|
||||
// // 调用VerifyURL方法校验当前请求,如果合法则把解密后的内容作为响应返回给微信服务器
|
||||
// echo, err := kfClient.VerifyURL(options)
|
||||
// if err == nil {
|
||||
// c.String(http.StatusOK, echo)
|
||||
// } else {
|
||||
// c.String(http.StatusUnauthorized, "非法请求来源")
|
||||
// }
|
||||
// })
|
||||
func (r *Client) VerifyURL(options SignatureOptions) (string, error) {
|
||||
if options.Signature != util.Signature(r.ctx.Token, options.TimeStamp, options.Nonce, options.EchoStr) {
|
||||
return "", NewSDKErr(40015)
|
||||
@@ -59,27 +60,28 @@ type CallbackMessage struct {
|
||||
}
|
||||
|
||||
// GetCallbackMessage 获取回调事件中的消息内容
|
||||
// //Gin框架的使用示例
|
||||
// r.POST("/v1/event/callback", func(c *gin.Context) {
|
||||
// var (
|
||||
// message kf.CallbackMessage
|
||||
// body []byte
|
||||
// )
|
||||
// // 读取原始消息内容
|
||||
// body, err = c.GetRawData()
|
||||
// if err != nil {
|
||||
// c.String(http.StatusInternalServerError, err.Error())
|
||||
// return
|
||||
// }
|
||||
// // 解析原始数据
|
||||
// message, err = kfClient.GetCallbackMessage(body)
|
||||
// if err != nil {
|
||||
// c.String(http.StatusInternalServerError, "消息获取失败")
|
||||
// return
|
||||
// }
|
||||
// fmt.Println(message)
|
||||
// c.String(200, "ok")
|
||||
// })
|
||||
//
|
||||
// //Gin框架的使用示例
|
||||
// r.POST("/v1/event/callback", func(c *gin.Context) {
|
||||
// var (
|
||||
// message kf.CallbackMessage
|
||||
// body []byte
|
||||
// )
|
||||
// // 读取原始消息内容
|
||||
// body, err = c.GetRawData()
|
||||
// if err != nil {
|
||||
// c.String(http.StatusInternalServerError, err.Error())
|
||||
// return
|
||||
// }
|
||||
// // 解析原始数据
|
||||
// message, err = kfClient.GetCallbackMessage(body)
|
||||
// if err != nil {
|
||||
// c.String(http.StatusInternalServerError, "消息获取失败")
|
||||
// return
|
||||
// }
|
||||
// fmt.Println(message)
|
||||
// c.String(200, "ok")
|
||||
// })
|
||||
func (r *Client) GetCallbackMessage(encryptedMsg []byte) (msg CallbackMessage, err error) {
|
||||
var origin callbackOriginMessage
|
||||
if err = xml.Unmarshal(encryptedMsg, &origin); err != nil {
|
||||
|
||||
@@ -38,12 +38,10 @@ func (r *Client) CustomerBatchGet(options CustomerBatchGetOptions) (info Custome
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(customerBatchGetAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(customerBatchGetAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -31,12 +31,10 @@ func (r *Client) GetCorpQualification() (info CorpQualificationSchema, err error
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.HTTPGet(fmt.Sprintf(corpQualification, accessToken))
|
||||
if err != nil {
|
||||
if data, err = util.HTTPGet(fmt.Sprintf(corpQualification, accessToken)); err != nil {
|
||||
return info, err
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -31,12 +31,10 @@ func (r *Client) SendMsg(options interface{}) (info SendMsgSchema, err error) {
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(sendMsgAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(sendMsgAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -2,9 +2,9 @@ package sendmsg
|
||||
|
||||
// Message 发送消息
|
||||
type Message struct {
|
||||
ToUser string `json:"touser"` // 指定接收消息的客户UserID
|
||||
OpenKFID string `json:"open_kfid"` // 指定发送消息的客服帐号ID
|
||||
MsgID string `json:"msgid"` // 指定消息ID
|
||||
ToUser string `json:"touser"` // 指定接收消息的客户UserID
|
||||
OpenKFID string `json:"open_kfid"` // 指定发送消息的客服帐号ID
|
||||
MsgID string `json:"msgid,omitempty"` // 指定消息ID
|
||||
}
|
||||
|
||||
// Text 发送文本消息
|
||||
|
||||
@@ -38,12 +38,10 @@ func (r *Client) SendMsgOnEvent(options interface{}) (info SendMsgOnEventSchema,
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(sendMsgOnEventAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(sendMsgOnEventAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -37,12 +37,10 @@ func (r *Client) ReceptionistAdd(options ReceptionistOptions) (info Receptionist
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(receptionistAddAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(receptionistAddAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -39,12 +39,10 @@ func (r *Client) ServiceStateGet(options ServiceStateGetOptions) (info ServiceSt
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(serviceStateGetAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(serviceStateGetAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -76,12 +74,10 @@ func (r *Client) ServiceStateTrans(options ServiceStateTransOptions) (info Servi
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(serviceStateTransAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(serviceStateTransAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -45,12 +45,10 @@ func (r *Client) SyncMsg(options SyncMsgOptions) (info SyncMsgSchema, err error)
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(syncMsgAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(syncMsgAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
originInfo := syncMsgSchema{}
|
||||
|
||||
@@ -34,12 +34,10 @@ func (r *Client) UpgradeServiceConfig() (info UpgradeServiceConfigSchema, err er
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.HTTPGet(fmt.Sprintf(upgradeServiceConfigAddr, accessToken))
|
||||
if err != nil {
|
||||
if data, err = util.HTTPGet(fmt.Sprintf(upgradeServiceConfigAddr, accessToken)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -72,12 +70,10 @@ func (r *Client) UpgradeService(options UpgradeServiceOptions) (info util.Common
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(upgradeService, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(upgradeService, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -106,12 +102,10 @@ func (r *Client) UpgradeMemberService(options UpgradeMemberServiceOptions) (info
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(upgradeService, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(upgradeService, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -169,12 +163,10 @@ func (r *Client) UpgradeServiceCancel(options UpgradeServiceCancelOptions) (info
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(upgradeServiceCancel, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(upgradeServiceCancel, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
17
work/material/client.go
Normal file
17
work/material/client.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package material
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/v2/work/context"
|
||||
)
|
||||
|
||||
// Client 素材管理接口实例
|
||||
type Client struct {
|
||||
*context.Context
|
||||
}
|
||||
|
||||
// NewClient 初始化实例
|
||||
func NewClient(ctx *context.Context) *Client {
|
||||
return &Client{
|
||||
ctx,
|
||||
}
|
||||
}
|
||||
39
work/material/media.go
Normal file
39
work/material/media.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package material
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// UploadImgURL 上传图片
|
||||
UploadImgURL = "https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg?access_token=%s"
|
||||
)
|
||||
|
||||
// UploadImgResponse 上传图片响应
|
||||
type UploadImgResponse struct {
|
||||
util.CommonError
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// UploadImg 上传图片
|
||||
// @see https://developer.work.weixin.qq.com/document/path/90256
|
||||
func (r *Client) UploadImg(filename string) (*UploadImgResponse, error) {
|
||||
var (
|
||||
accessToken string
|
||||
err error
|
||||
)
|
||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var response []byte
|
||||
if response, err = util.PostFile("media", filename, fmt.Sprintf(UploadImgURL, accessToken)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &UploadImgResponse{}
|
||||
if err = util.DecodeWithError(response, result, "UploadImg"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
@@ -17,6 +17,8 @@ type Oauth struct {
|
||||
var (
|
||||
// oauthTargetURL 企业微信内跳转地址
|
||||
oauthTargetURL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
|
||||
// oauthTargetURL 企业微信内跳转地址(获取成员的详细信息)
|
||||
oauthTargetPrivateURL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_privateinfo&agentid=%s&state=STATE#wechat_redirect"
|
||||
// oauthUserInfoURL 获取用户信息地址
|
||||
oauthUserInfoURL = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=%s&code=%s"
|
||||
// oauthQrContentTargetURL 构造独立窗口登录二维码
|
||||
@@ -33,23 +35,32 @@ func NewOauth(ctx *context.Context) *Oauth {
|
||||
// GetTargetURL 获取授权地址
|
||||
func (ctr *Oauth) GetTargetURL(callbackURL string) string {
|
||||
// url encode
|
||||
urlStr := url.QueryEscape(callbackURL)
|
||||
return fmt.Sprintf(
|
||||
oauthTargetURL,
|
||||
ctr.CorpID,
|
||||
urlStr,
|
||||
url.QueryEscape(callbackURL),
|
||||
)
|
||||
}
|
||||
|
||||
// GetTargetPrivateURL 获取个人信息授权地址
|
||||
func (ctr *Oauth) GetTargetPrivateURL(callbackURL string, agentID string) string {
|
||||
// url encode
|
||||
return fmt.Sprintf(
|
||||
oauthTargetPrivateURL,
|
||||
ctr.CorpID,
|
||||
url.QueryEscape(callbackURL),
|
||||
agentID,
|
||||
)
|
||||
}
|
||||
|
||||
// GetQrContentTargetURL 构造独立窗口登录二维码
|
||||
func (ctr *Oauth) GetQrContentTargetURL(callbackURL string) string {
|
||||
// url encode
|
||||
urlStr := url.QueryEscape(callbackURL)
|
||||
return fmt.Sprintf(
|
||||
oauthQrContentTargetURL,
|
||||
ctr.CorpID,
|
||||
ctr.AgentID,
|
||||
urlStr,
|
||||
url.QueryEscape(callbackURL),
|
||||
util.RandomStr(16),
|
||||
)
|
||||
}
|
||||
@@ -61,21 +72,18 @@ type ResUserInfo struct {
|
||||
UserID string `json:"UserId"`
|
||||
DeviceID string `json:"DeviceId"`
|
||||
// 非企业成员授权时返回
|
||||
OpenID string `json:"OpenId"`
|
||||
OpenID string `json:"OpenId"`
|
||||
ExternalUserID string `json:"external_userid"`
|
||||
}
|
||||
|
||||
// UserFromCode 根据code获取用户信息
|
||||
func (ctr *Oauth) UserFromCode(code string) (result ResUserInfo, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = ctr.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = ctr.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(
|
||||
fmt.Sprintf(oauthUserInfoURL, accessToken, code),
|
||||
)
|
||||
if err != nil {
|
||||
if response, err = util.HTTPGet(fmt.Sprintf(oauthUserInfoURL, accessToken, code)); err != nil {
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(response, &result)
|
||||
|
||||
17
work/robot/client.go
Normal file
17
work/robot/client.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package robot
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/v2/work/context"
|
||||
)
|
||||
|
||||
// Client 群聊机器人接口实例
|
||||
type Client struct {
|
||||
*context.Context
|
||||
}
|
||||
|
||||
// NewClient 初始化实例
|
||||
func NewClient(ctx *context.Context) *Client {
|
||||
return &Client{
|
||||
ctx,
|
||||
}
|
||||
}
|
||||
29
work/robot/robot.go
Normal file
29
work/robot/robot.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package robot
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// WebhookSendURL 机器人发送群组消息
|
||||
WebhookSendURL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=%s"
|
||||
)
|
||||
|
||||
// RobotBroadcast 群机器人消息发送
|
||||
// @see https://developer.work.weixin.qq.com/document/path/91770
|
||||
func (r *Client) RobotBroadcast(webhookKey string, options interface{}) (info util.CommonError, err error) {
|
||||
var data []byte
|
||||
if data, err = util.PostJSON(fmt.Sprintf(WebhookSendURL, webhookKey), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
return
|
||||
}
|
||||
if info.ErrCode != 0 {
|
||||
return info, err
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
126
work/robot/send_option.go
Normal file
126
work/robot/send_option.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package robot
|
||||
|
||||
import "github.com/silenceper/wechat/v2/util"
|
||||
|
||||
// WebhookSendResponse 机器人发送群组消息响应
|
||||
type WebhookSendResponse struct {
|
||||
util.CommonError
|
||||
}
|
||||
|
||||
// WebhookSendTextOption 机器人发送文本消息请求参数
|
||||
type WebhookSendTextOption struct {
|
||||
MsgType string `json:"msgtype"` // 消息类型,此时固定为text
|
||||
Text struct {
|
||||
Content string `json:"content"` // 文本内容,最长不超过2048个字节,必须是utf8编码
|
||||
MentionedList []string `json:"mentioned_list"` // userid的列表,提醒群中的指定成员(@某个成员),@all表示提醒所有人,如果开发者获取不到userid,可以使用mentioned_mobile_list
|
||||
MentionedMobileList []string `json:"mentioned_mobile_list"` // 手机号列表,提醒手机号对应的群成员(@某个成员),@all表示提醒所有人
|
||||
} `json:"text"` // 文本消息内容
|
||||
}
|
||||
|
||||
// WebhookSendMarkdownOption 机器人发送markdown消息请求参数
|
||||
// 支持语法参考 https://developer.work.weixin.qq.com/document/path/91770
|
||||
type WebhookSendMarkdownOption struct {
|
||||
MsgType string `json:"msgtype"` // 消息类型,此时固定为markdown
|
||||
Markdown struct {
|
||||
Content string `json:"content"` // markdown内容,最长不超过4096个字节,必须是utf8编码
|
||||
} `json:"markdown"` // markdown消息内容
|
||||
}
|
||||
|
||||
// WebhookSendImageOption 机器人发送图片消息请求参数
|
||||
type WebhookSendImageOption struct {
|
||||
MsgType string `json:"msgtype"` // 消息类型,此时固定为image
|
||||
Image struct {
|
||||
Base64 string `json:"base64"` // 图片内容的base64编码
|
||||
MD5 string `json:"md5"` // 图片内容(base64编码前)的md5值
|
||||
} `json:"image"` // 图片消息内容
|
||||
}
|
||||
|
||||
// WebhookSendNewsOption 机器人发送图文消息请求参数
|
||||
type WebhookSendNewsOption struct {
|
||||
MsgType string `json:"msgtype"` // 消息类型,此时固定为news
|
||||
News struct {
|
||||
Articles []struct {
|
||||
Title string `json:"title"` // 标题,不超过128个字节,超过会自动截断
|
||||
Description string `json:"description"` // 描述,不超过512个字节,超过会自动截断
|
||||
URL string `json:"url"` // 点击后跳转的链接
|
||||
PicURL string `json:"picurl"` // 图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图 1068*455,小图150*150
|
||||
} `json:"articles"` // 图文消息列表 一个图文消息支持1到8条图文
|
||||
} `json:"news"` // 图文消息内容
|
||||
}
|
||||
|
||||
// WebhookSendFileOption 机器人发送文件消息请求参数
|
||||
type WebhookSendFileOption struct {
|
||||
MsgType string `json:"msgtype"` // 消息类型,此时固定为file
|
||||
File struct {
|
||||
MediaID string `json:"media_id"` // 文件id,通过下文的文件上传接口获取
|
||||
} `json:"file"` // 文件类型
|
||||
}
|
||||
|
||||
// WebHookSendTempNoticeOption 机器人发送文本通知模版消息请求参数
|
||||
type WebHookSendTempNoticeOption struct {
|
||||
MsgType string `json:"msgtype"` // 消息类型,此时的消息类型固定为template_card
|
||||
TemplateCard TemplateCard `json:"template_card"` // 具体的模版卡片参数
|
||||
}
|
||||
|
||||
// TemplateCard 具体的模版卡片参数
|
||||
type TemplateCard struct {
|
||||
CardType string `json:"card_type"` // 模版卡片的模版类型,文本通知模版卡片的类型为text_notice
|
||||
Source CardSource `json:"source"` // 卡片来源样式信息,不需要来源样式可不填写
|
||||
MainTitle CardTitle `json:"main_title"` // 模版卡片的主要内容,包括一级标题和标题辅助信息
|
||||
EmphasisContent CardTitle `json:"emphasis_content"` // 关键数据样式
|
||||
QuoteArea CardQuoteArea `json:"quote_area"` // 引用文献样式,建议不与关键数据共用
|
||||
SubTitleText string `json:"sub_title_text"` // 二级普通文本,建议不超过112个字。模版卡片主要内容的一级标题main_title.title和二级普通文本sub_title_text必须有一项填写
|
||||
HorizontalContentList []CardContent `json:"horizontal_content_list"` // 二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
|
||||
JumpList []JumpContent `json:"jump_list"` // 跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3
|
||||
CardAction CardAction `json:"card_action"` // 整体卡片的点击跳转事件,text_notice模版卡片中该字段为必填项
|
||||
}
|
||||
|
||||
// CardSource 卡片来源样式信息,不需要来源样式可不填写
|
||||
type CardSource struct {
|
||||
IconURL string `json:"icon_url"` // 来源图片的url
|
||||
Desc string `json:"desc"` // 来源图片的描述,建议不超过13个字
|
||||
DescColor int `json:"desc_color"` // 来源文字的颜色,目前支持:0(默认) 灰色,1 黑色,2 红色,3 绿色
|
||||
}
|
||||
|
||||
// CardTitle 标题和标题辅助信息
|
||||
type CardTitle struct {
|
||||
Title string `json:"title"` // 标题,建议不超过26个字。模版卡片主要内容的一级标题main_title.title和二级普通文本sub_title_text必须有一项填写
|
||||
Desc string `json:"desc"` // 标题辅助信息,建议不超过30个字
|
||||
}
|
||||
|
||||
// CardQuoteArea 引用文献样式,建议不与关键数据共用
|
||||
type CardQuoteArea struct {
|
||||
Type int `json:"type"` // 引用文献样式区域点击事件,0或不填代表没有点击事件,1 代表跳转url,2 代表跳转小程序
|
||||
URL string `json:"url,omitempty"` // 点击跳转的url,quote_area.type是1时必填
|
||||
Appid string `json:"appid,omitempty"` // 点击跳转的小程序的appid,quote_area.type是2时必填
|
||||
Pagepath string `json:"pagepath,omitempty"` // 点击跳转的小程序的pagepath,quote_area.type是2时选填
|
||||
Title string `json:"title"` // 引用文献样式的标题
|
||||
QuoteText string `json:"quote_text"` // 引用文献样式的引用文案
|
||||
}
|
||||
|
||||
// CardContent 二级标题+文本列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
|
||||
type CardContent struct {
|
||||
KeyName string `json:"keyname"` // 链接类型,0或不填代表是普通文本,1 代表跳转url,2 代表下载附件,3 代表@员工
|
||||
Value string `json:"value"` // 二级标题,建议不超过5个字
|
||||
Type int `json:"type,omitempty"` // 二级文本,如果horizontal_content_list.type是2,该字段代表文件名称(要包含文件类型),建议不超过26个字
|
||||
URL string `json:"url,omitempty"` // 链接跳转的url,horizontal_content_list.type是1时必填
|
||||
MediaID string `json:"media_id,omitempty"` // 附件的media_id,horizontal_content_list.type是2时必填
|
||||
UserID string `json:"userid,omitempty"` // 被@的成员的userid,horizontal_content_list.type是3时必填
|
||||
}
|
||||
|
||||
// JumpContent 跳转指引样式的列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过3
|
||||
type JumpContent struct {
|
||||
Type int `json:"type"` // 跳转链接类型,0或不填代表不是链接,1 代表跳转url,2 代表跳转小程序
|
||||
URL string `json:"url,omitempty"` // 跳转链接的url,jump_list.type是1时必填
|
||||
Title string `json:"title"` // 跳转链接样式的文案内容,建议不超过13个字
|
||||
AppID string `json:"appid,omitempty"` // 跳转链接的小程序的appid,jump_list.type是2时必填
|
||||
PagePath string `json:"pagepath,omitempty"` // 跳转链接的小程序的pagepath,jump_list.type是2时选填
|
||||
}
|
||||
|
||||
// CardAction 整体卡片的点击跳转事件,text_notice模版卡片中该字段为必填项
|
||||
type CardAction struct {
|
||||
Type int `json:"type"` // 卡片跳转类型,1 代表跳转url,2 代表打开小程序。text_notice模版卡片中该字段取值范围为[1,2]
|
||||
URL string `json:"url,omitempty"` // 跳转事件的url,card_action.type是1时必填
|
||||
Appid string `json:"appid,omitempty"` // 跳转事件的小程序的appid,card_action.type是2时必填
|
||||
PagePath string `json:"pagepath,omitempty"` // 跳转事件的小程序的pagepath,card_action.type是2时选填
|
||||
}
|
||||
24
work/work.go
24
work/work.go
@@ -2,11 +2,15 @@ package work
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/v2/credential"
|
||||
"github.com/silenceper/wechat/v2/work/addresslist"
|
||||
"github.com/silenceper/wechat/v2/work/config"
|
||||
"github.com/silenceper/wechat/v2/work/context"
|
||||
"github.com/silenceper/wechat/v2/work/externalcontact"
|
||||
"github.com/silenceper/wechat/v2/work/kf"
|
||||
"github.com/silenceper/wechat/v2/work/material"
|
||||
"github.com/silenceper/wechat/v2/work/msgaudit"
|
||||
"github.com/silenceper/wechat/v2/work/oauth"
|
||||
"github.com/silenceper/wechat/v2/work/robot"
|
||||
)
|
||||
|
||||
// Work 企业微信
|
||||
@@ -43,3 +47,23 @@ func (wk *Work) GetMsgAudit() (*msgaudit.Client, error) {
|
||||
func (wk *Work) GetKF() (*kf.Client, error) {
|
||||
return kf.NewClient(wk.ctx.Config)
|
||||
}
|
||||
|
||||
// GetExternalContact get external_contact
|
||||
func (wk *Work) GetExternalContact() *externalcontact.Client {
|
||||
return externalcontact.NewClient(wk.ctx)
|
||||
}
|
||||
|
||||
// GetAddressList get address_list
|
||||
func (wk *Work) GetAddressList() *addresslist.Client {
|
||||
return addresslist.NewClient(wk.ctx)
|
||||
}
|
||||
|
||||
// GetMaterial get material
|
||||
func (wk *Work) GetMaterial() *material.Client {
|
||||
return material.NewClient(wk.ctx)
|
||||
}
|
||||
|
||||
// GetRobot get robot
|
||||
func (wk *Work) GetRobot() *robot.Client {
|
||||
return robot.NewClient(wk.ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user