mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-06 13:42:26 +08:00
Compare commits
58 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9df943df69 | ||
|
|
0a37184c2f | ||
|
|
b4f243ab13 | ||
|
|
d92cd35533 | ||
|
|
58621cd79d | ||
|
|
8821a3856d | ||
|
|
4094adc5b4 | ||
|
|
cb0928a03c | ||
|
|
d6371c7289 | ||
|
|
07b7dc40fc | ||
|
|
01784c2a4a | ||
|
|
8bc1474777 | ||
|
|
ca0b74e082 | ||
|
|
fbda048f62 | ||
|
|
494082ff4f | ||
|
|
9c0189340b | ||
|
|
d39615f2fa | ||
|
|
429219b53f | ||
|
|
6e80b71cb2 | ||
|
|
ab354c4d03 | ||
|
|
d1d034eb95 | ||
|
|
1a9dbc493b | ||
|
|
04559ed4bb | ||
|
|
abd583df01 | ||
|
|
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 |
12
.github/workflows/go.yml
vendored
12
.github/workflows/go.yml
vendored
@@ -10,17 +10,17 @@ jobs:
|
|||||||
golangci:
|
golangci:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go-version: [1.15.x,1.16.x]
|
go-version: [1.16.x,1.17.x,1.18.x]
|
||||||
name: golangci-lint
|
name: golangci-lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-go@v2
|
- uses: actions/setup-go@v3
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3.1.0
|
uses: golangci/golangci-lint-action@v3.2.0
|
||||||
with:
|
with:
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
# 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:
|
build:
|
||||||
name: Test
|
name: Test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -38,7 +38,7 @@ jobs:
|
|||||||
# strategy set
|
# strategy set
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go: ["1.14","1.15", "1.16", "1.17", "1.18"]
|
go: ["1.16", "1.17", "1.18"]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|||||||
@@ -36,8 +36,13 @@ linters:
|
|||||||
- whitespace
|
- whitespace
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
include:
|
||||||
|
- EXC0002 # disable excluding of issues about comments from golint
|
||||||
exclude-rules:
|
exclude-rules:
|
||||||
|
- linters:
|
||||||
|
- stylecheck
|
||||||
|
text: "ST1000:"
|
||||||
|
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||||
- path: _test\.go
|
- path: _test\.go
|
||||||
linters:
|
linters:
|
||||||
- gomnd
|
- gomnd
|
||||||
@@ -52,10 +57,10 @@ linters-settings:
|
|||||||
lines: 66
|
lines: 66
|
||||||
statements: 40
|
statements: 40
|
||||||
|
|
||||||
issues:
|
#issues:
|
||||||
include:
|
# include:
|
||||||
- EXC0002 # disable excluding of issues about comments from golint
|
# - EXC0002 # disable excluding of issues about comments from golint
|
||||||
exclude-rules:
|
# exclude-rules:
|
||||||
- linters:
|
# - linters:
|
||||||
- stylecheck
|
# - stylecheck
|
||||||
text: "ST1000:"
|
# text: "ST1000:"
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -25,35 +25,35 @@ import "github.com/silenceper/wechat/v2"
|
|||||||
以下是一个微信公众号处理消息接收以及回复的例子:
|
以下是一个微信公众号处理消息接收以及回复的例子:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
//使用memcache保存access_token,也可选择redis或自定义cache
|
// 使用memcache保存access_token,也可选择redis或自定义cache
|
||||||
wc := wechat.NewWechat()
|
wc := wechat.NewWechat()
|
||||||
memory := cache.NewMemory()
|
memory := cache.NewMemory()
|
||||||
cfg := &offConfig.Config{
|
cfg := &offConfig.Config{
|
||||||
AppID: "xxx",
|
AppID: "xxx",
|
||||||
AppSecret: "xxx",
|
AppSecret: "xxx",
|
||||||
Token: "xxx",
|
Token: "xxx",
|
||||||
//EncodingAESKey: "xxxx",
|
// EncodingAESKey: "xxxx",
|
||||||
Cache: memory,
|
Cache: memory,
|
||||||
}
|
}
|
||||||
officialAccount := wc.GetOfficialAccount(cfg)
|
officialAccount := wc.GetOfficialAccount(cfg)
|
||||||
|
|
||||||
// 传入request和responseWriter
|
// 传入request和responseWriter
|
||||||
server := officialAccount.GetServer(req, rw)
|
server := officialAccount.GetServer(req, rw)
|
||||||
//设置接收消息的处理方法
|
// 设置接收消息的处理方法
|
||||||
server.SetMessageHandler(func(msg *message.MixMessage) *message.Reply {
|
server.SetMessageHandler(func(msg *message.MixMessage) *message.Reply {
|
||||||
|
|
||||||
//回复消息:演示回复用户发送的消息
|
// 回复消息:演示回复用户发送的消息
|
||||||
text := message.NewText(msg.Content)
|
text := message.NewText(msg.Content)
|
||||||
return &message.Reply{MsgType: message.MsgTypeText, MsgData: text}
|
return &message.Reply{MsgType: message.MsgTypeText, MsgData: text}
|
||||||
})
|
})
|
||||||
|
|
||||||
//处理消息接收以及回复
|
// 处理消息接收以及回复
|
||||||
err := server.Serve()
|
err := server.Serve()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//发送回复的消息
|
// 发送回复的消息
|
||||||
server.Send()
|
server.Send()
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|||||||
46
cache/cache.go
vendored
46
cache/cache.go
vendored
@@ -1,6 +1,9 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// Cache interface
|
// Cache interface
|
||||||
type Cache interface {
|
type Cache interface {
|
||||||
@@ -9,3 +12,44 @@ type Cache interface {
|
|||||||
IsExist(key string) bool
|
IsExist(key string) bool
|
||||||
Delete(key string) error
|
Delete(key string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContextCache interface
|
||||||
|
type ContextCache interface {
|
||||||
|
Cache
|
||||||
|
GetContext(ctx context.Context, key string) interface{}
|
||||||
|
SetContext(ctx context.Context, key string, val interface{}, timeout time.Duration) error
|
||||||
|
IsExistContext(ctx context.Context, key string) bool
|
||||||
|
DeleteContext(ctx context.Context, key string) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetContext get value from cache
|
||||||
|
func GetContext(ctx context.Context, cache Cache, key string) interface{} {
|
||||||
|
if cache, ok := cache.(ContextCache); ok {
|
||||||
|
return cache.GetContext(ctx, key)
|
||||||
|
}
|
||||||
|
return cache.Get(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContext set value to cache
|
||||||
|
func SetContext(ctx context.Context, cache Cache, key string, val interface{}, timeout time.Duration) error {
|
||||||
|
if cache, ok := cache.(ContextCache); ok {
|
||||||
|
return cache.SetContext(ctx, key, val, timeout)
|
||||||
|
}
|
||||||
|
return cache.Set(key, val, timeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsExistContext check value exists in cache.
|
||||||
|
func IsExistContext(ctx context.Context, cache Cache, key string) bool {
|
||||||
|
if cache, ok := cache.(ContextCache); ok {
|
||||||
|
return cache.IsExistContext(ctx, key)
|
||||||
|
}
|
||||||
|
return cache.IsExist(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteContext delete value in cache.
|
||||||
|
func DeleteContext(ctx context.Context, cache Cache, key string) error {
|
||||||
|
if cache, ok := cache.(ContextCache); ok {
|
||||||
|
return cache.DeleteContext(ctx, key)
|
||||||
|
}
|
||||||
|
return cache.Delete(key)
|
||||||
|
}
|
||||||
|
|||||||
28
cache/redis.go
vendored
28
cache/redis.go
vendored
@@ -47,7 +47,12 @@ func (r *Redis) SetRedisCtx(ctx context.Context) {
|
|||||||
|
|
||||||
// Get 获取一个值
|
// Get 获取一个值
|
||||||
func (r *Redis) Get(key string) interface{} {
|
func (r *Redis) Get(key string) interface{} {
|
||||||
result, err := r.conn.Do(r.ctx, "GET", key).Result()
|
return r.GetContext(r.ctx, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetContext 获取一个值
|
||||||
|
func (r *Redis) GetContext(ctx context.Context, key string) interface{} {
|
||||||
|
result, err := r.conn.Do(ctx, "GET", key).Result()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -56,17 +61,32 @@ func (r *Redis) Get(key string) interface{} {
|
|||||||
|
|
||||||
// Set 设置一个值
|
// Set 设置一个值
|
||||||
func (r *Redis) Set(key string, val interface{}, timeout time.Duration) error {
|
func (r *Redis) Set(key string, val interface{}, timeout time.Duration) error {
|
||||||
return r.conn.SetEX(r.ctx, key, val, timeout).Err()
|
return r.SetContext(r.ctx, key, val, timeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContext 设置一个值
|
||||||
|
func (r *Redis) SetContext(ctx context.Context, key string, val interface{}, timeout time.Duration) error {
|
||||||
|
return r.conn.SetEX(ctx, key, val, timeout).Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsExist 判断key是否存在
|
// IsExist 判断key是否存在
|
||||||
func (r *Redis) IsExist(key string) bool {
|
func (r *Redis) IsExist(key string) bool {
|
||||||
result, _ := r.conn.Exists(r.ctx, key).Result()
|
return r.IsExistContext(r.ctx, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsExistContext 判断key是否存在
|
||||||
|
func (r *Redis) IsExistContext(ctx context.Context, key string) bool {
|
||||||
|
result, _ := r.conn.Exists(ctx, key).Result()
|
||||||
|
|
||||||
return result > 0
|
return result > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete 删除
|
// Delete 删除
|
||||||
func (r *Redis) Delete(key string) error {
|
func (r *Redis) Delete(key string) error {
|
||||||
return r.conn.Del(r.ctx, key).Err()
|
return r.DeleteContext(r.ctx, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteContext 删除
|
||||||
|
func (r *Redis) DeleteContext(ctx context.Context, key string) error {
|
||||||
|
return r.conn.Del(ctx, key).Err()
|
||||||
}
|
}
|
||||||
|
|||||||
10
cache/redis_test.go
vendored
10
cache/redis_test.go
vendored
@@ -4,17 +4,23 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/alicebob/miniredis/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRedis(t *testing.T) {
|
func TestRedis(t *testing.T) {
|
||||||
|
server, err := miniredis.Run()
|
||||||
|
if err != nil {
|
||||||
|
t.Error("miniredis.Run Error", err)
|
||||||
|
}
|
||||||
|
t.Cleanup(server.Close)
|
||||||
var (
|
var (
|
||||||
timeoutDuration = time.Second
|
timeoutDuration = time.Second
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
opts = &RedisOpts{
|
opts = &RedisOpts{
|
||||||
Host: "127.0.0.1:6379",
|
Host: server.Addr(),
|
||||||
}
|
}
|
||||||
redis = NewRedis(ctx, opts)
|
redis = NewRedis(ctx, opts)
|
||||||
err error
|
|
||||||
val = "silenceper"
|
val = "silenceper"
|
||||||
key = "username"
|
key = "username"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
package credential
|
package credential
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
// AccessTokenHandle AccessToken 接口
|
// AccessTokenHandle AccessToken 接口
|
||||||
type AccessTokenHandle interface {
|
type AccessTokenHandle interface {
|
||||||
GetAccessToken() (accessToken string, err error)
|
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
|
package credential
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -11,9 +12,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// AccessTokenURL 获取access_token的接口
|
// accessTokenURL 获取access_token的接口
|
||||||
accessTokenURL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"
|
accessTokenURL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"
|
||||||
// AccessTokenURL 企业微信获取access_token的接口
|
// stableAccessTokenURL 获取稳定版access_token的接口
|
||||||
|
stableAccessTokenURL = "https://api.weixin.qq.com/cgi-bin/stable_token"
|
||||||
|
// workAccessTokenURL 企业微信获取access_token的接口
|
||||||
workAccessTokenURL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s"
|
workAccessTokenURL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s"
|
||||||
// CacheKeyOfficialAccountPrefix 微信公众号cache key前缀
|
// CacheKeyOfficialAccountPrefix 微信公众号cache key前缀
|
||||||
CacheKeyOfficialAccountPrefix = "gowechat_officialaccount_"
|
CacheKeyOfficialAccountPrefix = "gowechat_officialaccount_"
|
||||||
@@ -33,7 +36,7 @@ type DefaultAccessToken struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewDefaultAccessToken new DefaultAccessToken
|
// 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 {
|
if cache == nil {
|
||||||
panic("cache is ineed")
|
panic("cache is ineed")
|
||||||
}
|
}
|
||||||
@@ -56,6 +59,11 @@ type ResAccessToken struct {
|
|||||||
|
|
||||||
// GetAccessToken 获取access_token,先从cache中获取,没有则从服务端获取
|
// GetAccessToken 获取access_token,先从cache中获取,没有则从服务端获取
|
||||||
func (ak *DefaultAccessToken) GetAccessToken() (accessToken string, err error) {
|
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中取
|
// 先从cache中取
|
||||||
accessTokenCacheKey := fmt.Sprintf("%s_access_token_%s", ak.cacheKeyPrefix, ak.appID)
|
accessTokenCacheKey := fmt.Sprintf("%s_access_token_%s", ak.cacheKeyPrefix, ak.appID)
|
||||||
if val := ak.cache.Get(accessTokenCacheKey); val != nil {
|
if val := ak.cache.Get(accessTokenCacheKey); val != nil {
|
||||||
@@ -73,17 +81,87 @@ func (ak *DefaultAccessToken) GetAccessToken() (accessToken string, err error) {
|
|||||||
|
|
||||||
// cache失效,从微信服务器获取
|
// cache失效,从微信服务器获取
|
||||||
var resAccessToken ResAccessToken
|
var resAccessToken ResAccessToken
|
||||||
resAccessToken, err = GetTokenFromServer(fmt.Sprintf(accessTokenURL, ak.appID, ak.appSecret))
|
if resAccessToken, err = GetTokenFromServerContext(ctx, fmt.Sprintf(accessTokenURL, ak.appID, ak.appSecret)); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = ak.cache.Set(accessTokenCacheKey, resAccessToken.AccessToken, time.Duration(resAccessToken.ExpiresIn-1500)*time.Second); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
accessToken = resAccessToken.AccessToken
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StableAccessToken 获取稳定版接口调用凭据(与getAccessToken获取的调用凭证完全隔离,互不影响)
|
||||||
|
// 不强制更新access_token,可用于不同环境不同服务而不需要分布式锁以及公用缓存,避免access_token争抢
|
||||||
|
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getStableAccessToken.html
|
||||||
|
type StableAccessToken struct {
|
||||||
|
appID string
|
||||||
|
appSecret string
|
||||||
|
cacheKeyPrefix string
|
||||||
|
cache cache.Cache
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewStableAccessToken new StableAccessToken
|
||||||
|
func NewStableAccessToken(appID, appSecret, cacheKeyPrefix string, cache cache.Cache) AccessTokenContextHandle {
|
||||||
|
if cache == nil {
|
||||||
|
panic("cache is need")
|
||||||
|
}
|
||||||
|
return &StableAccessToken{
|
||||||
|
appID: appID,
|
||||||
|
appSecret: appSecret,
|
||||||
|
cache: cache,
|
||||||
|
cacheKeyPrefix: cacheKeyPrefix,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAccessToken 获取access_token,先从cache中获取,没有则从服务端获取
|
||||||
|
func (ak *StableAccessToken) GetAccessToken() (accessToken string, err error) {
|
||||||
|
return ak.GetAccessTokenContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAccessTokenContext 获取access_token,先从cache中获取,没有则从服务端获取
|
||||||
|
func (ak *StableAccessToken) GetAccessTokenContext(ctx context.Context) (accessToken string, err error) {
|
||||||
|
// 先从cache中取
|
||||||
|
accessTokenCacheKey := fmt.Sprintf("%s_stable_access_token_%s", ak.cacheKeyPrefix, ak.appID)
|
||||||
|
if val := ak.cache.Get(accessTokenCacheKey); val != nil {
|
||||||
|
return val.(string), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// cache失效,从微信服务器获取
|
||||||
|
var resAccessToken ResAccessToken
|
||||||
|
resAccessToken, err = ak.GetAccessTokenDirectly(ctx, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
expires := resAccessToken.ExpiresIn - 1500
|
expires := resAccessToken.ExpiresIn - 300
|
||||||
err = ak.cache.Set(accessTokenCacheKey, resAccessToken.AccessToken, time.Duration(expires)*time.Second)
|
_ = ak.cache.Set(accessTokenCacheKey, resAccessToken.AccessToken, time.Duration(expires)*time.Second)
|
||||||
|
|
||||||
|
accessToken = resAccessToken.AccessToken
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAccessTokenDirectly 从微信获取access_token
|
||||||
|
func (ak *StableAccessToken) GetAccessTokenDirectly(ctx context.Context, forceRefresh bool) (resAccessToken ResAccessToken, err error) {
|
||||||
|
b, err := util.PostJSONContext(ctx, stableAccessTokenURL, map[string]interface{}{
|
||||||
|
"grant_type": "client_credential",
|
||||||
|
"appid": ak.appID,
|
||||||
|
"secret": ak.appSecret,
|
||||||
|
"force_refresh": forceRefresh,
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accessToken = resAccessToken.AccessToken
|
|
||||||
|
if err = json.Unmarshal(b, &resAccessToken); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if resAccessToken.ErrCode != 0 {
|
||||||
|
err = fmt.Errorf("get stable access_token error : errcode=%v , errormsg=%v", resAccessToken.ErrCode, resAccessToken.ErrMsg)
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +175,7 @@ type WorkAccessToken struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewWorkAccessToken new WorkAccessToken
|
// 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 {
|
if cache == nil {
|
||||||
panic("cache the not exist")
|
panic("cache the not exist")
|
||||||
}
|
}
|
||||||
@@ -112,6 +190,11 @@ func NewWorkAccessToken(corpID, corpSecret, cacheKeyPrefix string, cache cache.C
|
|||||||
|
|
||||||
// GetAccessToken 企业微信获取access_token,先从cache中获取,没有则从服务端获取
|
// GetAccessToken 企业微信获取access_token,先从cache中获取,没有则从服务端获取
|
||||||
func (ak *WorkAccessToken) GetAccessToken() (accessToken string, err error) {
|
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
|
// 加上lock,是为了防止在并发获取token时,cache刚好失效,导致从微信服务器上获取到不同token
|
||||||
ak.accessTokenLock.Lock()
|
ak.accessTokenLock.Lock()
|
||||||
defer ak.accessTokenLock.Unlock()
|
defer ak.accessTokenLock.Unlock()
|
||||||
@@ -124,7 +207,7 @@ func (ak *WorkAccessToken) GetAccessToken() (accessToken string, err error) {
|
|||||||
|
|
||||||
// cache失效,从微信服务器获取
|
// cache失效,从微信服务器获取
|
||||||
var resAccessToken ResAccessToken
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -140,8 +223,13 @@ func (ak *WorkAccessToken) GetAccessToken() (accessToken string, err error) {
|
|||||||
|
|
||||||
// GetTokenFromServer 强制从微信服务器获取token
|
// GetTokenFromServer 强制从微信服务器获取token
|
||||||
func GetTokenFromServer(url string) (resAccessToken ResAccessToken, err error) {
|
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
|
var body []byte
|
||||||
body, err = util.HTTPGet(url)
|
body, err = util.HTTPGetContext(ctx, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
2
doc.go
2
doc.go
@@ -7,4 +7,6 @@ Package wechat provide wechat sdk for go
|
|||||||
更多信息:https://github.com/silenceper/wechat
|
更多信息:https://github.com/silenceper/wechat
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Package wechat provide wechat sdk for go
|
||||||
package wechat
|
package wechat
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
# 微信公众号API列表
|
# 微信公众号 API 列表
|
||||||
|
|
||||||
## 基础接口
|
## 基础接口
|
||||||
|
|
||||||
[官方文档](https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html)
|
[官方文档](https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html)
|
||||||
|
|
||||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||||
| :---------------------: | -------- | :------------------------- | ---------- | -------- |
|
| :-----------------------: | -------- | :------------------------- | ---------- | -------- |
|
||||||
| 获取Access token | GET | /cgi-bin/token | YES | |
|
| 获取 Access token | GET | /cgi-bin/token | YES | |
|
||||||
| 获取微信服务器IP地址 | GET | /cgi-bin/get_api_domain_ip | YES | |
|
| 获取微信服务器 IP 地址 | GET | /cgi-bin/get_api_domain_ip | YES | |
|
||||||
| 获取微信callback IP地址 | GET | /cgi-bin/getcallbackip | YES | |
|
| 获取微信 callback IP 地址 | GET | /cgi-bin/getcallbackip | YES | |
|
||||||
| 清理接口调用次数 | POST | /cgi-bin/clear_quota | YES | |
|
| 清理接口调用次数 | POST | /cgi-bin/clear_quota | YES | |
|
||||||
|
|
||||||
## 订阅通知
|
## 订阅通知
|
||||||
|
|
||||||
[官方文档](https://developers.weixin.qq.com/doc/offiaccount/Subscription_Messages/api.html)
|
[官方文档](https://developers.weixin.qq.com/doc/offiaccount/Subscription_Messages/api.html)
|
||||||
|
|
||||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||||
| -------------------- | -------- | -------------------------------------- | ---------- | ----------------------- |
|
| -------------------- | -------- | -------------------------------------- | ---------- | -------------------------------------------- |
|
||||||
| 选用模板 | POST | /wxaapi/newtmpl/addtemplate | YES | (tpl *Subscribe) Add |
|
| 选用模板 | POST | /wxaapi/newtmpl/addtemplate | YES | (tpl \*Subscribe) Add |
|
||||||
| 删除模板 | POST | /wxaapi/newtmpl/deltemplate | YES | (tpl *Subscribe) Delete |
|
| 删除模板 | POST | /wxaapi/newtmpl/deltemplate | YES | (tpl \*Subscribe) Delete |
|
||||||
| 获取公众号类目 | GET | /wxaapi/newtmpl/getcategory | NO | |
|
| 获取公众号类目 | GET | /wxaapi/newtmpl/getcategory | YES | (tpl \*Subscribe) GetCategory |
|
||||||
| 获取模板中的关键词 | GET | /wxaapi/newtmpl/getpubtemplatekeywords | NO | |
|
| 获取模板中的关键词 | GET | /wxaapi/newtmpl/getpubtemplatekeywords | YES | (tpl \*Subscribe) GetPubTplKeyWordsByID |
|
||||||
| 获取类目下的公共模板 | GET | /wxaapi/newtmpl/getpubtemplatetitles | NO | |
|
| 获取类目下的公共模板 | GET | /wxaapi/newtmpl/getpubtemplatetitles | YES | (tpl \*Subscribe) GetPublicTemplateTitleList |
|
||||||
| 获取私有模板列表 | GET | /wxaapi/newtmpl/gettemplate | YES | (tpl *Subscribe) List() |
|
| 获取私有模板列表 | GET | /wxaapi/newtmpl/gettemplate | YES | (tpl \*Subscribe) List() |
|
||||||
| 发送订阅通知 | POST | /cgi-bin/message/subscribe/bizsend | YES | (tpl *Subscribe) Send |
|
| 发送订阅通知 | 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)
|
[官方文档](https://developers.weixin.qq.com/doc/offiaccount/Customer_Service/Customer_Service_Management.html)
|
||||||
|
|
||||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||||
| ---------------- | --------- | -------------------------------------- | ---------- | -------- |
|
| ---------------- | --------- | -------------------------------------- | ---------- | -------------------------------- |
|
||||||
| 获取客服基本信息 | GET | /cgi-bin/customservice/getkflist | NO | |
|
| 获取客服基本信息 | GET | /cgi-bin/customservice/getkflist | YES | (csm \*Manager) List |
|
||||||
| 添加客服帐号 | POST | /customservice/kfaccount/add | NO | |
|
| 添加客服帐号 | POST | /customservice/kfaccount/add | YES | (csm \*Manager) Add |
|
||||||
| 邀请绑定客服帐号 | POST | /customservice/kfaccount/inviteworker | NO | |
|
| 邀请绑定客服帐号 | POST | /customservice/kfaccount/inviteworker | YES | (csm \*Manager) InviteBind |
|
||||||
| 设置客服信息 | POST | /customservice/kfaccount/update | NO | |
|
| 设置客服信息 | POST | /customservice/kfaccount/update | YES | (csm \*Manager) Update |
|
||||||
| 上传客服头像 | POST/FORM | /customservice/kfaccount/uploadheadimg | NO | |
|
| 上传客服头像 | POST/FORM | /customservice/kfaccount/uploadheadimg | YES | (csm \*Manager) UploadHeadImg |
|
||||||
| 删除客服帐号 | GET | /customservice/kfaccount/del | NO | |
|
| 删除客服帐号 | 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)
|
[官方文档](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html)
|
||||||
|
|
||||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||||
| ------------------------------------------------------------ | -------- | --------------------------------------------------- | ---------- | ----------------------------------- |
|
| ----------------------------------------------------------------------- | -------- | --------------------------------------------------- | ---------- | ------------------------------------ |
|
||||||
| 获取跳转的url地址 | GET | https://open.weixin.qq.com/connect/oauth2/authorize | YES | (oauth *Oauth) GetRedirectURL |
|
| 获取跳转的 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 |
|
| 获取网页应用跳转的 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 |
|
| 通过网页授权的 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/oauth2/refresh_token? | YES | (oauth \*Oauth) RefreshAccessToken |
|
||||||
| 检验access_token是否有效 | GET | /sns/auth | YES | (oauth *Oauth) CheckAccessToken( |
|
| 检验 access_token 是否有效 | GET | /sns/auth | YES | (oauth \*Oauth) CheckAccessToken( |
|
||||||
| 拉取用户信息(需scope为 snsapi_userinfo) | GET | /sns/userinfo | YES | (oauth *Oauth) GetUserInfo |
|
| 拉取用户信息(需 scope 为 snsapi_userinfo) | GET | /sns/userinfo | YES | (oauth \*Oauth) GetUserInfo |
|
||||||
| 获取jssdk需要的配置参数 | GET | /cgi-bin/ticket/getticket | YES | (js *Js) GetConfig |
|
| 获取 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)
|
[官方文档](https://developers.weixin.qq.com/doc/offiaccount/Draft_Box/Add_draft.html)
|
||||||
|
|
||||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||||
| -------------------------- | -------- | ------------------------------------------------------------ | ---------- | ---------------------------- |
|
| --------------------------- | -------- | ------------------------------------------------------------ | ---------- | ----------------------------- |
|
||||||
| 新建草稿 | POST | /cgi-bin/draft/add | YES | (draft *Draft) AddDraft |
|
| 新建草稿 | POST | /cgi-bin/draft/add | YES | (draft \*Draft) AddDraft |
|
||||||
| 获取草稿 | POST | /cgi-bin/draft/get | YES | (draft *Draft) GetDraft |
|
| 获取草稿 | POST | /cgi-bin/draft/get | YES | (draft \*Draft) GetDraft |
|
||||||
| 删除草稿 | POST | /cgi-bin/draft/delete | YES | (draft *Draft) DeleteDraft |
|
| 删除草稿 | POST | /cgi-bin/draft/delete | YES | (draft \*Draft) DeleteDraft |
|
||||||
| 修改草稿 | POST | /cgi-bin/draft/update | YES | (draft *Draft) UpdateDraft |
|
| 修改草稿 | POST | /cgi-bin/draft/update | YES | (draft \*Draft) UpdateDraft |
|
||||||
| 获取草稿总数 | GET | /cgi-bin/draft/count | YES | (draft *Draft) CountDraft |
|
| 获取草稿总数 | GET | /cgi-bin/draft/count | YES | (draft \*Draft) CountDraft |
|
||||||
| 获取草稿列表 | POST | /cgi-bin/draft/batchget | YES | (draft *Draft) PaginateDraft |
|
| 获取草稿列表 | POST | /cgi-bin/draft/batchget | YES | (draft \*Draft) PaginateDraft |
|
||||||
| MP端开关(仅内测期间使用) | POST | /cgi-bin/draft/switch<br />/cgi-bin/draft/switch?checkonly=1 | NO | |
|
| MP 端开关(仅内测期间使用) | POST | /cgi-bin/draft/switch<br />/cgi-bin/draft/switch?checkonly=1 | NO | |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 发布能力
|
## 发布能力
|
||||||
|
|
||||||
@@ -185,20 +185,40 @@
|
|||||||
- 群发:主动推送给粉丝,历史消息可看,被搜一搜收录,可以限定部分的粉丝接收到。
|
- 群发:主动推送给粉丝,历史消息可看,被搜一搜收录,可以限定部分的粉丝接收到。
|
||||||
- 发布:不会主动推给粉丝,历史消息列表看不到,但是是公开给所有人的文章。也不会占用群发的次数。每天可以发布多篇内容。可以用于自动回复、自定义菜单、页面模板和话题中,发布成功时会生成一个永久链接。
|
- 发布:不会主动推给粉丝,历史消息列表看不到,但是是公开给所有人的文章。也不会占用群发的次数。每天可以发布多篇内容。可以用于自动回复、自定义菜单、页面模板和话题中,发布成功时会生成一个永久链接。
|
||||||
|
|
||||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||||
| ------------------------------ | -------- | ------------------------------- | ---------- | --------------------------------------- |
|
| ------------------------------ | -------- | ------------------------------- | ---------- | ---------------------------------------- |
|
||||||
| 发布接口 | POST | /cgi-bin/freepublish/submit | YES | (freePublish *FreePublish) Publish |
|
| 发布接口 | POST | /cgi-bin/freepublish/submit | YES | (freePublish \*FreePublish) Publish |
|
||||||
| 发布状态轮询接口 | POST | /cgi-bin/freepublish/get | YES | (freePublish *FreePublish) SelectStatus |
|
| 发布状态轮询接口 | POST | /cgi-bin/freepublish/get | YES | (freePublish \*FreePublish) SelectStatus |
|
||||||
| 事件推送发布结果 | | | YES | EventPublishJobFinish |
|
| 事件推送发布结果 | | | YES | EventPublishJobFinish |
|
||||||
| 删除发布 | POST | /cgi-bin/freepublish/delete | YES | (freePublish *FreePublish) Delete |
|
| 删除发布 | POST | /cgi-bin/freepublish/delete | YES | (freePublish \*FreePublish) Delete |
|
||||||
| 通过 article_id 获取已发布文章 | POST | /cgi-bin/freepublish/getarticle | YES | (freePublish *FreePublish) First |
|
| 通过 article_id 获取已发布文章 | POST | /cgi-bin/freepublish/getarticle | YES | (freePublish \*FreePublish) First |
|
||||||
| 获取成功发布列表 | POST | /cgi-bin/freepublish/batchget | YES | (freePublish *FreePublish) Paginate |
|
| 获取成功发布列表 | 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 |
|
| 获取客户基础信息 | POST | /cgi-bin/kf/customer/batchget | YES | (r *Client) CustomerBatchGet | NICEXAI |
|
||||||
| 获取视频号绑定状态 | GET | /cgi-bin/kf/get_corp_qualification | YES | (r *Client) GetCorpQualification | 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
|
TODO
|
||||||
|
|
||||||
|
|||||||
9
go.mod
9
go.mod
@@ -1,15 +1,16 @@
|
|||||||
module github.com/silenceper/wechat/v2
|
module github.com/silenceper/wechat/v2
|
||||||
|
|
||||||
go 1.14
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/alicebob/miniredis/v2 v2.30.0
|
||||||
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d
|
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d
|
||||||
github.com/fatih/structs v1.1.0
|
github.com/fatih/structs v1.1.0
|
||||||
github.com/go-redis/redis/v8 v8.11.6-0.20220405070650-99c79f7041fc
|
github.com/go-redis/redis/v8 v8.11.5
|
||||||
github.com/sirupsen/logrus v1.8.1
|
github.com/sirupsen/logrus v1.9.0
|
||||||
github.com/spf13/cast v1.4.1
|
github.com/spf13/cast v1.4.1
|
||||||
github.com/stretchr/testify v1.7.1
|
github.com/stretchr/testify v1.7.1
|
||||||
github.com/tidwall/gjson v1.14.1
|
github.com/tidwall/gjson v1.14.1
|
||||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
|
||||||
gopkg.in/h2non/gock.v1 v1.1.2
|
gopkg.in/h2non/gock.v1 v1.1.2
|
||||||
)
|
)
|
||||||
|
|||||||
42
go.sum
42
go.sum
@@ -1,3 +1,7 @@
|
|||||||
|
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk=
|
||||||
|
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc=
|
||||||
|
github.com/alicebob/miniredis/v2 v2.30.0 h1:uA3uhDbCxfO9+DI/DuGeAMr9qI+noVWwGPNTFuKID5M=
|
||||||
|
github.com/alicebob/miniredis/v2 v2.30.0/go.mod h1:84TWKZlxYkfgMucPBf5SOQBYJceZeQRFIaQgNMiCX6Q=
|
||||||
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d h1:pVrfxiGfwelyab6n21ZBkbkmbevaf+WvMIiR7sr97hw=
|
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d h1:pVrfxiGfwelyab6n21ZBkbkmbevaf+WvMIiR7sr97hw=
|
||||||
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
|
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
||||||
@@ -15,8 +19,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.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 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
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.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||||
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/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
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.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||||
@@ -26,12 +30,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.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
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.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/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.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.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.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/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/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
||||||
@@ -48,22 +50,22 @@ 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.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
||||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
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 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.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
||||||
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
|
||||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
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.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.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||||
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
|
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||||
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
|
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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
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.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
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 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
|
||||||
github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
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/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.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.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 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
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 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
|
||||||
@@ -73,11 +75,13 @@ github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JT
|
|||||||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
|
github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64 h1:5mLPGnFdSsevFRFc9q3yYbBkB6tsm4aCwwQV/j1JQAQ=
|
||||||
|
github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
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-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-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-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
||||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
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/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-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
@@ -85,18 +89,17 @@ 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-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-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-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-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-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-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
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-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-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-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-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -105,22 +108,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-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-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-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-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-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.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.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.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-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-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
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-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-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-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=
|
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-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||||
@@ -129,7 +130,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.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
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-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=
|
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 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
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 用户画像项目
|
// UserPortraitItem 用户画像项目
|
||||||
type UserPortraitItem struct {
|
type UserPortraitItem struct {
|
||||||
ID int `json:"id"` // 属性值id
|
ID int `json:"id"` // 属性值id
|
||||||
Name string `json:"name"` // 属性值名称
|
Name string `json:"name"` // 属性值名称
|
||||||
AccessSourceVisitUV int `json:"access_source_visit_uv"` // 该场景访问uv
|
Value int `json:"value"` // 该场景访问uv
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserPortrait 用户画像
|
// UserPortrait 用户画像
|
||||||
|
|||||||
@@ -84,7 +84,9 @@ func (auth *Auth) CheckEncryptedDataContext(ctx context2.Context, encryptedMsgHa
|
|||||||
if at, err = auth.GetAccessToken(); err != nil {
|
if at, err = auth.GetAccessToken(); err != nil {
|
||||||
return
|
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
|
return
|
||||||
}
|
}
|
||||||
if err = util.DecodeWithError(response, &result, "CheckEncryptedDataAuth"); err != nil {
|
if err = util.DecodeWithError(response, &result, "CheckEncryptedDataAuth"); err != nil {
|
||||||
@@ -111,8 +113,8 @@ type PhoneInfo struct {
|
|||||||
} `json:"watermark"` // 数据水印
|
} `json:"watermark"` // 数据水印
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPhoneNumber 小程序通过code获取用户手机号
|
// GetPhoneNumberContext 小程序通过code获取用户手机号
|
||||||
func (auth *Auth) GetPhoneNumber(code string) (*GetPhoneNumberResponse, error) {
|
func (auth *Auth) GetPhoneNumberContext(ctx context2.Context, code string) (*GetPhoneNumberResponse, error) {
|
||||||
var response []byte
|
var response []byte
|
||||||
var (
|
var (
|
||||||
at string
|
at string
|
||||||
@@ -124,12 +126,25 @@ func (auth *Auth) GetPhoneNumber(code string) (*GetPhoneNumberResponse, error) {
|
|||||||
body := map[string]interface{}{
|
body := map[string]interface{}{
|
||||||
"code": code,
|
"code": code,
|
||||||
}
|
}
|
||||||
if response, err = util.PostJSON(fmt.Sprintf(getPhoneNumber, at), body); err != nil {
|
|
||||||
|
bodyBytes, err := json.Marshal(body)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
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
|
var result GetPhoneNumberResponse
|
||||||
if err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber"); err != nil {
|
if err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result, nil
|
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 小程序
|
// Config .config for 小程序
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AppID string `json:"app_id"` // appid
|
AppID string `json:"app_id"` // appid
|
||||||
AppSecret string `json:"app_secret"` // appsecret
|
AppSecret string `json:"app_secret"` // appSecret
|
||||||
Cache cache.Cache
|
Cache cache.Cache
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ type ShortLinker struct {
|
|||||||
// resShortLinker 返回结构体
|
// resShortLinker 返回结构体
|
||||||
type resShortLinker struct {
|
type resShortLinker struct {
|
||||||
// 通用错误
|
// 通用错误
|
||||||
*util.CommonError
|
util.CommonError
|
||||||
|
|
||||||
// 返回的 shortLink
|
// 返回的 shortLink
|
||||||
Link string `json:"link"`
|
Link string `json:"link"`
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ type UniformMessage struct {
|
|||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Miniprogram struct {
|
Miniprogram struct {
|
||||||
Appid string `json:"appid"`
|
Appid string `json:"appid"`
|
||||||
Pagepath string `json:"page"`
|
Pagepath string `json:"pagepath"`
|
||||||
} `json:"miniprogram"`
|
} `json:"miniprogram"`
|
||||||
Data map[string]*DataItem `json:"data"`
|
Data map[string]*DataItem `json:"data"`
|
||||||
} `json:"mp_template_msg"`
|
} `json:"mp_template_msg"`
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ type InvokeCloudFunctionRes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InvokeCloudFunction 云函数调用
|
// InvokeCloudFunction 云函数调用
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/functions/invokeCloudFunction.html
|
//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) {
|
func (tcb *Tcb) InvokeCloudFunction(env, name, args string) (*InvokeCloudFunctionRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ type DatabaseCountRes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseMigrateImport 数据库导入
|
// DatabaseMigrateImport 数据库导入
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateImport.html
|
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateImport.html
|
||||||
func (tcb *Tcb) DatabaseMigrateImport(req *DatabaseMigrateImportReq) (*DatabaseMigrateImportRes, error) {
|
func (tcb *Tcb) DatabaseMigrateImport(req *DatabaseMigrateImportReq) (*DatabaseMigrateImportRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
@@ -209,6 +210,7 @@ func (tcb *Tcb) DatabaseMigrateImport(req *DatabaseMigrateImportReq) (*DatabaseM
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseMigrateExport 数据库导出
|
// DatabaseMigrateExport 数据库导出
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateExport.html
|
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateExport.html
|
||||||
func (tcb *Tcb) DatabaseMigrateExport(req *DatabaseMigrateExportReq) (*DatabaseMigrateExportRes, error) {
|
func (tcb *Tcb) DatabaseMigrateExport(req *DatabaseMigrateExportReq) (*DatabaseMigrateExportRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
@@ -226,6 +228,7 @@ func (tcb *Tcb) DatabaseMigrateExport(req *DatabaseMigrateExportReq) (*DatabaseM
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseMigrateQueryInfo 数据库迁移状态查询
|
// DatabaseMigrateQueryInfo 数据库迁移状态查询
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseMigrateQueryInfo.html
|
//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) {
|
func (tcb *Tcb) DatabaseMigrateQueryInfo(env string, jobID int64) (*DatabaseMigrateQueryInfoRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
@@ -261,6 +264,7 @@ func (tcb *Tcb) UpdateIndex(req *UpdateIndexReq) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseCollectionAdd 新增集合
|
// DatabaseCollectionAdd 新增集合
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionAdd.html
|
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionAdd.html
|
||||||
func (tcb *Tcb) DatabaseCollectionAdd(env, collectionName string) error {
|
func (tcb *Tcb) DatabaseCollectionAdd(env, collectionName string) error {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
@@ -279,6 +283,7 @@ func (tcb *Tcb) DatabaseCollectionAdd(env, collectionName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseCollectionDelete 删除集合
|
// DatabaseCollectionDelete 删除集合
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionDelete.html
|
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionDelete.html
|
||||||
func (tcb *Tcb) DatabaseCollectionDelete(env, collectionName string) error {
|
func (tcb *Tcb) DatabaseCollectionDelete(env, collectionName string) error {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
@@ -297,6 +302,7 @@ func (tcb *Tcb) DatabaseCollectionDelete(env, collectionName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseCollectionGet 获取特定云环境下集合信息
|
// DatabaseCollectionGet 获取特定云环境下集合信息
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCollectionGet.html
|
//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) {
|
func (tcb *Tcb) DatabaseCollectionGet(env string, limit, offset int64) (*DatabaseCollectionGetRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
@@ -318,6 +324,7 @@ func (tcb *Tcb) DatabaseCollectionGet(env string, limit, offset int64) (*Databas
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseAdd 数据库插入记录
|
// DatabaseAdd 数据库插入记录
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseAdd.html
|
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseAdd.html
|
||||||
func (tcb *Tcb) DatabaseAdd(env, query string) (*DatabaseAddRes, error) {
|
func (tcb *Tcb) DatabaseAdd(env, query string) (*DatabaseAddRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
@@ -338,6 +345,7 @@ func (tcb *Tcb) DatabaseAdd(env, query string) (*DatabaseAddRes, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseDelete 数据库插入记录
|
// DatabaseDelete 数据库插入记录
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseDelete.html
|
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseDelete.html
|
||||||
func (tcb *Tcb) DatabaseDelete(env, query string) (*DatabaseDeleteRes, error) {
|
func (tcb *Tcb) DatabaseDelete(env, query string) (*DatabaseDeleteRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
@@ -358,6 +366,7 @@ func (tcb *Tcb) DatabaseDelete(env, query string) (*DatabaseDeleteRes, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseUpdate 数据库插入记录
|
// DatabaseUpdate 数据库插入记录
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseUpdate.html
|
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseUpdate.html
|
||||||
func (tcb *Tcb) DatabaseUpdate(env, query string) (*DatabaseUpdateRes, error) {
|
func (tcb *Tcb) DatabaseUpdate(env, query string) (*DatabaseUpdateRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
@@ -378,6 +387,7 @@ func (tcb *Tcb) DatabaseUpdate(env, query string) (*DatabaseUpdateRes, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseQuery 数据库查询记录
|
// DatabaseQuery 数据库查询记录
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseQuery.html
|
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseQuery.html
|
||||||
func (tcb *Tcb) DatabaseQuery(env, query string) (*DatabaseQueryRes, error) {
|
func (tcb *Tcb) DatabaseQuery(env, query string) (*DatabaseQueryRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
@@ -398,6 +408,7 @@ func (tcb *Tcb) DatabaseQuery(env, query string) (*DatabaseQueryRes, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseCount 统计集合记录数或统计查询语句对应的结果记录数
|
// DatabaseCount 统计集合记录数或统计查询语句对应的结果记录数
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCount.html
|
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/database/databaseCount.html
|
||||||
func (tcb *Tcb) DatabaseCount(env, query string) (*DatabaseCountRes, error) {
|
func (tcb *Tcb) DatabaseCount(env, query string) (*DatabaseCountRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ type BatchDeleteFileRes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UploadFile 上传文件
|
// UploadFile 上传文件
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/uploadFile.html
|
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/uploadFile.html
|
||||||
func (tcb *Tcb) UploadFile(env, path string) (*UploadFileRes, error) {
|
func (tcb *Tcb) UploadFile(env, path string) (*UploadFileRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
@@ -92,6 +93,7 @@ func (tcb *Tcb) UploadFile(env, path string) (*UploadFileRes, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BatchDownloadFile 获取文件下载链接
|
// BatchDownloadFile 获取文件下载链接
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/batchDownloadFile.html
|
//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) {
|
func (tcb *Tcb) BatchDownloadFile(env string, fileList []*DownloadFile) (*BatchDownloadFileRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
accessToken, err := tcb.GetAccessToken()
|
||||||
@@ -113,6 +115,7 @@ func (tcb *Tcb) BatchDownloadFile(env string, fileList []*DownloadFile) (*BatchD
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BatchDeleteFile 批量删除文件
|
// BatchDeleteFile 批量删除文件
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/storage/batchDeleteFile.html
|
//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) {
|
func (tcb *Tcb) BatchDeleteFile(env string, fileIDList []string) (*BatchDeleteFileRes, error) {
|
||||||
accessToken, err := tcb.GetAccessToken()
|
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 批量获取永久素材
|
// BatchGetMaterial 批量获取永久素材
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html
|
//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) {
|
func (material *Material) BatchGetMaterial(permanentMaterialType PermanentMaterialType, offset, count int64) (list ArticleList, err error) {
|
||||||
var accessToken string
|
var accessToken string
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ type CustomerMessage struct {
|
|||||||
Wxcard *MediaWxcard `json:"wxcard,omitempty"` // 可选
|
Wxcard *MediaWxcard `json:"wxcard,omitempty"` // 可选
|
||||||
Msgmenu *MediaMsgmenu `json:"msgmenu,omitempty"` // 可选
|
Msgmenu *MediaMsgmenu `json:"msgmenu,omitempty"` // 可选
|
||||||
Miniprogrampage *MediaMiniprogrampage `json:"miniprogrampage,omitempty"` // 可选
|
Miniprogrampage *MediaMiniprogrampage `json:"miniprogrampage,omitempty"` // 可选
|
||||||
|
Mpnewsarticle *MediaArticle `json:"mpnewsarticle,omitempty"` // 可选
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCustomerTextMessage 文本消息结构体构造方法
|
// NewCustomerTextMessage 文本消息结构体构造方法
|
||||||
@@ -97,6 +98,11 @@ type MediaResource struct {
|
|||||||
MediaID string `json:"media_id"`
|
MediaID string `json:"media_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MediaArticle 消息使用的已发布文章id
|
||||||
|
type MediaArticle struct {
|
||||||
|
ArticleID string `json:"article_id"`
|
||||||
|
}
|
||||||
|
|
||||||
// MediaVideo 视频消息包含的内容
|
// MediaVideo 视频消息包含的内容
|
||||||
type MediaVideo struct {
|
type MediaVideo struct {
|
||||||
MediaID string `json:"media_id"`
|
MediaID string `json:"media_id"`
|
||||||
|
|||||||
@@ -68,6 +68,8 @@ const (
|
|||||||
EventPicWeixin EventType = "pic_weixin"
|
EventPicWeixin EventType = "pic_weixin"
|
||||||
// EventLocationSelect 弹出地理位置选择器的事件推送
|
// EventLocationSelect 弹出地理位置选择器的事件推送
|
||||||
EventLocationSelect EventType = "location_select"
|
EventLocationSelect EventType = "location_select"
|
||||||
|
// EventViewMiniprogram 点击菜单跳转小程序的事件推送
|
||||||
|
EventViewMiniprogram EventType = "view_miniprogram"
|
||||||
// EventTemplateSendJobFinish 发送模板消息推送通知
|
// EventTemplateSendJobFinish 发送模板消息推送通知
|
||||||
EventTemplateSendJobFinish EventType = "TEMPLATESENDJOBFINISH"
|
EventTemplateSendJobFinish EventType = "TEMPLATESENDJOBFINISH"
|
||||||
// EventMassSendJobFinish 群发消息推送通知
|
// EventMassSendJobFinish 群发消息推送通知
|
||||||
@@ -78,6 +80,12 @@ const (
|
|||||||
EventSubscribeMsgPopupEvent EventType = "subscribe_msg_popup_event"
|
EventSubscribeMsgPopupEvent EventType = "subscribe_msg_popup_event"
|
||||||
// EventPublishJobFinish 发布任务完成
|
// EventPublishJobFinish 发布任务完成
|
||||||
EventPublishJobFinish EventType = "PUBLISHJOBFINISH"
|
EventPublishJobFinish EventType = "PUBLISHJOBFINISH"
|
||||||
|
// EventWeappAuditSuccess 审核通过
|
||||||
|
EventWeappAuditSuccess EventType = "weapp_audit_success"
|
||||||
|
// EventWeappAuditFail 审核不通过
|
||||||
|
EventWeappAuditFail EventType = "weapp_audit_fail"
|
||||||
|
// EventWeappAuditDelay 审核延后
|
||||||
|
EventWeappAuditDelay EventType = "weapp_audit_delay"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -207,6 +215,13 @@ type MixMessage struct {
|
|||||||
|
|
||||||
// 设备相关
|
// 设备相关
|
||||||
device.MsgDevice
|
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 订阅通知事件推送的消息体
|
// SubscribeMsgPopupEvent 订阅通知事件推送的消息体
|
||||||
|
|||||||
@@ -8,10 +8,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
subscribeSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend"
|
subscribeSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend"
|
||||||
subscribeTemplateListURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
subscribeTemplateListURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
||||||
subscribeTemplateAddURL = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate"
|
subscribeTemplateAddURL = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate"
|
||||||
subscribeTemplateDelURL = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate"
|
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 订阅消息
|
// Subscribe 订阅消息
|
||||||
@@ -145,3 +148,108 @@ func (tpl *Subscribe) Delete(templateID string) (err error) {
|
|||||||
}
|
}
|
||||||
return util.DecodeWithCommonError(response, "DeleteSubscribe")
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,11 +29,12 @@ func NewTemplate(context *context.Context) *Template {
|
|||||||
|
|
||||||
// TemplateMessage 发送的模板消息内容
|
// TemplateMessage 发送的模板消息内容
|
||||||
type TemplateMessage struct {
|
type TemplateMessage struct {
|
||||||
ToUser string `json:"touser"` // 必须, 接受者OpenID
|
ToUser string `json:"touser"` // 必须, 接受者OpenID
|
||||||
TemplateID string `json:"template_id"` // 必须, 模版ID
|
TemplateID string `json:"template_id"` // 必须, 模版ID
|
||||||
URL string `json:"url,omitempty"` // 可选, 用户点击后跳转的URL, 该URL必须处于开发者在公众平台网站中设置的域中
|
URL string `json:"url,omitempty"` // 可选, 用户点击后跳转的URL, 该URL必须处于开发者在公众平台网站中设置的域中
|
||||||
Color string `json:"color,omitempty"` // 可选, 整个消息的颜色, 可以不设置
|
Color string `json:"color,omitempty"` // 可选, 整个消息的颜色, 可以不设置
|
||||||
Data map[string]*TemplateDataItem `json:"data"` // 必须, 模板数据
|
Data map[string]*TemplateDataItem `json:"data"` // 必须, 模板数据
|
||||||
|
ClientMsgID string `json:"client_msg_id,omitempty"` // 可选, 防重入ID
|
||||||
|
|
||||||
MiniProgram struct {
|
MiniProgram struct {
|
||||||
AppID string `json:"appid"` // 所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系)
|
AppID string `json:"appid"` // 所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系)
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ type ResAccessToken struct {
|
|||||||
OpenID string `json:"openid"`
|
OpenID string `json:"openid"`
|
||||||
Scope string `json:"scope"`
|
Scope string `json:"scope"`
|
||||||
|
|
||||||
|
// IsSnapShotUser 是否为快照页模式虚拟账号,只有当用户是快照页模式虚拟账号时返回,值为1
|
||||||
|
// 公众号文档 https://developers.weixin.qq.com/community/minihome/doc/000c2c34068880629ced91a2f56001
|
||||||
|
IsSnapShotUser int `json:"is_snapshotuser"`
|
||||||
|
|
||||||
// UnionID 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。
|
// UnionID 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。
|
||||||
// 公众号文档 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842
|
// 公众号文档 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140842
|
||||||
UnionID string `json:"unionid"`
|
UnionID string `json:"unionid"`
|
||||||
|
|||||||
@@ -154,134 +154,120 @@ func NewOCR(c *context.Context) *OCR {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IDCard 身份证OCR识别接口
|
// IDCard 身份证OCR识别接口
|
||||||
func (ocr *OCR) IDCard(path string) (ResIDCard ResIDCard, err error) {
|
func (ocr *OCR) IDCard(path string) (resIDCard ResIDCard, err error) {
|
||||||
accessToken, err := ocr.GetAccessToken()
|
accessToken, err := ocr.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrIDCardURL, url.QueryEscape(path), accessToken)
|
response, err := util.HTTPPost(fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrIDCardURL, url.QueryEscape(path), accessToken), "")
|
||||||
|
|
||||||
response, err := util.HTTPPost(uri, "")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = util.DecodeWithError(response, &ResIDCard, "OCRIDCard")
|
err = util.DecodeWithError(response, &resIDCard, "OCRIDCard")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// BankCard 银行卡OCR识别接口
|
// BankCard 银行卡OCR识别接口
|
||||||
func (ocr *OCR) BankCard(path string) (ResBankCard ResBankCard, err error) {
|
func (ocr *OCR) BankCard(path string) (resBankCard ResBankCard, err error) {
|
||||||
accessToken, err := ocr.GetAccessToken()
|
accessToken, err := ocr.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrBankCardURL, url.QueryEscape(path), accessToken)
|
response, err := util.HTTPPost(fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrBankCardURL, url.QueryEscape(path), accessToken), "")
|
||||||
|
|
||||||
response, err := util.HTTPPost(uri, "")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = util.DecodeWithError(response, &ResBankCard, "OCRBankCard")
|
err = util.DecodeWithError(response, &resBankCard, "OCRBankCard")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Driving 行驶证OCR识别接口
|
// Driving 行驶证OCR识别接口
|
||||||
func (ocr *OCR) Driving(path string) (ResDriving ResDriving, err error) {
|
func (ocr *OCR) Driving(path string) (resDriving ResDriving, err error) {
|
||||||
accessToken, err := ocr.GetAccessToken()
|
accessToken, err := ocr.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrDrivingURL, url.QueryEscape(path), accessToken)
|
response, err := util.HTTPPost(fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrDrivingURL, url.QueryEscape(path), accessToken), "")
|
||||||
|
|
||||||
response, err := util.HTTPPost(uri, "")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = util.DecodeWithError(response, &ResDriving, "OCRDriving")
|
err = util.DecodeWithError(response, &resDriving, "OCRDriving")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrivingLicense 驾驶证OCR识别接口
|
// DrivingLicense 驾驶证OCR识别接口
|
||||||
func (ocr *OCR) DrivingLicense(path string) (ResDrivingLicense ResDrivingLicense, err error) {
|
func (ocr *OCR) DrivingLicense(path string) (resDrivingLicense ResDrivingLicense, err error) {
|
||||||
accessToken, err := ocr.GetAccessToken()
|
accessToken, err := ocr.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrDrivingLicenseURL, url.QueryEscape(path), accessToken)
|
response, err := util.HTTPPost(fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrDrivingLicenseURL, url.QueryEscape(path), accessToken), "")
|
||||||
|
|
||||||
response, err := util.HTTPPost(uri, "")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = util.DecodeWithError(response, &ResDrivingLicense, "OCRDrivingLicense")
|
err = util.DecodeWithError(response, &resDrivingLicense, "OCRDrivingLicense")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// BizLicense 营业执照OCR识别接口
|
// BizLicense 营业执照OCR识别接口
|
||||||
func (ocr *OCR) BizLicense(path string) (ResBizLicense ResBizLicense, err error) {
|
func (ocr *OCR) BizLicense(path string) (resBizLicense ResBizLicense, err error) {
|
||||||
accessToken, err := ocr.GetAccessToken()
|
accessToken, err := ocr.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrBizLicenseURL, url.QueryEscape(path), accessToken)
|
response, err := util.HTTPPost(fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrBizLicenseURL, url.QueryEscape(path), accessToken), "")
|
||||||
|
|
||||||
response, err := util.HTTPPost(uri, "")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = util.DecodeWithError(response, &ResBizLicense, "OCRBizLicense")
|
err = util.DecodeWithError(response, &resBizLicense, "OCRBizLicense")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Common 通用印刷体OCR识别接口
|
// Common 通用印刷体OCR识别接口
|
||||||
func (ocr *OCR) Common(path string) (ResCommon ResCommon, err error) {
|
func (ocr *OCR) Common(path string) (resCommon ResCommon, err error) {
|
||||||
accessToken, err := ocr.GetAccessToken()
|
accessToken, err := ocr.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrCommonURL, url.QueryEscape(path), accessToken)
|
response, err := util.HTTPPost(fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrCommonURL, url.QueryEscape(path), accessToken), "")
|
||||||
|
|
||||||
response, err := util.HTTPPost(uri, "")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = util.DecodeWithError(response, &ResCommon, "OCRCommon")
|
err = util.DecodeWithError(response, &resCommon, "OCRCommon")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// PlateNumber 车牌OCR识别接口
|
// PlateNumber 车牌OCR识别接口
|
||||||
func (ocr *OCR) PlateNumber(path string) (ResPlateNumber ResPlateNumber, err error) {
|
func (ocr *OCR) PlateNumber(path string) (resPlateNumber ResPlateNumber, err error) {
|
||||||
accessToken, err := ocr.GetAccessToken()
|
accessToken, err := ocr.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrPlateNumberURL, url.QueryEscape(path), accessToken)
|
response, err := util.HTTPPost(fmt.Sprintf("%s?img_url=%s&access_token=%s", ocrPlateNumberURL, url.QueryEscape(path), accessToken), "")
|
||||||
|
|
||||||
response, err := util.HTTPPost(uri, "")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = util.DecodeWithError(response, &ResPlateNumber, "OCRPlateNumber")
|
err = util.DecodeWithError(response, &resPlateNumber, "OCRPlateNumber")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package officialaccount
|
package officialaccount
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
stdcontext "context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/draft"
|
"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/broadcast"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/config"
|
"github.com/silenceper/wechat/v2/officialaccount/config"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
"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/device"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/js"
|
"github.com/silenceper/wechat/v2/officialaccount/js"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/material"
|
"github.com/silenceper/wechat/v2/officialaccount/material"
|
||||||
@@ -26,7 +28,22 @@ import (
|
|||||||
|
|
||||||
// OfficialAccount 微信公众号相关API
|
// OfficialAccount 微信公众号相关API
|
||||||
type OfficialAccount struct {
|
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
|
// NewOfficialAccount 实例化公众号API
|
||||||
@@ -51,12 +68,18 @@ func (officialAccount *OfficialAccount) GetContext() *context.Context {
|
|||||||
|
|
||||||
// GetBasic qr/url 相关配置
|
// GetBasic qr/url 相关配置
|
||||||
func (officialAccount *OfficialAccount) GetBasic() *basic.Basic {
|
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 菜单管理接口
|
// GetMenu 菜单管理接口
|
||||||
func (officialAccount *OfficialAccount) GetMenu() *menu.Menu {
|
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 消息管理:接收事件,被动回复消息管理
|
// GetServer 消息管理:接收事件,被动回复消息管理
|
||||||
@@ -72,68 +95,120 @@ func (officialAccount *OfficialAccount) GetAccessToken() (string, error) {
|
|||||||
return officialAccount.ctx.GetAccessToken()
|
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网页授权
|
// GetOauth oauth2网页授权
|
||||||
func (officialAccount *OfficialAccount) GetOauth() *oauth.Oauth {
|
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 素材管理
|
// GetMaterial 素材管理
|
||||||
func (officialAccount *OfficialAccount) GetMaterial() *material.Material {
|
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 草稿箱
|
// GetDraft 草稿箱
|
||||||
func (officialAccount *OfficialAccount) GetDraft() *draft.Draft {
|
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 发布能力
|
// GetFreePublish 发布能力
|
||||||
func (officialAccount *OfficialAccount) GetFreePublish() *freepublish.FreePublish {
|
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配置
|
// GetJs js-sdk配置
|
||||||
func (officialAccount *OfficialAccount) GetJs() *js.Js {
|
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 用户管理接口
|
// GetUser 用户管理接口
|
||||||
func (officialAccount *OfficialAccount) GetUser() *user.User {
|
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 模板消息接口
|
// GetTemplate 模板消息接口
|
||||||
func (officialAccount *OfficialAccount) GetTemplate() *message.Template {
|
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 客服消息接口
|
// GetCustomerMessageManager 客服消息接口
|
||||||
func (officialAccount *OfficialAccount) GetCustomerMessageManager() *message.Manager {
|
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 获取智能设备的实例
|
// GetDevice 获取智能设备的实例
|
||||||
func (officialAccount *OfficialAccount) GetDevice() *device.Device {
|
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 群发消息
|
// GetBroadcast 群发消息
|
||||||
// TODO 待完善
|
// TODO 待完善
|
||||||
func (officialAccount *OfficialAccount) GetBroadcast() *broadcast.Broadcast {
|
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 数据统计
|
// GetDataCube 数据统计
|
||||||
func (officialAccount *OfficialAccount) GetDataCube() *datacube.DataCube {
|
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接口
|
// GetOCR OCR接口
|
||||||
func (officialAccount *OfficialAccount) GetOCR() *ocr.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 公众号订阅消息
|
// GetSubscribe 公众号订阅消息
|
||||||
func (officialAccount *OfficialAccount) GetSubscribe() *message.Subscribe {
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
@@ -13,11 +13,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/message"
|
"github.com/silenceper/wechat/v2/officialaccount/message"
|
||||||
"github.com/silenceper/wechat/v2/util"
|
"github.com/silenceper/wechat/v2/util"
|
||||||
"github.com/tidwall/gjson"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server struct
|
// Server struct
|
||||||
@@ -73,6 +73,11 @@ func (srv *Server) Serve() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// 非安全模式下,请求处理方法返回为nil则直接回复success给微信服务器
|
||||||
|
if response == nil && !srv.isSafeMode {
|
||||||
|
srv.String("success")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// debug print request msg
|
// debug print request msg
|
||||||
log.Debugf("request msg =%s", string(srv.RequestRawXMLMsg))
|
log.Debugf("request msg =%s", string(srv.RequestRawXMLMsg))
|
||||||
@@ -101,7 +106,7 @@ func (srv *Server) handleRequest() (reply *message.Reply, err error) {
|
|||||||
srv.isSafeMode = true
|
srv.isSafeMode = true
|
||||||
}
|
}
|
||||||
|
|
||||||
//set request contentType
|
// set request contentType
|
||||||
contentType := srv.Request.Header.Get("Content-Type")
|
contentType := srv.Request.Header.Get("Content-Type")
|
||||||
srv.isJSONContent = strings.Contains(contentType, "application/json")
|
srv.isJSONContent = strings.Contains(contentType, "application/json")
|
||||||
|
|
||||||
@@ -157,7 +162,7 @@ func (srv *Server) getMessage() (interface{}, error) {
|
|||||||
return nil, fmt.Errorf("消息解密失败, err=%v", err)
|
return nil, fmt.Errorf("消息解密失败, err=%v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rawXMLMsgBytes, err = ioutil.ReadAll(srv.Request.Body)
|
rawXMLMsgBytes, err = io.ReadAll(srv.Request.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("从body中解析xml失败, err=%v", err)
|
return nil, fmt.Errorf("从body中解析xml失败, err=%v", err)
|
||||||
}
|
}
|
||||||
@@ -188,7 +193,7 @@ func (srv *Server) parseRequestMessage(rawXMLMsgBytes []byte) (msg *message.MixM
|
|||||||
err = xml.Unmarshal(rawXMLMsgBytes, msg)
|
err = xml.Unmarshal(rawXMLMsgBytes, msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//parse json
|
// parse json
|
||||||
err = json.Unmarshal(rawXMLMsgBytes, msg)
|
err = json.Unmarshal(rawXMLMsgBytes, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
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)
|
||||||
|
}
|
||||||
@@ -2,11 +2,13 @@
|
|||||||
package context
|
package context
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/silenceper/wechat/v2/cache"
|
||||||
"github.com/silenceper/wechat/v2/util"
|
"github.com/silenceper/wechat/v2/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,24 +33,29 @@ type ComponentAccessToken struct {
|
|||||||
ExpiresIn int64 `json:"expires_in"`
|
ExpiresIn int64 `json:"expires_in"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetComponentAccessToken 获取 ComponentAccessToken
|
// GetComponentAccessTokenContext 获取 ComponentAccessToken
|
||||||
func (ctx *Context) GetComponentAccessToken() (string, error) {
|
func (ctx *Context) GetComponentAccessTokenContext(stdCtx context.Context) (string, error) {
|
||||||
accessTokenCacheKey := fmt.Sprintf("component_access_token_%s", ctx.AppID)
|
accessTokenCacheKey := fmt.Sprintf("component_access_token_%s", ctx.AppID)
|
||||||
val := ctx.Cache.Get(accessTokenCacheKey)
|
val := cache.GetContext(stdCtx, ctx.Cache, accessTokenCacheKey)
|
||||||
if val == nil {
|
if val == nil {
|
||||||
return "", fmt.Errorf("cann't get component access token")
|
return "", fmt.Errorf("cann't get component access token")
|
||||||
}
|
}
|
||||||
return val.(string), nil
|
return val.(string), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetComponentAccessToken 通过component_verify_ticket 获取 ComponentAccessToken
|
// GetComponentAccessToken 获取 ComponentAccessToken
|
||||||
func (ctx *Context) SetComponentAccessToken(verifyTicket string) (*ComponentAccessToken, error) {
|
func (ctx *Context) GetComponentAccessToken() (string, error) {
|
||||||
|
return ctx.GetComponentAccessTokenContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetComponentAccessTokenContext 通过component_verify_ticket 获取 ComponentAccessToken
|
||||||
|
func (ctx *Context) SetComponentAccessTokenContext(stdCtx context.Context, verifyTicket string) (*ComponentAccessToken, error) {
|
||||||
body := map[string]string{
|
body := map[string]string{
|
||||||
"component_appid": ctx.AppID,
|
"component_appid": ctx.AppID,
|
||||||
"component_appsecret": ctx.AppSecret,
|
"component_appsecret": ctx.AppSecret,
|
||||||
"component_verify_ticket": verifyTicket,
|
"component_verify_ticket": verifyTicket,
|
||||||
}
|
}
|
||||||
respBody, err := util.PostJSON(componentAccessTokenURL, body)
|
respBody, err := util.PostJSONContext(stdCtx, componentAccessTokenURL, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -64,15 +71,20 @@ func (ctx *Context) SetComponentAccessToken(verifyTicket string) (*ComponentAcce
|
|||||||
|
|
||||||
accessTokenCacheKey := fmt.Sprintf("component_access_token_%s", ctx.AppID)
|
accessTokenCacheKey := fmt.Sprintf("component_access_token_%s", ctx.AppID)
|
||||||
expires := at.ExpiresIn - 1500
|
expires := at.ExpiresIn - 1500
|
||||||
if err := ctx.Cache.Set(accessTokenCacheKey, at.AccessToken, time.Duration(expires)*time.Second); err != nil {
|
if err := cache.SetContext(stdCtx, ctx.Cache, accessTokenCacheKey, at.AccessToken, time.Duration(expires)*time.Second); err != nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return at, nil
|
return at, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPreCode 获取预授权码
|
// SetComponentAccessToken 通过component_verify_ticket 获取 ComponentAccessToken
|
||||||
func (ctx *Context) GetPreCode() (string, error) {
|
func (ctx *Context) SetComponentAccessToken(stdCtx context.Context, verifyTicket string) (*ComponentAccessToken, error) {
|
||||||
cat, err := ctx.GetComponentAccessToken()
|
return ctx.SetComponentAccessTokenContext(stdCtx, verifyTicket)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPreCodeContext 获取预授权码
|
||||||
|
func (ctx *Context) GetPreCodeContext(stdCtx context.Context) (string, error) {
|
||||||
|
cat, err := ctx.GetComponentAccessTokenContext(stdCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -80,7 +92,7 @@ func (ctx *Context) GetPreCode() (string, error) {
|
|||||||
"component_appid": ctx.AppID,
|
"component_appid": ctx.AppID,
|
||||||
}
|
}
|
||||||
uri := fmt.Sprintf(getPreCodeURL, cat)
|
uri := fmt.Sprintf(getPreCodeURL, cat)
|
||||||
body, err := util.PostJSON(uri, req)
|
body, err := util.PostJSONContext(stdCtx, uri, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -95,24 +107,39 @@ func (ctx *Context) GetPreCode() (string, error) {
|
|||||||
return ret.PreCode, nil
|
return ret.PreCode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetComponentLoginPage 获取第三方公众号授权链接(扫码授权)
|
// GetPreCode 获取预授权码
|
||||||
func (ctx *Context) GetComponentLoginPage(redirectURI string, authType int, bizAppID string) (string, error) {
|
func (ctx *Context) GetPreCode() (string, error) {
|
||||||
code, err := ctx.GetPreCode()
|
return ctx.GetPreCodeContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetComponentLoginPageContext 获取第三方公众号授权链接(扫码授权)
|
||||||
|
func (ctx *Context) GetComponentLoginPageContext(stdCtx context.Context, redirectURI string, authType int, bizAppID string) (string, error) {
|
||||||
|
code, err := ctx.GetPreCodeContext(stdCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return fmt.Sprintf(componentLoginURL, ctx.AppID, code, url.QueryEscape(redirectURI), authType, bizAppID), nil
|
return fmt.Sprintf(componentLoginURL, ctx.AppID, code, url.QueryEscape(redirectURI), authType, bizAppID), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBindComponentURL 获取第三方公众号授权链接(链接跳转,适用移动端)
|
// GetComponentLoginPage 获取第三方公众号授权链接(扫码授权)
|
||||||
func (ctx *Context) GetBindComponentURL(redirectURI string, authType int, bizAppID string) (string, error) {
|
func (ctx *Context) GetComponentLoginPage(redirectURI string, authType int, bizAppID string) (string, error) {
|
||||||
code, err := ctx.GetPreCode()
|
return ctx.GetComponentLoginPageContext(context.Background(), redirectURI, authType, bizAppID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetBindComponentURLContext 获取第三方公众号授权链接(链接跳转,适用移动端)
|
||||||
|
func (ctx *Context) GetBindComponentURLContext(stdCtx context.Context, redirectURI string, authType int, bizAppID string) (string, error) {
|
||||||
|
code, err := ctx.GetPreCodeContext(stdCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return fmt.Sprintf(bindComponentURL, authType, ctx.AppID, code, url.QueryEscape(redirectURI), bizAppID), nil
|
return fmt.Sprintf(bindComponentURL, authType, ctx.AppID, code, url.QueryEscape(redirectURI), bizAppID), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBindComponentURL 获取第三方公众号授权链接(链接跳转,适用移动端)
|
||||||
|
func (ctx *Context) GetBindComponentURL(redirectURI string, authType int, bizAppID string) (string, error) {
|
||||||
|
return ctx.GetBindComponentURLContext(context.Background(), redirectURI, authType, bizAppID)
|
||||||
|
}
|
||||||
|
|
||||||
// ID 微信返回接口中各种类型字段
|
// ID 微信返回接口中各种类型字段
|
||||||
type ID struct {
|
type ID struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
@@ -137,9 +164,9 @@ type AuthrAccessToken struct {
|
|||||||
RefreshToken string `json:"authorizer_refresh_token"`
|
RefreshToken string `json:"authorizer_refresh_token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryAuthCode 使用授权码换取公众号或小程序的接口调用凭据和授权信息
|
// QueryAuthCodeContext 使用授权码换取公众号或小程序的接口调用凭据和授权信息
|
||||||
func (ctx *Context) QueryAuthCode(authCode string) (*AuthBaseInfo, error) {
|
func (ctx *Context) QueryAuthCodeContext(stdCtx context.Context, authCode string) (*AuthBaseInfo, error) {
|
||||||
cat, err := ctx.GetComponentAccessToken()
|
cat, err := ctx.GetComponentAccessTokenContext(stdCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -149,7 +176,7 @@ func (ctx *Context) QueryAuthCode(authCode string) (*AuthBaseInfo, error) {
|
|||||||
"authorization_code": authCode,
|
"authorization_code": authCode,
|
||||||
}
|
}
|
||||||
uri := fmt.Sprintf(queryAuthURL, cat)
|
uri := fmt.Sprintf(queryAuthURL, cat)
|
||||||
body, err := util.PostJSON(uri, req)
|
body, err := util.PostJSONContext(stdCtx, uri, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -169,9 +196,14 @@ func (ctx *Context) QueryAuthCode(authCode string) (*AuthBaseInfo, error) {
|
|||||||
return ret.Info, nil
|
return ret.Info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RefreshAuthrToken 获取(刷新)授权公众号或小程序的接口调用凭据(令牌)
|
// QueryAuthCode 使用授权码换取公众号或小程序的接口调用凭据和授权信息
|
||||||
func (ctx *Context) RefreshAuthrToken(appid, refreshToken string) (*AuthrAccessToken, error) {
|
func (ctx *Context) QueryAuthCode(authCode string) (*AuthBaseInfo, error) {
|
||||||
cat, err := ctx.GetComponentAccessToken()
|
return ctx.QueryAuthCodeContext(context.Background(), authCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RefreshAuthrTokenContext 获取(刷新)授权公众号或小程序的接口调用凭据(令牌)
|
||||||
|
func (ctx *Context) RefreshAuthrTokenContext(stdCtx context.Context, appid, refreshToken string) (*AuthrAccessToken, error) {
|
||||||
|
cat, err := ctx.GetComponentAccessTokenContext(stdCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -182,7 +214,7 @@ func (ctx *Context) RefreshAuthrToken(appid, refreshToken string) (*AuthrAccessT
|
|||||||
"authorizer_refresh_token": refreshToken,
|
"authorizer_refresh_token": refreshToken,
|
||||||
}
|
}
|
||||||
uri := fmt.Sprintf(refreshTokenURL, cat)
|
uri := fmt.Sprintf(refreshTokenURL, cat)
|
||||||
body, err := util.PostJSON(uri, req)
|
body, err := util.PostJSONContext(stdCtx, uri, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -193,22 +225,32 @@ func (ctx *Context) RefreshAuthrToken(appid, refreshToken string) (*AuthrAccessT
|
|||||||
}
|
}
|
||||||
|
|
||||||
authrTokenKey := "authorizer_access_token_" + appid
|
authrTokenKey := "authorizer_access_token_" + appid
|
||||||
if err := ctx.Cache.Set(authrTokenKey, ret.AccessToken, time.Minute*80); err != nil {
|
if err := cache.SetContext(stdCtx, ctx.Cache, authrTokenKey, ret.AccessToken, time.Second*time.Duration(ret.ExpiresIn-30)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAuthrAccessToken 获取授权方AccessToken
|
// RefreshAuthrToken 获取(刷新)授权公众号或小程序的接口调用凭据(令牌)
|
||||||
func (ctx *Context) GetAuthrAccessToken(appid string) (string, error) {
|
func (ctx *Context) RefreshAuthrToken(appid, refreshToken string) (*AuthrAccessToken, error) {
|
||||||
|
return ctx.RefreshAuthrTokenContext(context.Background(), appid, refreshToken)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAuthrAccessTokenContext 获取授权方AccessToken
|
||||||
|
func (ctx *Context) GetAuthrAccessTokenContext(stdCtx context.Context, appid string) (string, error) {
|
||||||
authrTokenKey := "authorizer_access_token_" + appid
|
authrTokenKey := "authorizer_access_token_" + appid
|
||||||
val := ctx.Cache.Get(authrTokenKey)
|
val := cache.GetContext(stdCtx, ctx.Cache, authrTokenKey)
|
||||||
if val == nil {
|
if val == nil {
|
||||||
return "", fmt.Errorf("cannot get authorizer %s access token", appid)
|
return "", fmt.Errorf("cannot get authorizer %s access token", appid)
|
||||||
}
|
}
|
||||||
return val.(string), nil
|
return val.(string), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAuthrAccessToken 获取授权方AccessToken
|
||||||
|
func (ctx *Context) GetAuthrAccessToken(appid string) (string, error) {
|
||||||
|
return ctx.GetAuthrAccessTokenContext(context.Background(), appid)
|
||||||
|
}
|
||||||
|
|
||||||
// AuthorizerInfo 授权方详细信息
|
// AuthorizerInfo 授权方详细信息
|
||||||
type AuthorizerInfo struct {
|
type AuthorizerInfo struct {
|
||||||
NickName string `json:"nick_name"`
|
NickName string `json:"nick_name"`
|
||||||
@@ -226,11 +268,41 @@ type AuthorizerInfo struct {
|
|||||||
}
|
}
|
||||||
Alias string `json:"alias"`
|
Alias string `json:"alias"`
|
||||||
QrcodeURL string `json:"qrcode_url"`
|
QrcodeURL string `json:"qrcode_url"`
|
||||||
|
|
||||||
|
MiniProgramInfo *MiniProgramInfo `json:"MiniProgramInfo"`
|
||||||
|
RegisterType int `json:"register_type"`
|
||||||
|
AccountStatus int `json:"account_status"`
|
||||||
|
BasicConfig *AuthorizerBasicConfig `json:"basic_config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAuthrInfo 获取授权方的帐号基本信息
|
// AuthorizerBasicConfig 授权账号的基础配置结构体
|
||||||
func (ctx *Context) GetAuthrInfo(appid string) (*AuthorizerInfo, *AuthBaseInfo, error) {
|
type AuthorizerBasicConfig struct {
|
||||||
cat, err := ctx.GetComponentAccessToken()
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAuthrInfoContext 获取授权方的帐号基本信息
|
||||||
|
func (ctx *Context) GetAuthrInfoContext(stdCtx context.Context, appid string) (*AuthorizerInfo, *AuthBaseInfo, error) {
|
||||||
|
cat, err := ctx.GetComponentAccessTokenContext(stdCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -241,7 +313,7 @@ func (ctx *Context) GetAuthrInfo(appid string) (*AuthorizerInfo, *AuthBaseInfo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf(getComponentInfoURL, cat)
|
uri := fmt.Sprintf(getComponentInfoURL, cat)
|
||||||
body, err := util.PostJSON(uri, req)
|
body, err := util.PostJSONContext(stdCtx, uri, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -256,3 +328,8 @@ func (ctx *Context) GetAuthrInfo(appid string) (*AuthorizerInfo, *AuthBaseInfo,
|
|||||||
|
|
||||||
return ret.AuthorizerInfo, ret.AuthorizationInfo, nil
|
return ret.AuthorizerInfo, ret.AuthorizationInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAuthrInfo 获取授权方的帐号基本信息
|
||||||
|
func (ctx *Context) GetAuthrInfo(appid string) (*AuthorizerInfo, *AuthBaseInfo, error) {
|
||||||
|
return ctx.GetAuthrInfoContext(context.Background(), appid)
|
||||||
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ type AccountBasicInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetAccountBasicInfo 获取小程序基础信息
|
// GetAccountBasicInfo 获取小程序基础信息
|
||||||
|
//
|
||||||
//reference:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/Mini_Program_Information_Settings.html
|
//reference:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/Mini_Program_Information_Settings.html
|
||||||
func (basic *Basic) GetAccountBasicInfo() (*AccountBasicInfo, error) {
|
func (basic *Basic) GetAccountBasicInfo() (*AccountBasicInfo, error) {
|
||||||
ak, err := basic.GetAuthrAccessToken(basic.AppID)
|
ak, err := basic.GetAuthrAccessToken(basic.AppID)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type RegisterMiniProgramParam struct {
|
|||||||
func (component *Component) RegisterMiniProgram(param *RegisterMiniProgramParam) error {
|
func (component *Component) RegisterMiniProgram(param *RegisterMiniProgramParam) error {
|
||||||
componentAK, err := component.GetComponentAccessToken()
|
componentAK, err := component.GetComponentAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
url := fmt.Sprintf(fastregisterweappURL+"?action=create&component_access_token=%s", componentAK)
|
url := fmt.Sprintf(fastregisterweappURL+"?action=create&component_access_token=%s", componentAK)
|
||||||
data, err := util.PostJSON(url, param)
|
data, err := util.PostJSON(url, param)
|
||||||
@@ -58,7 +58,7 @@ type GetRegistrationStatusParam struct {
|
|||||||
func (component *Component) GetRegistrationStatus(param *GetRegistrationStatusParam) error {
|
func (component *Component) GetRegistrationStatus(param *GetRegistrationStatusParam) error {
|
||||||
componentAK, err := component.GetComponentAccessToken()
|
componentAK, err := component.GetComponentAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
url := fmt.Sprintf(fastregisterweappURL+"?action=search&component_access_token=%s", componentAK)
|
url := fmt.Sprintf(fastregisterweappURL+"?action=search&component_access_token=%s", componentAK)
|
||||||
data, err := util.PostJSON(url, param)
|
data, err := util.PostJSON(url, param)
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
package miniprogram
|
package miniprogram
|
||||||
|
|
||||||
import (
|
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"
|
openContext "github.com/silenceper/wechat/v2/openplatform/context"
|
||||||
"github.com/silenceper/wechat/v2/openplatform/miniprogram/basic"
|
"github.com/silenceper/wechat/v2/openplatform/miniprogram/basic"
|
||||||
"github.com/silenceper/wechat/v2/openplatform/miniprogram/component"
|
"github.com/silenceper/wechat/v2/openplatform/miniprogram/component"
|
||||||
@@ -10,14 +17,41 @@ import (
|
|||||||
type MiniProgram struct {
|
type MiniProgram struct {
|
||||||
AppID string
|
AppID string
|
||||||
openContext *openContext.Context
|
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 实例化
|
// NewMiniProgram 实例化
|
||||||
func NewMiniProgram(opCtx *openContext.Context, appID string) *MiniProgram {
|
func NewMiniProgram(opCtx *openContext.Context, appID string) *MiniProgram {
|
||||||
return &MiniProgram{
|
miniProgram := miniprogram.NewMiniProgram(&miniConfig.Config{
|
||||||
openContext: opCtx,
|
AppID: opCtx.AppID,
|
||||||
AppID: appID,
|
Cache: opCtx.Cache,
|
||||||
}
|
})
|
||||||
|
// 设置获取access_token的函数
|
||||||
|
miniProgram.SetAccessTokenHandle(NewDefaultAuthrAccessToken(opCtx, appID))
|
||||||
|
return &MiniProgram{AppID: appID, MiniProgram: miniProgram, openContext: opCtx}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetComponent get component
|
// GetComponent get component
|
||||||
@@ -30,3 +64,29 @@ func (miniProgram *MiniProgram) GetComponent() *component.Component {
|
|||||||
func (miniProgram *MiniProgram) GetBasic() *basic.Basic {
|
func (miniProgram *MiniProgram) GetBasic() *basic.Basic {
|
||||||
return basic.NewBasic(miniProgram.openContext, miniProgram.AppID)
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -18,9 +18,6 @@ type OpenPlatform struct {
|
|||||||
|
|
||||||
// NewOpenPlatform new openplatform
|
// NewOpenPlatform new openplatform
|
||||||
func NewOpenPlatform(cfg *config.Config) *OpenPlatform {
|
func NewOpenPlatform(cfg *config.Config) *OpenPlatform {
|
||||||
if cfg.Cache == nil {
|
|
||||||
panic("cache 未设置")
|
|
||||||
}
|
|
||||||
ctx := &context.Context{
|
ctx := &context.Context{
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ type RefundedResp struct {
|
|||||||
|
|
||||||
// DecryptReqInfo 对退款结果进行解密
|
// DecryptReqInfo 对退款结果进行解密
|
||||||
func (notify *Notify) DecryptReqInfo(result *RefundedResult) (*RefundedReqInfo, error) {
|
func (notify *Notify) DecryptReqInfo(result *RefundedResult) (*RefundedReqInfo, error) {
|
||||||
var err error
|
|
||||||
if result == nil || result.ReqInfo == nil {
|
if result == nil || result.ReqInfo == nil {
|
||||||
return nil, errors.New("empty refunded_result or req_info")
|
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
|
// BridgeAppConfig get app bridge config
|
||||||
func (o *Order) BridgeAppConfig(p *Params) (cfg ConfigForApp, err error) {
|
func (o *Order) BridgeAppConfig(p *Params) (cfg ConfigForApp, err error) {
|
||||||
var (
|
var (
|
||||||
timestamp = strconv.FormatInt(time.Now().Unix(), 10)
|
timestamp = strconv.FormatInt(util.GetCurrTS(), 10)
|
||||||
noncestr = util.RandomStr(32)
|
noncestr = util.RandomStr(32)
|
||||||
_package = "Sign=WXPay"
|
_package = "Sign=WXPay"
|
||||||
)
|
)
|
||||||
@@ -273,7 +273,7 @@ func (o *Order) PrePayOrder(p *Params) (payOrder PreOrder, err error) {
|
|||||||
return
|
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) {
|
func (o *Order) PrePayID(p *Params) (prePayID string, err error) {
|
||||||
order, err := o.PrePayOrder(p)
|
order, err := o.PrePayOrder(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -23,12 +23,12 @@ func (pay *Pay) GetOrder() *order.Order {
|
|||||||
return order.NewOrder(pay.cfg)
|
return order.NewOrder(pay.cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNotify 通知
|
// GetNotify 通知
|
||||||
func (pay *Pay) GetNotify() *notify.Notify {
|
func (pay *Pay) GetNotify() *notify.Notify {
|
||||||
return notify.NewNotify(pay.cfg)
|
return notify.NewNotify(pay.cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRefund 退款
|
// GetRefund 退款
|
||||||
func (pay *Pay) GetRefund() *refund.Refund {
|
func (pay *Pay) GetRefund() *refund.Refund {
|
||||||
return refund.NewRefund(pay.cfg)
|
return refund.NewRefund(pay.cfg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/silenceper/wechat/v2/util"
|
"github.com/silenceper/wechat/v2/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 付款到零钱
|
// walletTransferGateway 付款到零钱
|
||||||
// https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
|
// 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"
|
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
|
// NewTransfer return an instance of Transfer package
|
||||||
func NewTransfer(cfg *config.Config) *Transfer {
|
func NewTransfer(cfg *config.Config) *Transfer {
|
||||||
transfer := Transfer{cfg}
|
return &Transfer{cfg}
|
||||||
return &transfer
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Params 调用参数
|
// Params 调用参数
|
||||||
|
|||||||
@@ -8,10 +8,24 @@ import (
|
|||||||
|
|
||||||
// CommonError 微信返回的通用错误json
|
// CommonError 微信返回的通用错误json
|
||||||
type CommonError struct {
|
type CommonError struct {
|
||||||
|
apiName string
|
||||||
ErrCode int64 `json:"errcode"`
|
ErrCode int64 `json:"errcode"`
|
||||||
ErrMsg string `json:"errmsg"`
|
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解析
|
// DecodeWithCommonError 将返回值按照CommonError解析
|
||||||
func DecodeWithCommonError(response []byte, apiName string) (err error) {
|
func DecodeWithCommonError(response []byte, apiName string) (err error) {
|
||||||
var commError CommonError
|
var commError CommonError
|
||||||
@@ -19,8 +33,9 @@ func DecodeWithCommonError(response []byte, apiName string) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
commError.apiName = apiName
|
||||||
if commError.ErrCode != 0 {
|
if commError.ErrCode != 0 {
|
||||||
return fmt.Errorf("%s Error , errcode=%d , errmsg=%s", apiName, commError.ErrCode, commError.ErrMsg)
|
return &commError
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -45,7 +60,11 @@ func DecodeWithError(response []byte, obj interface{}, apiName string) error {
|
|||||||
return fmt.Errorf("errcode or errmsg is invalid")
|
return fmt.Errorf("errcode or errmsg is invalid")
|
||||||
}
|
}
|
||||||
if errCode.Int() != 0 {
|
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
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
50
util/http.go
50
util/http.go
@@ -9,7 +9,6 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
"log"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -38,21 +37,26 @@ func HTTPGetContext(ctx context.Context, uri string) ([]byte, error) {
|
|||||||
if response.StatusCode != http.StatusOK {
|
if response.StatusCode != http.StatusOK {
|
||||||
return nil, fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
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 请求
|
// HTTPPost post 请求
|
||||||
func HTTPPost(uri string, data string) ([]byte, error) {
|
func HTTPPost(uri string, data string) ([]byte, error) {
|
||||||
return HTTPPostContext(context.Background(), uri, data)
|
return HTTPPostContext(context.Background(), uri, []byte(data), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTPPostContext post 请求
|
// HTTPPostContext post 请求
|
||||||
func HTTPPostContext(ctx context.Context, uri string, data string) ([]byte, error) {
|
func HTTPPostContext(ctx context.Context, uri string, data []byte, header map[string]string) ([]byte, error) {
|
||||||
body := bytes.NewBuffer([]byte(data))
|
body := bytes.NewBuffer(data)
|
||||||
request, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, body)
|
request, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for key, value := range header {
|
||||||
|
request.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
response, err := http.DefaultClient.Do(request)
|
response, err := http.DefaultClient.Do(request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -60,13 +64,13 @@ func HTTPPostContext(ctx context.Context, uri string, data string) ([]byte, erro
|
|||||||
|
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
if response.StatusCode != http.StatusOK {
|
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 数据请求
|
// PostJSONContext post json 数据请求
|
||||||
func PostJSON(uri string, obj interface{}) ([]byte, error) {
|
func PostJSONContext(ctx context.Context, uri string, obj interface{}) ([]byte, error) {
|
||||||
jsonBuf := new(bytes.Buffer)
|
jsonBuf := new(bytes.Buffer)
|
||||||
enc := json.NewEncoder(jsonBuf)
|
enc := json.NewEncoder(jsonBuf)
|
||||||
enc.SetEscapeHTML(false)
|
enc.SetEscapeHTML(false)
|
||||||
@@ -74,7 +78,12 @@ func PostJSON(uri string, obj interface{}) ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
response, err := http.Post(uri, "application/json;charset=utf-8", jsonBuf)
|
req, err := http.NewRequestWithContext(ctx, "POST", uri, jsonBuf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
req.Header.Set("Content-Type", "application/json;charset=utf-8")
|
||||||
|
response, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -83,7 +92,12 @@ func PostJSON(uri string, obj interface{}) ([]byte, error) {
|
|||||||
if response.StatusCode != http.StatusOK {
|
if response.StatusCode != http.StatusOK {
|
||||||
return nil, fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
return nil, fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
||||||
}
|
}
|
||||||
return ioutil.ReadAll(response.Body)
|
return io.ReadAll(response.Body)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostJSON post json 数据请求
|
||||||
|
func PostJSON(uri string, obj interface{}) ([]byte, error) {
|
||||||
|
return PostJSONContext(context.Background(), uri, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostJSONWithRespContentType post json数据请求,且返回数据类型
|
// PostJSONWithRespContentType post json数据请求,且返回数据类型
|
||||||
@@ -105,17 +119,17 @@ func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, e
|
|||||||
if response.StatusCode != http.StatusOK {
|
if response.StatusCode != http.StatusOK {
|
||||||
return nil, "", fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
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")
|
contentType := response.Header.Get("Content-Type")
|
||||||
return responseData, contentType, err
|
return responseData, contentType, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// PostFile 上传文件
|
// PostFile 上传文件
|
||||||
func PostFile(fieldname, filename, uri string) ([]byte, error) {
|
func PostFile(fieldName, filename, uri string) ([]byte, error) {
|
||||||
fields := []MultipartFormField{
|
fields := []MultipartFormField{
|
||||||
{
|
{
|
||||||
IsFile: true,
|
IsFile: true,
|
||||||
Fieldname: fieldname,
|
Fieldname: fieldName,
|
||||||
Filename: filename,
|
Filename: filename,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -178,7 +192,7 @@ func PostMultipartForm(fields []MultipartFormField, uri string) (respBody []byte
|
|||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
respBody, err = ioutil.ReadAll(resp.Body)
|
respBody, err = io.ReadAll(resp.Body)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,13 +213,13 @@ func PostXML(uri string, obj interface{}) ([]byte, error) {
|
|||||||
if response.StatusCode != http.StatusOK {
|
if response.StatusCode != http.StatusOK {
|
||||||
return nil, fmt.Errorf("http code error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
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证书
|
// httpWithTLS CA证书
|
||||||
func httpWithTLS(rootCa, key string) (*http.Client, error) {
|
func httpWithTLS(rootCa, key string) (*http.Client, error) {
|
||||||
var client *http.Client
|
var client *http.Client
|
||||||
certData, err := ioutil.ReadFile(rootCa)
|
certData, err := os.ReadFile(rootCa)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to find cert path=%s, error=%v", rootCa, err)
|
return nil, fmt.Errorf("unable to find cert path=%s, error=%v", rootCa, err)
|
||||||
}
|
}
|
||||||
@@ -264,5 +278,5 @@ func PostXMLWithTLS(uri string, obj interface{}, ca, key string) ([]byte, error)
|
|||||||
if response.StatusCode != http.StatusOK {
|
if response.StatusCode != http.StatusOK {
|
||||||
return nil, fmt.Errorf("http code error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
return nil, fmt.Errorf("http code error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
||||||
}
|
}
|
||||||
return ioutil.ReadAll(response.Body)
|
return io.ReadAll(response.Body)
|
||||||
}
|
}
|
||||||
|
|||||||
10
wechat.go
10
wechat.go
@@ -41,8 +41,8 @@ func NewWechat() *Wechat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetCache 设置cache
|
// SetCache 设置cache
|
||||||
func (wc *Wechat) SetCache(cahce cache.Cache) {
|
func (wc *Wechat) SetCache(cache cache.Cache) {
|
||||||
wc.cache = cahce
|
wc.cache = cache
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOfficialAccount 获取微信公众号实例
|
// GetOfficialAccount 获取微信公众号实例
|
||||||
@@ -68,10 +68,16 @@ func (wc *Wechat) GetPay(cfg *payConfig.Config) *pay.Pay {
|
|||||||
|
|
||||||
// GetOpenPlatform 获取微信开放平台的实例
|
// GetOpenPlatform 获取微信开放平台的实例
|
||||||
func (wc *Wechat) GetOpenPlatform(cfg *openConfig.Config) *openplatform.OpenPlatform {
|
func (wc *Wechat) GetOpenPlatform(cfg *openConfig.Config) *openplatform.OpenPlatform {
|
||||||
|
if cfg.Cache == nil {
|
||||||
|
cfg.Cache = wc.cache
|
||||||
|
}
|
||||||
return openplatform.NewOpenPlatform(cfg)
|
return openplatform.NewOpenPlatform(cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetWork 获取企业微信的实例
|
// GetWork 获取企业微信的实例
|
||||||
func (wc *Wechat) GetWork(cfg *workConfig.Config) *work.Work {
|
func (wc *Wechat) GetWork(cfg *workConfig.Config) *work.Work {
|
||||||
|
if cfg.Cache == nil {
|
||||||
|
cfg.Cache = wc.cache
|
||||||
|
}
|
||||||
return work.NewWork(cfg)
|
return work.NewWork(cfg)
|
||||||
}
|
}
|
||||||
|
|||||||
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
|
||||||
|
}
|
||||||
242
work/addresslist/tag.go
Normal file
242
work/addresslist/tag.go
Normal file
@@ -0,0 +1,242 @@
|
|||||||
|
package addresslist
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/silenceper/wechat/v2/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// createTagURL 创建标签
|
||||||
|
createTagURL = "https://qyapi.weixin.qq.com/cgi-bin/tag/create?access_token=%s"
|
||||||
|
// updateTagURL 更新标签名字
|
||||||
|
updateTagURL = "https://qyapi.weixin.qq.com/cgi-bin/tag/update?access_token=%s"
|
||||||
|
// deleteTagURL 删除标签
|
||||||
|
deleteTagURL = "https://qyapi.weixin.qq.com/cgi-bin/tag/delete?access_token=%s&tagid=%d"
|
||||||
|
// getTagURL 获取标签成员
|
||||||
|
getTagURL = "https://qyapi.weixin.qq.com/cgi-bin/tag/get?access_token=%s&tagid=%d"
|
||||||
|
// addTagUsersURL 增加标签成员
|
||||||
|
addTagUsersURL = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers?access_token=%s"
|
||||||
|
// delTagUsersURL 删除标签成员
|
||||||
|
delTagUsersURL = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers?access_token=%s"
|
||||||
|
// listTagURL 获取标签列表
|
||||||
|
listTagURL = "https://qyapi.weixin.qq.com/cgi-bin/tag/list?access_token=%s"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// CreateTagRequest 创建标签请求
|
||||||
|
CreateTagRequest struct {
|
||||||
|
TagName string `json:"tagname"`
|
||||||
|
TagID int `json:"tagid,omitempty"`
|
||||||
|
}
|
||||||
|
// CreateTagResponse 创建标签响应
|
||||||
|
CreateTagResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
TagID int `json:"tagid"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateTag 创建标签
|
||||||
|
// see https://developer.work.weixin.qq.com/document/path/90210
|
||||||
|
func (r *Client) CreateTag(req *CreateTagRequest) (*CreateTagResponse, 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(createTagURL, accessToken), req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &CreateTagResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "CreateTag"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// UpdateTagRequest 更新标签名字请求
|
||||||
|
UpdateTagRequest struct {
|
||||||
|
TagID int `json:"tagid"`
|
||||||
|
TagName string `json:"tagname"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// UpdateTag 更新标签名字
|
||||||
|
// see https://developer.work.weixin.qq.com/document/path/90211
|
||||||
|
func (r *Client) UpdateTag(req *UpdateTagRequest) 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(updateTagURL, accessToken), req); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return util.DecodeWithCommonError(response, "UpdateTag")
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteTag 删除标签
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/90212
|
||||||
|
func (r *Client) DeleteTag(tagID int) error {
|
||||||
|
var (
|
||||||
|
accessToken string
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if accessToken, err = r.GetAccessToken(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var response []byte
|
||||||
|
if response, err = util.HTTPGet(fmt.Sprintf(deleteTagURL, accessToken, tagID)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return util.DecodeWithCommonError(response, "DeleteTag")
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// GetTagResponse 获取标签成员响应
|
||||||
|
GetTagResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
TagName string `json:"tagname"`
|
||||||
|
UserList []GetTagUserList `json:"userlist"`
|
||||||
|
PartyList []int `json:"partylist"`
|
||||||
|
}
|
||||||
|
// GetTagUserList 标签中包含的成员列表
|
||||||
|
GetTagUserList struct {
|
||||||
|
UserID string `json:"userid"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetTag 获取标签成员
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/90213
|
||||||
|
func (r *Client) GetTag(tagID int) (*GetTagResponse, 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(getTagURL, accessToken, tagID)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &GetTagResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "GetTag"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// AddTagUsersRequest 增加标签成员请求
|
||||||
|
AddTagUsersRequest struct {
|
||||||
|
TagID int `json:"tagid"`
|
||||||
|
UserList []string `json:"userlist"`
|
||||||
|
PartyList []int `json:"partylist"`
|
||||||
|
}
|
||||||
|
// AddTagUsersResponse 增加标签成员响应
|
||||||
|
AddTagUsersResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
InvalidList string `json:"invalidlist"`
|
||||||
|
InvalidParty []int `json:"invalidparty"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddTagUsers 增加标签成员
|
||||||
|
// see https://developer.work.weixin.qq.com/document/path/90214
|
||||||
|
func (r *Client) AddTagUsers(req *AddTagUsersRequest) (*AddTagUsersResponse, 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(addTagUsersURL, accessToken), req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &AddTagUsersResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "AddTagUsers"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// DelTagUsersRequest 删除标签成员请求
|
||||||
|
DelTagUsersRequest struct {
|
||||||
|
TagID int `json:"tagid"`
|
||||||
|
UserList []string `json:"userlist"`
|
||||||
|
PartyList []int `json:"partylist"`
|
||||||
|
}
|
||||||
|
// DelTagUsersResponse 删除标签成员响应
|
||||||
|
DelTagUsersResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
InvalidList string `json:"invalidlist"`
|
||||||
|
InvalidParty []int `json:"invalidparty"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// DelTagUsers 删除标签成员
|
||||||
|
// see https://developer.work.weixin.qq.com/document/path/90215
|
||||||
|
func (r *Client) DelTagUsers(req *DelTagUsersRequest) (*DelTagUsersResponse, 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(delTagUsersURL, accessToken), req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &DelTagUsersResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "DelTagUsers"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// ListTagResponse 获取标签列表响应
|
||||||
|
ListTagResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
TagList []Tag `json:"taglist"`
|
||||||
|
}
|
||||||
|
// Tag 标签
|
||||||
|
Tag struct {
|
||||||
|
TagID int `json:"tagid"`
|
||||||
|
TagName string `json:"tagname"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// ListTag 获取标签列表
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/90216
|
||||||
|
func (r *Client) ListTag() (*ListTagResponse, 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(listTagURL, accessToken)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &ListTagResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "ListTag"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
253
work/addresslist/user.go
Normal file
253
work/addresslist/user.go
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
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"
|
||||||
|
// convertToOpenIDURL userID转openID
|
||||||
|
convertToOpenIDURL = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid?access_token=%s"
|
||||||
|
// convertToUserIDURL openID转userID
|
||||||
|
convertToUserIDURL = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_userid?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
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// convertToOpenIDRequest userID转openID请求
|
||||||
|
convertToOpenIDRequest struct {
|
||||||
|
UserID string `json:"userid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// convertToOpenIDResponse userID转openID响应
|
||||||
|
convertToOpenIDResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
OpenID string `json:"openid"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// ConvertToOpenID userID转openID
|
||||||
|
// see https://developer.work.weixin.qq.com/document/path/90202
|
||||||
|
func (r *Client) ConvertToOpenID(userID string) (string, 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(convertToOpenIDURL, accessToken), &convertToOpenIDRequest{
|
||||||
|
UserID: userID,
|
||||||
|
}); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
result := &convertToOpenIDResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "ConvertToOpenID"); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return result.OpenID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// convertToUserIDRequest openID转userID请求
|
||||||
|
convertToUserIDRequest struct {
|
||||||
|
OpenID string `json:"openid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// convertToUserIDResponse openID转userID响应
|
||||||
|
convertToUserIDResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
UserID string `json:"userid"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// ConvertToUserID openID转userID
|
||||||
|
// see https://developer.work.weixin.qq.com/document/path/90202
|
||||||
|
func (r *Client) ConvertToUserID(openID string) (string, 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(convertToUserIDURL, accessToken), &convertToUserIDRequest{
|
||||||
|
OpenID: openID,
|
||||||
|
}); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
result := &convertToUserIDResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "ConvertToUserID"); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return result.UserID, nil
|
||||||
|
}
|
||||||
115
work/appchat/appchat.go
Normal file
115
work/appchat/appchat.go
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
package appchat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/silenceper/wechat/v2/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// 应用推送消息接口地址
|
||||||
|
sendURL = "https://qyapi.weixin.qq.com/cgi-bin/appchat/send?access_token=%s"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// SendRequestCommon 发送应用推送消息请求公共参数
|
||||||
|
SendRequestCommon struct {
|
||||||
|
// 群聊id
|
||||||
|
ChatID string `json:"chatid"`
|
||||||
|
// 消息类型
|
||||||
|
MsgType string `json:"msgtype"`
|
||||||
|
// 表示是否是保密消息,0表示否,1表示是,默认0
|
||||||
|
Safe int `json:"safe"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendResponse 发送应用消息响应参数
|
||||||
|
SendResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendTextRequest 发送文本消息的请求
|
||||||
|
SendTextRequest struct {
|
||||||
|
*SendRequestCommon
|
||||||
|
Text TextField `json:"text"`
|
||||||
|
}
|
||||||
|
// TextField 文本消息参数
|
||||||
|
TextField struct {
|
||||||
|
// 消息内容,最长不超过2048个字节
|
||||||
|
Content string `json:"content"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendImageRequest 发送图片消息的请求
|
||||||
|
SendImageRequest struct {
|
||||||
|
*SendRequestCommon
|
||||||
|
Image ImageField `json:"image"`
|
||||||
|
}
|
||||||
|
// ImageField 图片消息参数
|
||||||
|
ImageField struct {
|
||||||
|
// 图片媒体文件id,可以调用上传临时素材接口获取
|
||||||
|
MediaID string `json:"media_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendVoiceRequest 发送语音消息的请求
|
||||||
|
SendVoiceRequest struct {
|
||||||
|
*SendRequestCommon
|
||||||
|
Voice VoiceField `json:"voice"`
|
||||||
|
}
|
||||||
|
// VoiceField 语音消息参数
|
||||||
|
VoiceField struct {
|
||||||
|
// 语音文件id,可以调用上传临时素材接口获取
|
||||||
|
MediaID string `json:"media_id"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Send 发送应用消息
|
||||||
|
// @desc 实现企业微信发送应用消息接口:https://developer.work.weixin.qq.com/document/path/90248
|
||||||
|
func (r *Client) Send(apiName string, request interface{}) (*SendResponse, error) {
|
||||||
|
// 获取accessToken
|
||||||
|
accessToken, err := r.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// 请求参数转 JSON 格式
|
||||||
|
jsonData, err := json.Marshal(request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// 发起http请求
|
||||||
|
response, err := util.HTTPPost(fmt.Sprintf(sendURL, accessToken), string(jsonData))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// 按照结构体解析返回值
|
||||||
|
result := &SendResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, apiName); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// 返回数据
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendText 发送文本消息
|
||||||
|
func (r *Client) SendText(request SendTextRequest) (*SendResponse, error) {
|
||||||
|
// 发送文本消息MsgType参数固定为:text
|
||||||
|
request.MsgType = "text"
|
||||||
|
return r.Send("MessageSendText", request)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendImage 发送图片消息
|
||||||
|
func (r *Client) SendImage(request SendImageRequest) (*SendResponse, error) {
|
||||||
|
// 发送图片消息MsgType参数固定为:image
|
||||||
|
request.MsgType = "image"
|
||||||
|
return r.Send("MessageSendImage", request)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendVoice 发送语音消息
|
||||||
|
func (r *Client) SendVoice(request SendVoiceRequest) (*SendResponse, error) {
|
||||||
|
// 发送语音消息MsgType参数固定为:voice
|
||||||
|
request.MsgType = "voice"
|
||||||
|
return r.Send("MessageSendVoice", request)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 以上实现了部分常用消息推送:SendText 发送文本消息、SendImage 发送图片消息、SendVoice 发送语音消息,
|
||||||
|
// 如需扩展其他消息类型,建议按照以上格式,扩展对应消息类型的参数即可
|
||||||
|
// 也可以直接使用Send方法,按照企业微信消息推送的接口文档传对应消息类型的参数来使用
|
||||||
16
work/appchat/client.go
Normal file
16
work/appchat/client.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Package appchat 应用发送消息到群聊会话,企业微信接口:https://developer.work.weixin.qq.com/document/path/90248
|
||||||
|
package appchat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/silenceper/wechat/v2/work/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Client 接口实例
|
||||||
|
type Client struct {
|
||||||
|
*context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient 初始化实例
|
||||||
|
func NewClient(ctx *context.Context) *Client {
|
||||||
|
return &Client{ctx}
|
||||||
|
}
|
||||||
45
work/externalcontact/callback.go
Normal file
45
work/externalcontact/callback.go
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package externalcontact
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/xml"
|
||||||
|
|
||||||
|
"github.com/silenceper/wechat/v2/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 原始回调消息内容
|
||||||
|
type callbackOriginMessage struct {
|
||||||
|
ToUserName string // 企业微信的CorpID,当为第三方套件回调事件时,CorpID的内容为suiteid
|
||||||
|
AgentID string // 接收的应用id,可在应用的设置页面获取
|
||||||
|
Encrypt string // 消息结构体加密后的字符串
|
||||||
|
}
|
||||||
|
|
||||||
|
// EventCallbackMessage 微信客户联系回调消息
|
||||||
|
// https://developer.work.weixin.qq.com/document/path/92130
|
||||||
|
type EventCallbackMessage struct {
|
||||||
|
ToUserName string `json:"to_user_name"`
|
||||||
|
FromUserName string `json:"from_user_name"`
|
||||||
|
CreateTime int64 `json:"create_time"`
|
||||||
|
MsgType string `json:"msg_type"`
|
||||||
|
Event string `json:"event"`
|
||||||
|
ChangeType string `json:"change_type"`
|
||||||
|
UserID string `json:"user_id"`
|
||||||
|
ExternalUserID string `json:"external_user_id"`
|
||||||
|
State string `json:"state"`
|
||||||
|
WelcomeCode string `json:"welcome_code"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCallbackMessage 获取联系客户回调事件中的消息内容
|
||||||
|
func (r *Client) GetCallbackMessage(encryptedMsg []byte) (msg EventCallbackMessage, err error) {
|
||||||
|
var origin callbackOriginMessage
|
||||||
|
if err = xml.Unmarshal(encryptedMsg, &origin); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, bData, err := util.DecryptMsg(r.CorpID, origin.Encrypt, r.EncodingAESKey)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = xml.Unmarshal(bData, &msg); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
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
|
||||||
|
}
|
||||||
@@ -8,14 +8,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// FetchExternalContactUserListURL 获取客户列表
|
// fetchExternalContactUserListURL 获取客户列表
|
||||||
FetchExternalContactUserListURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list"
|
fetchExternalContactUserListURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/list"
|
||||||
// FetchExternalContactUserDetailURL 获取客户详情
|
// fetchExternalContactUserDetailURL 获取客户详情
|
||||||
FetchExternalContactUserDetailURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get"
|
fetchExternalContactUserDetailURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get"
|
||||||
// FetchBatchExternalContactUserDetailURL 批量获取客户详情
|
// fetchBatchExternalContactUserDetailURL 批量获取客户详情
|
||||||
FetchBatchExternalContactUserDetailURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/batch/get_by_user"
|
fetchBatchExternalContactUserDetailURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/batch/get_by_user"
|
||||||
// UpdateUserRemarkURL 更新客户备注信息
|
// updateUserRemarkURL 更新客户备注信息
|
||||||
UpdateUserRemarkURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/remark"
|
updateUserRemarkURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/remark"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExternalUserListResponse 外部联系人列表响应
|
// ExternalUserListResponse 外部联系人列表响应
|
||||||
@@ -27,13 +27,12 @@ type ExternalUserListResponse struct {
|
|||||||
// GetExternalUserList 获取客户列表
|
// GetExternalUserList 获取客户列表
|
||||||
// @see https://developer.work.weixin.qq.com/document/path/92113
|
// @see https://developer.work.weixin.qq.com/document/path/92113
|
||||||
func (r *Client) GetExternalUserList(userID string) ([]string, error) {
|
func (r *Client) GetExternalUserList(userID string) ([]string, error) {
|
||||||
var accessToken string
|
|
||||||
accessToken, err := r.GetAccessToken()
|
accessToken, err := r.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response []byte
|
var response []byte
|
||||||
response, err = util.HTTPGet(fmt.Sprintf("%s?access_token=%v&userid=%v", FetchExternalContactUserListURL, accessToken, userID))
|
response, err = util.HTTPGet(fmt.Sprintf("%s?access_token=%v&userid=%v", fetchExternalContactUserListURL, accessToken, userID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -48,23 +47,23 @@ func (r *Client) GetExternalUserList(userID string) ([]string, error) {
|
|||||||
// ExternalUserDetailResponse 外部联系人详情响应
|
// ExternalUserDetailResponse 外部联系人详情响应
|
||||||
type ExternalUserDetailResponse struct {
|
type ExternalUserDetailResponse struct {
|
||||||
util.CommonError
|
util.CommonError
|
||||||
ExternalUser
|
ExternalContact ExternalUser `json:"external_contact"`
|
||||||
|
FollowUser []FollowUser `json:"follow_user"`
|
||||||
|
NextCursor string `json:"next_cursor"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExternalUser 外部联系人
|
// ExternalUser 外部联系人
|
||||||
type ExternalUser struct {
|
type ExternalUser struct {
|
||||||
ExternalUserID string `json:"external_userid"`
|
ExternalUserID string `json:"external_userid"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
Type int64 `json:"type"`
|
Type int64 `json:"type"`
|
||||||
Gender int64 `json:"gender"`
|
Gender int64 `json:"gender"`
|
||||||
UnionID string `json:"unionid"`
|
UnionID string `json:"unionid"`
|
||||||
Position string `json:"position"`
|
Position string `json:"position"`
|
||||||
CorpName string `json:"corp_name"`
|
CorpName string `json:"corp_name"`
|
||||||
CorpFullName string `json:"corp_full_name"`
|
CorpFullName string `json:"corp_full_name"`
|
||||||
ExternalProfile string `json:"external_profile"`
|
ExternalProfile string `json:"external_profile"`
|
||||||
FollowUser []FollowUser `json:"follow_user"`
|
|
||||||
NextCursor string `json:"next_cursor"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FollowUser 跟进用户(指企业内部用户)
|
// FollowUser 跟进用户(指企业内部用户)
|
||||||
@@ -97,47 +96,89 @@ type WechatChannel struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetExternalUserDetail 获取外部联系人详情
|
// GetExternalUserDetail 获取外部联系人详情
|
||||||
func (r *Client) GetExternalUserDetail(externalUserID string, nextCursor ...string) (*ExternalUser, error) {
|
// @see https://developer.work.weixin.qq.com/document/path/92114
|
||||||
var accessToken string
|
func (r *Client) GetExternalUserDetail(externalUserID string, nextCursor ...string) (*ExternalUserDetailResponse, error) {
|
||||||
accessToken, err := r.GetAccessToken()
|
accessToken, err := r.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response []byte
|
var response []byte
|
||||||
response, err = util.HTTPGet(fmt.Sprintf("%s?access_token=%v&external_userid=%v&cursor=%v", FetchExternalContactUserDetailURL, accessToken, externalUserID, nextCursor))
|
var cursor string
|
||||||
|
if len(nextCursor) > 0 {
|
||||||
|
cursor = nextCursor[0]
|
||||||
|
}
|
||||||
|
response, err = util.HTTPGet(fmt.Sprintf("%s?access_token=%v&external_userid=%v&cursor=%v", fetchExternalContactUserDetailURL, accessToken, externalUserID, cursor))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var result ExternalUserDetailResponse
|
result := &ExternalUserDetailResponse{}
|
||||||
err = util.DecodeWithError(response, &result, "get_external_user_detail")
|
err = util.DecodeWithError(response, result, "get_external_user_detail")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &result.ExternalUser, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BatchGetExternalUserDetailsRequest 批量获取外部联系人详情请求
|
// BatchGetExternalUserDetailsRequest 批量获取外部联系人详情请求
|
||||||
type BatchGetExternalUserDetailsRequest struct {
|
type BatchGetExternalUserDetailsRequest struct {
|
||||||
UserIDList []string `json:"userid_list"`
|
UserIDList []string `json:"userid_list"`
|
||||||
Cursor string `json:"cursor"`
|
Cursor string `json:"cursor"`
|
||||||
|
Limit int `json:"limit,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExternalUserDetailListResponse 批量获取外部联系人详情响应
|
// ExternalUserDetailListResponse 批量获取外部联系人详情响应
|
||||||
type ExternalUserDetailListResponse struct {
|
type ExternalUserDetailListResponse struct {
|
||||||
util.CommonError
|
util.CommonError
|
||||||
ExternalContactList []ExternalUser `json:"external_contact_list"`
|
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 批量获取外部联系人详情
|
// BatchGetExternalUserDetails 批量获取外部联系人详情
|
||||||
func (r *Client) BatchGetExternalUserDetails(request BatchGetExternalUserDetailsRequest) ([]ExternalUser, error) {
|
// @see https://developer.work.weixin.qq.com/document/path/92994
|
||||||
var accessToken string
|
func (r *Client) BatchGetExternalUserDetails(request BatchGetExternalUserDetailsRequest) ([]ExternalUserForBatch, error) {
|
||||||
accessToken, err := r.GetAccessToken()
|
accessToken, err := r.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response []byte
|
var response []byte
|
||||||
jsonData, _ := json.Marshal(request)
|
jsonData, err := json.Marshal(request)
|
||||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", FetchBatchExternalContactUserDetailURL, accessToken), string(jsonData))
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", fetchBatchExternalContactUserDetailURL, accessToken), string(jsonData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -157,19 +198,22 @@ type UpdateUserRemarkRequest struct {
|
|||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
RemarkCompany string `json:"remark_company"`
|
RemarkCompany string `json:"remark_company"`
|
||||||
RemarkMobiles []string `json:"remark_mobiles"`
|
RemarkMobiles []string `json:"remark_mobiles"`
|
||||||
RemarkPicMediaid string `json:"remark_pic_mediaid"`
|
RemarkPicMediaID string `json:"remark_pic_mediaid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateUserRemark 修改客户备注信息
|
// UpdateUserRemark 修改客户备注信息
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/92115
|
||||||
func (r *Client) UpdateUserRemark(request UpdateUserRemarkRequest) error {
|
func (r *Client) UpdateUserRemark(request UpdateUserRemarkRequest) error {
|
||||||
var accessToken string
|
|
||||||
accessToken, err := r.GetAccessToken()
|
accessToken, err := r.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var response []byte
|
var response []byte
|
||||||
jsonData, _ := json.Marshal(request)
|
jsonData, err := json.Marshal(request)
|
||||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", UpdateUserRemarkURL, accessToken), string(jsonData))
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", updateUserRemarkURL, accessToken), string(jsonData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// FetchFollowUserListURL 获取配置了客户联系功能的成员列表
|
// fetchFollowUserListURL 获取配置了客户联系功能的成员列表
|
||||||
FetchFollowUserListURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_follow_user_list"
|
fetchFollowUserListURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_follow_user_list"
|
||||||
)
|
)
|
||||||
|
|
||||||
// followerUserResponse 客户联系功能的成员列表响应
|
// followerUserResponse 客户联系功能的成员列表响应
|
||||||
@@ -17,16 +17,15 @@ type followerUserResponse struct {
|
|||||||
FollowUser []string `json:"follow_user"`
|
FollowUser []string `json:"follow_user"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetFollowUserList 获取配置了客户联系功能的成员列表
|
// GetFollowUserList 获取配置了客户联系功能的成员列表
|
||||||
//@see https://developer.work.weixin.qq.com/document/path/92571
|
// @see https://developer.work.weixin.qq.com/document/path/92571
|
||||||
func (r *Client) GetFollowUserList() ([]string, error) {
|
func (r *Client) GetFollowUserList() ([]string, error) {
|
||||||
var accessToken string
|
|
||||||
accessToken, err := r.GetAccessToken()
|
accessToken, err := r.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response []byte
|
var response []byte
|
||||||
response, err = util.HTTPGet(fmt.Sprintf("%s?access_token=%s", FetchFollowUserListURL, accessToken))
|
response, err = util.HTTPGet(fmt.Sprintf("%s?access_token=%s", fetchFollowUserListURL, accessToken))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
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
|
||||||
|
}
|
||||||
@@ -8,16 +8,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// GetCropTagURL 获取标签列表
|
// getCropTagURL 获取标签列表
|
||||||
GetCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list"
|
getCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list"
|
||||||
// AddCropTagURL 添加标签
|
// addCropTagURL 添加标签
|
||||||
AddCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag"
|
addCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag"
|
||||||
// EditCropTagURL 修改标签
|
// editCropTagURL 修改标签
|
||||||
EditCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/edit_corp_tag"
|
editCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/edit_corp_tag"
|
||||||
// DelCropTagURL 删除标签
|
// delCropTagURL 删除标签
|
||||||
DelCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_corp_tag"
|
delCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_corp_tag"
|
||||||
// MarkCropTagURL 为客户打上、删除标签
|
// markCropTagURL 为客户打上、删除标签
|
||||||
MarkCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag"
|
markCropTagURL = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetCropTagRequest 获取企业标签请求
|
// GetCropTagRequest 获取企业标签请求
|
||||||
@@ -36,7 +36,7 @@ type GetCropTagListResponse struct {
|
|||||||
type TagGroup struct {
|
type TagGroup struct {
|
||||||
GroupID string `json:"group_id"`
|
GroupID string `json:"group_id"`
|
||||||
GroupName string `json:"group_name"`
|
GroupName string `json:"group_name"`
|
||||||
CreateTime string `json:"create_time"`
|
CreateTime int `json:"create_time"`
|
||||||
GroupOrder int `json:"group_order"`
|
GroupOrder int `json:"group_order"`
|
||||||
Deleted bool `json:"deleted"`
|
Deleted bool `json:"deleted"`
|
||||||
Tag []TagGroupTagItem `json:"tag"`
|
Tag []TagGroupTagItem `json:"tag"`
|
||||||
@@ -54,14 +54,16 @@ type TagGroupTagItem struct {
|
|||||||
// GetCropTagList 获取企业标签库
|
// GetCropTagList 获取企业标签库
|
||||||
// @see https://developer.work.weixin.qq.com/document/path/92117
|
// @see https://developer.work.weixin.qq.com/document/path/92117
|
||||||
func (r *Client) GetCropTagList(req GetCropTagRequest) ([]TagGroup, error) {
|
func (r *Client) GetCropTagList(req GetCropTagRequest) ([]TagGroup, error) {
|
||||||
var accessToken string
|
|
||||||
accessToken, err := r.GetAccessToken()
|
accessToken, err := r.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response []byte
|
var response []byte
|
||||||
jsonData, _ := json.Marshal(req)
|
jsonData, err := json.Marshal(req)
|
||||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", GetCropTagURL, accessToken), string(jsonData))
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", getCropTagURL, accessToken), string(jsonData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -75,7 +77,7 @@ func (r *Client) GetCropTagList(req GetCropTagRequest) ([]TagGroup, error) {
|
|||||||
|
|
||||||
// AddCropTagRequest 添加企业标签请求
|
// AddCropTagRequest 添加企业标签请求
|
||||||
type AddCropTagRequest struct {
|
type AddCropTagRequest struct {
|
||||||
GroupID string `json:"group_id"`
|
GroupID string `json:"group_id,omitempty"`
|
||||||
GroupName string `json:"group_name"`
|
GroupName string `json:"group_name"`
|
||||||
Order int `json:"order"`
|
Order int `json:"order"`
|
||||||
Tag []AddCropTagItem `json:"tag"`
|
Tag []AddCropTagItem `json:"tag"`
|
||||||
@@ -103,8 +105,11 @@ func (r *Client) AddCropTag(req AddCropTagRequest) (*TagGroup, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response []byte
|
var response []byte
|
||||||
jsonData, _ := json.Marshal(req)
|
jsonData, err := json.Marshal(req)
|
||||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", AddCropTagURL, accessToken), string(jsonData))
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", addCropTagURL, accessToken), string(jsonData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -127,14 +132,16 @@ type EditCropTagRequest struct {
|
|||||||
// EditCropTag 修改企业客户标签
|
// EditCropTag 修改企业客户标签
|
||||||
// @see https://developer.work.weixin.qq.com/document/path/92117
|
// @see https://developer.work.weixin.qq.com/document/path/92117
|
||||||
func (r *Client) EditCropTag(req EditCropTagRequest) error {
|
func (r *Client) EditCropTag(req EditCropTagRequest) error {
|
||||||
var accessToken string
|
|
||||||
accessToken, err := r.GetAccessToken()
|
accessToken, err := r.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var response []byte
|
var response []byte
|
||||||
jsonData, _ := json.Marshal(req)
|
jsonData, err := json.Marshal(req)
|
||||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", EditCropTagURL, accessToken), string(jsonData))
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", editCropTagURL, accessToken), string(jsonData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -151,14 +158,16 @@ type DeleteCropTagRequest struct {
|
|||||||
// DeleteCropTag 删除企业客户标签
|
// DeleteCropTag 删除企业客户标签
|
||||||
// @see https://developer.work.weixin.qq.com/document/path/92117
|
// @see https://developer.work.weixin.qq.com/document/path/92117
|
||||||
func (r *Client) DeleteCropTag(req DeleteCropTagRequest) error {
|
func (r *Client) DeleteCropTag(req DeleteCropTagRequest) error {
|
||||||
var accessToken string
|
|
||||||
accessToken, err := r.GetAccessToken()
|
accessToken, err := r.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var response []byte
|
var response []byte
|
||||||
jsonData, _ := json.Marshal(req)
|
jsonData, err := json.Marshal(req)
|
||||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", DelCropTagURL, accessToken), string(jsonData))
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", delCropTagURL, accessToken), string(jsonData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -166,8 +175,9 @@ func (r *Client) DeleteCropTag(req DeleteCropTagRequest) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MarkTagRequest 给客户打标签请求
|
// MarkTagRequest 给客户打标签请求
|
||||||
|
// 相关文档地址:https://developer.work.weixin.qq.com/document/path/92118
|
||||||
type MarkTagRequest struct {
|
type MarkTagRequest struct {
|
||||||
UserID string `json:"user_id"`
|
UserID string `json:"userid"`
|
||||||
ExternalUserID string `json:"external_userid"`
|
ExternalUserID string `json:"external_userid"`
|
||||||
AddTag []string `json:"add_tag"`
|
AddTag []string `json:"add_tag"`
|
||||||
RemoveTag []string `json:"remove_tag"`
|
RemoveTag []string `json:"remove_tag"`
|
||||||
@@ -176,14 +186,16 @@ type MarkTagRequest struct {
|
|||||||
// MarkTag 为客户打上标签
|
// MarkTag 为客户打上标签
|
||||||
// @see https://developer.work.weixin.qq.com/document/path/92118
|
// @see https://developer.work.weixin.qq.com/document/path/92118
|
||||||
func (r *Client) MarkTag(request MarkTagRequest) error {
|
func (r *Client) MarkTag(request MarkTagRequest) error {
|
||||||
var accessToken string
|
|
||||||
accessToken, err := r.GetAccessToken()
|
accessToken, err := r.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var response []byte
|
var response []byte
|
||||||
jsonData, _ := json.Marshal(request)
|
jsonData, err := json.Marshal(request)
|
||||||
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", MarkCropTagURL, accessToken), string(jsonData))
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
response, err = util.HTTPPost(fmt.Sprintf("%s?access_token=%v", markCropTagURL, accessToken), string(jsonData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,12 +38,10 @@ func (r *Client) AccountAdd(options AccountAddOptions) (info AccountAddSchema, e
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(accountAddAddr, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(accountAddAddr, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
@@ -66,12 +64,10 @@ func (r *Client) AccountDel(options AccountDelOptions) (info util.CommonError, e
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(accountDelAddr, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(accountDelAddr, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
@@ -96,12 +92,10 @@ func (r *Client) AccountUpdate(options AccountUpdateOptions) (info util.CommonEr
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(accountUpdateAddr, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(accountUpdateAddr, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
@@ -132,12 +126,10 @@ func (r *Client) AccountList() (info AccountListSchema, err error) {
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.HTTPGet(fmt.Sprintf(accountListAddr, accessToken))
|
if data, err = util.HTTPGet(fmt.Sprintf(accountListAddr, accessToken)); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
@@ -171,12 +163,10 @@ func (r *Client) AddContactWay(options AddContactWayOptions) (info AddContactWay
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(addContactWayAddr, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(addContactWayAddr, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
|
|||||||
@@ -15,21 +15,22 @@ type SignatureOptions struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// VerifyURL 验证请求参数是否合法并返回解密后的消息内容
|
// VerifyURL 验证请求参数是否合法并返回解密后的消息内容
|
||||||
// //Gin框架的使用示例
|
//
|
||||||
// r.GET("/v1/event/callback", func(c *gin.Context) {
|
// //Gin框架的使用示例
|
||||||
// options := kf.SignatureOptions{}
|
// r.GET("/v1/event/callback", func(c *gin.Context) {
|
||||||
// //获取回调的的校验参数
|
// options := kf.SignatureOptions{}
|
||||||
// if = c.ShouldBindQuery(&options); err != nil {
|
// //获取回调的的校验参数
|
||||||
// c.String(http.StatusUnauthorized, "参数解析失败")
|
// if = c.ShouldBindQuery(&options); err != nil {
|
||||||
// }
|
// c.String(http.StatusUnauthorized, "参数解析失败")
|
||||||
// // 调用VerifyURL方法校验当前请求,如果合法则把解密后的内容作为响应返回给微信服务器
|
// }
|
||||||
// echo, err := kfClient.VerifyURL(options)
|
// // 调用VerifyURL方法校验当前请求,如果合法则把解密后的内容作为响应返回给微信服务器
|
||||||
// if err == nil {
|
// echo, err := kfClient.VerifyURL(options)
|
||||||
// c.String(http.StatusOK, echo)
|
// if err == nil {
|
||||||
// } else {
|
// c.String(http.StatusOK, echo)
|
||||||
// c.String(http.StatusUnauthorized, "非法请求来源")
|
// } else {
|
||||||
// }
|
// c.String(http.StatusUnauthorized, "非法请求来源")
|
||||||
// })
|
// }
|
||||||
|
// })
|
||||||
func (r *Client) VerifyURL(options SignatureOptions) (string, error) {
|
func (r *Client) VerifyURL(options SignatureOptions) (string, error) {
|
||||||
if options.Signature != util.Signature(r.ctx.Token, options.TimeStamp, options.Nonce, options.EchoStr) {
|
if options.Signature != util.Signature(r.ctx.Token, options.TimeStamp, options.Nonce, options.EchoStr) {
|
||||||
return "", NewSDKErr(40015)
|
return "", NewSDKErr(40015)
|
||||||
@@ -51,35 +52,37 @@ type callbackOriginMessage struct {
|
|||||||
|
|
||||||
// CallbackMessage 微信客服回调消息
|
// CallbackMessage 微信客服回调消息
|
||||||
type CallbackMessage struct {
|
type CallbackMessage struct {
|
||||||
ToUserName string `json:"to_user_name"` // 微信客服组件ID
|
ToUserName string `json:"to_user_name" xml:"ToUserName"` // 微信客服组件ID
|
||||||
CreateTime int `json:"create_time"` // 消息创建时间,unix时间戳
|
CreateTime int `json:"create_time" xml:"CreateTime"` // 消息创建时间,unix时间戳
|
||||||
MsgType string `json:"msgtype"` // 消息的类型,此时固定为 event
|
MsgType string `json:"msgtype" xml:"MsgType"` // 消息的类型,此时固定为 event
|
||||||
Event string `json:"event"` // 事件的类型,此时固定为 kf_msg_or_event
|
Event string `json:"event" xml:"Event"` // 事件的类型,此时固定为 kf_msg_or_event
|
||||||
Token string `json:"token"` // 调用拉取消息接口时,需要传此token,用于校验请求的合法性
|
Token string `json:"token" xml:"Token"` // 调用拉取消息接口时,需要传此token,用于校验请求的合法性
|
||||||
|
OpenKfID string `json:"open_kfid" xml:"OpenKfId"` // 有新消息的客服帐号。可通过sync_msg接口指定open_kfid获取此客服帐号的消息
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCallbackMessage 获取回调事件中的消息内容
|
// GetCallbackMessage 获取回调事件中的消息内容
|
||||||
// //Gin框架的使用示例
|
//
|
||||||
// r.POST("/v1/event/callback", func(c *gin.Context) {
|
// //Gin框架的使用示例
|
||||||
// var (
|
// r.POST("/v1/event/callback", func(c *gin.Context) {
|
||||||
// message kf.CallbackMessage
|
// var (
|
||||||
// body []byte
|
// message kf.CallbackMessage
|
||||||
// )
|
// body []byte
|
||||||
// // 读取原始消息内容
|
// )
|
||||||
// body, err = c.GetRawData()
|
// // 读取原始消息内容
|
||||||
// if err != nil {
|
// body, err = c.GetRawData()
|
||||||
// c.String(http.StatusInternalServerError, err.Error())
|
// if err != nil {
|
||||||
// return
|
// c.String(http.StatusInternalServerError, err.Error())
|
||||||
// }
|
// return
|
||||||
// // 解析原始数据
|
// }
|
||||||
// message, err = kfClient.GetCallbackMessage(body)
|
// // 解析原始数据
|
||||||
// if err != nil {
|
// message, err = kfClient.GetCallbackMessage(body)
|
||||||
// c.String(http.StatusInternalServerError, "消息获取失败")
|
// if err != nil {
|
||||||
// return
|
// c.String(http.StatusInternalServerError, "消息获取失败")
|
||||||
// }
|
// return
|
||||||
// fmt.Println(message)
|
// }
|
||||||
// c.String(200, "ok")
|
// fmt.Println(message)
|
||||||
// })
|
// c.String(200, "ok")
|
||||||
|
// })
|
||||||
func (r *Client) GetCallbackMessage(encryptedMsg []byte) (msg CallbackMessage, err error) {
|
func (r *Client) GetCallbackMessage(encryptedMsg []byte) (msg CallbackMessage, err error) {
|
||||||
var origin callbackOriginMessage
|
var origin callbackOriginMessage
|
||||||
if err = xml.Unmarshal(encryptedMsg, &origin); err != nil {
|
if err = xml.Unmarshal(encryptedMsg, &origin); err != nil {
|
||||||
|
|||||||
@@ -38,12 +38,10 @@ func (r *Client) CustomerBatchGet(options CustomerBatchGetOptions) (info Custome
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(customerBatchGetAddr, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(customerBatchGetAddr, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
|
|||||||
@@ -31,12 +31,10 @@ func (r *Client) GetCorpQualification() (info CorpQualificationSchema, err error
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.HTTPGet(fmt.Sprintf(corpQualification, accessToken))
|
if data, err = util.HTTPGet(fmt.Sprintf(corpQualification, accessToken)); err != nil {
|
||||||
if err != nil {
|
|
||||||
return info, err
|
return info, err
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
|
|||||||
@@ -31,12 +31,10 @@ func (r *Client) SendMsg(options interface{}) (info SendMsgSchema, err error) {
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(sendMsgAddr, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(sendMsgAddr, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
|
|||||||
@@ -38,12 +38,10 @@ func (r *Client) SendMsgOnEvent(options interface{}) (info SendMsgOnEventSchema,
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(sendMsgOnEventAddr, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(sendMsgOnEventAddr, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
|
|||||||
@@ -37,12 +37,10 @@ func (r *Client) ReceptionistAdd(options ReceptionistOptions) (info Receptionist
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(receptionistAddAddr, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(receptionistAddAddr, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
|
|||||||
@@ -39,12 +39,10 @@ func (r *Client) ServiceStateGet(options ServiceStateGetOptions) (info ServiceSt
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(serviceStateGetAddr, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(serviceStateGetAddr, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
@@ -76,12 +74,10 @@ func (r *Client) ServiceStateTrans(options ServiceStateTransOptions) (info Servi
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(serviceStateTransAddr, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(serviceStateTransAddr, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
|
|||||||
@@ -16,9 +16,11 @@ const (
|
|||||||
|
|
||||||
// SyncMsgOptions 获取消息查询参数
|
// SyncMsgOptions 获取消息查询参数
|
||||||
type SyncMsgOptions struct {
|
type SyncMsgOptions struct {
|
||||||
Cursor string `json:"cursor"` // 上一次调用时返回的next_cursor,第一次拉取可以不填, 不多于64字节
|
Cursor string `json:"cursor"` // 上一次调用时返回的next_cursor,第一次拉取可以不填, 不多于64字节
|
||||||
Token string `json:"token"` // 回调事件返回的token字段,10分钟内有效;可不填,如果不填接口有严格的频率限制, 不多于128字节
|
Token string `json:"token"` // 回调事件返回的token字段,10分钟内有效;可不填,如果不填接口有严格的频率限制, 不多于128字节
|
||||||
Limit uint `json:"limit"` // 期望请求的数据量,默认值和最大值都为1000, 注意:可能会出现返回条数少于limit的情况,需结合返回的has_more字段判断是否继续请求。
|
Limit uint `json:"limit"` // 期望请求的数据量,默认值和最大值都为1000, 注意:可能会出现返回条数少于limit的情况,需结合返回的has_more字段判断是否继续请求。
|
||||||
|
VoiceFormat uint `json:"voice_format,omitempty"` // 语音消息类型,0-Amr 1-Silk,默认0。可通过该参数控制返回的语音格式,开发者可按需选择自己程序支持的一种格式
|
||||||
|
OpenKfID string `json:"open_kfid,omitempty"` // 指定拉取某个客服帐号的消息,否则默认返回有权限的客服帐号的消息。当客服帐号较多,建议按open_kfid来拉取以获取更好的性能。
|
||||||
}
|
}
|
||||||
|
|
||||||
// SyncMsgSchema 获取消息查询响应内容
|
// SyncMsgSchema 获取消息查询响应内容
|
||||||
@@ -45,12 +47,10 @@ func (r *Client) SyncMsg(options SyncMsgOptions) (info SyncMsgSchema, err error)
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(syncMsgAddr, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(syncMsgAddr, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
originInfo := syncMsgSchema{}
|
originInfo := syncMsgSchema{}
|
||||||
|
|||||||
@@ -34,12 +34,10 @@ func (r *Client) UpgradeServiceConfig() (info UpgradeServiceConfigSchema, err er
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.HTTPGet(fmt.Sprintf(upgradeServiceConfigAddr, accessToken))
|
if data, err = util.HTTPGet(fmt.Sprintf(upgradeServiceConfigAddr, accessToken)); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
@@ -72,12 +70,10 @@ func (r *Client) UpgradeService(options UpgradeServiceOptions) (info util.Common
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(upgradeService, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(upgradeService, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
@@ -106,12 +102,10 @@ func (r *Client) UpgradeMemberService(options UpgradeMemberServiceOptions) (info
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(upgradeService, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(upgradeService, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
if err = json.Unmarshal(data, &info); err != nil {
|
||||||
@@ -169,12 +163,10 @@ func (r *Client) UpgradeServiceCancel(options UpgradeServiceCancelOptions) (info
|
|||||||
accessToken string
|
accessToken string
|
||||||
data []byte
|
data []byte
|
||||||
)
|
)
|
||||||
accessToken, err = r.ctx.GetAccessToken()
|
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, err = util.PostJSON(fmt.Sprintf(upgradeServiceCancel, accessToken), options)
|
if data, err = util.PostJSON(fmt.Sprintf(upgradeServiceCancel, accessToken), options); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal(data, &info); err != nil {
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
71
work/material/media.go
Normal file
71
work/material/media.go
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
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"
|
||||||
|
// uploadTempFile 上传临时素材
|
||||||
|
uploadTempFile = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UploadImgResponse 上传图片响应
|
||||||
|
type UploadImgResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UploadTempFileResponse 上传临时素材响应
|
||||||
|
type UploadTempFileResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
MediaID string `json:"media_id"`
|
||||||
|
CreateAt string `json:"created_at"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
// UploadTempFile 上传临时素材
|
||||||
|
// @see https://developer.work.weixin.qq.com/document/path/90253
|
||||||
|
// @mediaType 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file)
|
||||||
|
func (r *Client) UploadTempFile(filename string, mediaType string) (*UploadTempFileResponse, 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(uploadTempFile, accessToken, mediaType)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result := &UploadTempFileResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, "UploadTempFile"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
16
work/message/client.go
Normal file
16
work/message/client.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Package message 消息推送,实现企业微信消息推送相关接口:https://developer.work.weixin.qq.com/document/path/90235
|
||||||
|
package message
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/silenceper/wechat/v2/work/context"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Client 消息推送接口实例
|
||||||
|
type Client struct {
|
||||||
|
*context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient 初始化实例
|
||||||
|
func NewClient(ctx *context.Context) *Client {
|
||||||
|
return &Client{ctx}
|
||||||
|
}
|
||||||
132
work/message/message.go
Normal file
132
work/message/message.go
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
package message
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/silenceper/wechat/v2/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// 发送应用消息的接口地址
|
||||||
|
sendURL = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// SendRequestCommon 发送应用消息请求公共参数
|
||||||
|
SendRequestCommon struct {
|
||||||
|
// 指定接收消息的成员,成员ID列表(多个接收者用‘|’分隔,最多支持1000个)。 特殊情况:指定为"@all",则向该企业应用的全部成员发送
|
||||||
|
ToUser string `json:"touser"`
|
||||||
|
// 指定接收消息的部门,部门ID列表,多个接收者用‘|’分隔,最多支持100个。 当touser为"@all"时忽略本参数
|
||||||
|
ToParty string `json:"toparty"`
|
||||||
|
// 指定接收消息的标签,标签ID列表,多个接收者用‘|’分隔,最多支持100个。 当touser为"@all"时忽略本参数
|
||||||
|
ToTag string `json:"totag"`
|
||||||
|
// 消息类型,此时固定为:text
|
||||||
|
MsgType string `json:"msgtype"`
|
||||||
|
// 企业应用的id,整型。企业内部开发,可在应用的设置页面查看;第三方服务商,可通过接口 获取企业授权信息 获取该参数值
|
||||||
|
AgentID string `json:"agentid"`
|
||||||
|
// 表示是否是保密消息,0表示可对外分享,1表示不能分享且内容显示水印,默认为0
|
||||||
|
Safe int `json:"safe"`
|
||||||
|
// 表示是否开启id转译,0表示否,1表示是,默认0。仅第三方应用需要用到,企业自建应用可以忽略。
|
||||||
|
EnableIDTrans int `json:"enable_id_trans"`
|
||||||
|
// 表示是否开启重复消息检查,0表示否,1表示是,默认0
|
||||||
|
EnableDuplicateCheck int `json:"enable_duplicate_check"`
|
||||||
|
// 表示是否重复消息检查的时间间隔,默认1800s,最大不超过4小时
|
||||||
|
DuplicateCheckInterval int `json:"duplicate_check_interval"`
|
||||||
|
}
|
||||||
|
// SendResponse 发送应用消息响应参数
|
||||||
|
SendResponse struct {
|
||||||
|
util.CommonError
|
||||||
|
InvalidUser string `json:"invaliduser"` // 不合法的userid,不区分大小写,统一转为小写
|
||||||
|
InvalidParty string `json:"invalidparty"` // 不合法的partyid
|
||||||
|
InvalidTag string `json:"invalidtag"` // 不合法的标签id
|
||||||
|
UnlicensedUser string `json:"unlicenseduser"` // 没有基础接口许可(包含已过期)的userid
|
||||||
|
MsgID string `json:"msgid"` // 消息id
|
||||||
|
ResponseCode string `json:"response_code"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendTextRequest 发送文本消息的请求
|
||||||
|
SendTextRequest struct {
|
||||||
|
*SendRequestCommon
|
||||||
|
Text TextField `json:"text"`
|
||||||
|
}
|
||||||
|
// TextField 文本消息参数
|
||||||
|
TextField struct {
|
||||||
|
// 消息内容,最长不超过2048个字节,超过将截断(支持id转译)
|
||||||
|
Content string `json:"content"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendImageRequest 发送图片消息的请求
|
||||||
|
SendImageRequest struct {
|
||||||
|
*SendRequestCommon
|
||||||
|
Image ImageField `json:"image"`
|
||||||
|
}
|
||||||
|
// ImageField 图片消息参数
|
||||||
|
ImageField struct {
|
||||||
|
// 图片媒体文件id,可以调用上传临时素材接口获取
|
||||||
|
MediaID string `json:"media_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendVoiceRequest 发送语音消息的请求
|
||||||
|
SendVoiceRequest struct {
|
||||||
|
*SendRequestCommon
|
||||||
|
Voice VoiceField `json:"voice"`
|
||||||
|
}
|
||||||
|
// VoiceField 语音消息参数
|
||||||
|
VoiceField struct {
|
||||||
|
// 语音文件id,可以调用上传临时素材接口获取
|
||||||
|
MediaID string `json:"media_id"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Send 发送应用消息
|
||||||
|
// @desc 实现企业微信发送应用消息接口:https://developer.work.weixin.qq.com/document/path/90236
|
||||||
|
func (r *Client) Send(apiName string, request interface{}) (*SendResponse, error) {
|
||||||
|
// 获取accessToken
|
||||||
|
accessToken, err := r.GetAccessToken()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// 请求参数转 JSON 格式
|
||||||
|
jsonData, err := json.Marshal(request)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// 发起http请求
|
||||||
|
response, err := util.HTTPPost(fmt.Sprintf(sendURL, accessToken), string(jsonData))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// 按照结构体解析返回值
|
||||||
|
result := &SendResponse{}
|
||||||
|
if err = util.DecodeWithError(response, result, apiName); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// 返回数据
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendText 发送文本消息
|
||||||
|
func (r *Client) SendText(request SendTextRequest) (*SendResponse, error) {
|
||||||
|
// 发送文本消息MsgType参数固定为:text
|
||||||
|
request.MsgType = "text"
|
||||||
|
return r.Send("MessageSendText", request)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendImage 发送图片消息
|
||||||
|
func (r *Client) SendImage(request SendImageRequest) (*SendResponse, error) {
|
||||||
|
// 发送图片消息MsgType参数固定为:image
|
||||||
|
request.MsgType = "image"
|
||||||
|
return r.Send("MessageSendImage", request)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendVoice 发送语音消息
|
||||||
|
func (r *Client) SendVoice(request SendVoiceRequest) (*SendResponse, error) {
|
||||||
|
// 发送语音消息MsgType参数固定为:voice
|
||||||
|
request.MsgType = "voice"
|
||||||
|
return r.Send("MessageSendVoice", request)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 以上实现了部分常用消息推送:SendText 发送文本消息、SendImage 发送图片消息、SendVoice 发送语音消息,
|
||||||
|
// 如需扩展其他消息类型,建议按照以上格式,扩展对应消息类型的参数即可
|
||||||
|
// 也可以直接使用Send方法,按照企业微信消息推送的接口文档传对应消息类型的参数来使用
|
||||||
@@ -150,7 +150,7 @@ type TodoMessage struct {
|
|||||||
BaseMessage
|
BaseMessage
|
||||||
Todo struct {
|
Todo struct {
|
||||||
Title string `json:"title,omitempty"` // 代办的来源文本
|
Title string `json:"title,omitempty"` // 代办的来源文本
|
||||||
Content string `json:"content,omitempty"` // 代办的具体内容
|
Content string `json:"content,omitempty"` // 代办的具体内容
|
||||||
} `json:"todo,omitempty"`
|
} `json:"todo,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,10 +266,10 @@ type VoipDocShareMessage struct {
|
|||||||
type ExternalRedPacketMessage struct {
|
type ExternalRedPacketMessage struct {
|
||||||
BaseMessage
|
BaseMessage
|
||||||
RedPacket struct {
|
RedPacket struct {
|
||||||
Type int32 `json:"type,omitempty"` // 红包消息类型。1 普通红包、2 拼手气群红包。Uint32类型
|
Type uint32 `json:"type,omitempty"` // 红包消息类型。1 普通红包、2 拼手气群红包。Uint32类型
|
||||||
Wish int32 `json:"wish,omitempty"` // 红包祝福语。String类型
|
Wish string `json:"wish,omitempty"` // 红包祝福语。String类型
|
||||||
TotalCnt int32 `json:"totalcnt,omitempty"` // 红包总个数。Uint32类型
|
TotalCnt uint32 `json:"totalcnt,omitempty"` // 红包总个数。Uint32类型
|
||||||
TotalAmount int32 `json:"totalamount,omitempty"` // 红包消息类型。1 普通红包、2 拼手气群红包。Uint32类型
|
TotalAmount uint32 `json:"totalamount,omitempty"` // 红包总金额。Uint32类型,单位为分。
|
||||||
} `json:"redpacket,omitempty"`
|
} `json:"redpacket,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,9 +277,9 @@ type ExternalRedPacketMessage struct {
|
|||||||
type SphFeedMessage struct {
|
type SphFeedMessage struct {
|
||||||
BaseMessage
|
BaseMessage
|
||||||
SphFeed struct {
|
SphFeed struct {
|
||||||
FeedType string `json:"feed_type,omitempty"` // 视频号消息类型
|
FeedType uint32 `json:"feed_type,omitempty"` // 视频号消息类型。2 图片、4 视频、9 直播。Uint32类型
|
||||||
SphName string `json:"sph_name,omitempty"` // 视频号账号名称
|
SphName string `json:"sph_name,omitempty"` // 视频号账号名称。String类型
|
||||||
FeedDesc uint64 `json:"feed_desc,omitempty"` // 视频号账号名称
|
FeedDesc string `json:"feed_desc,omitempty"` // 视频号消息描述。String类型
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ type Oauth struct {
|
|||||||
var (
|
var (
|
||||||
// oauthTargetURL 企业微信内跳转地址
|
// 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 = "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 获取用户信息地址
|
||||||
oauthUserInfoURL = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=%s&code=%s"
|
oauthUserInfoURL = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=%s&code=%s"
|
||||||
// oauthQrContentTargetURL 构造独立窗口登录二维码
|
// oauthQrContentTargetURL 构造独立窗口登录二维码
|
||||||
@@ -33,23 +35,32 @@ func NewOauth(ctx *context.Context) *Oauth {
|
|||||||
// GetTargetURL 获取授权地址
|
// GetTargetURL 获取授权地址
|
||||||
func (ctr *Oauth) GetTargetURL(callbackURL string) string {
|
func (ctr *Oauth) GetTargetURL(callbackURL string) string {
|
||||||
// url encode
|
// url encode
|
||||||
urlStr := url.QueryEscape(callbackURL)
|
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
oauthTargetURL,
|
oauthTargetURL,
|
||||||
ctr.CorpID,
|
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 构造独立窗口登录二维码
|
// GetQrContentTargetURL 构造独立窗口登录二维码
|
||||||
func (ctr *Oauth) GetQrContentTargetURL(callbackURL string) string {
|
func (ctr *Oauth) GetQrContentTargetURL(callbackURL string) string {
|
||||||
// url encode
|
// url encode
|
||||||
urlStr := url.QueryEscape(callbackURL)
|
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
oauthQrContentTargetURL,
|
oauthQrContentTargetURL,
|
||||||
ctr.CorpID,
|
ctr.CorpID,
|
||||||
ctr.AgentID,
|
ctr.AgentID,
|
||||||
urlStr,
|
url.QueryEscape(callbackURL),
|
||||||
util.RandomStr(16),
|
util.RandomStr(16),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -68,15 +79,11 @@ type ResUserInfo struct {
|
|||||||
// UserFromCode 根据code获取用户信息
|
// UserFromCode 根据code获取用户信息
|
||||||
func (ctr *Oauth) UserFromCode(code string) (result ResUserInfo, err error) {
|
func (ctr *Oauth) UserFromCode(code string) (result ResUserInfo, err error) {
|
||||||
var accessToken string
|
var accessToken string
|
||||||
accessToken, err = ctr.GetAccessToken()
|
if accessToken, err = ctr.GetAccessToken(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var response []byte
|
var response []byte
|
||||||
response, err = util.HTTPGet(
|
if response, err = util.HTTPGet(fmt.Sprintf(oauthUserInfoURL, accessToken, code)); err != nil {
|
||||||
fmt.Sprintf(oauthUserInfoURL, accessToken, code),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(response, &result)
|
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时选填
|
||||||
|
}
|
||||||
30
work/work.go
30
work/work.go
@@ -2,12 +2,17 @@ package work
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/silenceper/wechat/v2/credential"
|
"github.com/silenceper/wechat/v2/credential"
|
||||||
|
"github.com/silenceper/wechat/v2/work/addresslist"
|
||||||
|
"github.com/silenceper/wechat/v2/work/appchat"
|
||||||
"github.com/silenceper/wechat/v2/work/config"
|
"github.com/silenceper/wechat/v2/work/config"
|
||||||
"github.com/silenceper/wechat/v2/work/context"
|
"github.com/silenceper/wechat/v2/work/context"
|
||||||
"github.com/silenceper/wechat/v2/work/externalcontact"
|
"github.com/silenceper/wechat/v2/work/externalcontact"
|
||||||
"github.com/silenceper/wechat/v2/work/kf"
|
"github.com/silenceper/wechat/v2/work/kf"
|
||||||
|
"github.com/silenceper/wechat/v2/work/material"
|
||||||
|
"github.com/silenceper/wechat/v2/work/message"
|
||||||
"github.com/silenceper/wechat/v2/work/msgaudit"
|
"github.com/silenceper/wechat/v2/work/msgaudit"
|
||||||
"github.com/silenceper/wechat/v2/work/oauth"
|
"github.com/silenceper/wechat/v2/work/oauth"
|
||||||
|
"github.com/silenceper/wechat/v2/work/robot"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Work 企业微信
|
// Work 企业微信
|
||||||
@@ -49,3 +54,28 @@ func (wk *Work) GetKF() (*kf.Client, error) {
|
|||||||
func (wk *Work) GetExternalContact() *externalcontact.Client {
|
func (wk *Work) GetExternalContact() *externalcontact.Client {
|
||||||
return externalcontact.NewClient(wk.ctx)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMessage 获取发送应用消息接口实例
|
||||||
|
func (wk *Work) GetMessage() *message.Client {
|
||||||
|
return message.NewClient(wk.ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAppChat 获取应用发送消息到群聊会话接口实例
|
||||||
|
func (wk *Work) GetAppChat() *appchat.Client {
|
||||||
|
return appchat.NewClient(wk.ctx)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user