mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
Compare commits
12 Commits
v2.1.3-rc.
...
v2.1.4-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a07c50fda7 | ||
|
|
eb3dbf1646 | ||
|
|
27e18b6958 | ||
|
|
252fc4838b | ||
|
|
fdaffb6aa2 | ||
|
|
108a65ecf3 | ||
|
|
cc9be30ed1 | ||
|
|
adf142dac2 | ||
|
|
ded5a10f9f | ||
|
|
e1307648fd | ||
|
|
c6325ace85 | ||
|
|
f2e7979a9f |
4
.github/workflows/go.yml
vendored
4
.github/workflows/go.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
golangci:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.15.x,1.16.x]
|
||||
go-version: [1.15.x,1.16.x,1.17.x]
|
||||
name: golangci-lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
# strategy set
|
||||
strategy:
|
||||
matrix:
|
||||
go: ["1.14","1.15", "1.16", "1.17", "1.18"]
|
||||
go: ["1.15", "1.16", "1.17", "1.18"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
@@ -36,8 +36,13 @@ linters:
|
||||
- whitespace
|
||||
|
||||
issues:
|
||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||
include:
|
||||
- EXC0002 # disable excluding of issues about comments from golint
|
||||
exclude-rules:
|
||||
- linters:
|
||||
- stylecheck
|
||||
text: "ST1000:"
|
||||
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- gomnd
|
||||
@@ -52,10 +57,10 @@ linters-settings:
|
||||
lines: 66
|
||||
statements: 40
|
||||
|
||||
issues:
|
||||
include:
|
||||
- EXC0002 # disable excluding of issues about comments from golint
|
||||
exclude-rules:
|
||||
- linters:
|
||||
- stylecheck
|
||||
text: "ST1000:"
|
||||
#issues:
|
||||
# include:
|
||||
# - EXC0002 # disable excluding of issues about comments from golint
|
||||
# exclude-rules:
|
||||
# - linters:
|
||||
# - stylecheck
|
||||
# text: "ST1000:"
|
||||
|
||||
12
README.md
12
README.md
@@ -25,35 +25,35 @@ import "github.com/silenceper/wechat/v2"
|
||||
以下是一个微信公众号处理消息接收以及回复的例子:
|
||||
|
||||
```go
|
||||
//使用memcache保存access_token,也可选择redis或自定义cache
|
||||
// 使用memcache保存access_token,也可选择redis或自定义cache
|
||||
wc := wechat.NewWechat()
|
||||
memory := cache.NewMemory()
|
||||
cfg := &offConfig.Config{
|
||||
AppID: "xxx",
|
||||
AppSecret: "xxx",
|
||||
Token: "xxx",
|
||||
//EncodingAESKey: "xxxx",
|
||||
// EncodingAESKey: "xxxx",
|
||||
Cache: memory,
|
||||
}
|
||||
officialAccount := wc.GetOfficialAccount(cfg)
|
||||
|
||||
// 传入request和responseWriter
|
||||
server := officialAccount.GetServer(req, rw)
|
||||
//设置接收消息的处理方法
|
||||
// 设置接收消息的处理方法
|
||||
server.SetMessageHandler(func(msg *message.MixMessage) *message.Reply {
|
||||
|
||||
//回复消息:演示回复用户发送的消息
|
||||
// 回复消息:演示回复用户发送的消息
|
||||
text := message.NewText(msg.Content)
|
||||
return &message.Reply{MsgType: message.MsgTypeText, MsgData: text}
|
||||
})
|
||||
|
||||
//处理消息接收以及回复
|
||||
// 处理消息接收以及回复
|
||||
err := server.Serve()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
//发送回复的消息
|
||||
// 发送回复的消息
|
||||
server.Send()
|
||||
|
||||
```
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
| -------------------- | -------- | -------------------------------------- | ---------- | ----------------------- |
|
||||
| 选用模板 | POST | /wxaapi/newtmpl/addtemplate | YES | (tpl *Subscribe) Add |
|
||||
| 删除模板 | POST | /wxaapi/newtmpl/deltemplate | YES | (tpl *Subscribe) Delete |
|
||||
| 获取公众号类目 | GET | /wxaapi/newtmpl/getcategory | NO | |
|
||||
| 获取模板中的关键词 | GET | /wxaapi/newtmpl/getpubtemplatekeywords | NO | |
|
||||
| 获取类目下的公共模板 | GET | /wxaapi/newtmpl/getpubtemplatetitles | NO | |
|
||||
| 获取公众号类目 | GET | /wxaapi/newtmpl/getcategory | YES | (tpl *Subscribe) GetCategory |
|
||||
| 获取模板中的关键词 | GET | /wxaapi/newtmpl/getpubtemplatekeywords | YES | (tpl *Subscribe) GetPubTplKeyWordsByID |
|
||||
| 获取类目下的公共模板 | GET | /wxaapi/newtmpl/getpubtemplatetitles | YES | (tpl *Subscribe) GetPublicTemplateTitleList |
|
||||
| 获取私有模板列表 | GET | /wxaapi/newtmpl/gettemplate | YES | (tpl *Subscribe) List() |
|
||||
| 发送订阅通知 | POST | /cgi-bin/message/subscribe/bizsend | YES | (tpl *Subscribe) Send |
|
||||
|
||||
|
||||
@@ -59,6 +59,15 @@ host: https://qyapi.weixin.qq.com/
|
||||
| 获取客户基础信息 | POST | /cgi-bin/kf/customer/batchget | YES | (r *Client) CustomerBatchGet | NICEXAI |
|
||||
| 获取视频号绑定状态 | GET | /cgi-bin/kf/get_corp_qualification | YES | (r *Client) GetCorpQualification | NICEXAI |
|
||||
|
||||
### 客户联系
|
||||
[官方文档](https://developer.work.weixin.qq.com/document/path/92132/92133)
|
||||
|
||||
| 名称 | 请求方式 | 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 |
|
||||
|
||||
## 应用管理
|
||||
|
||||
TODO
|
||||
|
||||
8
go.mod
8
go.mod
@@ -1,15 +1,15 @@
|
||||
module github.com/silenceper/wechat/v2
|
||||
|
||||
go 1.14
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/go-redis/redis/v8 v8.11.6-0.20220405070650-99c79f7041fc
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/go-redis/redis/v8 v8.11.5
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/spf13/cast v1.4.1
|
||||
github.com/stretchr/testify v1.7.1
|
||||
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
|
||||
)
|
||||
|
||||
32
go.sum
32
go.sum
@@ -15,8 +15,8 @@ github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/go-redis/redis/v8 v8.11.6-0.20220405070650-99c79f7041fc h1:jZY+lpZB92nvBo2f31oPC/ivGll6NcsnEOORm8Fkr4M=
|
||||
github.com/go-redis/redis/v8 v8.11.6-0.20220405070650-99c79f7041fc/go.mod h1:25mL1NKxbJhB63ihiK8MnNeTRd+xAizd6bOdydrTLUQ=
|
||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
@@ -48,22 +48,23 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108
|
||||
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||
github.com/onsi/ginkgo/v2 v2.1.3 h1:e/3Cwtogj0HA+25nMP1jCMDIf8RtRYbGwGGuBIFztkc=
|
||||
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
||||
github.com/onsi/ginkgo/v2 v2.0.0 h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ=
|
||||
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
|
||||
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
|
||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA=
|
||||
github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
|
||||
@@ -76,8 +77,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
|
||||
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
@@ -85,9 +86,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -96,7 +96,6 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -105,15 +104,14 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
|
||||
@@ -84,7 +84,9 @@ func (auth *Auth) CheckEncryptedDataContext(ctx context2.Context, encryptedMsgHa
|
||||
if at, err = auth.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
if response, err = util.HTTPPostContext(ctx, fmt.Sprintf(checkEncryptedDataURL, at), "encrypted_msg_hash="+encryptedMsgHash); err != nil {
|
||||
|
||||
// 由于GetPhoneNumberContext需要传入JSON,所以HTTPPostContext入参改为[]byte
|
||||
if response, err = util.HTTPPostContext(ctx, fmt.Sprintf(checkEncryptedDataURL, at), []byte("encrypted_msg_hash="+encryptedMsgHash), nil); err != nil {
|
||||
return
|
||||
}
|
||||
if err = util.DecodeWithError(response, &result, "CheckEncryptedDataAuth"); err != nil {
|
||||
@@ -111,8 +113,8 @@ type PhoneInfo struct {
|
||||
} `json:"watermark"` // 数据水印
|
||||
}
|
||||
|
||||
// GetPhoneNumber 小程序通过code获取用户手机号
|
||||
func (auth *Auth) GetPhoneNumber(code string) (*GetPhoneNumberResponse, error) {
|
||||
// GetPhoneNumberContext 小程序通过code获取用户手机号
|
||||
func (auth *Auth) GetPhoneNumberContext(ctx context2.Context, code string) (*GetPhoneNumberResponse, error) {
|
||||
var response []byte
|
||||
var (
|
||||
at string
|
||||
@@ -124,12 +126,25 @@ func (auth *Auth) GetPhoneNumber(code string) (*GetPhoneNumberResponse, error) {
|
||||
body := map[string]interface{}{
|
||||
"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
|
||||
}
|
||||
|
||||
header := map[string]string{"Content-Type": "application/json;charset=utf-8"}
|
||||
if response, err = util.HTTPPostContext(ctx, fmt.Sprintf(getPhoneNumber, at), bodyBytes, header); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var result GetPhoneNumberResponse
|
||||
if err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// GetPhoneNumber 小程序通过code获取用户手机号
|
||||
func (auth *Auth) GetPhoneNumber(code string) (*GetPhoneNumberResponse, error) {
|
||||
return auth.GetPhoneNumberContext(context2.Background(), code)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,6 @@ import (
|
||||
// Config .config for 小程序
|
||||
type Config struct {
|
||||
AppID string `json:"app_id"` // appid
|
||||
AppSecret string `json:"app_secret"` // appsecret
|
||||
AppSecret string `json:"app_secret"` // appSecret
|
||||
Cache cache.Cache
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -68,6 +68,8 @@ const (
|
||||
EventPicWeixin EventType = "pic_weixin"
|
||||
// EventLocationSelect 弹出地理位置选择器的事件推送
|
||||
EventLocationSelect EventType = "location_select"
|
||||
// EventViewMiniprogram 点击菜单跳转小程序的事件推送
|
||||
EventViewMiniprogram EventType = "view_miniprogram"
|
||||
// EventTemplateSendJobFinish 发送模板消息推送通知
|
||||
EventTemplateSendJobFinish EventType = "TEMPLATESENDJOBFINISH"
|
||||
// EventMassSendJobFinish 群发消息推送通知
|
||||
|
||||
@@ -8,10 +8,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
subscribeSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend"
|
||||
subscribeTemplateListURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
||||
subscribeTemplateAddURL = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate"
|
||||
subscribeTemplateDelURL = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate"
|
||||
subscribeSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend"
|
||||
subscribeTemplateListURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
|
||||
subscribeTemplateAddURL = "https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate"
|
||||
subscribeTemplateDelURL = "https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate"
|
||||
subscribeTemplateGetCategoryURL = "https://api.weixin.qq.com/wxaapi/newtmpl/getcategory"
|
||||
subscribeTemplateGetPubTplKeyWorksURL = "https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords"
|
||||
subscribeTemplateGetPubTplTitles = "https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles"
|
||||
)
|
||||
|
||||
// Subscribe 订阅消息
|
||||
@@ -145,3 +148,108 @@ func (tpl *Subscribe) Delete(templateID string) (err error) {
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "DeleteSubscribe")
|
||||
}
|
||||
|
||||
// PublicTemplateCategory 公众号类目
|
||||
type PublicTemplateCategory struct {
|
||||
ID int `json:"id"` //类目ID
|
||||
Name string `json:"name"` //类目的中文名
|
||||
}
|
||||
|
||||
type resSubscribeCategoryList struct {
|
||||
util.CommonError
|
||||
CategoryList []*PublicTemplateCategory `json:"data"`
|
||||
}
|
||||
|
||||
// GetCategory 获取公众号类目
|
||||
func (tpl *Subscribe) GetCategory() (categoryList []*PublicTemplateCategory, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = tpl.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", subscribeTemplateGetCategoryURL, accessToken)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var result resSubscribeCategoryList
|
||||
err = util.DecodeWithError(response, &result, "GetCategory")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
categoryList = result.CategoryList
|
||||
return
|
||||
}
|
||||
|
||||
// PublicTemplateKeyWords 模板中的关键词
|
||||
type PublicTemplateKeyWords struct {
|
||||
KeyWordsID int `json:"kid"` // 关键词 id
|
||||
Name string `json:"name"` // 关键词内容
|
||||
Example string `json:"example"` //关键词内容对应的示例
|
||||
Rule string `json:"rule"` // 参数类型
|
||||
}
|
||||
|
||||
type resPublicTemplateKeyWordsList struct {
|
||||
util.CommonError
|
||||
KeyWordsList []*PublicTemplateKeyWords `json:"data"` //关键词列表
|
||||
}
|
||||
|
||||
// GetPubTplKeyWordsByID 获取模板中的关键词
|
||||
func (tpl *Subscribe) GetPubTplKeyWordsByID(titleID string) (keyWordsList []*PublicTemplateKeyWords, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = tpl.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s&tid=%s", subscribeTemplateGetPubTplKeyWorksURL, accessToken, titleID)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var result resPublicTemplateKeyWordsList
|
||||
err = util.DecodeWithError(response, &result, "GetPublicTemplateKeyWords")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
keyWordsList = result.KeyWordsList
|
||||
return
|
||||
}
|
||||
|
||||
// PublicTemplateTitle 类目下的公共模板
|
||||
type PublicTemplateTitle struct {
|
||||
TitleID int `json:"tid"` // 模版标题 id
|
||||
Title string `json:"title"` // 模版标题
|
||||
Type int `json:"type"` // 模版类型,2 为一次性订阅,3 为长期订阅
|
||||
CategoryID string `json:"categoryId"` // 模版所属类目 id
|
||||
}
|
||||
|
||||
type resPublicTemplateTitleList struct {
|
||||
util.CommonError
|
||||
Count int `json:"count"` //公共模板列表总数
|
||||
TemplateTitleList []*PublicTemplateTitle `json:"data"` //模板标题列表
|
||||
}
|
||||
|
||||
// GetPublicTemplateTitleList 获取类目下的公共模板
|
||||
func (tpl *Subscribe) GetPublicTemplateTitleList(ids string, start int, limit int) (count int, templateTitleList []*PublicTemplateTitle, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = tpl.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s&ids=%s&start=%d&limit=%d", subscribeTemplateGetPubTplTitles, accessToken, ids, start, limit)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var result resPublicTemplateTitleList
|
||||
err = util.DecodeWithError(response, &result, "GetPublicTemplateTitle")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = result.Count
|
||||
templateTitleList = result.TemplateTitleList
|
||||
return
|
||||
}
|
||||
|
||||
@@ -26,7 +26,22 @@ import (
|
||||
|
||||
// OfficialAccount 微信公众号相关API
|
||||
type OfficialAccount struct {
|
||||
ctx *context.Context
|
||||
ctx *context.Context
|
||||
basic *basic.Basic
|
||||
menu *menu.Menu
|
||||
oauth *oauth.Oauth
|
||||
material *material.Material
|
||||
draft *draft.Draft
|
||||
freepublish *freepublish.FreePublish
|
||||
js *js.Js
|
||||
user *user.User
|
||||
templateMsg *message.Template
|
||||
managerMsg *message.Manager
|
||||
device *device.Device
|
||||
broadcast *broadcast.Broadcast
|
||||
datacube *datacube.DataCube
|
||||
ocr *ocr.OCR
|
||||
subscribeMsg *message.Subscribe
|
||||
}
|
||||
|
||||
// NewOfficialAccount 实例化公众号API
|
||||
@@ -51,12 +66,18 @@ func (officialAccount *OfficialAccount) GetContext() *context.Context {
|
||||
|
||||
// GetBasic qr/url 相关配置
|
||||
func (officialAccount *OfficialAccount) GetBasic() *basic.Basic {
|
||||
return basic.NewBasic(officialAccount.ctx)
|
||||
if officialAccount.basic == nil {
|
||||
officialAccount.basic = basic.NewBasic(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.basic
|
||||
}
|
||||
|
||||
// GetMenu 菜单管理接口
|
||||
func (officialAccount *OfficialAccount) GetMenu() *menu.Menu {
|
||||
return menu.NewMenu(officialAccount.ctx)
|
||||
if officialAccount.menu == nil {
|
||||
officialAccount.menu = menu.NewMenu(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.menu
|
||||
}
|
||||
|
||||
// GetServer 消息管理:接收事件,被动回复消息管理
|
||||
@@ -74,66 +95,105 @@ func (officialAccount *OfficialAccount) GetAccessToken() (string, error) {
|
||||
|
||||
// GetOauth oauth2网页授权
|
||||
func (officialAccount *OfficialAccount) GetOauth() *oauth.Oauth {
|
||||
return oauth.NewOauth(officialAccount.ctx)
|
||||
if officialAccount.oauth == nil {
|
||||
officialAccount.oauth = oauth.NewOauth(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.oauth
|
||||
}
|
||||
|
||||
// GetMaterial 素材管理
|
||||
func (officialAccount *OfficialAccount) GetMaterial() *material.Material {
|
||||
return material.NewMaterial(officialAccount.ctx)
|
||||
if officialAccount.material == nil {
|
||||
officialAccount.material = material.NewMaterial(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.material
|
||||
}
|
||||
|
||||
// GetDraft 草稿箱
|
||||
func (officialAccount *OfficialAccount) GetDraft() *draft.Draft {
|
||||
return draft.NewDraft(officialAccount.ctx)
|
||||
if officialAccount.draft == nil {
|
||||
officialAccount.draft = draft.NewDraft(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.draft
|
||||
}
|
||||
|
||||
// GetFreePublish 发布能力
|
||||
func (officialAccount *OfficialAccount) GetFreePublish() *freepublish.FreePublish {
|
||||
return freepublish.NewFreePublish(officialAccount.ctx)
|
||||
if officialAccount.freepublish == nil {
|
||||
officialAccount.freepublish = freepublish.NewFreePublish(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.freepublish
|
||||
}
|
||||
|
||||
// GetJs js-sdk配置
|
||||
func (officialAccount *OfficialAccount) GetJs() *js.Js {
|
||||
return js.NewJs(officialAccount.ctx)
|
||||
if officialAccount.js == nil {
|
||||
officialAccount.js = js.NewJs(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.js
|
||||
}
|
||||
|
||||
// GetUser 用户管理接口
|
||||
func (officialAccount *OfficialAccount) GetUser() *user.User {
|
||||
return user.NewUser(officialAccount.ctx)
|
||||
if officialAccount.user == nil {
|
||||
officialAccount.user = user.NewUser(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.user
|
||||
}
|
||||
|
||||
// GetTemplate 模板消息接口
|
||||
func (officialAccount *OfficialAccount) GetTemplate() *message.Template {
|
||||
return message.NewTemplate(officialAccount.ctx)
|
||||
if officialAccount.templateMsg == nil {
|
||||
officialAccount.templateMsg = message.NewTemplate(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.templateMsg
|
||||
}
|
||||
|
||||
// GetCustomerMessageManager 客服消息接口
|
||||
func (officialAccount *OfficialAccount) GetCustomerMessageManager() *message.Manager {
|
||||
return message.NewMessageManager(officialAccount.ctx)
|
||||
if officialAccount.managerMsg == nil {
|
||||
officialAccount.managerMsg = message.NewMessageManager(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.managerMsg
|
||||
}
|
||||
|
||||
// GetDevice 获取智能设备的实例
|
||||
func (officialAccount *OfficialAccount) GetDevice() *device.Device {
|
||||
return device.NewDevice(officialAccount.ctx)
|
||||
if officialAccount.device == nil {
|
||||
officialAccount.device = device.NewDevice(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.device
|
||||
}
|
||||
|
||||
// GetBroadcast 群发消息
|
||||
// TODO 待完善
|
||||
func (officialAccount *OfficialAccount) GetBroadcast() *broadcast.Broadcast {
|
||||
return broadcast.NewBroadcast(officialAccount.ctx)
|
||||
if officialAccount.broadcast == nil {
|
||||
officialAccount.broadcast = broadcast.NewBroadcast(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.broadcast
|
||||
}
|
||||
|
||||
// GetDataCube 数据统计
|
||||
func (officialAccount *OfficialAccount) GetDataCube() *datacube.DataCube {
|
||||
return datacube.NewCube(officialAccount.ctx)
|
||||
if officialAccount.datacube == nil {
|
||||
officialAccount.datacube = datacube.NewCube(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.datacube
|
||||
}
|
||||
|
||||
// GetOCR OCR接口
|
||||
func (officialAccount *OfficialAccount) GetOCR() *ocr.OCR {
|
||||
return ocr.NewOCR(officialAccount.ctx)
|
||||
if officialAccount.ocr == nil {
|
||||
officialAccount.ocr = ocr.NewOCR(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.ocr
|
||||
}
|
||||
|
||||
// GetSubscribe 公众号订阅消息
|
||||
func (officialAccount *OfficialAccount) GetSubscribe() *message.Subscribe {
|
||||
return message.NewSubscribe(officialAccount.ctx)
|
||||
if officialAccount.subscribeMsg == nil {
|
||||
officialAccount.subscribeMsg = message.NewSubscribe(officialAccount.ctx)
|
||||
}
|
||||
return officialAccount.subscribeMsg
|
||||
}
|
||||
|
||||
@@ -73,6 +73,11 @@ func (srv *Server) Serve() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 非安全模式下,请求处理方法返回为nil则直接回复success给微信服务器
|
||||
if response == nil && !srv.isSafeMode {
|
||||
srv.String("success")
|
||||
return nil
|
||||
}
|
||||
|
||||
// debug print request msg
|
||||
log.Debugf("request msg =%s", string(srv.RequestRawXMLMsg))
|
||||
|
||||
@@ -226,6 +226,36 @@ type AuthorizerInfo struct {
|
||||
}
|
||||
Alias string `json:"alias"`
|
||||
QrcodeURL string `json:"qrcode_url"`
|
||||
|
||||
MiniProgramInfo *MiniProgramInfo `json:"MiniProgramInfo"`
|
||||
RegisterType int `json:"register_type"`
|
||||
AccountStatus int `json:"account_status"`
|
||||
BasicConfig *AuthorizerBasicConfig `json:"basic_config"`
|
||||
}
|
||||
|
||||
// AuthorizerBasicConfig 授权账号的基础配置结构体
|
||||
type AuthorizerBasicConfig struct {
|
||||
IsPhoneConfigured bool `json:"isPhoneConfigured"`
|
||||
IsEmailConfigured bool `json:"isEmailConfigured"`
|
||||
}
|
||||
|
||||
// MiniProgramInfo 授权账号小程序配置 授权账号为小程序时存在
|
||||
type MiniProgramInfo struct {
|
||||
Network struct {
|
||||
RequestDomain []string `json:"RequestDomain"`
|
||||
WsRequestDomain []string `json:"WsRequestDomain"`
|
||||
UploadDomain []string `json:"UploadDomain"`
|
||||
DownloadDomain []string `json:"DownloadDomain"`
|
||||
BizDomain []string `json:"BizDomain"`
|
||||
UDPDomain []string `json:"UDPDomain"`
|
||||
} `json:"network"`
|
||||
Categories []CategoriesInfo `json:"categories"`
|
||||
}
|
||||
|
||||
// CategoriesInfo 授权账号小程序配置的类目信息
|
||||
type CategoriesInfo struct {
|
||||
First string `wx:"first"`
|
||||
Second string `wx:"second"`
|
||||
}
|
||||
|
||||
// GetAuthrInfo 获取授权方的帐号基本信息
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package miniprogram
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
miniContext "github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/urllink"
|
||||
openContext "github.com/silenceper/wechat/v2/openplatform/context"
|
||||
"github.com/silenceper/wechat/v2/openplatform/miniprogram/basic"
|
||||
"github.com/silenceper/wechat/v2/openplatform/miniprogram/component"
|
||||
@@ -10,6 +14,30 @@ import (
|
||||
type MiniProgram struct {
|
||||
AppID string
|
||||
openContext *openContext.Context
|
||||
|
||||
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 实例化
|
||||
@@ -30,3 +58,10 @@ func (miniProgram *MiniProgram) GetComponent() *component.Component {
|
||||
func (miniProgram *MiniProgram) GetBasic() *basic.Basic {
|
||||
return basic.NewBasic(miniProgram.openContext, miniProgram.AppID)
|
||||
}
|
||||
|
||||
// GetURLLink 小程序URL Link接口 调用前需确认已调用 SetAuthorizerRefreshToken 避免由于缓存中 authorizer_access_token 过期执行中断
|
||||
func (miniProgram *MiniProgram) GetURLLink() *urllink.URLLink {
|
||||
return urllink.NewURLLink(&miniContext.Context{
|
||||
AccessTokenHandle: miniProgram,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ type RefundedResp struct {
|
||||
|
||||
// DecryptReqInfo 对退款结果进行解密
|
||||
func (notify *Notify) DecryptReqInfo(result *RefundedResult) (*RefundedReqInfo, error) {
|
||||
var err error
|
||||
if result == nil || result.ReqInfo == nil {
|
||||
return nil, errors.New("empty refunded_result or req_info")
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ func (o *Order) BridgeConfig(p *Params) (cfg Config, err error) {
|
||||
// BridgeAppConfig get app bridge config
|
||||
func (o *Order) BridgeAppConfig(p *Params) (cfg ConfigForApp, err error) {
|
||||
var (
|
||||
timestamp = strconv.FormatInt(time.Now().Unix(), 10)
|
||||
timestamp = strconv.FormatInt(util.GetCurrTS(), 10)
|
||||
noncestr = util.RandomStr(32)
|
||||
_package = "Sign=WXPay"
|
||||
)
|
||||
@@ -273,7 +273,7 @@ func (o *Order) PrePayOrder(p *Params) (payOrder PreOrder, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// PrePayID will request wechat merchant api and request for a pre payment order id
|
||||
// PrePayID will request wechat merchant api and request for a pre-payment order id
|
||||
func (o *Order) PrePayID(p *Params) (prePayID string, err error) {
|
||||
order, err := o.PrePayOrder(p)
|
||||
if err != nil {
|
||||
|
||||
@@ -23,12 +23,12 @@ func (pay *Pay) GetOrder() *order.Order {
|
||||
return order.NewOrder(pay.cfg)
|
||||
}
|
||||
|
||||
// GetNotify 通知
|
||||
// GetNotify 通知
|
||||
func (pay *Pay) GetNotify() *notify.Notify {
|
||||
return notify.NewNotify(pay.cfg)
|
||||
}
|
||||
|
||||
// GetRefund 退款
|
||||
// GetRefund 退款
|
||||
func (pay *Pay) GetRefund() *refund.Refund {
|
||||
return refund.NewRefund(pay.cfg)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
// 付款到零钱
|
||||
// walletTransferGateway 付款到零钱
|
||||
// https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
|
||||
var walletTransferGateway = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"
|
||||
|
||||
@@ -20,8 +20,7 @@ type Transfer struct {
|
||||
|
||||
// NewTransfer return an instance of Transfer package
|
||||
func NewTransfer(cfg *config.Config) *Transfer {
|
||||
transfer := Transfer{cfg}
|
||||
return &transfer
|
||||
return &Transfer{cfg}
|
||||
}
|
||||
|
||||
// Params 调用参数
|
||||
|
||||
@@ -8,10 +8,15 @@ import (
|
||||
|
||||
// CommonError 微信返回的通用错误json
|
||||
type CommonError struct {
|
||||
apiName string
|
||||
ErrCode int64 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
}
|
||||
|
||||
func (c *CommonError) Error() string {
|
||||
return fmt.Sprintf("%s Error , errcode=%d , errmsg=%s", c.apiName, c.ErrCode, c.ErrMsg)
|
||||
}
|
||||
|
||||
// DecodeWithCommonError 将返回值按照CommonError解析
|
||||
func DecodeWithCommonError(response []byte, apiName string) (err error) {
|
||||
var commError CommonError
|
||||
@@ -19,8 +24,9 @@ func DecodeWithCommonError(response []byte, apiName string) (err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
commError.apiName = apiName
|
||||
if commError.ErrCode != 0 {
|
||||
return fmt.Errorf("%s Error , errcode=%d , errmsg=%s", apiName, commError.ErrCode, commError.ErrMsg)
|
||||
return &commError
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -45,7 +51,11 @@ func DecodeWithError(response []byte, obj interface{}, apiName string) error {
|
||||
return fmt.Errorf("errcode or errmsg is invalid")
|
||||
}
|
||||
if errCode.Int() != 0 {
|
||||
return fmt.Errorf("%s Error , errcode=%d , errmsg=%s", apiName, errCode.Int(), errMsg.String())
|
||||
return &CommonError{
|
||||
apiName: apiName,
|
||||
ErrCode: errCode.Int(),
|
||||
ErrMsg: errMsg.String(),
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
55
util/error_test.go
Normal file
55
util/error_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package util
|
||||
|
||||
import "testing"
|
||||
|
||||
var okErrData string = `{"errcode": 0}`
|
||||
var errData string = `{"errcode": 43101, "errmsg": "user refuse to accept the msg"}`
|
||||
var expectError string = "Send Error , errcode=43101 , errmsg=user refuse to accept the msg"
|
||||
|
||||
func TestDecodeWithCommonErrorNoError(t *testing.T) {
|
||||
err := DecodeWithCommonError([]byte(okErrData), "Send")
|
||||
if err != nil {
|
||||
t.Error("DecodeWithCommonError should not return error")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeWithCommonError(t *testing.T) {
|
||||
err := DecodeWithCommonError([]byte(errData), "Send")
|
||||
if err == nil {
|
||||
t.Error("DecodeWithCommonError should return error")
|
||||
return
|
||||
}
|
||||
|
||||
cErr, ok := err.(*CommonError)
|
||||
if !ok {
|
||||
t.Errorf("DecodeWithCommonError should return *CommonError but %T", err)
|
||||
return
|
||||
}
|
||||
if !(cErr.ErrCode == 43101 && cErr.ErrMsg == "user refuse to accept the msg" && cErr.Error() == expectError) {
|
||||
t.Error("DecodeWithCommonError return bad *CommonError")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecodeWithError(t *testing.T) {
|
||||
type DE struct {
|
||||
CommonError
|
||||
}
|
||||
var obj DE
|
||||
err := DecodeWithError([]byte(errData), &obj, "Send")
|
||||
if err == nil {
|
||||
t.Error("DecodeWithError should return error")
|
||||
return
|
||||
}
|
||||
|
||||
cErr, ok := err.(*CommonError)
|
||||
if !ok {
|
||||
t.Errorf("DecodeWithError should return *CommonError but %T", err)
|
||||
return
|
||||
}
|
||||
if !(cErr.ErrCode == 43101 && cErr.ErrMsg == "user refuse to accept the msg" && cErr.Error() == expectError) {
|
||||
t.Error("DecodeWithError return bad *CommonError")
|
||||
return
|
||||
}
|
||||
}
|
||||
17
util/http.go
17
util/http.go
@@ -43,16 +43,21 @@ func HTTPGetContext(ctx context.Context, uri string) ([]byte, error) {
|
||||
|
||||
// HTTPPost post 请求
|
||||
func HTTPPost(uri string, data string) ([]byte, error) {
|
||||
return HTTPPostContext(context.Background(), uri, data)
|
||||
return HTTPPostContext(context.Background(), uri, []byte(data), nil)
|
||||
}
|
||||
|
||||
// HTTPPostContext post 请求
|
||||
func HTTPPostContext(ctx context.Context, uri string, data string) ([]byte, error) {
|
||||
body := bytes.NewBuffer([]byte(data))
|
||||
func HTTPPostContext(ctx context.Context, uri string, data []byte, header map[string]string) ([]byte, error) {
|
||||
body := bytes.NewBuffer(data)
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for key, value := range header {
|
||||
request.Header.Set(key, value)
|
||||
}
|
||||
|
||||
response, err := http.DefaultClient.Do(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -60,7 +65,7 @@ func HTTPPostContext(ctx context.Context, uri string, data string) ([]byte, erro
|
||||
|
||||
defer response.Body.Close()
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
||||
return nil, fmt.Errorf("http post error : uri=%v , statusCode=%v", uri, response.StatusCode)
|
||||
}
|
||||
return ioutil.ReadAll(response.Body)
|
||||
}
|
||||
@@ -111,11 +116,11 @@ func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, e
|
||||
}
|
||||
|
||||
// PostFile 上传文件
|
||||
func PostFile(fieldname, filename, uri string) ([]byte, error) {
|
||||
func PostFile(fieldName, filename, uri string) ([]byte, error) {
|
||||
fields := []MultipartFormField{
|
||||
{
|
||||
IsFile: true,
|
||||
Fieldname: fieldname,
|
||||
Fieldname: fieldName,
|
||||
Filename: filename,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ func NewWechat() *Wechat {
|
||||
}
|
||||
|
||||
// SetCache 设置cache
|
||||
func (wc *Wechat) SetCache(cahce cache.Cache) {
|
||||
wc.cache = cahce
|
||||
func (wc *Wechat) SetCache(cache cache.Cache) {
|
||||
wc.cache = cache
|
||||
}
|
||||
|
||||
// GetOfficialAccount 获取微信公众号实例
|
||||
|
||||
@@ -27,7 +27,6 @@ type ExternalUserListResponse struct {
|
||||
// GetExternalUserList 获取客户列表
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92113
|
||||
func (r *Client) GetExternalUserList(userID string) ([]string, error) {
|
||||
var accessToken string
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -98,7 +97,6 @@ type WechatChannel struct {
|
||||
|
||||
// GetExternalUserDetail 获取外部联系人详情
|
||||
func (r *Client) GetExternalUserDetail(externalUserID string, nextCursor ...string) (*ExternalUser, error) {
|
||||
var accessToken string
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -130,7 +128,6 @@ type ExternalUserDetailListResponse struct {
|
||||
|
||||
// BatchGetExternalUserDetails 批量获取外部联系人详情
|
||||
func (r *Client) BatchGetExternalUserDetails(request BatchGetExternalUserDetailsRequest) ([]ExternalUser, error) {
|
||||
var accessToken string
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -157,12 +154,11 @@ type UpdateUserRemarkRequest struct {
|
||||
Description string `json:"description"`
|
||||
RemarkCompany string `json:"remark_company"`
|
||||
RemarkMobiles []string `json:"remark_mobiles"`
|
||||
RemarkPicMediaid string `json:"remark_pic_mediaid"`
|
||||
RemarkPicMediaID string `json:"remark_pic_mediaid"`
|
||||
}
|
||||
|
||||
// UpdateUserRemark 修改客户备注信息
|
||||
func (r *Client) UpdateUserRemark(request UpdateUserRemarkRequest) error {
|
||||
var accessToken string
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -17,10 +17,9 @@ type followerUserResponse struct {
|
||||
FollowUser []string `json:"follow_user"`
|
||||
}
|
||||
|
||||
//GetFollowUserList 获取配置了客户联系功能的成员列表
|
||||
//@see https://developer.work.weixin.qq.com/document/path/92571
|
||||
// GetFollowUserList 获取配置了客户联系功能的成员列表
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92571
|
||||
func (r *Client) GetFollowUserList() ([]string, error) {
|
||||
var accessToken string
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
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
|
||||
}
|
||||
@@ -54,7 +54,6 @@ type TagGroupTagItem struct {
|
||||
// GetCropTagList 获取企业标签库
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92117
|
||||
func (r *Client) GetCropTagList(req GetCropTagRequest) ([]TagGroup, error) {
|
||||
var accessToken string
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -127,7 +126,6 @@ type EditCropTagRequest struct {
|
||||
// EditCropTag 修改企业客户标签
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92117
|
||||
func (r *Client) EditCropTag(req EditCropTagRequest) error {
|
||||
var accessToken string
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -151,7 +149,6 @@ type DeleteCropTagRequest struct {
|
||||
// DeleteCropTag 删除企业客户标签
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92117
|
||||
func (r *Client) DeleteCropTag(req DeleteCropTagRequest) error {
|
||||
var accessToken string
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -166,8 +163,9 @@ func (r *Client) DeleteCropTag(req DeleteCropTagRequest) error {
|
||||
}
|
||||
|
||||
// MarkTagRequest 给客户打标签请求
|
||||
// 相关文档地址:https://developer.work.weixin.qq.com/document/path/92118
|
||||
type MarkTagRequest struct {
|
||||
UserID string `json:"user_id"`
|
||||
UserID string `json:"userid"`
|
||||
ExternalUserID string `json:"external_userid"`
|
||||
AddTag []string `json:"add_tag"`
|
||||
RemoveTag []string `json:"remove_tag"`
|
||||
@@ -176,7 +174,6 @@ type MarkTagRequest struct {
|
||||
// MarkTag 为客户打上标签
|
||||
// @see https://developer.work.weixin.qq.com/document/path/92118
|
||||
func (r *Client) MarkTag(request MarkTagRequest) error {
|
||||
var accessToken string
|
||||
accessToken, err := r.GetAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -38,12 +38,10 @@ func (r *Client) AccountAdd(options AccountAddOptions) (info AccountAddSchema, e
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(accountAddAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(accountAddAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -66,12 +64,10 @@ func (r *Client) AccountDel(options AccountDelOptions) (info util.CommonError, e
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(accountDelAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(accountDelAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -96,12 +92,10 @@ func (r *Client) AccountUpdate(options AccountUpdateOptions) (info util.CommonEr
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(accountUpdateAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(accountUpdateAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -132,12 +126,10 @@ func (r *Client) AccountList() (info AccountListSchema, err error) {
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.HTTPGet(fmt.Sprintf(accountListAddr, accessToken))
|
||||
if err != nil {
|
||||
if data, err = util.HTTPGet(fmt.Sprintf(accountListAddr, accessToken)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -171,12 +163,10 @@ func (r *Client) AddContactWay(options AddContactWayOptions) (info AddContactWay
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(addContactWayAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(addContactWayAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -38,12 +38,10 @@ func (r *Client) CustomerBatchGet(options CustomerBatchGetOptions) (info Custome
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(customerBatchGetAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(customerBatchGetAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -31,12 +31,10 @@ func (r *Client) GetCorpQualification() (info CorpQualificationSchema, err error
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.HTTPGet(fmt.Sprintf(corpQualification, accessToken))
|
||||
if err != nil {
|
||||
if data, err = util.HTTPGet(fmt.Sprintf(corpQualification, accessToken)); err != nil {
|
||||
return info, err
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -31,12 +31,10 @@ func (r *Client) SendMsg(options interface{}) (info SendMsgSchema, err error) {
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(sendMsgAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(sendMsgAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -38,12 +38,10 @@ func (r *Client) SendMsgOnEvent(options interface{}) (info SendMsgOnEventSchema,
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(sendMsgOnEventAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(sendMsgOnEventAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -37,12 +37,10 @@ func (r *Client) ReceptionistAdd(options ReceptionistOptions) (info Receptionist
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(receptionistAddAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(receptionistAddAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -39,12 +39,10 @@ func (r *Client) ServiceStateGet(options ServiceStateGetOptions) (info ServiceSt
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(serviceStateGetAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(serviceStateGetAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -76,12 +74,10 @@ func (r *Client) ServiceStateTrans(options ServiceStateTransOptions) (info Servi
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(serviceStateTransAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(serviceStateTransAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -45,12 +45,10 @@ func (r *Client) SyncMsg(options SyncMsgOptions) (info SyncMsgSchema, err error)
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(syncMsgAddr, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(syncMsgAddr, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
originInfo := syncMsgSchema{}
|
||||
|
||||
@@ -34,12 +34,10 @@ func (r *Client) UpgradeServiceConfig() (info UpgradeServiceConfigSchema, err er
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.HTTPGet(fmt.Sprintf(upgradeServiceConfigAddr, accessToken))
|
||||
if err != nil {
|
||||
if data, err = util.HTTPGet(fmt.Sprintf(upgradeServiceConfigAddr, accessToken)); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -72,12 +70,10 @@ func (r *Client) UpgradeService(options UpgradeServiceOptions) (info util.Common
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(upgradeService, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(upgradeService, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -106,12 +102,10 @@ func (r *Client) UpgradeMemberService(options UpgradeMemberServiceOptions) (info
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(upgradeService, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(upgradeService, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
@@ -169,12 +163,10 @@ func (r *Client) UpgradeServiceCancel(options UpgradeServiceCancelOptions) (info
|
||||
accessToken string
|
||||
data []byte
|
||||
)
|
||||
accessToken, err = r.ctx.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = r.ctx.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
data, err = util.PostJSON(fmt.Sprintf(upgradeServiceCancel, accessToken), options)
|
||||
if err != nil {
|
||||
if data, err = util.PostJSON(fmt.Sprintf(upgradeServiceCancel, accessToken), options); err != nil {
|
||||
return
|
||||
}
|
||||
if err = json.Unmarshal(data, &info); err != nil {
|
||||
|
||||
@@ -33,23 +33,21 @@ func NewOauth(ctx *context.Context) *Oauth {
|
||||
// GetTargetURL 获取授权地址
|
||||
func (ctr *Oauth) GetTargetURL(callbackURL string) string {
|
||||
// url encode
|
||||
urlStr := url.QueryEscape(callbackURL)
|
||||
return fmt.Sprintf(
|
||||
oauthTargetURL,
|
||||
ctr.CorpID,
|
||||
urlStr,
|
||||
url.QueryEscape(callbackURL),
|
||||
)
|
||||
}
|
||||
|
||||
// GetQrContentTargetURL 构造独立窗口登录二维码
|
||||
func (ctr *Oauth) GetQrContentTargetURL(callbackURL string) string {
|
||||
// url encode
|
||||
urlStr := url.QueryEscape(callbackURL)
|
||||
return fmt.Sprintf(
|
||||
oauthQrContentTargetURL,
|
||||
ctr.CorpID,
|
||||
ctr.AgentID,
|
||||
urlStr,
|
||||
url.QueryEscape(callbackURL),
|
||||
util.RandomStr(16),
|
||||
)
|
||||
}
|
||||
@@ -68,15 +66,11 @@ type ResUserInfo struct {
|
||||
// UserFromCode 根据code获取用户信息
|
||||
func (ctr *Oauth) UserFromCode(code string) (result ResUserInfo, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = ctr.GetAccessToken()
|
||||
if err != nil {
|
||||
if accessToken, err = ctr.GetAccessToken(); err != nil {
|
||||
return
|
||||
}
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(
|
||||
fmt.Sprintf(oauthUserInfoURL, accessToken, code),
|
||||
)
|
||||
if err != nil {
|
||||
if response, err = util.HTTPGet(fmt.Sprintf(oauthUserInfoURL, accessToken, code)); err != nil {
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(response, &result)
|
||||
|
||||
Reference in New Issue
Block a user