mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
Compare commits
39 Commits
feature/au
...
feature/go
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8e3208ef2 | ||
|
|
d8fde54f2d | ||
|
|
ba0a1477eb | ||
|
|
01eedc4274 | ||
|
|
05ac7148d4 | ||
|
|
6b3532cc2d | ||
|
|
1138a7db0e | ||
|
|
1842f08f4c | ||
|
|
d28ca4f334 | ||
|
|
74795e86ee | ||
|
|
179704187b | ||
|
|
ceb006bf58 | ||
|
|
9f14122a87 | ||
|
|
7fcd7a34dd | ||
|
|
5b29289dbb | ||
|
|
74e3e9c04e | ||
|
|
97c9f7d908 | ||
|
|
97e1af5904 | ||
|
|
a5e674bf10 | ||
|
|
0ffe34187a | ||
|
|
04b62f6c3c | ||
|
|
4adc59b1b0 | ||
|
|
dad7932574 | ||
|
|
56a3734546 | ||
|
|
d4fd145bb5 | ||
|
|
038037b89d | ||
|
|
479ff1f242 | ||
|
|
3f1c5e7637 | ||
|
|
da5067bcb2 | ||
|
|
8f10936479 | ||
|
|
9bfebc8a27 | ||
|
|
4f6cbc3d59 | ||
|
|
49c4cfaf54 | ||
|
|
ead8a6fadb | ||
|
|
ae40639b56 | ||
|
|
8bb145155e | ||
|
|
85bf989242 | ||
|
|
b4f2d1793c | ||
|
|
4a2c44c7c8 |
6
.github/ISSUE_TEMPLATE/bug.md
vendored
6
.github/ISSUE_TEMPLATE/bug.md
vendored
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: 报告Bug
|
||||
about: 反馈BUG信息
|
||||
name: 报告 Bug
|
||||
about: 反馈 BUG 信息
|
||||
title: "[BUG]"
|
||||
labels: bug
|
||||
assignees: ''
|
||||
@@ -18,4 +18,4 @@ assignees: ''
|
||||
|
||||
|
||||
**使用的版本**
|
||||
- SDK版本: [比如 v0.0.0]
|
||||
- SDK 版本:[比如 v0.0.0]
|
||||
|
||||
8
.github/ISSUE_TEMPLATE/feature.md
vendored
8
.github/ISSUE_TEMPLATE/feature.md
vendored
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: API需求
|
||||
about: 待实现的API接口,SDK的强大离不开社区的帮助,欢迎为项目贡献PR
|
||||
name: API 需求
|
||||
about: 待实现的 API 接口,SDK 的强大离不开社区的帮助,欢迎为项目贡献 PR
|
||||
title: "[Feature]"
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
@@ -8,8 +8,8 @@ assignees: ''
|
||||
---
|
||||
|
||||
<!--
|
||||
!!!SDK的强大离不开社区的帮助,欢迎为本项目贡献PR!!!
|
||||
!!!SDK 的强大离不开社区的帮助,欢迎为本项目贡献 PR!!!
|
||||
-->
|
||||
**你想要实现的模块或API**
|
||||
**你想要实现的模块或 API**
|
||||
|
||||
|
||||
|
||||
6
.github/ISSUE_TEMPLATE/question.md
vendored
6
.github/ISSUE_TEMPLATE/question.md
vendored
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: 使用咨询
|
||||
about: 关于SDK使用相关的咨询,在使用前请先阅读官方微信文档
|
||||
about: 关于 SDK 使用相关的咨询,在使用前请先阅读官方微信文档
|
||||
title: "[咨询]"
|
||||
labels: question
|
||||
assignees: ''
|
||||
@@ -9,7 +9,7 @@ assignees: ''
|
||||
|
||||
<!--
|
||||
重要:
|
||||
1、在使用本SDK前请先阅读对应的官方微信API文档:https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html
|
||||
2、本SDK部分接口文档: https://silenceper.com/wechat/
|
||||
1、在使用本 SDK 前请先阅读对应的官方微信 API 文档:https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Overview.html
|
||||
2、本 SDK 部分接口文档:https://silenceper.com/wechat/
|
||||
-->
|
||||
**请描述您的问题**
|
||||
|
||||
20
.github/workflows/go.yml
vendored
20
.github/workflows/go.yml
vendored
@@ -2,29 +2,29 @@ name: Go
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master,release-*,v2 ]
|
||||
branches: [ master,release-*,v2,feature/**,fix/** ]
|
||||
pull_request:
|
||||
branches: [ master,release-*,v2 ]
|
||||
branches: [ master,release-*,v2,feature/**,fix/** ]
|
||||
|
||||
jobs:
|
||||
golangci:
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [ '1.16','1.17','1.18','1.19','1.20' ]
|
||||
go-version: [ '1.18','1.19','1.20','1.21.4','1.22' ]
|
||||
name: golangci-lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Setup Golang ${{ matrix.go-version }}
|
||||
uses: actions/setup-go@v4
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.52.2
|
||||
version: v1.58.2
|
||||
build:
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
@@ -42,12 +42,12 @@ jobs:
|
||||
# strategy set
|
||||
strategy:
|
||||
matrix:
|
||||
go: [ '1.16','1.17','1.18','1.19','1.20' ]
|
||||
go: [ '1.18','1.19','1.20','1.21','1.22' ]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Go 1.x
|
||||
uses: actions/setup-go@v4
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
id: go
|
||||
|
||||
29
.github/workflows/release.yml
vendored
29
.github/workflows/release.yml
vendored
@@ -1,29 +0,0 @@
|
||||
name: goreleaser
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: 1.16
|
||||
-
|
||||
name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v4
|
||||
with:
|
||||
version: latest
|
||||
args: release --rm-dist
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -4,36 +4,32 @@ linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- bodyclose
|
||||
- deadcode
|
||||
- depguard
|
||||
- dogsled
|
||||
- dupl
|
||||
- errcheck
|
||||
- exportloopref
|
||||
- funlen
|
||||
- goconst
|
||||
# - gocritic
|
||||
- gocyclo
|
||||
- gofmt
|
||||
- goimports
|
||||
- golint
|
||||
- goprintffuncname
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- interfacer
|
||||
- misspell
|
||||
- nolintlint
|
||||
- rowserrcheck
|
||||
- scopelint
|
||||
- staticcheck
|
||||
- structcheck
|
||||
- stylecheck
|
||||
- typecheck
|
||||
# - typecheck
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- varcheck
|
||||
- whitespace
|
||||
# - revive
|
||||
|
||||
issues:
|
||||
include:
|
||||
@@ -57,10 +53,68 @@ linters-settings:
|
||||
lines: 66
|
||||
statements: 50
|
||||
|
||||
#issues:
|
||||
# include:
|
||||
# - EXC0002 # disable excluding of issues about comments from golint
|
||||
# exclude-rules:
|
||||
# - linters:
|
||||
# - stylecheck
|
||||
# text: "ST1000:"
|
||||
errcheck:
|
||||
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
|
||||
# Such cases aren't reported by default.
|
||||
# Default: false
|
||||
check-type-assertions: true
|
||||
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
|
||||
# Such cases aren't reported by default.
|
||||
# Default: false
|
||||
check-blank: true
|
||||
# To disable the errcheck built-in exclude list.
|
||||
# See `-excludeonly` option in https://github.com/kisielk/errcheck#excluding-functions for details.
|
||||
# Default: false
|
||||
disable-default-exclusions: true
|
||||
# List of functions to exclude from checking, where each entry is a single function to exclude.
|
||||
# See https://github.com/kisielk/errcheck#excluding-functions for details.
|
||||
exclude-functions:
|
||||
- io/ioutil.ReadFile
|
||||
- io.Copy(*bytes.Buffer)
|
||||
- io.Copy(os.Stdout)
|
||||
- (*bytes.Buffer).WriteString
|
||||
- (*bytes.Buffer).Write
|
||||
- url.Parse
|
||||
- (*strings.Builder).WriteString
|
||||
- io.WriteString
|
||||
- (*bytes.Buffer).WriteByte
|
||||
- (*hmac.New).Write
|
||||
- (*int)
|
||||
- (*string)
|
||||
- (hash.Hash).Write
|
||||
|
||||
depguard:
|
||||
# Rules to apply.
|
||||
#
|
||||
# Variables:
|
||||
# - File Variables
|
||||
# you can still use and exclamation mark ! in front of a variable to say not to use it.
|
||||
# Example !$test will match any file that is not a go test file.
|
||||
#
|
||||
# `$all` - matches all go files
|
||||
# `$test` - matches all go test files
|
||||
#
|
||||
# - Package Variables
|
||||
#
|
||||
# `$gostd` - matches all of go's standard library (Pulled from `GOROOT`)
|
||||
#
|
||||
# Default: Only allow $gostd in all files.
|
||||
rules:
|
||||
# Name of a rule.
|
||||
main:
|
||||
# Used to determine the package matching priority.
|
||||
# There are three different modes: `original`, `strict`, and `lax`.
|
||||
# Default: "original"
|
||||
list-mode: lax
|
||||
# List of file globs that will match this list of settings to compare against.
|
||||
# Default: $all
|
||||
files:
|
||||
- "!**/*_a _file.go"
|
||||
# List of allowed packages.
|
||||
allow:
|
||||
- $gostd
|
||||
- github.com/OpenPeeDeeP
|
||||
# Packages that are not allowed where the value is a suggestion.
|
||||
deny:
|
||||
- pkg: "github.com/pkg/errors"
|
||||
desc: Should be replaced by standard lib errors package
|
||||
@@ -1,29 +0,0 @@
|
||||
# This is an example goreleaser.yaml file with some sane defaults.
|
||||
# Make sure to check the documentation at http://goreleaser.com
|
||||
before:
|
||||
hooks:
|
||||
# You may remove this if you don't use go modules.
|
||||
- go mod download
|
||||
# you may remove this if you don't need go generate
|
||||
- go generate ./...
|
||||
builds:
|
||||
- skip: true
|
||||
|
||||
archives:
|
||||
- replacements:
|
||||
darwin: Darwin
|
||||
linux: Linux
|
||||
windows: Windows
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
|
||||
checksum:
|
||||
name_template: 'checksums.txt'
|
||||
snapshot:
|
||||
name_template: "{{ .Tag }}-next"
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- '^docs:'
|
||||
- '^test:'
|
||||
28
README.md
28
README.md
@@ -5,12 +5,12 @@
|
||||
[](https://pkg.go.dev/github.com/silenceper/wechat/v2?tab=doc)
|
||||

|
||||
|
||||
使用Golang开发的微信SDK,简单、易用。
|
||||
> 注意:当前版本为v2版本,v1版本已废弃
|
||||
使用 Golang 开发的微信 SDK,简单、易用。
|
||||
> 注意:当前版本为 v2 版本,v1 版本已废弃
|
||||
|
||||
## 文档 && 例子
|
||||
|
||||
[API列表](https://github.com/silenceper/wechat/tree/v2/doc/api)
|
||||
[API 列表](https://github.com/silenceper/wechat/tree/v2/doc/api)
|
||||
|
||||
[Wechat SDK 2.0 文档](https://silenceper.com/wechat)
|
||||
|
||||
@@ -25,7 +25,7 @@ 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{
|
||||
@@ -37,7 +37,7 @@ cfg := &offConfig.Config{
|
||||
}
|
||||
officialAccount := wc.GetOfficialAccount(cfg)
|
||||
|
||||
// 传入request和responseWriter
|
||||
// 传入 request 和 responseWriter
|
||||
server := officialAccount.GetServer(req, rw)
|
||||
// 设置接收消息的处理方法
|
||||
server.SetMessageHandler(func(msg *message.MixMessage) *message.Reply {
|
||||
@@ -60,20 +60,20 @@ server.Send()
|
||||
|
||||
## 目录说明
|
||||
|
||||
- officialaccount: 微信公众号API
|
||||
- miniprogram: 小程序API
|
||||
- minigame:小游戏API
|
||||
- pay:微信支付API
|
||||
- openplatform:开放平台API
|
||||
- officialaccount: 微信公众号 API
|
||||
- miniprogram: 小程序 API
|
||||
- minigame:小游戏 API
|
||||
- pay:微信支付 API
|
||||
- openplatform:开放平台 API
|
||||
- work:企业微信
|
||||
- aispeech:智能对话
|
||||
- doc: api文档
|
||||
- doc: api 文档
|
||||
|
||||
## 贡献
|
||||
|
||||
- 在[API列表](https://github.com/silenceper/wechat/tree/v2/doc/api)中查看哪些API未实现
|
||||
- 提交issue,描述需要贡献的内容
|
||||
- 完成更改后,提交PR
|
||||
- 在[API 列表](https://github.com/silenceper/wechat/tree/v2/doc/api)中查看哪些 API 未实现
|
||||
- 提交 issue,描述需要贡献的内容
|
||||
- 完成更改后,提交 PR
|
||||
|
||||
## 公众号
|
||||
|
||||
|
||||
6
cache/memcache_test.go
vendored
6
cache/memcache_test.go
vendored
@@ -22,12 +22,16 @@ func TestMemcache(t *testing.T) {
|
||||
exists := mem.IsExist("unknown-key")
|
||||
assert.Equal(t, false, exists)
|
||||
|
||||
name := mem.Get("username").(string)
|
||||
name, ok := mem.Get("username").(string)
|
||||
if !ok {
|
||||
t.Error("get Error")
|
||||
}
|
||||
if name != "" {
|
||||
if name != "silenceper" {
|
||||
t.Error("get Error")
|
||||
}
|
||||
}
|
||||
|
||||
data := mem.Get("unknown-key")
|
||||
assert.Nil(t, data)
|
||||
|
||||
|
||||
14
cache/redis.go
vendored
14
cache/redis.go
vendored
@@ -35,12 +35,12 @@ func NewRedis(ctx context.Context, opts *RedisOpts) *Redis {
|
||||
return &Redis{ctx: ctx, conn: conn}
|
||||
}
|
||||
|
||||
// SetConn 设置conn
|
||||
// SetConn 设置 conn
|
||||
func (r *Redis) SetConn(conn redis.UniversalClient) {
|
||||
r.conn = conn
|
||||
}
|
||||
|
||||
// SetRedisCtx 设置redis ctx 参数
|
||||
// SetRedisCtx 设置 redis ctx 参数
|
||||
func (r *Redis) SetRedisCtx(ctx context.Context) {
|
||||
r.ctx = ctx
|
||||
}
|
||||
@@ -69,15 +69,17 @@ func (r *Redis) SetContext(ctx context.Context, key string, val interface{}, tim
|
||||
return r.conn.SetEX(ctx, key, val, timeout).Err()
|
||||
}
|
||||
|
||||
// IsExist 判断key是否存在
|
||||
// IsExist 判断 key 是否存在
|
||||
func (r *Redis) IsExist(key string) bool {
|
||||
return r.IsExistContext(r.ctx, key)
|
||||
}
|
||||
|
||||
// IsExistContext 判断key是否存在
|
||||
// IsExistContext 判断 key 是否存在
|
||||
func (r *Redis) IsExistContext(ctx context.Context, key string) bool {
|
||||
result, _ := r.conn.Exists(ctx, key).Result()
|
||||
|
||||
result, err := r.conn.Exists(ctx, key).Result()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return result > 0
|
||||
}
|
||||
|
||||
|
||||
5
cache/redis_test.go
vendored
5
cache/redis_test.go
vendored
@@ -35,7 +35,10 @@ func TestRedis(t *testing.T) {
|
||||
t.Error("IsExist Error")
|
||||
}
|
||||
|
||||
name := redis.Get(key).(string)
|
||||
name, ok := redis.Get(key).(string)
|
||||
if !ok {
|
||||
t.Error("get Error")
|
||||
}
|
||||
if name != val {
|
||||
t.Error("get Error")
|
||||
}
|
||||
|
||||
@@ -12,21 +12,21 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// accessTokenURL 获取access_token的接口
|
||||
// accessTokenURL 获取 access_token 的接口
|
||||
accessTokenURL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"
|
||||
// stableAccessTokenURL 获取稳定版access_token的接口
|
||||
// stableAccessTokenURL 获取稳定版 access_token 的接口
|
||||
stableAccessTokenURL = "https://api.weixin.qq.com/cgi-bin/stable_token"
|
||||
// workAccessTokenURL 企业微信获取access_token的接口
|
||||
// workAccessTokenURL 企业微信获取 access_token 的接口
|
||||
workAccessTokenURL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s"
|
||||
// CacheKeyOfficialAccountPrefix 微信公众号cache key前缀
|
||||
// CacheKeyOfficialAccountPrefix 微信公众号 cache key 前缀
|
||||
CacheKeyOfficialAccountPrefix = "gowechat_officialaccount_"
|
||||
// CacheKeyMiniProgramPrefix 小程序cache key前缀
|
||||
// CacheKeyMiniProgramPrefix 小程序 cache key 前缀
|
||||
CacheKeyMiniProgramPrefix = "gowechat_miniprogram_"
|
||||
// CacheKeyWorkPrefix 企业微信cache key前缀
|
||||
// CacheKeyWorkPrefix 企业微信 cache key 前缀
|
||||
CacheKeyWorkPrefix = "gowechat_work_"
|
||||
)
|
||||
|
||||
// DefaultAccessToken 默认AccessToken 获取
|
||||
// DefaultAccessToken 默认 AccessToken 获取
|
||||
type DefaultAccessToken struct {
|
||||
appID string
|
||||
appSecret string
|
||||
@@ -57,43 +57,50 @@ type ResAccessToken struct {
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
}
|
||||
|
||||
// GetAccessToken 获取access_token,先从cache中获取,没有则从服务端获取
|
||||
// GetAccessToken 获取 access_token,先从 cache 中获取,没有则从服务端获取
|
||||
func (ak *DefaultAccessToken) GetAccessToken() (accessToken string, err error) {
|
||||
return ak.GetAccessTokenContext(context.Background())
|
||||
}
|
||||
|
||||
// GetAccessTokenContext 获取access_token,先从cache中获取,没有则从服务端获取
|
||||
// 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)
|
||||
|
||||
if val := ak.cache.Get(accessTokenCacheKey); val != nil {
|
||||
return val.(string), nil
|
||||
var ok bool
|
||||
if accessToken, ok = val.(string); ok && accessToken != "" {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 加上lock,是为了防止在并发获取token时,cache刚好失效,导致从微信服务器上获取到不同token
|
||||
// 加上 lock,是为了防止在并发获取 token 时,cache 刚好失效,导致从微信服务器上获取到不同 token
|
||||
ak.accessTokenLock.Lock()
|
||||
defer ak.accessTokenLock.Unlock()
|
||||
|
||||
// 双检,防止重复从微信服务器获取
|
||||
if val := ak.cache.Get(accessTokenCacheKey); val != nil {
|
||||
return val.(string), nil
|
||||
var ok bool
|
||||
if accessToken, ok = val.(string); ok && accessToken != "" {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// cache失效,从微信服务器获取
|
||||
// cache 失效,从微信服务器获取
|
||||
var resAccessToken ResAccessToken
|
||||
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
|
||||
}
|
||||
expires := resAccessToken.ExpiresIn - 1500
|
||||
err = ak.cache.Set(accessTokenCacheKey, resAccessToken.AccessToken, time.Duration(expires)*time.Second)
|
||||
|
||||
accessToken = resAccessToken.AccessToken
|
||||
return
|
||||
}
|
||||
|
||||
// StableAccessToken 获取稳定版接口调用凭据(与getAccessToken获取的调用凭证完全隔离,互不影响)
|
||||
// 不强制更新access_token,可用于不同环境不同服务而不需要分布式锁以及公用缓存,避免access_token争抢
|
||||
// StableAccessToken 获取稳定版接口调用凭据 (与 getAccessToken 获取的调用凭证完全隔离,互不影响)
|
||||
// 不强制更新 access_token,可用于不同环境不同服务而不需要分布式锁以及公用缓存,避免 access_token 争抢
|
||||
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getStableAccessToken.html
|
||||
type StableAccessToken struct {
|
||||
appID string
|
||||
@@ -115,20 +122,20 @@ func NewStableAccessToken(appID, appSecret, cacheKeyPrefix string, cache cache.C
|
||||
}
|
||||
}
|
||||
|
||||
// GetAccessToken 获取access_token,先从cache中获取,没有则从服务端获取
|
||||
// GetAccessToken 获取 access_token,先从 cache 中获取,没有则从服务端获取
|
||||
func (ak *StableAccessToken) GetAccessToken() (accessToken string, err error) {
|
||||
return ak.GetAccessTokenContext(context.Background())
|
||||
}
|
||||
|
||||
// GetAccessTokenContext 获取access_token,先从cache中获取,没有则从服务端获取
|
||||
// GetAccessTokenContext 获取 access_token,先从 cache 中获取,没有则从服务端获取
|
||||
func (ak *StableAccessToken) GetAccessTokenContext(ctx context.Context) (accessToken string, err error) {
|
||||
// 先从cache中取
|
||||
// 先从 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失效,从微信服务器获取
|
||||
// cache 失效,从微信服务器获取
|
||||
var resAccessToken ResAccessToken
|
||||
resAccessToken, err = ak.GetAccessTokenDirectly(ctx, false)
|
||||
if err != nil {
|
||||
@@ -136,13 +143,13 @@ func (ak *StableAccessToken) GetAccessTokenContext(ctx context.Context) (accessT
|
||||
}
|
||||
|
||||
expires := resAccessToken.ExpiresIn - 300
|
||||
_ = ak.cache.Set(accessTokenCacheKey, resAccessToken.AccessToken, time.Duration(expires)*time.Second)
|
||||
err = ak.cache.Set(accessTokenCacheKey, resAccessToken.AccessToken, time.Duration(expires)*time.Second)
|
||||
|
||||
accessToken = resAccessToken.AccessToken
|
||||
return
|
||||
}
|
||||
|
||||
// GetAccessTokenDirectly 从微信获取access_token
|
||||
// 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",
|
||||
@@ -165,7 +172,7 @@ func (ak *StableAccessToken) GetAccessTokenDirectly(ctx context.Context, forceRe
|
||||
return
|
||||
}
|
||||
|
||||
// WorkAccessToken 企业微信AccessToken 获取
|
||||
// WorkAccessToken 企业微信 AccessToken 获取
|
||||
type WorkAccessToken struct {
|
||||
CorpID string
|
||||
CorpSecret string
|
||||
@@ -188,24 +195,27 @@ 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) {
|
||||
return ak.GetAccessTokenContext(context.Background())
|
||||
}
|
||||
|
||||
// GetAccessTokenContext 企业微信获取access_token,先从cache中获取,没有则从服务端获取
|
||||
// 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()
|
||||
defer ak.accessTokenLock.Unlock()
|
||||
accessTokenCacheKey := fmt.Sprintf("%s_access_token_%s", ak.cacheKeyPrefix, ak.CorpID)
|
||||
val := ak.cache.Get(accessTokenCacheKey)
|
||||
if val != nil {
|
||||
accessToken = val.(string)
|
||||
var ok bool
|
||||
if accessToken, ok = val.(string); !ok {
|
||||
accessToken = ""
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// cache失效,从微信服务器获取
|
||||
// cache 失效,从微信服务器获取
|
||||
var resAccessToken ResAccessToken
|
||||
resAccessToken, err = GetTokenFromServerContext(ctx, fmt.Sprintf(workAccessTokenURL, ak.CorpID, ak.CorpSecret))
|
||||
if err != nil {
|
||||
@@ -214,19 +224,17 @@ func (ak *WorkAccessToken) GetAccessTokenContext(ctx context.Context) (accessTok
|
||||
|
||||
expires := resAccessToken.ExpiresIn - 1500
|
||||
err = ak.cache.Set(accessTokenCacheKey, resAccessToken.AccessToken, time.Duration(expires)*time.Second)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
accessToken = resAccessToken.AccessToken
|
||||
return
|
||||
}
|
||||
|
||||
// GetTokenFromServer 强制从微信服务器获取token
|
||||
// GetTokenFromServer 强制从微信服务器获取 token
|
||||
func GetTokenFromServer(url string) (resAccessToken ResAccessToken, err error) {
|
||||
return GetTokenFromServerContext(context.Background(), url)
|
||||
}
|
||||
|
||||
// GetTokenFromServerContext 强制从微信服务器获取token
|
||||
// GetTokenFromServerContext 强制从微信服务器获取 token
|
||||
func GetTokenFromServerContext(ctx context.Context, url string) (resAccessToken ResAccessToken, err error) {
|
||||
var body []byte
|
||||
body, err = util.HTTPGetContext(ctx, url)
|
||||
|
||||
@@ -10,15 +10,15 @@ import (
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
// getTicketURL 获取ticket的url
|
||||
// getTicketURL 获取 ticket 的 url
|
||||
const getTicketURL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi"
|
||||
|
||||
// DefaultJsTicket 默认获取js ticket方法
|
||||
// DefaultJsTicket 默认获取 js ticket 方法
|
||||
type DefaultJsTicket struct {
|
||||
appID string
|
||||
cacheKeyPrefix string
|
||||
cache cache.Cache
|
||||
// jsAPITicket 读写锁 同一个AppID一个
|
||||
// jsAPITicket 读写锁 同一个 AppID 一个
|
||||
jsAPITicketLock *sync.Mutex
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func NewDefaultJsTicket(appID string, cacheKeyPrefix string, cache cache.Cache)
|
||||
}
|
||||
}
|
||||
|
||||
// ResTicket 请求jsapi_tikcet返回结果
|
||||
// ResTicket 请求 jsapi_tikcet 返回结果
|
||||
type ResTicket struct {
|
||||
util.CommonError
|
||||
|
||||
@@ -40,9 +40,9 @@ type ResTicket struct {
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
}
|
||||
|
||||
// GetTicket 获取jsapi_ticket
|
||||
// GetTicket 获取 jsapi_ticket
|
||||
func (js *DefaultJsTicket) GetTicket(accessToken string) (ticketStr string, err error) {
|
||||
// 先从cache中取
|
||||
// 先从 cache 中取
|
||||
jsAPITicketCacheKey := fmt.Sprintf("%s_jsapi_ticket_%s", js.cacheKeyPrefix, js.appID)
|
||||
if val := js.cache.Get(jsAPITicketCacheKey); val != nil {
|
||||
return val.(string), nil
|
||||
@@ -67,7 +67,7 @@ func (js *DefaultJsTicket) GetTicket(accessToken string) (ticketStr string, err
|
||||
return
|
||||
}
|
||||
|
||||
// GetTicketFromServer 从服务器中获取ticket
|
||||
// GetTicketFromServer 从服务器中获取 ticket
|
||||
func GetTicketFromServer(accessToken string) (ticket ResTicket, err error) {
|
||||
var response []byte
|
||||
url := fmt.Sprintf(getTicketURL, accessToken)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package credential
|
||||
|
||||
// JsTicketHandle js ticket获取
|
||||
// JsTicketHandle js ticket 获取
|
||||
type JsTicketHandle interface {
|
||||
// GetTicket 获取ticket
|
||||
// GetTicket 获取 ticket
|
||||
GetTicket(accessToken string) (ticket string, err error)
|
||||
}
|
||||
|
||||
2
doc.go
2
doc.go
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Package wechat provide wechat sdk for go
|
||||
|
||||
使用Golang开发的微信SDK,简单、易用。
|
||||
使用 Golang 开发的微信 SDK,简单、易用。
|
||||
|
||||
|
||||
更多信息:https://github.com/silenceper/wechat
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# API 文档
|
||||
|
||||
已完成以及未完成API列表汇总
|
||||
已完成以及未完成 API 列表汇总
|
||||
|
||||
如果有兴趣参与贡献,可以在具体的API表格后面标识自己为贡献者以及完成时间,例如:
|
||||
如果有兴趣参与贡献,可以在具体的 API 表格后面标识自己为贡献者以及完成时间,例如:
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |贡献者|完成时间|
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |贡献者 | 完成时间|
|
||||
| :---------------------: | -------- | :------------------------- | ---------- | -------- |-------- |-------- |
|
||||
| 获取公众号类目 | GET | /wxaapi/newtmpl/getcategory | NO | |silenceper| 2021-12-20|
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ TODO
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 |
|
||||
| :----------------: | -------- | :------------------------------- | ---------- | ----------------------------------- |
|
||||
| code换取用户手机号 | POST | /wxa/business/getuserphonenumber | YES | (business *Business) GetPhoneNumber |
|
||||
| code 换取用户手机号 | POST | /wxa/business/getuserphonenumber | YES | (business *Business) GetPhoneNumber |
|
||||
|
||||
|
||||
## 安全风控
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
| 通过网页授权的 code 换取 access_token(区别于 context 中的 access_token) | GET | /sns/oauth2/access_token | YES | (oauth \*Oauth) GetUserAccessToken |
|
||||
| 刷新 access_token | GET | /sns/oauth2/refresh_token? | YES | (oauth \*Oauth) RefreshAccessToken |
|
||||
| 检验 access_token 是否有效 | GET | /sns/auth | YES | (oauth \*Oauth) CheckAccessToken( |
|
||||
| 拉取用户信息(需 scope 为 snsapi_userinfo) | GET | /sns/userinfo | YES | (oauth \*Oauth) GetUserInfo |
|
||||
| 拉取用户信息 (需 scope 为 snsapi_userinfo) | GET | /sns/userinfo | YES | (oauth \*Oauth) GetUserInfo |
|
||||
| 获取 jssdk 需要的配置参数 | GET | /cgi-bin/ticket/getticket | YES | (js \*Js) GetConfig |
|
||||
|
||||
## 素材管理
|
||||
|
||||
@@ -89,9 +89,11 @@ host: https://qyapi.weixin.qq.com/
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 |
|
||||
|:---------:|------|:----------------------------------------| ---------- | ------------------------------- |----------|
|
||||
| 获取子部门ID列表 | GET | /cgi-bin/department/simplelist | YES | (r *Client) DepartmentSimpleList| MARKWANG |
|
||||
| 获取子部门 ID 列表 | GET | /cgi-bin/department/simplelist | YES | (r *Client) DepartmentSimpleList| MARKWANG |
|
||||
| 获取部门列表 | GET | /cgi-bin/department/list | YES | (r *Client) DepartmentList| just5325, ourines |
|
||||
| 获取部门成员 | GET | /cgi-bin/user/simplelist | YES | (r *Client) UserSimpleList | MARKWANG |
|
||||
| 获取成员ID列表 | Post | /cgi-bin/user/list_id | YES | (r *Client) UserListId | MARKWANG |
|
||||
| 获取成员 ID 列表 | Post | /cgi-bin/user/list_id | YES | (r *Client) UserListId | MARKWANG |
|
||||
|
||||
|
||||
|
||||
## 素材管理
|
||||
@@ -116,5 +118,14 @@ host: https://qyapi.weixin.qq.com/
|
||||
| ---------------- | -------- | --------------------- | ---------- | -------------------------- | -------- |
|
||||
| 群机器人发送消息 | POST | /cgi-bin/webhook/send | YES | (r *Client) RobotBroadcast | chcthink |
|
||||
|
||||
## 打卡
|
||||
|
||||
[官方文档](https://developer.work.weixin.qq.com/document/path/96497)
|
||||
|
||||
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 |
|
||||
|----------| -------- | --------------------- | ---------- | -------------------------- |---------|
|
||||
| 获取打卡日报数据 | POST | /cgi-bin/checkin/getcheckin_daydata | YES | (r *Client) GetDayData | Thinker |
|
||||
| 获取打卡月报数据 | POST | /cgi-bin/checkin/getcheckin_monthdata | YES | (r *Client) GetMonthData | Thinker |
|
||||
|
||||
## 应用管理
|
||||
TODO
|
||||
|
||||
@@ -2,12 +2,12 @@ package openapi
|
||||
|
||||
import "github.com/silenceper/wechat/v2/util"
|
||||
|
||||
// GetAPIQuotaParams 查询API调用额度参数
|
||||
// GetAPIQuotaParams 查询 API 调用额度参数
|
||||
type GetAPIQuotaParams struct {
|
||||
CgiPath string `json:"cgi_path"` // api的请求地址,例如"/cgi-bin/message/custom/send";不要前缀“https://api.weixin.qq.com” ,也不要漏了"/",否则都会76003的报错
|
||||
CgiPath string `json:"cgi_path"` // api 的请求地址,例如"/cgi-bin/message/custom/send";不要前缀“https://api.weixin.qq.com” ,也不要漏了"/",否则都会 76003 的报错
|
||||
}
|
||||
|
||||
// APIQuota API调用额度
|
||||
// APIQuota API 调用额度
|
||||
type APIQuota struct {
|
||||
util.CommonError
|
||||
Quota struct {
|
||||
@@ -17,20 +17,20 @@ type APIQuota struct {
|
||||
} `json:"quota"` // 详情
|
||||
}
|
||||
|
||||
// GetRidInfoParams 查询rid信息参数
|
||||
// GetRidInfoParams 查询 rid 信息参数
|
||||
type GetRidInfoParams struct {
|
||||
Rid string `json:"rid"` // 调用接口报错返回的rid
|
||||
Rid string `json:"rid"` // 调用接口报错返回的 rid
|
||||
}
|
||||
|
||||
// RidInfo rid信息
|
||||
// RidInfo rid 信息
|
||||
type RidInfo struct {
|
||||
util.CommonError
|
||||
Request struct {
|
||||
InvokeTime int64 `json:"invoke_time"` // 发起请求的时间戳
|
||||
CostInMs int64 `json:"cost_in_ms"` // 请求毫秒级耗时
|
||||
RequestURL string `json:"request_url"` // 请求的URL参数
|
||||
RequestBody string `json:"request_body"` // post请求的请求参数
|
||||
RequestURL string `json:"request_url"` // 请求的 URL 参数
|
||||
RequestBody string `json:"request_body"` // post 请求的请求参数
|
||||
ResponseBody string `json:"response_body"` // 接口请求返回参数
|
||||
ClientIP string `json:"client_ip"` // 接口请求的客户端ip
|
||||
} `json:"request"` // 该rid对应的请求详情
|
||||
ClientIP string `json:"client_ip"` // 接口请求的客户端 ip
|
||||
} `json:"request"` // 该 rid 对应的请求详情
|
||||
}
|
||||
|
||||
30
go.mod
30
go.mod
@@ -1,16 +1,30 @@
|
||||
module github.com/silenceper/wechat/v2
|
||||
|
||||
go 1.16
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/alicebob/miniredis/v2 v2.30.0
|
||||
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d
|
||||
github.com/alicebob/miniredis/v2 v2.33.0
|
||||
github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874
|
||||
github.com/fatih/structs v1.1.0
|
||||
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-20220622213112-05595931fe9d
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/spf13/cast v1.6.0
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/tidwall/gjson v1.17.1
|
||||
golang.org/x/crypto v0.25.0
|
||||
gopkg.in/h2non/gock.v1 v1.1.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.0 // indirect
|
||||
github.com/yuin/gopher-lua v1.1.1 // indirect
|
||||
golang.org/x/sys v0.22.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
137
go.sum
137
go.sum
@@ -1,14 +1,11 @@
|
||||
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/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
|
||||
github.com/alicebob/miniredis/v2 v2.33.0 h1:uvTF0EDeu9RLnUEG27Db5I68ESoIxTiXbNUiji6lZrA=
|
||||
github.com/alicebob/miniredis/v2 v2.33.0/go.mod h1:MhP4a3EU7aENRi9aO+tHfTBZicLqQevyi/DJpoj6mi0=
|
||||
github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874 h1:N7oVaKyGp8bttX0bfZGmcGkjz7DLQXhAn3DNd3T0ous=
|
||||
github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874/go.mod h1:r5xuitiExdLAJ09PR7vBVENGvp4ZuTBeWTGtxuX3K+c=
|
||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -16,132 +13,52 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
||||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
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.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=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
|
||||
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
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.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.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.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/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
|
||||
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=
|
||||
github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
|
||||
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
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-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-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=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
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/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=
|
||||
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-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-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=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/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-20210615035016-665e8c7367d1/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=
|
||||
github.com/yuin/gopher-lua v1.1.1 h1:kYKnWBjvbNP4XLT3+bPEwAXJx262OhaHDWDVOPjL46M=
|
||||
github.com/yuin/gopher-lua v1.1.1/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw=
|
||||
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
||||
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
||||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
|
||||
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/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/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
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/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/h2non/gock.v1 v1.1.2 h1:jBbHXgGBK/AoPVfJh5x4r/WxIrElvbLel8TCZkkZJoY=
|
||||
gopkg.in/h2non/gock.v1 v1.1.2/go.mod h1:n7UGz/ckNChHiK05rDoiC4MYSunEC/lyaUm2WWaDva0=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
clearQuotaURL = "https://api.weixin.qq.com/cgi-bin/clear_quota" // 重置API调用次数
|
||||
getAPIQuotaURL = "https://api.weixin.qq.com/cgi-bin/openapi/quota/get" // 查询API调用额度
|
||||
getRidInfoURL = "https://api.weixin.qq.com/cgi-bin/openapi/rid/get" // 查询rid信息
|
||||
clearQuotaByAppSecretURL = "https://api.weixin.qq.com/cgi-bin/clear_quota/v2" // 使用AppSecret重置 API 调用次数
|
||||
clearQuotaURL = "https://api.weixin.qq.com/cgi-bin/clear_quota" // 重置 API 调用次数
|
||||
getAPIQuotaURL = "https://api.weixin.qq.com/cgi-bin/openapi/quota/get" // 查询 API 调用额度
|
||||
getRidInfoURL = "https://api.weixin.qq.com/cgi-bin/openapi/rid/get" // 查询 rid 信息
|
||||
clearQuotaByAppSecretURL = "https://api.weixin.qq.com/cgi-bin/clear_quota/v2" // 使用 AppSecret 重置 API 调用次数
|
||||
)
|
||||
|
||||
// OpenAPI openApi管理
|
||||
// OpenAPI openApi 管理
|
||||
type OpenAPI struct {
|
||||
ctx interface{}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func NewOpenAPI(ctx interface{}) *OpenAPI {
|
||||
return &OpenAPI{ctx: ctx}
|
||||
}
|
||||
|
||||
// ClearQuota 重置API调用次数
|
||||
// ClearQuota 重置 API 调用次数
|
||||
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/clearQuota.html
|
||||
func (o *OpenAPI) ClearQuota() error {
|
||||
appID, _, err := o.getAppIDAndSecret()
|
||||
@@ -48,7 +48,7 @@ func (o *OpenAPI) ClearQuota() error {
|
||||
return util.DecodeWithCommonError(res, "ClearQuota")
|
||||
}
|
||||
|
||||
// GetAPIQuota 查询API调用额度
|
||||
// GetAPIQuota 查询 API 调用额度
|
||||
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/getApiQuota.html
|
||||
func (o *OpenAPI) GetAPIQuota(params openapi.GetAPIQuotaParams) (quota openapi.APIQuota, err error) {
|
||||
res, err := o.doPostRequest(getAPIQuotaURL, params)
|
||||
@@ -60,7 +60,7 @@ func (o *OpenAPI) GetAPIQuota(params openapi.GetAPIQuotaParams) (quota openapi.A
|
||||
return
|
||||
}
|
||||
|
||||
// GetRidInfo 查询rid信息
|
||||
// GetRidInfo 查询 rid 信息
|
||||
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/getRidInfo.html
|
||||
func (o *OpenAPI) GetRidInfo(params openapi.GetRidInfoParams) (r openapi.RidInfo, err error) {
|
||||
res, err := o.doPostRequest(getRidInfoURL, params)
|
||||
@@ -72,7 +72,7 @@ func (o *OpenAPI) GetRidInfo(params openapi.GetRidInfoParams) (r openapi.RidInfo
|
||||
return
|
||||
}
|
||||
|
||||
// ClearQuotaByAppSecret 使用AppSecret重置 API 调用次数
|
||||
// ClearQuotaByAppSecret 使用 AppSecret 重置 API 调用次数
|
||||
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/clearQuotaByAppSecret.html
|
||||
func (o *OpenAPI) ClearQuotaByAppSecret() error {
|
||||
id, secret, err := o.getAppIDAndSecret()
|
||||
@@ -93,10 +93,16 @@ func (o *OpenAPI) ClearQuotaByAppSecret() error {
|
||||
func (o *OpenAPI) getAppIDAndSecret() (string, string, error) {
|
||||
switch o.ctx.(type) {
|
||||
case *mpContext.Context:
|
||||
c := o.ctx.(*mpContext.Context)
|
||||
c, ok := o.ctx.(*mpContext.Context)
|
||||
if !ok {
|
||||
return "", "", errors.New("invalid context type")
|
||||
}
|
||||
return c.AppID, c.AppSecret, nil
|
||||
case *ocContext.Context:
|
||||
c := o.ctx.(*ocContext.Context)
|
||||
c, ok := o.ctx.(*ocContext.Context)
|
||||
if !ok {
|
||||
return "", "", errors.New("invalid context type")
|
||||
}
|
||||
return c.AppID, c.AppSecret, nil
|
||||
default:
|
||||
return "", "", errors.New("invalid context type")
|
||||
|
||||
@@ -56,8 +56,8 @@ func (analysis *Analysis) fetchData(urlStr string, body interface{}) (response [
|
||||
|
||||
// RetainItem 留存项结构
|
||||
type RetainItem struct {
|
||||
Key int `json:"key"` // 标识,0开始表示当天,1表示1甜后,以此类推
|
||||
Value int `json:"value"` // key对应日期的新增用户数/活跃用户数(key=0时)或留存用户数(k>0时)
|
||||
Key int `json:"key"` // 标识,0 开始表示当天,1 表示 1 甜后,以此类推
|
||||
Value int `json:"value"` // key 对应日期的新增用户数/活跃用户数(key=0 时)或留存用户数(k>0 时)
|
||||
}
|
||||
|
||||
// ResAnalysisRetain 小程序留存数据返回
|
||||
@@ -68,7 +68,7 @@ type ResAnalysisRetain struct {
|
||||
VisitUV []RetainItem `json:"visit_uv"` // 活跃用户留存
|
||||
}
|
||||
|
||||
// getAnalysisRetain 获取用户访问小程序留存数据(日、月、周)
|
||||
// getAnalysisRetain 获取用户访问小程序留存数据 (日、月、周)
|
||||
func (analysis *Analysis) getAnalysisRetain(urlStr string, beginDate, endDate string) (result ResAnalysisRetain, err error) {
|
||||
body := map[string]string{
|
||||
"begin_date": beginDate,
|
||||
@@ -137,7 +137,7 @@ func (analysis *Analysis) GetAnalysisDailySummary(beginDate, endDate string) (re
|
||||
return
|
||||
}
|
||||
|
||||
// ResAnalysisVisitTrend 小程序访问数据趋势(日、月、周)
|
||||
// ResAnalysisVisitTrend 小程序访问数据趋势 (日、月、周)
|
||||
type ResAnalysisVisitTrend struct {
|
||||
util.CommonError
|
||||
List []struct {
|
||||
@@ -152,7 +152,7 @@ type ResAnalysisVisitTrend struct {
|
||||
} `json:"list"`
|
||||
}
|
||||
|
||||
// getAnalysisRetain 获取小程序访问数据趋势(日、月、周)
|
||||
// getAnalysisRetain 获取小程序访问数据趋势 (日、月、周)
|
||||
func (analysis *Analysis) getAnalysisVisitTrend(urlStr string, beginDate, endDate string) (result ResAnalysisVisitTrend, err error) {
|
||||
body := map[string]string{
|
||||
"begin_date": beginDate,
|
||||
@@ -190,9 +190,9 @@ func (analysis *Analysis) GetAnalysisWeeklyVisitTrend(beginDate, endDate string)
|
||||
|
||||
// UserPortraitItem 用户画像项目
|
||||
type UserPortraitItem struct {
|
||||
ID int `json:"id"` // 属性值id
|
||||
ID int `json:"id"` // 属性值 id
|
||||
Name string `json:"name"` // 属性值名称
|
||||
Value int `json:"value"` // 该场景访问uv
|
||||
Value int `json:"value"` // 该场景访问 uv
|
||||
}
|
||||
|
||||
// UserPortrait 用户画像
|
||||
@@ -201,9 +201,9 @@ type UserPortrait struct {
|
||||
Province []UserPortraitItem `json:"province"` // 省份,如北京、广东等
|
||||
City []UserPortraitItem `json:"city"` // 城市,如北京、广州等
|
||||
Genders []UserPortraitItem `json:"genders"` // 性别,包括男、女、未知
|
||||
Platforms []UserPortraitItem `json:"platforms"` // 终端类型,包括iPhone, android, 其他
|
||||
Devices []UserPortraitItem `json:"devices"` // 机型,如苹果iPhone 6, OPPO R9等
|
||||
Ages []UserPortraitItem `json:"ages"` // 年龄,包括17岁以下、18-24对等区间
|
||||
Platforms []UserPortraitItem `json:"platforms"` // 终端类型,包括 iPhone, android, 其他
|
||||
Devices []UserPortraitItem `json:"devices"` // 机型,如苹果 iPhone 6, OPPO R9 等
|
||||
Ages []UserPortraitItem `json:"ages"` // 年龄,包括 17 岁以下、18-24 对等区间
|
||||
}
|
||||
|
||||
// ResAnalysisUserPortrait 小程序新增或活跃用户的画像分布数据返回
|
||||
@@ -237,9 +237,9 @@ func (analysis *Analysis) GetAnalysisUserPortrait(beginDate, endDate string) (re
|
||||
|
||||
// VisitDistributionIndexItem 访问分数数据结构
|
||||
type VisitDistributionIndexItem struct {
|
||||
Key int `json:"key"` // 场景id
|
||||
Value int `json:"value"` // 该场景id访问pv
|
||||
AccessSourceVisitUV int `json:"access_source_visit_uv"` // 该场景id访问uv
|
||||
Key int `json:"key"` // 场景 id
|
||||
Value int `json:"value"` // 该场景 id 访问 pv
|
||||
AccessSourceVisitUV int `json:"access_source_visit_uv"` // 该场景 id 访问 uv
|
||||
}
|
||||
|
||||
// VisitDistributionIndex 访问分布单分布类型数据
|
||||
|
||||
@@ -15,8 +15,6 @@ const (
|
||||
checkEncryptedDataURL = "https://api.weixin.qq.com/wxa/business/checkencryptedmsg?access_token=%s"
|
||||
|
||||
getPhoneNumber = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s"
|
||||
|
||||
checkSessionURL = "https://api.weixin.qq.com/wxa/checksession?access_token=%s&openid=%s&signature=%s&sig_method=hmac_sha256"
|
||||
)
|
||||
|
||||
// Auth 登录/用户信息
|
||||
@@ -116,61 +114,35 @@ type PhoneInfo struct {
|
||||
}
|
||||
|
||||
// GetPhoneNumberContext 小程序通过 code 获取用户手机号
|
||||
func (auth *Auth) GetPhoneNumberContext(ctx context2.Context, code string) (result *GetPhoneNumberResponse, err error) {
|
||||
var accessToken string
|
||||
if accessToken, err = auth.GetAccessToken(); err != nil {
|
||||
func (auth *Auth) GetPhoneNumberContext(ctx context2.Context, code string) (*GetPhoneNumberResponse, error) {
|
||||
var response []byte
|
||||
var (
|
||||
at string
|
||||
err error
|
||||
)
|
||||
if at, err = auth.GetAccessToken(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bodyBytes, err := json.Marshal(map[string]interface{}{
|
||||
body := map[string]interface{}{
|
||||
"code": code,
|
||||
})
|
||||
}
|
||||
|
||||
bodyBytes, err := json.Marshal(body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
header = map[string]string{"Content-Type": "application/json;charset=utf-8"}
|
||||
response []byte
|
||||
)
|
||||
|
||||
if response, err = util.HTTPPostContext(ctx, fmt.Sprintf(getPhoneNumber, accessToken), bodyBytes, header); err != nil {
|
||||
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
|
||||
err = util.DecodeWithError(response, &result, "phonenumber.getPhoneNumber")
|
||||
return
|
||||
return &result, err
|
||||
}
|
||||
|
||||
// GetPhoneNumber 小程序通过 code 获取用户手机号
|
||||
func (auth *Auth) GetPhoneNumber(code string) (*GetPhoneNumberResponse, error) {
|
||||
return auth.GetPhoneNumberContext(context2.Background(), code)
|
||||
}
|
||||
|
||||
// // CheckSession 检验登录态是否过期。
|
||||
// func (auth *Auth) CheckSession(sessionKey, openID string) (result *CheckSessionResponse, err error) {
|
||||
// return auth.CheckSessionContext(context2.Background(), sessionKey, openID)
|
||||
// }
|
||||
//
|
||||
// // CheckSessionContext 检验登录态是否过期。
|
||||
// func (auth *Auth) CheckSessionContext(ctx context2.Context, sessionKey, openID string) (result *CheckSessionResponse, err error) {
|
||||
// var accessToken string
|
||||
// if accessToken, err = auth.GetAccessToken(); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// var (
|
||||
// response []byte
|
||||
// signature string = sessionKey
|
||||
// )
|
||||
// if response, err = util.HTTPGetContext(ctx, fmt.Sprintf(checkSessionURL, accessToken, openID, signature)); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
//
|
||||
// err = util.DecodeWithError(response, &result, "CheckSessionContext")
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // CheckSessionResponse 检验登录态是否过期。
|
||||
// type CheckSessionResponse struct {
|
||||
// util.CommonError
|
||||
// }
|
||||
|
||||
@@ -21,12 +21,12 @@ type PhoneInfo struct {
|
||||
PurePhoneNumber string `json:"purePhoneNumber"` // 没有区号的手机号
|
||||
CountryCode string `json:"countryCode"` // 区号
|
||||
Watermark struct {
|
||||
AppID string `json:"appid"` // 小程序appid
|
||||
AppID string `json:"appid"` // 小程序 appid
|
||||
Timestamp int64 `json:"timestamp"` // 用户获取手机号操作的时间戳
|
||||
} `json:"watermark"`
|
||||
}
|
||||
|
||||
// GetPhoneNumber code换取用户手机号。 每个code只能使用一次,code的有效期为5min
|
||||
// GetPhoneNumber code 换取用户手机号。每个 code 只能使用一次,code 的有效期为 5min
|
||||
func (business *Business) GetPhoneNumber(in *GetPhoneNumberRequest) (info PhoneInfo, err error) {
|
||||
accessToken, err := business.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -45,10 +45,5 @@ func (business *Business) GetPhoneNumber(in *GetPhoneNumberRequest) (info PhoneI
|
||||
PhoneInfo PhoneInfo `json:"phone_info"`
|
||||
}
|
||||
err = util.DecodeWithError(response, &resp, "business.GetPhoneNumber")
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
info = resp.PhoneInfo
|
||||
return
|
||||
return resp.PhoneInfo, err
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (content *Content) CheckText(text string) error {
|
||||
}
|
||||
|
||||
// CheckImage 检测图片
|
||||
// 所传参数为要检测的图片文件的绝对路径,图片格式支持PNG、JPEG、JPG、GIF, 像素不超过 750 x 1334,同时文件大小以不超过 300K 为宜,否则可能报错
|
||||
// 所传参数为要检测的图片文件的绝对路径,图片格式支持 PNG、JPEG、JPG、GIF, 像素不超过 750 x 1334,同时文件大小以不超过 300K 为宜,否则可能报错
|
||||
// @media 图片文件的绝对路径
|
||||
// Deprecated
|
||||
// 采用 security.ImageCheckV1 替代,返回值更加丰富
|
||||
|
||||
@@ -24,13 +24,13 @@ func NewEncryptor(context *context.Context) *Encryptor {
|
||||
}
|
||||
|
||||
var (
|
||||
// ErrAppIDNotMatch appid不匹配
|
||||
// ErrAppIDNotMatch appid 不匹配
|
||||
ErrAppIDNotMatch = errors.New("app id not match")
|
||||
// ErrInvalidBlockSize block size不合法
|
||||
// ErrInvalidBlockSize block size 不合法
|
||||
ErrInvalidBlockSize = errors.New("invalid block size")
|
||||
// ErrInvalidPKCS7Data PKCS7数据不合法
|
||||
// ErrInvalidPKCS7Data PKCS7 数据不合法
|
||||
ErrInvalidPKCS7Data = errors.New("invalid PKCS7 data")
|
||||
// ErrInvalidPKCS7Padding 输入padding失败
|
||||
// ErrInvalidPKCS7Padding 输入 padding 失败
|
||||
ErrInvalidPKCS7Padding = errors.New("invalid padding on input")
|
||||
)
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ const (
|
||||
MsgTypeMiniProgramPage = "miniprogrampage"
|
||||
// MsgTypeEvent 事件
|
||||
MsgTypeEvent MsgType = "event"
|
||||
// DataTypeXML XML格式数据
|
||||
// DataTypeXML XML 格式数据
|
||||
DataTypeXML = "xml"
|
||||
// DataTypeJSON JSON格式数据
|
||||
// DataTypeJSON JSON 格式数据
|
||||
DataTypeJSON = "json"
|
||||
)
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ type MediaText struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// MediaResource 消息使用的临时素材id
|
||||
// MediaResource 消息使用的临时素材 id
|
||||
type MediaResource struct {
|
||||
MediaID string `json:"media_id"`
|
||||
}
|
||||
@@ -51,7 +51,7 @@ type MediaLink struct {
|
||||
|
||||
// CustomerMessage 客服消息
|
||||
type CustomerMessage struct {
|
||||
ToUser string `json:"touser"` // 接受者OpenID
|
||||
ToUser string `json:"touser"` // 接受者 OpenID
|
||||
Msgtype MsgType `json:"msgtype"` // 客服消息类型
|
||||
Text *MediaText `json:"text,omitempty"` // 可选
|
||||
Image *MediaResource `json:"image,omitempty"` // 可选
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/security"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
@@ -18,11 +20,11 @@ import (
|
||||
type ConfirmReceiveMethod int8
|
||||
|
||||
const (
|
||||
// EventTypeTradeManageRemindAccessAPI 提醒接入发货信息管理服务API
|
||||
// EventTypeTradeManageRemindAccessAPI 提醒接入发货信息管理服务 API
|
||||
// 小程序完成账期授权时/小程序产生第一笔交易时/已产生交易但从未发货的小程序,每天一次
|
||||
EventTypeTradeManageRemindAccessAPI EventType = "trade_manage_remind_access_api"
|
||||
// EventTypeTradeManageRemindShipping 提醒需要上传发货信息
|
||||
// 曾经发过货的小程序,订单超过48小时未发货时
|
||||
// 曾经发过货的小程序,订单超过 48 小时未发货时
|
||||
EventTypeTradeManageRemindShipping EventType = "trade_manage_remind_shipping"
|
||||
// EventTypeTradeManageOrderSettlement 订单将要结算或已经结算
|
||||
// 订单完成发货时/订单结算时
|
||||
@@ -39,14 +41,27 @@ const (
|
||||
EventTypeXpayGoodsDeliverNotify EventType = "xpay_goods_deliver_notify"
|
||||
// EventTypeXpayCoinPayNotify 代币支付推送事件
|
||||
EventTypeXpayCoinPayNotify EventType = "xpay_coin_pay_notify"
|
||||
// EventSubscribePopup 用户操作订阅通知弹窗事件推送,用户在图文等场景内订阅通知的操作
|
||||
EventSubscribePopup EventType = "subscribe_msg_popup_event"
|
||||
// EventSubscribeMsgChange 用户管理订阅通知,用户在服务通知管理页面做通知管理时的操作
|
||||
EventSubscribeMsgChange EventType = "subscribe_msg_change_event"
|
||||
// EventSubscribeMsgSent 发送订阅通知,调用 bizsend 接口发送通知
|
||||
EventSubscribeMsgSent EventType = "subscribe_msg_sent_event"
|
||||
// ConfirmReceiveMethodAuto 自动确认收货
|
||||
ConfirmReceiveMethodAuto ConfirmReceiveMethod = 1
|
||||
// ConfirmReceiveMethodManual 手动确认收货
|
||||
ConfirmReceiveMethodManual ConfirmReceiveMethod = 2
|
||||
)
|
||||
|
||||
const (
|
||||
// InfoTypeAcceptSubscribeMessage 接受订阅通知
|
||||
InfoTypeAcceptSubscribeMessage InfoType = "accept"
|
||||
// InfoTypeRejectSubscribeMessage 拒绝订阅通知
|
||||
InfoTypeRejectSubscribeMessage InfoType = "reject"
|
||||
)
|
||||
|
||||
// PushReceiver 接收消息推送
|
||||
// 暂仅支付Aes加密方式
|
||||
// 暂仅支付 Aes 加密方式
|
||||
type PushReceiver struct {
|
||||
*context.Context
|
||||
}
|
||||
@@ -58,16 +73,16 @@ func NewPushReceiver(ctx *context.Context) *PushReceiver {
|
||||
}
|
||||
}
|
||||
|
||||
// GetMsg 获取接收到的消息(如果是加密的返回解密数据)
|
||||
// GetMsg 获取接收到的消息 (如果是加密的返回解密数据)
|
||||
func (receiver *PushReceiver) GetMsg(r *http.Request) (string, []byte, error) {
|
||||
// 判断请求格式
|
||||
var dataType string
|
||||
contentType := r.Header.Get("Content-Type")
|
||||
if strings.HasPrefix(contentType, "text/xml") {
|
||||
// xml格式
|
||||
// xml 格式
|
||||
dataType = DataTypeXML
|
||||
} else {
|
||||
// json格式
|
||||
// json 格式
|
||||
dataType = DataTypeJSON
|
||||
}
|
||||
|
||||
@@ -108,7 +123,7 @@ func (receiver *PushReceiver) GetMsg(r *http.Request) (string, []byte, error) {
|
||||
return dataType, byteData, err
|
||||
}
|
||||
|
||||
// GetMsgData 获取接收到的消息(解密数据)
|
||||
// GetMsgData 获取接收到的消息 (解密数据)
|
||||
func (receiver *PushReceiver) GetMsgData(r *http.Request) (MsgType, EventType, PushData, error) {
|
||||
dataType, decryptMsg, err := receiver.GetMsg(r)
|
||||
if err != nil {
|
||||
@@ -144,7 +159,7 @@ func (receiver *PushReceiver) GetMsgData(r *http.Request) (MsgType, EventType, P
|
||||
func (receiver *PushReceiver) getEvent(dataType string, eventType EventType, decryptMsg []byte) (PushData, error) {
|
||||
switch eventType {
|
||||
case EventTypeTradeManageRemindAccessAPI:
|
||||
// 提醒接入发货信息管理服务API
|
||||
// 提醒接入发货信息管理服务 API
|
||||
var pushData PushDataRemindAccessAPI
|
||||
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||
return &pushData, err
|
||||
@@ -188,25 +203,104 @@ func (receiver *PushReceiver) getEvent(dataType string, eventType EventType, dec
|
||||
var pushData PushDataXpayCoinPayNotify
|
||||
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||
return &pushData, err
|
||||
case EventSubscribePopup:
|
||||
// 用户操作订阅通知弹窗事件推送
|
||||
return receiver.unmarshalSubscribePopup(dataType, decryptMsg)
|
||||
case EventSubscribeMsgChange:
|
||||
// 用户管理订阅通知事件推送
|
||||
return receiver.unmarshalSubscribeMsgChange(dataType, decryptMsg)
|
||||
case EventSubscribeMsgSent:
|
||||
// 用户发送订阅通知事件推送
|
||||
return receiver.unmarshalSubscribeMsgSent(dataType, decryptMsg)
|
||||
}
|
||||
// 暂不支持其他事件类型,直接返回解密后的数据,由调用方处理
|
||||
return decryptMsg, nil
|
||||
}
|
||||
|
||||
// unmarshal 解析推送的数据
|
||||
func (receiver *PushReceiver) unmarshal(dateType string, decryptMsg []byte, pushData interface{}) error {
|
||||
if dateType == DataTypeXML {
|
||||
func (receiver *PushReceiver) unmarshal(dataType string, decryptMsg []byte, pushData interface{}) error {
|
||||
if dataType == DataTypeXML {
|
||||
return xml.Unmarshal(decryptMsg, pushData)
|
||||
}
|
||||
return json.Unmarshal(decryptMsg, pushData)
|
||||
}
|
||||
|
||||
// unmarshalSubscribePopup
|
||||
func (receiver *PushReceiver) unmarshalSubscribePopup(dataType string, decryptMsg []byte) (PushData, error) {
|
||||
var pushData PushDataSubscribePopup
|
||||
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||
if err == nil {
|
||||
listData := gjson.Get(string(decryptMsg), "List")
|
||||
if listData.IsObject() {
|
||||
listItem := SubscribeMsgPopupEventList{}
|
||||
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItem); parseErr != nil {
|
||||
return &pushData, parseErr
|
||||
}
|
||||
pushData.SetSubscribeMsgPopupEvents([]SubscribeMsgPopupEventList{listItem})
|
||||
} else if listData.IsArray() {
|
||||
listItems := make([]SubscribeMsgPopupEventList, 0)
|
||||
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItems); parseErr != nil {
|
||||
return &pushData, parseErr
|
||||
}
|
||||
pushData.SetSubscribeMsgPopupEvents(listItems)
|
||||
}
|
||||
}
|
||||
|
||||
return &pushData, err
|
||||
}
|
||||
|
||||
// unmarshalSubscribeMsgChange 解析用户管理订阅通知事件推送
|
||||
func (receiver *PushReceiver) unmarshalSubscribeMsgChange(dataType string, decryptMsg []byte) (PushData, error) {
|
||||
var pushData PushDataSubscribeMsgChange
|
||||
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||
if err == nil {
|
||||
listData := gjson.Get(string(decryptMsg), "List")
|
||||
if listData.IsObject() {
|
||||
listItem := SubscribeMsgChangeList{}
|
||||
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItem); parseErr != nil {
|
||||
return &pushData, parseErr
|
||||
}
|
||||
pushData.SetSubscribeMsgChangeEvents([]SubscribeMsgChangeList{listItem})
|
||||
} else if listData.IsArray() {
|
||||
listItems := make([]SubscribeMsgChangeList, 0)
|
||||
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItems); parseErr != nil {
|
||||
return &pushData, parseErr
|
||||
}
|
||||
pushData.SetSubscribeMsgChangeEvents(listItems)
|
||||
}
|
||||
}
|
||||
return &pushData, err
|
||||
}
|
||||
|
||||
// unmarshalSubscribeMsgSent 解析用户发送订阅通知事件推送
|
||||
func (receiver *PushReceiver) unmarshalSubscribeMsgSent(dataType string, decryptMsg []byte) (PushData, error) {
|
||||
var pushData PushDataSubscribeMsgSent
|
||||
err := receiver.unmarshal(dataType, decryptMsg, &pushData)
|
||||
if err == nil {
|
||||
listData := gjson.Get(string(decryptMsg), "List")
|
||||
if listData.IsObject() {
|
||||
listItem := SubscribeMsgSentList{}
|
||||
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItem); parseErr != nil {
|
||||
return &pushData, parseErr
|
||||
}
|
||||
pushData.SetSubscribeMsgSentEvents([]SubscribeMsgSentList{listItem})
|
||||
} else if listData.IsArray() {
|
||||
listItems := make([]SubscribeMsgSentList, 0)
|
||||
if parseErr := json.Unmarshal([]byte(listData.Raw), &listItems); parseErr != nil {
|
||||
return &pushData, parseErr
|
||||
}
|
||||
pushData.SetSubscribeMsgSentEvents(listItems)
|
||||
}
|
||||
}
|
||||
return &pushData, err
|
||||
}
|
||||
|
||||
// DataReceived 接收到的数据
|
||||
type DataReceived struct {
|
||||
Encrypt string `json:"Encrypt" xml:"Encrypt"` // 加密的消息体
|
||||
}
|
||||
|
||||
// PushData 推送的数据(已转对应的结构体)
|
||||
// PushData 推送的数据 (已转对应的结构体)
|
||||
type PushData interface{}
|
||||
|
||||
// CommonPushData 推送数据通用部分
|
||||
@@ -216,7 +310,7 @@ type CommonPushData struct {
|
||||
Event EventType `json:"Event" xml:"Event"` // 事件类型
|
||||
ToUserName string `json:"ToUserName" xml:"ToUserName"` // 小程序的原始 ID
|
||||
FromUserName string `json:"FromUserName" xml:"FromUserName"` // 发送方账号(一个 OpenID,此时发送方是系统账号)
|
||||
CreateTime int64 `json:"CreateTime" xml:"CreateTime"` // 消息创建时间 (整型),时间戳
|
||||
CreateTime int64 `json:"CreateTime" xml:"CreateTime"` // 消息创建时间(整型),时间戳
|
||||
}
|
||||
|
||||
// MediaCheckAsyncData 媒体内容安全异步审查结果通知
|
||||
@@ -272,7 +366,7 @@ type PushDataRemindShipping struct {
|
||||
Msg string `json:"msg" xml:"msg"` // 消息文本内容
|
||||
}
|
||||
|
||||
// PushDataRemindAccessAPI 提醒接入发货信息管理服务API信息
|
||||
// PushDataRemindAccessAPI 提醒接入发货信息管理服务 API 信息
|
||||
type PushDataRemindAccessAPI struct {
|
||||
CommonPushData
|
||||
Msg string `json:"msg" xml:"msg"` // 消息文本内容
|
||||
@@ -281,9 +375,9 @@ type PushDataRemindAccessAPI struct {
|
||||
// PushDataAddExpressPath 运单轨迹更新信息
|
||||
type PushDataAddExpressPath struct {
|
||||
CommonPushData
|
||||
DeliveryID string `json:"DeliveryID" xml:"DeliveryID"` // 快递公司ID
|
||||
WayBillID string `json:"WaybillId" xml:"WaybillId"` // 运单ID
|
||||
OrderID string `json:"OrderId" xml:"OrderId"` // 订单ID
|
||||
DeliveryID string `json:"DeliveryID" xml:"DeliveryID"` // 快递公司 ID
|
||||
WayBillID string `json:"WaybillId" xml:"WaybillId"` // 运单 ID
|
||||
OrderID string `json:"OrderId" xml:"OrderId"` // 订单 ID
|
||||
Version int `json:"Version" xml:"Version"` // 轨迹版本号(整型)
|
||||
Count int `json:"Count" xml:"Count"` // 轨迹节点数(整型)
|
||||
Actions []*PushDataAddExpressPathAction `json:"Actions" xml:"Actions"` // 轨迹节点列表
|
||||
@@ -304,10 +398,10 @@ type PushDataSecVodUpload struct {
|
||||
|
||||
// SecVodUploadEvent 短剧媒资上传完成事件
|
||||
type SecVodUploadEvent struct {
|
||||
MediaID string `json:"media_id" xml:"media_id"` // 媒资id
|
||||
MediaID int64 `json:"media_id" xml:"media_id"` // 媒资 id
|
||||
SourceContext string `json:"source_context" xml:"source_context"` // 透传上传接口中开发者设置的值。
|
||||
Errcode int `json:"errcode" xml:"errcode"` // 错误码,上传失败时该值非
|
||||
Errmsg string `json:"errmsg" xml:"errmsg"` // 错误提示
|
||||
ErrCode int `json:"errcode" xml:"errcode"` // 错误码,上传失败时该值非
|
||||
ErrMsg string `json:"errmsg" xml:"errmsg"` // 错误提示
|
||||
}
|
||||
|
||||
// PushDataSecVodAudit 短剧媒资审核状态
|
||||
@@ -318,14 +412,14 @@ type PushDataSecVodAudit struct {
|
||||
|
||||
// SecVodAuditEvent 短剧媒资审核状态事件
|
||||
type SecVodAuditEvent struct {
|
||||
DramaID string `json:"drama_id" xml:"drama_id"` // 剧目id
|
||||
DramaID int64 `json:"drama_id" xml:"drama_id"` // 剧目 id
|
||||
SourceContext string `json:"source_context" xml:"source_context"` // 透传上传接口中开发者设置的值
|
||||
AuditDetail DramaAuditDetail `json:"audit_detail" xml:"audit_detail"` // 剧目审核结果,单独每一集的审核结果可以根据drama_id查询剧集详情得到
|
||||
AuditDetail DramaAuditDetail `json:"audit_detail" xml:"audit_detail"` // 剧目审核结果,单独每一集的审核结果可以根据 drama_id 查询剧集详情得到
|
||||
}
|
||||
|
||||
// DramaAuditDetail 剧目审核结果
|
||||
type DramaAuditDetail struct {
|
||||
Status int `json:"status" xml:"status"` // 审核状态,0为无效值;1为审核中;2为最终失败;3为审核通过;4为驳回重填
|
||||
Status int `json:"status" xml:"status"` // 审核状态,0 为无效值;1 为审核中;2 为最终失败;3 为审核通过;4 为驳回重填
|
||||
CreateTime int64 `json:"create_time" xml:"create_time"` // 提审时间戳
|
||||
AuditTime int64 `json:"audit_time" xml:"audit_time"` // 审核时间戳
|
||||
}
|
||||
@@ -333,9 +427,9 @@ type DramaAuditDetail struct {
|
||||
// PushDataXpayGoodsDeliverNotify 道具发货推送
|
||||
type PushDataXpayGoodsDeliverNotify struct {
|
||||
CommonPushData
|
||||
OpenID string `json:"OpenId" xml:"OpenId"` // 用户openid
|
||||
OpenID string `json:"OpenId" xml:"OpenId"` // 用户 openid
|
||||
OutTradeNo string `json:"OutTradeNo" xml:"OutTradeNo"` // 业务订单号
|
||||
Env int `json:"Env" xml:"Env"` //,环境配置 0:现网环境(也叫正式环境)1:沙箱环境
|
||||
Env int `json:"Env" xml:"Env"` // ,环境配置 0:现网环境(也叫正式环境)1:沙箱环境
|
||||
WeChatPayInfo WeChatPayInfo `json:"WeChatPayInfo" xml:"WeChatPayInfo"` // 微信支付信息 非微信支付渠道可能没有
|
||||
GoodsInfo GoodsInfo `json:"GoodsInfo" xml:"GoodsInfo"` // 道具参数信息
|
||||
}
|
||||
@@ -344,14 +438,14 @@ type PushDataXpayGoodsDeliverNotify struct {
|
||||
type WeChatPayInfo struct {
|
||||
MchOrderNo string `json:"MchOrderNo" xml:"MchOrderNo"` // 微信支付商户单号
|
||||
TransactionID string `json:"TransactionId" xml:"TransactionId"` // 交易单号(微信支付订单号)
|
||||
PaidTime int64 `json:"PaidTime" xml:"PaidTime"` // 用户支付时间,Linux秒级时间戳
|
||||
PaidTime int64 `json:"PaidTime" xml:"PaidTime"` // 用户支付时间,Linux 秒级时间戳
|
||||
}
|
||||
|
||||
// GoodsInfo 道具参数信息
|
||||
type GoodsInfo struct {
|
||||
ProductID string `json:"ProductId" xml:"ProductId"` // 道具ID
|
||||
ProductID string `json:"ProductId" xml:"ProductId"` // 道具 ID
|
||||
Quantity int `json:"Quantity" xml:"Quantity"` // 数量
|
||||
OrigPrice int64 `json:"OrigPrice" xml:"OrigPrice"` // 物品原始价格 (单位:分)
|
||||
OrigPrice int64 `json:"OrigPrice" xml:"OrigPrice"` // 物品原始价格(单位:分)
|
||||
ActualPrice int64 `json:"ActualPrice" xml:"ActualPrice"` // 物品实际支付价格(单位:分)
|
||||
Attach string `json:"Attach" xml:"Attach"` // 透传信息
|
||||
}
|
||||
@@ -359,9 +453,9 @@ type GoodsInfo struct {
|
||||
// PushDataXpayCoinPayNotify 代币支付推送
|
||||
type PushDataXpayCoinPayNotify struct {
|
||||
CommonPushData
|
||||
OpenID string `json:"OpenId" xml:"OpenId"` // 用户openid
|
||||
OpenID string `json:"OpenId" xml:"OpenId"` // 用户 openid
|
||||
OutTradeNo string `json:"OutTradeNo" xml:"OutTradeNo"` // 业务订单号
|
||||
Env int `json:"Env" xml:"Env"` //,环境配置 0:现网环境(也叫正式环境)1:沙箱环境
|
||||
Env int `json:"Env" xml:"Env"` // ,环境配置 0:现网环境(也叫正式环境)1:沙箱环境
|
||||
WeChatPayInfo WeChatPayInfo `json:"WeChatPayInfo" xml:"WeChatPayInfo"` // 微信支付信息 非微信支付渠道可能没有
|
||||
CoinInfo CoinInfo `json:"CoinInfo" xml:"CoinInfo"` // 代币参数信息
|
||||
}
|
||||
@@ -369,7 +463,117 @@ type PushDataXpayCoinPayNotify struct {
|
||||
// CoinInfo 代币参数信息
|
||||
type CoinInfo struct {
|
||||
Quantity int `json:"Quantity" xml:"Quantity"` // 数量
|
||||
OrigPrice int64 `json:"OrigPrice" xml:"OrigPrice"` // 物品原始价格 (单位:分)
|
||||
OrigPrice int64 `json:"OrigPrice" xml:"OrigPrice"` // 物品原始价格(单位:分)
|
||||
ActualPrice int64 `json:"ActualPrice" xml:"ActualPrice"` // 物品实际支付价格(单位:分)
|
||||
Attach string `json:"Attach" xml:"Attach"` // 透传信息
|
||||
}
|
||||
|
||||
// PushDataSubscribePopup 用户操作订阅通知弹窗事件推送
|
||||
type PushDataSubscribePopup struct {
|
||||
CommonPushData
|
||||
subscribeMsgPopupEventList []SubscribeMsgPopupEventList `json:"-"`
|
||||
SubscribeMsgPopupEvent SubscribeMsgPopupEvent `xml:"SubscribeMsgPopupEvent"`
|
||||
}
|
||||
|
||||
// SubscribeMsgPopupEvent 用户操作订阅通知弹窗消息回调
|
||||
type SubscribeMsgPopupEvent struct {
|
||||
List []SubscribeMsgPopupEventList `xml:"List"`
|
||||
}
|
||||
|
||||
// SubscribeMsgPopupEventList 订阅消息事件列表
|
||||
type SubscribeMsgPopupEventList struct {
|
||||
TemplateID string `xml:"TemplateId" json:"TemplateId"`
|
||||
SubscribeStatusString string `xml:"SubscribeStatusString" json:"SubscribeStatusString"`
|
||||
PopupScene string `xml:"PopupScene" json:"PopupScene"`
|
||||
}
|
||||
|
||||
// SetSubscribeMsgPopupEvents 设置订阅消息事件
|
||||
func (s *PushDataSubscribePopup) SetSubscribeMsgPopupEvents(list []SubscribeMsgPopupEventList) {
|
||||
s.subscribeMsgPopupEventList = list
|
||||
}
|
||||
|
||||
// GetSubscribeMsgPopupEvents 获取订阅消息事件数据
|
||||
func (s *PushDataSubscribePopup) GetSubscribeMsgPopupEvents() []SubscribeMsgPopupEventList {
|
||||
if s.subscribeMsgPopupEventList != nil {
|
||||
return s.subscribeMsgPopupEventList
|
||||
}
|
||||
|
||||
if s.SubscribeMsgPopupEvent.List == nil || len(s.SubscribeMsgPopupEvent.List) < 1 {
|
||||
return nil
|
||||
}
|
||||
return s.SubscribeMsgPopupEvent.List
|
||||
}
|
||||
|
||||
// PushDataSubscribeMsgChange 用户管理订阅通知事件推送
|
||||
type PushDataSubscribeMsgChange struct {
|
||||
CommonPushData
|
||||
SubscribeMsgChangeEvent SubscribeMsgChangeEvent `xml:"SubscribeMsgChangeEvent"`
|
||||
subscribeMsgChangeList []SubscribeMsgChangeList `json:"-"`
|
||||
}
|
||||
|
||||
// SubscribeMsgChangeEvent 用户管理订阅通知回调
|
||||
type SubscribeMsgChangeEvent struct {
|
||||
List []SubscribeMsgChangeList `xml:"List" json:"List"`
|
||||
}
|
||||
|
||||
// SubscribeMsgChangeList 订阅消息事件列表
|
||||
type SubscribeMsgChangeList struct {
|
||||
TemplateID string `xml:"TemplateId" json:"TemplateId"`
|
||||
SubscribeStatusString string `xml:"SubscribeStatusString" json:"SubscribeStatusString"`
|
||||
}
|
||||
|
||||
// SetSubscribeMsgChangeEvents 设置订阅消息事件
|
||||
func (s *PushDataSubscribeMsgChange) SetSubscribeMsgChangeEvents(list []SubscribeMsgChangeList) {
|
||||
s.subscribeMsgChangeList = list
|
||||
}
|
||||
|
||||
// GetSubscribeMsgChangeEvents 获取订阅消息事件数据
|
||||
func (s *PushDataSubscribeMsgChange) GetSubscribeMsgChangeEvents() []SubscribeMsgChangeList {
|
||||
if s.subscribeMsgChangeList != nil {
|
||||
return s.subscribeMsgChangeList
|
||||
}
|
||||
|
||||
if s.SubscribeMsgChangeEvent.List == nil || len(s.SubscribeMsgChangeEvent.List) < 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return s.SubscribeMsgChangeEvent.List
|
||||
}
|
||||
|
||||
// PushDataSubscribeMsgSent 用户发送订阅通知事件推送
|
||||
type PushDataSubscribeMsgSent struct {
|
||||
CommonPushData
|
||||
SubscribeMsgSentEvent SubscribeMsgSentEvent `xml:"SubscribeMsgSentEvent"`
|
||||
subscribeMsgSentEventList []SubscribeMsgSentList `json:"-"`
|
||||
}
|
||||
|
||||
// SubscribeMsgSentEvent 用户发送订阅通知回调
|
||||
type SubscribeMsgSentEvent struct {
|
||||
List []SubscribeMsgSentList `xml:"List" json:"List"`
|
||||
}
|
||||
|
||||
// SubscribeMsgSentList 订阅消息事件列表
|
||||
type SubscribeMsgSentList struct {
|
||||
TemplateID string `xml:"TemplateId" json:"TemplateId"`
|
||||
MsgID string `xml:"MsgID" json:"MsgID"`
|
||||
ErrorCode int `xml:"ErrorCode" json:"ErrorCode"`
|
||||
ErrorStatus string `xml:"ErrorStatus" json:"ErrorStatus"`
|
||||
}
|
||||
|
||||
// SetSubscribeMsgSentEvents 设置订阅消息事件
|
||||
func (s *PushDataSubscribeMsgSent) SetSubscribeMsgSentEvents(list []SubscribeMsgSentList) {
|
||||
s.subscribeMsgSentEventList = list
|
||||
}
|
||||
|
||||
// GetSubscribeMsgSentEvents 获取订阅消息事件数据
|
||||
func (s *PushDataSubscribeMsgSent) GetSubscribeMsgSentEvents() []SubscribeMsgSentList {
|
||||
if s.subscribeMsgSentEventList != nil {
|
||||
return s.subscribeMsgSentEventList
|
||||
}
|
||||
|
||||
if s.SubscribeMsgSentEvent.List == nil || len(s.SubscribeMsgSentEvent.List) < 1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return s.SubscribeMsgSentEvent.List
|
||||
}
|
||||
|
||||
15
miniprogram/message/reply.go
Normal file
15
miniprogram/message/reply.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package message
|
||||
|
||||
import "errors"
|
||||
|
||||
// ErrInvalidReply 无效的回复
|
||||
var ErrInvalidReply = errors.New("无效的回复信息")
|
||||
|
||||
// ErrUnsupportedReply 不支持的回复类型
|
||||
var ErrUnsupportedReply = errors.New("不支持的回复消息")
|
||||
|
||||
// Reply 消息回复
|
||||
type Reply struct {
|
||||
MsgType MsgType
|
||||
MsgData interface{}
|
||||
}
|
||||
102
miniprogram/message/updatable_msg.go
Normal file
102
miniprogram/message/updatable_msg.go
Normal file
@@ -0,0 +1,102 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
// createActivityURL 创建 activity_id
|
||||
createActivityURL = "https://api.weixin.qq.com/cgi-bin/message/wxopen/activityid/create?access_token=%s"
|
||||
// SendUpdatableMsgURL 修改动态消息
|
||||
setUpdatableMsgURL = "https://api.weixin.qq.com/cgi-bin/message/wxopen/updatablemsg/send?access_token=%s"
|
||||
)
|
||||
|
||||
// UpdatableTargetState 动态消息状态
|
||||
type UpdatableTargetState int
|
||||
|
||||
const (
|
||||
// TargetStateNotStarted 未开始
|
||||
TargetStateNotStarted UpdatableTargetState = 0
|
||||
// TargetStateStarted 已开始
|
||||
TargetStateStarted UpdatableTargetState = 1
|
||||
// TargetStateFinished 已结束
|
||||
TargetStateFinished UpdatableTargetState = 2
|
||||
)
|
||||
|
||||
// UpdatableMessage 动态消息
|
||||
type UpdatableMessage struct {
|
||||
*context.Context
|
||||
}
|
||||
|
||||
// NewUpdatableMessage 实例化
|
||||
func NewUpdatableMessage(ctx *context.Context) *UpdatableMessage {
|
||||
return &UpdatableMessage{
|
||||
Context: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// CreateActivityID 创建 activity_id
|
||||
func (updatableMessage *UpdatableMessage) CreateActivityID() (res CreateActivityIDResponse, err error) {
|
||||
accessToken, err := updatableMessage.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
uri := fmt.Sprintf(createActivityURL, accessToken)
|
||||
response, err := util.HTTPGet(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = util.DecodeWithError(response, &res, "CreateActivityID")
|
||||
return
|
||||
}
|
||||
|
||||
// SetUpdatableMsg 修改动态消息
|
||||
func (updatableMessage *UpdatableMessage) SetUpdatableMsg(activityID string, targetState UpdatableTargetState, template UpdatableMsgTemplate) (err error) {
|
||||
accessToken, err := updatableMessage.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
uri := fmt.Sprintf(setUpdatableMsgURL, accessToken)
|
||||
data := SendUpdatableMsgReq{
|
||||
ActivityID: activityID,
|
||||
TargetState: targetState,
|
||||
TemplateInfo: template,
|
||||
}
|
||||
|
||||
response, err := util.PostJSON(uri, data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "SendUpdatableMsg")
|
||||
}
|
||||
|
||||
// CreateActivityIDResponse 创建 activity_id 返回
|
||||
type CreateActivityIDResponse struct {
|
||||
util.CommonError
|
||||
|
||||
ActivityID string `json:"activity_id"`
|
||||
ExpirationTime int64 `json:"expiration_time"`
|
||||
}
|
||||
|
||||
// UpdatableMsgTemplate 动态消息模板
|
||||
type UpdatableMsgTemplate struct {
|
||||
ParameterList []UpdatableMsgParameter `json:"parameter_list"`
|
||||
}
|
||||
|
||||
// UpdatableMsgParameter 动态消息参数
|
||||
type UpdatableMsgParameter struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// SendUpdatableMsgReq 修改动态消息参数
|
||||
type SendUpdatableMsgReq struct {
|
||||
ActivityID string `json:"activity_id"`
|
||||
TemplateInfo UpdatableMsgTemplate `json:"template_info"`
|
||||
TargetState UpdatableTargetState `json:"target_state"`
|
||||
}
|
||||
@@ -180,7 +180,7 @@ type MediaInfo struct {
|
||||
CreateTime int64 `json:"create_time"` // 上传时间,时间戳。
|
||||
ExpireTime int64 `json:"expire_time"` // 过期时间,时间戳。
|
||||
DramaID int64 `json:"drama_id"` // 所属剧目 id。
|
||||
FileSize string `json:"file_size"` // 媒资文件大小,单位:字节。
|
||||
FileSize int64 `json:"file_size"` // 媒资文件大小,单位:字节。
|
||||
Duration int64 `json:"duration"` // 播放时长,单位:秒。
|
||||
Name string `json:"name"` // 媒资文件名。
|
||||
Description string `json:"description"` // 描述。
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
// SingleFileUpload 单文件上传
|
||||
func (s *MiniDrama) SingleFileUpload(ctx context.Context, in *SingleFileUploadRequest) (out *SingleFileUploadResponse, err error) {
|
||||
func (s *MiniDrama) SingleFileUpload(ctx context.Context, in *SingleFileUploadRequest) (out SingleFileUploadResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, singleFileUpload); err != nil {
|
||||
return
|
||||
@@ -76,12 +76,12 @@ func (s *MiniDrama) SingleFileUpload(ctx context.Context, in *SingleFileUploadRe
|
||||
return
|
||||
}
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "SingleFileUpload")
|
||||
err = util.DecodeWithError(response, &out, "SingleFileUpload")
|
||||
return
|
||||
}
|
||||
|
||||
// PullUpload 拉取上传
|
||||
func (s *MiniDrama) PullUpload(ctx context.Context, in *PullUploadRequest) (out *PullUploadResponse, err error) {
|
||||
func (s *MiniDrama) PullUpload(ctx context.Context, in *PullUploadRequest) (out PullUploadResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, pullUpload); err != nil {
|
||||
return
|
||||
@@ -92,12 +92,12 @@ func (s *MiniDrama) PullUpload(ctx context.Context, in *PullUploadRequest) (out
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "PullUpload")
|
||||
err = util.DecodeWithError(response, &out, "PullUpload")
|
||||
return
|
||||
}
|
||||
|
||||
// GetTask 查询任务状态
|
||||
func (s *MiniDrama) GetTask(ctx context.Context, in *GetTaskRequest) (out *GetTaskResponse, err error) {
|
||||
func (s *MiniDrama) GetTask(ctx context.Context, in *GetTaskRequest) (out GetTaskResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, getTask); err != nil {
|
||||
return
|
||||
@@ -109,12 +109,12 @@ func (s *MiniDrama) GetTask(ctx context.Context, in *GetTaskRequest) (out *GetTa
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "GetTask")
|
||||
err = util.DecodeWithError(response, &out, "GetTask")
|
||||
return
|
||||
}
|
||||
|
||||
// ApplyUpload 申请分片上传
|
||||
func (s *MiniDrama) ApplyUpload(ctx context.Context, in *ApplyUploadRequest) (out *ApplyUploadResponse, err error) {
|
||||
func (s *MiniDrama) ApplyUpload(ctx context.Context, in *ApplyUploadRequest) (out ApplyUploadResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, applyUpload); err != nil {
|
||||
return
|
||||
@@ -126,13 +126,13 @@ func (s *MiniDrama) ApplyUpload(ctx context.Context, in *ApplyUploadRequest) (ou
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "ApplyUpload")
|
||||
err = util.DecodeWithError(response, &out, "ApplyUpload")
|
||||
return
|
||||
}
|
||||
|
||||
// UploadPart 上传分片
|
||||
// Content-Type 需要指定为 multipart/form-data; boundary=<delimiter>,<箭头括号>表示必须替换为有效值的变量。
|
||||
func (s *MiniDrama) UploadPart(ctx context.Context, in *UploadPartRequest) (out *UploadPartResponse, err error) {
|
||||
func (s *MiniDrama) UploadPart(ctx context.Context, in *UploadPartRequest) (out UploadPartResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, uploadPart); err != nil {
|
||||
return
|
||||
@@ -165,12 +165,12 @@ func (s *MiniDrama) UploadPart(ctx context.Context, in *UploadPartRequest) (out
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "UploadPart")
|
||||
err = util.DecodeWithError(response, &out, "UploadPart")
|
||||
return
|
||||
}
|
||||
|
||||
// CommitUpload 确认上传
|
||||
func (s *MiniDrama) CommitUpload(ctx context.Context, in *CommitUploadRequest) (out *CommitUploadResponse, err error) {
|
||||
func (s *MiniDrama) CommitUpload(ctx context.Context, in *CommitUploadRequest) (out CommitUploadResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, commitUpload); err != nil {
|
||||
return
|
||||
@@ -182,12 +182,12 @@ func (s *MiniDrama) CommitUpload(ctx context.Context, in *CommitUploadRequest) (
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "CommitUpload")
|
||||
err = util.DecodeWithError(response, &out, "CommitUpload")
|
||||
return
|
||||
}
|
||||
|
||||
// ListMedia 获取媒体列表
|
||||
func (s *MiniDrama) ListMedia(ctx context.Context, in *ListMediaRequest) (out *ListMediaResponse, err error) {
|
||||
func (s *MiniDrama) ListMedia(ctx context.Context, in *ListMediaRequest) (out ListMediaResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, listMedia); err != nil {
|
||||
return
|
||||
@@ -199,12 +199,12 @@ func (s *MiniDrama) ListMedia(ctx context.Context, in *ListMediaRequest) (out *L
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "ListMedia")
|
||||
err = util.DecodeWithError(response, &out, "ListMedia")
|
||||
return
|
||||
}
|
||||
|
||||
// GetMedia 获取媒资详细信息
|
||||
func (s *MiniDrama) GetMedia(ctx context.Context, in *GetMediaRequest) (out *GetMediaResponse, err error) {
|
||||
func (s *MiniDrama) GetMedia(ctx context.Context, in *GetMediaRequest) (out GetMediaResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, getMedia); err != nil {
|
||||
return
|
||||
@@ -216,12 +216,12 @@ func (s *MiniDrama) GetMedia(ctx context.Context, in *GetMediaRequest) (out *Get
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "GetMedia")
|
||||
err = util.DecodeWithError(response, &out, "GetMedia")
|
||||
return
|
||||
}
|
||||
|
||||
// GetMediaLink 获取媒资播放链接
|
||||
func (s *MiniDrama) GetMediaLink(ctx context.Context, in *GetMediaLinkRequest) (out *GetMediaLinkResponse, err error) {
|
||||
func (s *MiniDrama) GetMediaLink(ctx context.Context, in *GetMediaLinkRequest) (out GetMediaLinkResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, getMediaLink); err != nil {
|
||||
return
|
||||
@@ -233,12 +233,12 @@ func (s *MiniDrama) GetMediaLink(ctx context.Context, in *GetMediaLinkRequest) (
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "GetMediaLink")
|
||||
err = util.DecodeWithError(response, &out, "GetMediaLink")
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteMedia 删除媒体
|
||||
func (s *MiniDrama) DeleteMedia(ctx context.Context, in *DeleteMediaRequest) (out *DeleteMediaResponse, err error) {
|
||||
func (s *MiniDrama) DeleteMedia(ctx context.Context, in *DeleteMediaRequest) (out DeleteMediaResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, deleteMedia); err != nil {
|
||||
return
|
||||
@@ -250,12 +250,12 @@ func (s *MiniDrama) DeleteMedia(ctx context.Context, in *DeleteMediaRequest) (ou
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "DeleteMedia")
|
||||
err = util.DecodeWithError(response, &out, "DeleteMedia")
|
||||
return
|
||||
}
|
||||
|
||||
// AuditDrama 审核剧本
|
||||
func (s *MiniDrama) AuditDrama(ctx context.Context, in *AuditDramaRequest) (out *AuditDramaResponse, err error) {
|
||||
func (s *MiniDrama) AuditDrama(ctx context.Context, in *AuditDramaRequest) (out AuditDramaResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, auditDrama); err != nil {
|
||||
return
|
||||
@@ -267,12 +267,12 @@ func (s *MiniDrama) AuditDrama(ctx context.Context, in *AuditDramaRequest) (out
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "AuditDrama")
|
||||
err = util.DecodeWithError(response, &out, "AuditDrama")
|
||||
return
|
||||
}
|
||||
|
||||
// ListDramas 获取剧目列表
|
||||
func (s *MiniDrama) ListDramas(ctx context.Context, in *ListDramasRequest) (out *ListDramasResponse, err error) {
|
||||
func (s *MiniDrama) ListDramas(ctx context.Context, in *ListDramasRequest) (out ListDramasResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, listDramas); err != nil {
|
||||
return
|
||||
@@ -284,12 +284,12 @@ func (s *MiniDrama) ListDramas(ctx context.Context, in *ListDramasRequest) (out
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "ListDramas")
|
||||
err = util.DecodeWithError(response, &out, "ListDramas")
|
||||
return
|
||||
}
|
||||
|
||||
// GetDrama 获取剧目信息
|
||||
func (s *MiniDrama) GetDrama(ctx context.Context, in *GetDramaRequest) (out *GetDramaResponse, err error) {
|
||||
func (s *MiniDrama) GetDrama(ctx context.Context, in *GetDramaRequest) (out GetDramaResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, getDrama); err != nil {
|
||||
return
|
||||
@@ -300,12 +300,12 @@ func (s *MiniDrama) GetDrama(ctx context.Context, in *GetDramaRequest) (out *Get
|
||||
return
|
||||
}
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "GetDrama")
|
||||
err = util.DecodeWithError(response, &out, "GetDrama")
|
||||
return
|
||||
}
|
||||
|
||||
// GetCdnUsageData 查询 CDN 用量数据
|
||||
func (s *MiniDrama) GetCdnUsageData(ctx context.Context, in *GetCdnUsageDataRequest) (out *GetCdnUsageDataResponse, err error) {
|
||||
func (s *MiniDrama) GetCdnUsageData(ctx context.Context, in *GetCdnUsageDataRequest) (out GetCdnUsageDataResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, getCdnUsageData); err != nil {
|
||||
return
|
||||
@@ -316,12 +316,12 @@ func (s *MiniDrama) GetCdnUsageData(ctx context.Context, in *GetCdnUsageDataRequ
|
||||
return
|
||||
}
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "GetCdnUsageData")
|
||||
err = util.DecodeWithError(response, &out, "GetCdnUsageData")
|
||||
return
|
||||
}
|
||||
|
||||
// GetCdnLogs 查询 CDN 日志
|
||||
func (s *MiniDrama) GetCdnLogs(ctx context.Context, in *GetCdnLogsRequest) (out *GetCdnLogsResponse, err error) {
|
||||
func (s *MiniDrama) GetCdnLogs(ctx context.Context, in *GetCdnLogsRequest) (out GetCdnLogsResponse, err error) {
|
||||
var address string
|
||||
if address, err = s.requestAddress(ctx, getCdnLogs); err != nil {
|
||||
return
|
||||
@@ -332,7 +332,7 @@ func (s *MiniDrama) GetCdnLogs(ctx context.Context, in *GetCdnLogsRequest) (out
|
||||
return
|
||||
}
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "GetCdnLogs")
|
||||
err = util.DecodeWithError(response, &out, "GetCdnLogs")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/silenceper/wechat/v2/miniprogram/order"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/privacy"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/qrcode"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/redpacketcover"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/riskcontrol"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/security"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/shortlink"
|
||||
@@ -155,3 +156,13 @@ func (miniProgram *MiniProgram) GetShipping() *order.Shipping {
|
||||
func (miniProgram *MiniProgram) GetMiniDrama() *minidrama.MiniDrama {
|
||||
return minidrama.NewMiniDrama(miniProgram.ctx)
|
||||
}
|
||||
|
||||
// GetRedPacketCover 小程序微信红包封面 API
|
||||
func (miniProgram *MiniProgram) GetRedPacketCover() *redpacketcover.RedPacketCover {
|
||||
return redpacketcover.NewRedPacketCover(miniProgram.ctx)
|
||||
}
|
||||
|
||||
// GetUpdatableMessage 小程序动态消息
|
||||
func (miniProgram *MiniProgram) GetUpdatableMessage() *message.UpdatableMessage {
|
||||
return message.NewUpdatableMessage(miniProgram.ctx)
|
||||
}
|
||||
|
||||
@@ -114,29 +114,29 @@ type UploadShippingInfoRequest struct {
|
||||
|
||||
// ShippingOrderKey 订单
|
||||
type ShippingOrderKey struct {
|
||||
OrderNumberType NumberType `json:"order_number_type"` // 订单单号类型,用于确认需要上传详情的订单。枚举值1,使用下单商户号和商户侧单号;枚举值2,使用微信支付单号。
|
||||
OrderNumberType NumberType `json:"order_number_type"` // 订单单号类型,用于确认需要上传详情的订单。枚举值 1,使用下单商户号和商户侧单号;枚举值 2,使用微信支付单号。
|
||||
TransactionID string `json:"transaction_id"` // 原支付交易对应的微信订单号
|
||||
Mchid string `json:"mchid"` // 支付下单商户的商户号,由微信支付生成并下发
|
||||
OutTradeNo string `json:"out_trade_no"` // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
|
||||
OutTradeNo string `json:"out_trade_no"` // 商户系统内部订单号,只能是数字、大小写字母 `_-*` 且在同一个商户号下唯一
|
||||
}
|
||||
|
||||
// ShippingPayer 支付者信息
|
||||
type ShippingPayer struct {
|
||||
Openid string `json:"openid"` // 用户标识,用户在小程序appid下的唯一标识
|
||||
Openid string `json:"openid"` // 用户标识,用户在小程序 appid 下的唯一标识
|
||||
}
|
||||
|
||||
// ShippingInfo 物流信息
|
||||
type ShippingInfo struct {
|
||||
TrackingNo string `json:"tracking_no"` // 物流单号,物流快递发货时必填
|
||||
ExpressCompany string `json:"express_company"` // 物流公司编码,快递公司ID,物流快递发货时必填;参见「查询物流公司编码列表」
|
||||
ItemDesc string `json:"item_desc"` // 商品信息,例如:微信红包抱枕*1个,限120个字以内
|
||||
ExpressCompany string `json:"express_company"` // 物流公司编码,快递公司 ID,物流快递发货时必填;参见「查询物流公司编码列表」
|
||||
ItemDesc string `json:"item_desc"` // 商品信息,例如:微信红包抱枕*1 个,限 120 个字以内
|
||||
Contact ShippingContact `json:"contact"` // 联系方式,当发货的物流公司为顺丰时,联系方式为必填,收件人或寄件人联系方式二选一
|
||||
}
|
||||
|
||||
// ShippingContact 联系方式
|
||||
type ShippingContact struct {
|
||||
ConsignorContact string `json:"consignor_contact"` // 寄件人联系方式,寄件人联系方式,采用掩码传输,最后4位数字不能打掩码
|
||||
ReceiverContact string `json:"receiver_contact"` // 收件人联系方式,收件人联系方式,采用掩码传输,最后4位数字不能打掩码
|
||||
ConsignorContact string `json:"consignor_contact"` // 寄件人联系方式,寄件人联系方式,采用掩码传输,最后 4 位数字不能打掩码
|
||||
ReceiverContact string `json:"receiver_contact"` // 收件人联系方式,收件人联系方式,采用掩码传输,最后 4 位数字不能打掩码
|
||||
}
|
||||
|
||||
// DeliveryMode 发货模式
|
||||
@@ -178,13 +178,13 @@ type GetShippingOrderRequest struct {
|
||||
TransactionID string `json:"transaction_id"` // 原支付交易对应的微信订单号
|
||||
MerchantID string `json:"merchant_id"` // 支付下单商户的商户号,由微信支付生成并下发
|
||||
SubMerchantID string `json:"sub_merchant_id"` //二级商户号
|
||||
MerchantTradeNo string `json:"merchant_trade_no"` //商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一。
|
||||
MerchantTradeNo string `json:"merchant_trade_no"` //商户系统内部订单号,只能是数字、大小写字母 `_-*` 且在同一个商户号下唯一。
|
||||
}
|
||||
|
||||
// ShippingItem 物流信息
|
||||
type ShippingItem struct {
|
||||
TrackingNo string `json:"tracking_no"` // 物流单号,示例值: "323244567777
|
||||
ExpressCompany string `json:"express_company"` // 物流公司编码,快递公司ID,物流快递发货时必填;参见「查询物流公司编码列表」
|
||||
TrackingNo string `json:"tracking_no"` // 物流单号,示例值:"323244567777
|
||||
ExpressCompany string `json:"express_company"` // 物流公司编码,快递公司 ID,物流快递发货时必填;参见「查询物流公司编码列表」
|
||||
UploadTime int64 `json:"upload_time"` // 上传物流信息时间,时间戳形式
|
||||
}
|
||||
|
||||
@@ -201,12 +201,12 @@ type ShippingDetail struct {
|
||||
// ShippingOrder 订单发货状态
|
||||
type ShippingOrder struct {
|
||||
TransactionID string `json:"transaction_id"` // 原支付交易对应的微信订单号
|
||||
MerchantTradeNo string `json:"merchant_trade_no"` // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
|
||||
MerchantTradeNo string `json:"merchant_trade_no"` // 商户系统内部订单号,只能是数字、大小写字母 `_-*` 且在同一个商户号下唯一
|
||||
MerchantID string `json:"merchant_id"` // 支付下单商户的商户号,由微信支付生成并下发
|
||||
SubMerchantID string `json:"sub_merchant_id"` // 二级商户号
|
||||
Description string `json:"description"` // 以分号连接的该支付单的所有商品描述,当超过120字时自动截断并以 “...” 结尾
|
||||
Description string `json:"description"` // 以分号连接的该支付单的所有商品描述,当超过 120 字时自动截断并以“...”结尾
|
||||
PaidAmount int64 `json:"paid_amount"` // 支付单实际支付金额,整型,单位:分钱
|
||||
Openid string `json:"openid"` // 支付者openid
|
||||
Openid string `json:"openid"` // 支付者 openid
|
||||
TradeCreateTime int64 `json:"trade_create_time"` // 交易创建时间,时间戳形式
|
||||
PayTime int64 `json:"pay_time"` // 支付时间,时间戳形式
|
||||
InComplaint bool `json:"in_complaint"` // 是否处在交易纠纷中
|
||||
@@ -240,9 +240,9 @@ const (
|
||||
type GetShippingOrderListRequest struct {
|
||||
PayTimeRange *TimeRange `json:"pay_time_range"` // 支付时间范围
|
||||
OrderState State `json:"order_state,omitempty"` // 订单状态
|
||||
Openid string `json:"openid,omitempty"` // 支付者openid
|
||||
Openid string `json:"openid,omitempty"` // 支付者 openid
|
||||
LastIndex string `json:"last_index,omitempty"` // 翻页时使用,获取第一页时不用传入,如果查询结果中 has_more 字段为 true,则传入该次查询结果中返回的 last_index 字段可获取下一页
|
||||
PageSize int64 `json:"page_size"` // 每页数量,最多50条
|
||||
PageSize int64 `json:"page_size"` // 每页数量,最多 50 条
|
||||
}
|
||||
|
||||
// TimeRange 时间范围
|
||||
@@ -264,6 +264,6 @@ type NotifyConfirmReceiveRequest struct {
|
||||
TransactionID string `json:"transaction_id"` // 原支付交易对应的微信订单号
|
||||
MerchantID string `json:"merchant_id"` // 支付下单商户的商户号,由微信支付生成并下发
|
||||
SubMerchantID string `json:"sub_merchant_id"` // 二级商户号
|
||||
MerchantTradeNo string `json:"merchant_trade_no"` // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
|
||||
MerchantTradeNo string `json:"merchant_trade_no"` // 商户系统内部订单号,只能是数字、大小写字母 `_-*` 且在同一个商户号下唯一
|
||||
ReceivedTime int64 `json:"received_time"` // 收货时间,时间戳形式
|
||||
}
|
||||
|
||||
@@ -53,9 +53,9 @@ const (
|
||||
getPrivacySettingURL = "https://api.weixin.qq.com/cgi-bin/component/getprivacysetting"
|
||||
uploadPrivacyExtFileURL = "https://api.weixin.qq.com/cgi-bin/component/uploadprivacyextfile"
|
||||
|
||||
// PrivacyV1 用户隐私保护指引的版本,1表示现网版本。
|
||||
// PrivacyV1 用户隐私保护指引的版本,1 表示现网版本。
|
||||
PrivacyV1 = 1
|
||||
// PrivacyV2 2表示开发版。默认是2开发版。
|
||||
// PrivacyV2 2 表示开发版。默认是 2 开发版。
|
||||
PrivacyV2 = 2
|
||||
)
|
||||
|
||||
@@ -77,12 +77,12 @@ type SettingResponseItem struct {
|
||||
PrivacyLabel string `json:"privacy_label"`
|
||||
}
|
||||
|
||||
// DescList 权限列表(保持与官方一致)
|
||||
// DescList 权限列表 (保持与官方一致)
|
||||
type DescList struct {
|
||||
PrivacyDescList []Desc `json:"privacy_desc_list"`
|
||||
}
|
||||
|
||||
// Desc 权限列表明细(保持与官方一致)
|
||||
// Desc 权限列表明细 (保持与官方一致)
|
||||
type Desc struct {
|
||||
PrivacyDesc string `json:"privacy_desc"`
|
||||
PrivacyKey string `json:"privacy_key"`
|
||||
@@ -103,17 +103,14 @@ func (s *Privacy) GetPrivacySetting(privacyVer int) (GetPrivacySettingResponse,
|
||||
}
|
||||
// 返回错误信息
|
||||
var result GetPrivacySettingResponse
|
||||
if err = util.DecodeWithError(response, &result, "getprivacysetting"); err != nil {
|
||||
return GetPrivacySettingResponse{}, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
err = util.DecodeWithError(response, &result, "getprivacysetting")
|
||||
return result, err
|
||||
}
|
||||
|
||||
// SetPrivacySetting 更新小程序权限配置
|
||||
func (s *Privacy) SetPrivacySetting(privacyVer int, ownerSetting OwnerSetting, settingList []SettingItem) error {
|
||||
if privacyVer == PrivacyV1 && len(settingList) > 0 {
|
||||
return errors.New("当privacy_ver传2或者不传时,setting_list是必填;当privacy_ver传1时,该参数不可传")
|
||||
return errors.New("当 privacy_ver 传 2 或者不传时,setting_list 是必填;当 privacy_ver 传 1 时,该参数不可传")
|
||||
}
|
||||
accessToken, err := s.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -130,11 +127,7 @@ func (s *Privacy) SetPrivacySetting(privacyVer int, ownerSetting OwnerSetting, s
|
||||
}
|
||||
|
||||
// 返回错误信息
|
||||
if err = util.DecodeWithCommonError(response, "setprivacysetting"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
return util.DecodeWithCommonError(response, "setprivacysetting")
|
||||
}
|
||||
|
||||
// UploadPrivacyExtFileResponse 上传权限定义模板响应参数
|
||||
@@ -159,9 +152,6 @@ func (s *Privacy) UploadPrivacyExtFile(fileData []byte) (UploadPrivacyExtFileRes
|
||||
|
||||
// 返回错误信息
|
||||
var result UploadPrivacyExtFileResponse
|
||||
if err = util.DecodeWithError(response, &result, "setprivacysetting"); err != nil {
|
||||
return UploadPrivacyExtFileResponse{}, err
|
||||
}
|
||||
|
||||
err = util.DecodeWithError(response, &result, "setprivacysetting")
|
||||
return result, err
|
||||
}
|
||||
|
||||
@@ -36,21 +36,21 @@ type Color struct {
|
||||
|
||||
// QRCoder 小程序码参数
|
||||
type QRCoder struct {
|
||||
// page 必须是已经发布的小程序存在的页面,根路径前不要填加 /,不能携带参数(参数请放在scene字段里),如果不填写这个字段,默认跳主页面
|
||||
// page 必须是已经发布的小程序存在的页面,根路径前不要填加 /,不能携带参数(参数请放在 scene 字段里),如果不填写这个字段,默认跳主页面
|
||||
Page string `json:"page,omitempty"`
|
||||
// path 扫码进入的小程序页面路径
|
||||
Path string `json:"path,omitempty"`
|
||||
// checkPath 检查page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);为 false 时允许小程序未发布或者 page 不存在, 但page 有数量上限(60000个)请勿滥用,默认true
|
||||
// checkPath 检查 page 是否存在,为 true 时 page 必须是已经发布的小程序存在的页面(否则报错);为 false 时允许小程序未发布或者 page 不存在,但 page 有数量上限(60000 个)请勿滥用,默认 true
|
||||
CheckPath *bool `json:"check_path,omitempty"`
|
||||
// width 图片宽度
|
||||
Width int `json:"width,omitempty"`
|
||||
// scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
|
||||
// scene 最大 32 个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理,请使用其他编码方式)
|
||||
Scene string `json:"scene,omitempty"`
|
||||
// autoColor 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调,默认false
|
||||
// autoColor 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调,默认 false
|
||||
AutoColor bool `json:"auto_color,omitempty"`
|
||||
// lineColor AutoColor 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"},十进制表示
|
||||
LineColor *Color `json:"line_color,omitempty"`
|
||||
// isHyaline 是否需要透明底色,默认false
|
||||
// isHyaline 是否需要透明底色,默认 false
|
||||
IsHyaline bool `json:"is_hyaline,omitempty"`
|
||||
// envVersion 要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"
|
||||
EnvVersion string `json:"env_version,omitempty"`
|
||||
@@ -88,19 +88,19 @@ func (qrCode *QRCode) fetchCode(urlStr string, body interface{}) (response []byt
|
||||
}
|
||||
|
||||
// CreateWXAQRCode 获取小程序二维码,适用于需要的码数量较少的业务场景
|
||||
// 文档地址: https://developers.weixin.qq.com/miniprogram/dev/api/createWXAQRCode.html
|
||||
// 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api/createWXAQRCode.html
|
||||
func (qrCode *QRCode) CreateWXAQRCode(coderParams QRCoder) (response []byte, err error) {
|
||||
return qrCode.fetchCode(createWXAQRCodeURL, coderParams)
|
||||
}
|
||||
|
||||
// GetWXACode 获取小程序码,适用于需要的码数量较少的业务场景
|
||||
// 文档地址: https://developers.weixin.qq.com/miniprogram/dev/api/getWXACode.html
|
||||
// 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api/getWXACode.html
|
||||
func (qrCode *QRCode) GetWXACode(coderParams QRCoder) (response []byte, err error) {
|
||||
return qrCode.fetchCode(getWXACodeURL, coderParams)
|
||||
}
|
||||
|
||||
// GetWXACodeUnlimit 获取小程序码,适用于需要的码数量极多的业务场景
|
||||
// 文档地址: https://developers.weixin.qq.com/miniprogram/dev/api/getWXACodeUnlimit.html
|
||||
// 文档地址:https://developers.weixin.qq.com/miniprogram/dev/api/getWXACodeUnlimit.html
|
||||
func (qrCode *QRCode) GetWXACodeUnlimit(coderParams QRCoder) (response []byte, err error) {
|
||||
return qrCode.fetchCode(getWXACodeUnlimitURL, coderParams)
|
||||
}
|
||||
|
||||
59
miniprogram/redpacketcover/redpacketcover.go
Normal file
59
miniprogram/redpacketcover/redpacketcover.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package redpacketcover
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
getRedPacketCoverURL = "https://api.weixin.qq.com/redpacketcover/wxapp/cover_url/get_by_token?access_token=%s"
|
||||
)
|
||||
|
||||
// RedPacketCover struct
|
||||
type RedPacketCover struct {
|
||||
*context.Context
|
||||
}
|
||||
|
||||
// NewRedPacketCover 实例
|
||||
func NewRedPacketCover(context *context.Context) *RedPacketCover {
|
||||
redPacketCover := new(RedPacketCover)
|
||||
redPacketCover.Context = context
|
||||
return redPacketCover
|
||||
}
|
||||
|
||||
// GetRedPacketCoverRequest 获取微信红包封面参数
|
||||
type GetRedPacketCoverRequest struct {
|
||||
// openid 可领取用户的 openid
|
||||
OpenID string `json:"openid"`
|
||||
// ctoken 在红包封面平台获取发放 ctoken(需要指定可以发放的 appid)
|
||||
CToken string `json:"ctoken"`
|
||||
}
|
||||
|
||||
// GetRedPacketCoverResp 获取微信红包封面
|
||||
type GetRedPacketCoverResp struct {
|
||||
util.CommonError
|
||||
Data struct {
|
||||
URL string `json:"url"`
|
||||
} `json:"data"` // 唯一请求标识
|
||||
}
|
||||
|
||||
// GetRedPacketCoverURL 获得指定用户可以领取的红包封面链接。获取参数 ctoken 参考微信红包封面开放平台
|
||||
// 文档地址:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/red-packet-cover/getRedPacketCoverUrl.html
|
||||
func (cover *RedPacketCover) GetRedPacketCoverURL(coderParams GetRedPacketCoverRequest) (res GetRedPacketCoverResp, err error) {
|
||||
accessToken, err := cover.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
uri := fmt.Sprintf(getRedPacketCoverURL, accessToken)
|
||||
response, err := util.PostJSON(uri, coderParams)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, &res, "GetRedPacketCoverURL")
|
||||
return
|
||||
}
|
||||
@@ -26,7 +26,7 @@ type UserRiskRankRequest struct {
|
||||
AppID string `json:"appid"` // 小程序 app id
|
||||
OpenID string `json:"openid"` // 用户的 openid
|
||||
Scene uint8 `json:"scene"` // 场景值,0:注册,1:营销作弊
|
||||
ClientIP string `json:"client_ip"` // 用户访问源ip
|
||||
ClientIP string `json:"client_ip"` // 用户访问源 ip
|
||||
|
||||
Mobile string `json:"mobile_no"` // 用户手机号
|
||||
Email string `json:"email_address"` // 用户邮箱地址
|
||||
|
||||
@@ -26,13 +26,13 @@ func NewSecurity(ctx *context.Context) *Security {
|
||||
|
||||
// MediaCheckAsyncV1Request 图片/音频异步校验请求参数
|
||||
type MediaCheckAsyncV1Request struct {
|
||||
MediaURL string `json:"media_url"` // 要检测的图片或音频的url,支持图片格式包括jpg, jepg, png, bmp, gif(取首帧),支持的音频格式包括mp3, aac, ac3, wma, flac, vorbis, opus, wav
|
||||
MediaURL string `json:"media_url"` // 要检测的图片或音频的 url,支持图片格式包括 jpg, jepg, png, bmp, gif(取首帧),支持的音频格式包括 mp3, aac, ac3, wma, flac, vorbis, opus, wav
|
||||
MediaType uint8 `json:"media_type"` // 1:音频;2:图片
|
||||
}
|
||||
|
||||
// MediaCheckAsyncV1 异步校验图片/音频是否含有违法违规内容
|
||||
// Deprecated
|
||||
// 在2021年9月1日停止更新,请尽快更新至 2.0 接口。建议使用 MediaCheckAsync
|
||||
// 在 2021 年 9 月 1 日停止更新,请尽快更新至 2.0 接口。建议使用 MediaCheckAsync
|
||||
func (security *Security) MediaCheckAsyncV1(in *MediaCheckAsyncV1Request) (traceID string, err error) {
|
||||
accessToken, err := security.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -51,19 +51,14 @@ func (security *Security) MediaCheckAsyncV1(in *MediaCheckAsyncV1Request) (trace
|
||||
TraceID string `json:"trace_id"`
|
||||
}
|
||||
err = util.DecodeWithError(response, &res, "MediaCheckAsyncV1")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
traceID = res.TraceID
|
||||
return
|
||||
return res.TraceID, err
|
||||
}
|
||||
|
||||
// MediaCheckAsyncRequest 图片/音频异步校验请求参数
|
||||
type MediaCheckAsyncRequest struct {
|
||||
MediaURL string `json:"media_url"` // 要检测的图片或音频的url,支持图片格式包括jpg, jepg, png, bmp, gif(取首帧),支持的音频格式包括mp3, aac, ac3, wma, flac, vorbis, opus, wav
|
||||
MediaURL string `json:"media_url"` // 要检测的图片或音频的 url,支持图片格式包括 jpg, jepg, png, bmp, gif(取首帧),支持的音频格式包括 mp3, aac, ac3, wma, flac, vorbis, opus, wav
|
||||
MediaType uint8 `json:"media_type"` // 1:音频;2:图片
|
||||
OpenID string `json:"openid"` // 用户的openid(用户需在近两小时访问过小程序)
|
||||
OpenID string `json:"openid"` // 用户的 openid(用户需在近两小时访问过小程序)
|
||||
Scene uint8 `json:"scene"` // 场景枚举值(1 资料;2 评论;3 论坛;4 社交日志)
|
||||
}
|
||||
|
||||
@@ -76,7 +71,7 @@ func (security *Security) MediaCheckAsync(in *MediaCheckAsyncRequest) (traceID s
|
||||
|
||||
var req struct {
|
||||
MediaCheckAsyncRequest
|
||||
Version uint `json:"version"` // 接口版本号,2.0版本为固定值2
|
||||
Version uint `json:"version"` // 接口版本号,2.0 版本为固定值 2
|
||||
}
|
||||
req.MediaCheckAsyncRequest = *in
|
||||
req.Version = 2
|
||||
@@ -93,18 +88,13 @@ func (security *Security) MediaCheckAsync(in *MediaCheckAsyncRequest) (traceID s
|
||||
TraceID string `json:"trace_id"`
|
||||
}
|
||||
err = util.DecodeWithError(response, &res, "MediaCheckAsync")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
traceID = res.TraceID
|
||||
return
|
||||
return res.TraceID, err
|
||||
}
|
||||
|
||||
// ImageCheckV1 校验一张图片是否含有违法违规内容(同步)
|
||||
// https://developers.weixin.qq.com/miniprogram/dev/framework/security.imgSecCheck.html
|
||||
// Deprecated
|
||||
// 在2021年9月1日停止更新。建议使用 MediaCheckAsync
|
||||
// 在 2021 年 9 月 1 日停止更新。建议使用 MediaCheckAsync
|
||||
func (security *Security) ImageCheckV1(filename string) (err error) {
|
||||
accessToken, err := security.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -179,12 +169,12 @@ func (cl CheckLabel) String() string {
|
||||
|
||||
// MsgCheckRequest 文本检查请求
|
||||
type MsgCheckRequest struct {
|
||||
OpenID string `json:"openid"` // 用户的openid(用户需在近两小时访问过小程序)
|
||||
OpenID string `json:"openid"` // 用户的 openid(用户需在近两小时访问过小程序)
|
||||
Scene MsgScene `json:"scene"` // 场景枚举值(1 资料;2 评论;3 论坛;4 社交日志)
|
||||
Content string `json:"content"` // 需检测的文本内容,文本字数的上限为 2500 字,需使用 UTF-8 编码
|
||||
Nickname string `json:"nickname"` // (非必填)用户昵称,需使用UTF-8编码
|
||||
Title string `json:"title"` // (非必填)文本标题,需使用UTF-8编码
|
||||
Signature string `json:"signature"` // (非必填)个性签名,该参数仅在资料类场景有效(scene=1),需使用UTF-8编码
|
||||
Nickname string `json:"nickname"` // (非必填)用户昵称,需使用 UTF-8 编码
|
||||
Title string `json:"title"` // (非必填)文本标题,需使用 UTF-8 编码
|
||||
Signature string `json:"signature"` // (非必填)个性签名,该参数仅在资料类场景有效 (scene=1),需使用 UTF-8 编码
|
||||
}
|
||||
|
||||
// MsgCheckResponse 文本检查响应
|
||||
@@ -196,7 +186,7 @@ type MsgCheckResponse struct {
|
||||
Label CheckLabel `json:"label"` // 命中标签
|
||||
} `json:"result"` // 综合结果
|
||||
Detail []struct {
|
||||
ErrCode int64 `json:"errcode"` // 错误码,仅当该值为0时,该项结果有效
|
||||
ErrCode int64 `json:"errcode"` // 错误码,仅当该值为 0 时,该项结果有效
|
||||
Strategy string `json:"strategy"` // 策略类型
|
||||
Suggest string `json:"suggest"` // 建议
|
||||
Label CheckLabel `json:"label"` // 命中标签
|
||||
@@ -207,7 +197,7 @@ type MsgCheckResponse struct {
|
||||
|
||||
// MsgCheckV1 检查一段文本是否含有违法违规内容
|
||||
// Deprecated
|
||||
// 在2021年9月1日停止更新,请尽快更新至 2.0 接口。建议使用 MsgCheck
|
||||
// 在 2021 年 9 月 1 日停止更新,请尽快更新至 2.0 接口。建议使用 MsgCheck
|
||||
func (security *Security) MsgCheckV1(content string) (res MsgCheckResponse, err error) {
|
||||
accessToken, err := security.GetAccessToken()
|
||||
if err != nil {
|
||||
|
||||
@@ -60,11 +60,7 @@ func (shortLink *ShortLink) generate(shortLinkParams ShortLinker) (string, error
|
||||
// 使用通用方法返回错误
|
||||
var res resShortLinker
|
||||
err = util.DecodeWithError(response, &res, "GenerateShortLink")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return res.Link, nil
|
||||
return res.Link, err
|
||||
}
|
||||
|
||||
// GenerateShortLinkPermanent 生成永久 shortLink
|
||||
|
||||
@@ -42,11 +42,11 @@ func NewSubscribe(ctx *context.Context) *Subscribe {
|
||||
// Message 订阅消息请求参数
|
||||
type Message struct {
|
||||
ToUser string `json:"touser"` // 必选,接收者(用户)的 openid
|
||||
TemplateID string `json:"template_id"` // 必选,所需下发的订阅模板id
|
||||
Page string `json:"page"` // 可选,点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
|
||||
Data map[string]*DataItem `json:"data"` // 必选, 模板内容
|
||||
MiniprogramState string `json:"miniprogram_state"` // 可选,跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
|
||||
Lang string `json:"lang"` // 入小程序查看”的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN
|
||||
TemplateID string `json:"template_id"` // 必选,所需下发的订阅模板 id
|
||||
Page string `json:"page"` // 可选,点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例 index?foo=bar)。该字段不填则模板无跳转。
|
||||
Data map[string]*DataItem `json:"data"` // 必选,模板内容
|
||||
MiniprogramState string `json:"miniprogram_state"` // 可选,跳转小程序类型:developer 为开发版;trial 为体验版;formal 为正式版;默认为正式版
|
||||
Lang string `json:"lang"` // 入小程序查看”的语言类型,支持 zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为 zh_CN
|
||||
}
|
||||
|
||||
// DataItem 模版内某个 .DATA 的值
|
||||
@@ -168,11 +168,7 @@ func (s *Subscribe) Add(ShortID string, kidList []int, sceneDesc string) (templa
|
||||
}
|
||||
var result resSubscribeAdd
|
||||
err = util.DecodeWithError(response, &result, "AddSubscribe")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
templateID = result.TemplateID
|
||||
return
|
||||
return result.TemplateID, err
|
||||
}
|
||||
|
||||
// Delete 删除私有模板
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# 小程序-云开发 SDK
|
||||
# 小程序 - 云开发 SDK
|
||||
|
||||
Tencent Cloud Base [文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-http-api/)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ const (
|
||||
// InvokeCloudFunctionRes 云函数调用返回结果
|
||||
type InvokeCloudFunctionRes struct {
|
||||
util.CommonError
|
||||
RespData string `json:"resp_data"` // 云函数返回的buffer
|
||||
RespData string `json:"resp_data"` // 云函数返回的 buffer
|
||||
}
|
||||
|
||||
// InvokeCloudFunction 云函数调用
|
||||
|
||||
@@ -49,13 +49,13 @@ type ConflictMode int
|
||||
// FileType 文件上传和导出的允许文件类型
|
||||
type FileType int
|
||||
|
||||
// ValidDirections 合法的direction值
|
||||
// ValidDirections 合法的 direction 值
|
||||
var ValidDirections = []string{"1", "-1", "2dsphere"}
|
||||
|
||||
// DatabaseMigrateExportReq 数据库出 请求参数
|
||||
type DatabaseMigrateExportReq struct {
|
||||
Env string `json:"env,omitempty"` // 云环境ID
|
||||
FilePath string `json:"file_path,omitempty"` // 导出文件路径(导入文件需先上传到同环境的存储中,可使用开发者工具或 HTTP API的上传文件 API上传)
|
||||
Env string `json:"env,omitempty"` // 云环境 ID
|
||||
FilePath string `json:"file_path,omitempty"` // 导出文件路径 (导入文件需先上传到同环境的存储中,可使用开发者工具或 HTTP API 的上传文件 API 上传)
|
||||
FileType FileType `json:"file_type,omitempty"` // 导出文件类型,文件格式参考数据库导入指引中的文件格式部分 1:json 2:csv
|
||||
Query string `json:"query,omitempty"` // 导出条件
|
||||
}
|
||||
@@ -63,12 +63,12 @@ type DatabaseMigrateExportReq struct {
|
||||
// DatabaseMigrateExportRes 数据库导出 返回结果
|
||||
type DatabaseMigrateExportRes struct {
|
||||
util.CommonError
|
||||
JobID int64 `json:"job_id"` // 导出任务ID,可使用数据库迁移进度查询 API 查询导入进度及结果
|
||||
JobID int64 `json:"job_id"` // 导出任务 ID,可使用数据库迁移进度查询 API 查询导入进度及结果
|
||||
}
|
||||
|
||||
// DatabaseMigrateImportReq 数据库导入 请求参数
|
||||
type DatabaseMigrateImportReq struct {
|
||||
Env string `json:"env,omitempty"` // 云环境ID
|
||||
Env string `json:"env,omitempty"` // 云环境 ID
|
||||
CollectionName string `json:"collection_name,omitempty"` // 集合名称
|
||||
FilePath string `json:"file_path,omitempty"` // 导出文件路径(文件会导出到同环境的云存储中,可使用获取下载链接 API 获取下载链接)
|
||||
FileType FileType `json:"file_type,omitempty"` // 导入文件类型,文件格式参考数据库导入指引中的文件格式部分 1:json 2:csv
|
||||
@@ -79,7 +79,7 @@ type DatabaseMigrateImportReq struct {
|
||||
// DatabaseMigrateImportRes 数据库导入 返回结果
|
||||
type DatabaseMigrateImportRes struct {
|
||||
util.CommonError
|
||||
JobID int64 `json:"job_id"` // 导入任务ID,可使用数据库迁移进度查询 API 查询导入进度及结果
|
||||
JobID int64 `json:"job_id"` // 导入任务 ID,可使用数据库迁移进度查询 API 查询导入进度及结果
|
||||
}
|
||||
|
||||
// DatabaseMigrateQueryInfoRes 数据库迁移状态查询
|
||||
@@ -94,7 +94,7 @@ type DatabaseMigrateQueryInfoRes struct {
|
||||
|
||||
// UpdateIndexReq 变更数据库索引 请求参数
|
||||
type UpdateIndexReq struct {
|
||||
Env string `json:"env,omitempty"` // 云环境ID
|
||||
Env string `json:"env,omitempty"` // 云环境 ID
|
||||
CollectionName string `json:"collection_name,omitempty"` // 集合名称
|
||||
CreateIndexes []CreateIndex `json:"create_indexes,omitempty"` // 新增索引
|
||||
DropIndexes []DropIndex `json:"drop_indexes,omitempty"` // 删除索引
|
||||
@@ -120,13 +120,13 @@ type DropIndex struct {
|
||||
|
||||
// DatabaseCollectionReq 新增/删除集合请求参数
|
||||
type DatabaseCollectionReq struct {
|
||||
Env string `json:"env,omitempty"` // 云环境ID
|
||||
Env string `json:"env,omitempty"` // 云环境 ID
|
||||
CollectionName string `json:"collection_name,omitempty"` // 集合名称
|
||||
}
|
||||
|
||||
// DatabaseCollectionGetReq 获取特定云环境下集合信息请求
|
||||
type DatabaseCollectionGetReq struct {
|
||||
Env string `json:"env,omitempty"` // 云环境ID
|
||||
Env string `json:"env,omitempty"` // 云环境 ID
|
||||
Limit int64 `json:"limit,omitempty"` // 获取数量限制
|
||||
Offset int64 `json:"offset,omitempty"` // 偏移量
|
||||
}
|
||||
@@ -150,7 +150,7 @@ type DatabaseCollectionGetRes struct {
|
||||
|
||||
// DatabaseReq 数据库插入/删除/更新/查询/统计记录请求参数
|
||||
type DatabaseReq struct {
|
||||
Env string `json:"env,omitempty"` // 云环境ID
|
||||
Env string `json:"env,omitempty"` // 云环境 ID
|
||||
Query string `json:"query,omitempty"` // 数据库操作语句
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ type DatabaseDeleteRes struct {
|
||||
type DatabaseUpdateRes struct {
|
||||
util.CommonError
|
||||
Matched int64 `json:"matched"` // 更新条件匹配到的结果数
|
||||
Modified int64 `json:"modified"` // 修改的记录数,注意:使用set操作新插入的数据不计入修改数目
|
||||
Modified int64 `json:"modified"` // 修改的记录数,注意:使用 set 操作新插入的数据不计入修改数目
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,11 @@ type UploadFileReq struct {
|
||||
// UploadFileRes 上传文件返回结果
|
||||
type UploadFileRes struct {
|
||||
util.CommonError
|
||||
URL string `json:"url"` // 上传url
|
||||
URL string `json:"url"` // 上传 url
|
||||
Token string `json:"token"` // token
|
||||
Authorization string `json:"authorization"` // authorization
|
||||
FileID string `json:"file_id"` // 文件ID
|
||||
CosFileID string `json:"cos_file_id"` // cos文件ID
|
||||
FileID string `json:"file_id"` // 文件 ID
|
||||
CosFileID string `json:"cos_file_id"` // cos 文件 ID
|
||||
}
|
||||
|
||||
// BatchDownloadFileReq 上传文件请求值
|
||||
@@ -39,7 +39,7 @@ type BatchDownloadFileReq struct {
|
||||
|
||||
// DownloadFile 文件信息
|
||||
type DownloadFile struct {
|
||||
FileID string `json:"fileid"` // 文件ID
|
||||
FileID string `json:"fileid"` // 文件 ID
|
||||
MaxAge int64 `json:"max_age"` // 下载链接有效期
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ type DownloadFile struct {
|
||||
type BatchDownloadFileRes struct {
|
||||
util.CommonError
|
||||
FileList []struct {
|
||||
FileID string `json:"file_id"` // 文件ID
|
||||
FileID string `json:"file_id"` // 文件 ID
|
||||
DownloadURL string `json:"download_url"` // 下载链接
|
||||
Status int64 `json:"status"` // 状态码
|
||||
ErrMsg string `json:"errmsg"` // 该文件错误信息
|
||||
|
||||
@@ -51,7 +51,7 @@ type ULResult struct {
|
||||
URLLink string `json:"url_link"`
|
||||
}
|
||||
|
||||
// Generate 生成url link
|
||||
// Generate 生成 url link
|
||||
func (u *URLLink) Generate(params *ULParams) (string, error) {
|
||||
accessToken, err := u.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -65,8 +65,5 @@ func (u *URLLink) Generate(params *ULParams) (string, error) {
|
||||
}
|
||||
var resp ULResult
|
||||
err = util.DecodeWithError(response, &resp, "URLLink.Generate")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return resp.URLLink, nil
|
||||
return resp.URLLink, err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ const (
|
||||
querySchemeURL = "https://api.weixin.qq.com/wxa/queryscheme?access_token=%s"
|
||||
)
|
||||
|
||||
// QueryScheme 获取小程序访问scheme
|
||||
// QueryScheme 获取小程序访问 scheme
|
||||
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.query.html#参数
|
||||
type QueryScheme struct {
|
||||
// 小程序 scheme 码
|
||||
@@ -23,7 +23,7 @@ type SchemeInfo struct {
|
||||
AppID string `json:"appid"`
|
||||
// 小程序页面路径。
|
||||
Path string `json:"path"`
|
||||
// 小程序页面query。
|
||||
// 小程序页面 query。
|
||||
Query string `json:"query"`
|
||||
// 创建时间,为 Unix 时间戳。
|
||||
CreateTime int64 `json:"create_time"`
|
||||
@@ -37,10 +37,10 @@ type SchemeInfo struct {
|
||||
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/url-scheme/urlscheme.query.html#参数
|
||||
type resQueryScheme struct {
|
||||
// 通用错误
|
||||
*util.CommonError
|
||||
util.CommonError
|
||||
// scheme 配置
|
||||
SchemeInfo SchemeInfo `json:"scheme_info"`
|
||||
// 访问该链接的openid,没有用户访问过则为空字符串
|
||||
// 访问该链接的 openid,没有用户访问过则为空字符串
|
||||
VisitOpenid string `json:"visit_openid"`
|
||||
}
|
||||
|
||||
@@ -62,9 +62,5 @@ func (u *URLScheme) QueryScheme(querySchemeParams QueryScheme) (schemeInfo Schem
|
||||
// 使用通用方法返回错误
|
||||
var res resQueryScheme
|
||||
err = util.DecodeWithError(response, &res, "QueryScheme")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return res.SchemeInfo, res.VisitOpenid, nil
|
||||
return res.SchemeInfo, res.VisitOpenid, err
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ type USResult struct {
|
||||
OpenLink string `json:"openlink"`
|
||||
}
|
||||
|
||||
// Generate 生成url link
|
||||
// Generate 生成 url link
|
||||
func (u *URLScheme) Generate(params *USParams) (string, error) {
|
||||
accessToken, err := u.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -78,8 +78,5 @@ func (u *URLScheme) Generate(params *USParams) (string, error) {
|
||||
}
|
||||
var resp USResult
|
||||
err = util.DecodeWithError(response, &resp, "URLScheme.Generate")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return resp.OpenLink, nil
|
||||
return resp.OpenLink, err
|
||||
}
|
||||
|
||||
@@ -117,24 +117,6 @@ const (
|
||||
|
||||
// queryPublishGoods 查询批量发布道具任务状态
|
||||
queryPublishGoods = "/xpay/query_publish_goods"
|
||||
|
||||
// queryBizBalance 查询商家账户里的可提现余额
|
||||
queryBizBalance = "/xpay/query_biz_balance"
|
||||
|
||||
// queryTransferAccount 查询广告金充值账户
|
||||
queryTransferAccount = "/xpay/query_transfer_account"
|
||||
|
||||
// queryAdverFunds 查询广告金发放记录
|
||||
queryAdverFunds = "/xpay/query_adver_funds"
|
||||
|
||||
// createFundsBill 充值广告金
|
||||
createFundsBill = "/xpay/create_funds_bill"
|
||||
|
||||
// bindTransferAccount 绑定广告金充值账户
|
||||
bindTransferAccount = "/xpay/bind_transfer_accout"
|
||||
|
||||
// defaultUnifiedOrderURL default unified order url
|
||||
defaultUnifiedOrderURL = "requestVirtualPayment"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -136,7 +136,7 @@ type OrderItem struct {
|
||||
PaidFee int `json:"paid_fee"` // 用户支付金额,单位:分
|
||||
OrderType int `json:"order_type"` // 订单类型 0-支付单 1-退款单
|
||||
RefundFee int `json:"refund_fee"` // 当类型为退款单时表示退款金额,单位分
|
||||
PaidTime int64 `json:"paid_time"` // 支付/退款时间,unix秒级时间戳
|
||||
PaidTime int64 `json:"paid_time"` // 支付/退款时间,unix 秒级时间戳
|
||||
ProvideTime int64 `json:"provide_time"` // 发货时间,unix 秒级时间戳
|
||||
BizMeta string `json:"biz_meta"` // 业务自定义数据 订单创建时传的信息
|
||||
EnvType int `json:"env_type"` // 环境类型 1-现网 2-沙箱
|
||||
@@ -145,8 +145,6 @@ type OrderItem struct {
|
||||
WxOrderID string `json:"wx_order_id"` // 微信内部单号
|
||||
ChannelOrderID string `json:"channel_order_id"` // 渠道订单号,为用户微信支付详情页面上的商户单号
|
||||
WxPayOrderID string `json:"wxpay_order_id"` // 微信支付交易单号,为用户微信支付详情页面上的交易单号
|
||||
SettTime int64 `json:"sett_time"` // 结算时间,unix 秒级时间戳,结算时间的秒级时间戳,大于 0 表示结算成功
|
||||
SettState uint `json:"sett_state"` // 结算状态 0-未开始结算 1-结算中 2-结算成功
|
||||
}
|
||||
|
||||
// QueryOrderResponse 查询创建的订单(现金单,非代币单)响应参数
|
||||
|
||||
@@ -37,7 +37,7 @@ func (s *VirtualPayment) SetSessionKey(sessionKey string) {
|
||||
}
|
||||
|
||||
// QueryUserBalance 查询虚拟支付余额
|
||||
func (s *VirtualPayment) QueryUserBalance(ctx context.Context, in *QueryUserBalanceRequest) (out *QueryUserBalanceResponse, err error) {
|
||||
func (s *VirtualPayment) QueryUserBalance(ctx context.Context, in *QueryUserBalanceRequest) (out QueryUserBalanceResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -60,12 +60,12 @@ func (s *VirtualPayment) QueryUserBalance(ctx context.Context, in *QueryUserBala
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "QueryUserBalance")
|
||||
err = util.DecodeWithError(response, &out, "QueryUserBalance")
|
||||
return
|
||||
}
|
||||
|
||||
// CurrencyPay currency pay 扣减代币(一般用于代币支付)
|
||||
func (s *VirtualPayment) CurrencyPay(ctx context.Context, in *CurrencyPayRequest) (out *CurrencyPayResponse, err error) {
|
||||
func (s *VirtualPayment) CurrencyPay(ctx context.Context, in *CurrencyPayRequest) (out CurrencyPayResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -88,12 +88,12 @@ func (s *VirtualPayment) CurrencyPay(ctx context.Context, in *CurrencyPayRequest
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "CurrencyPay")
|
||||
err = util.DecodeWithError(response, &out, "CurrencyPay")
|
||||
return
|
||||
}
|
||||
|
||||
// QueryOrder 查询创建的订单(现金单,非代币单)
|
||||
func (s *VirtualPayment) QueryOrder(ctx context.Context, in *QueryOrderRequest) (out *QueryOrderResponse, err error) {
|
||||
func (s *VirtualPayment) QueryOrder(ctx context.Context, in *QueryOrderRequest) (out QueryOrderResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -116,12 +116,12 @@ func (s *VirtualPayment) QueryOrder(ctx context.Context, in *QueryOrderRequest)
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "QueryOrder")
|
||||
err = util.DecodeWithError(response, &out, "QueryOrder")
|
||||
return
|
||||
}
|
||||
|
||||
// CancelCurrencyPay 取消订单 代币支付退款 (currency_pay 接口的逆操作)
|
||||
func (s *VirtualPayment) CancelCurrencyPay(ctx context.Context, in *CancelCurrencyPayRequest) (out *CancelCurrencyPayResponse, err error) {
|
||||
func (s *VirtualPayment) CancelCurrencyPay(ctx context.Context, in *CancelCurrencyPayRequest) (out CancelCurrencyPayResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -144,13 +144,13 @@ func (s *VirtualPayment) CancelCurrencyPay(ctx context.Context, in *CancelCurren
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "CancelCurrencyPay")
|
||||
err = util.DecodeWithError(response, &out, "CancelCurrencyPay")
|
||||
return
|
||||
}
|
||||
|
||||
// NotifyProvideGoods 通知发货
|
||||
// 通知已经发货完成(只能通知现金单),正常通过 xpay_goods_deliver_notify 消息推送返回成功就不需要调用这个 api 接口。这个接口用于异常情况推送不成功时手动将单改成已发货状态
|
||||
func (s *VirtualPayment) NotifyProvideGoods(ctx context.Context, in *NotifyProvideGoodsRequest) (out *NotifyProvideGoodsResponse, err error) {
|
||||
func (s *VirtualPayment) NotifyProvideGoods(ctx context.Context, in *NotifyProvideGoodsRequest) (out NotifyProvideGoodsResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -174,12 +174,12 @@ func (s *VirtualPayment) NotifyProvideGoods(ctx context.Context, in *NotifyProvi
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "NotifyProvideGoods")
|
||||
err = util.DecodeWithError(response, &out, "NotifyProvideGoods")
|
||||
return
|
||||
}
|
||||
|
||||
// PresentCurrency 代币赠送接口,由于目前不支付按单号查赠送单的功能,所以当需要赠送的时候可以一直重试到返回 0 或者返回 268490004(重复操作)为止
|
||||
func (s *VirtualPayment) PresentCurrency(ctx context.Context, in *PresentCurrencyRequest) (out *PresentCurrencyResponse, err error) {
|
||||
func (s *VirtualPayment) PresentCurrency(ctx context.Context, in *PresentCurrencyRequest) (out PresentCurrencyResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -203,12 +203,12 @@ func (s *VirtualPayment) PresentCurrency(ctx context.Context, in *PresentCurrenc
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "PresentCurrency")
|
||||
err = util.DecodeWithError(response, &out, "PresentCurrency")
|
||||
return
|
||||
}
|
||||
|
||||
// DownloadBill 下载订单交易账单
|
||||
func (s *VirtualPayment) DownloadBill(ctx context.Context, in *DownloadBillRequest) (out *DownloadBillResponse, err error) {
|
||||
func (s *VirtualPayment) DownloadBill(ctx context.Context, in *DownloadBillRequest) (out DownloadBillResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -232,12 +232,12 @@ func (s *VirtualPayment) DownloadBill(ctx context.Context, in *DownloadBillReque
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "DownloadBill")
|
||||
err = util.DecodeWithError(response, &out, "DownloadBill")
|
||||
return
|
||||
}
|
||||
|
||||
// RefundOrder 退款 对使用 jsapi 接口下的单进行退款
|
||||
func (s *VirtualPayment) RefundOrder(ctx context.Context, in *RefundOrderRequest) (out *RefundOrderResponse, err error) {
|
||||
func (s *VirtualPayment) RefundOrder(ctx context.Context, in *RefundOrderRequest) (out RefundOrderResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -261,12 +261,12 @@ func (s *VirtualPayment) RefundOrder(ctx context.Context, in *RefundOrderRequest
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "RefundOrder")
|
||||
err = util.DecodeWithError(response, &out, "RefundOrder")
|
||||
return
|
||||
}
|
||||
|
||||
// CreateWithdrawOrder 创建提现单
|
||||
func (s *VirtualPayment) CreateWithdrawOrder(ctx context.Context, in *CreateWithdrawOrderRequest) (out *CreateWithdrawOrderResponse, err error) {
|
||||
func (s *VirtualPayment) CreateWithdrawOrder(ctx context.Context, in *CreateWithdrawOrderRequest) (out CreateWithdrawOrderResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -290,12 +290,12 @@ func (s *VirtualPayment) CreateWithdrawOrder(ctx context.Context, in *CreateWith
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "CreateWithdrawOrder")
|
||||
err = util.DecodeWithError(response, &out, "CreateWithdrawOrder")
|
||||
return
|
||||
}
|
||||
|
||||
// QueryWithdrawOrder 查询提现单
|
||||
func (s *VirtualPayment) QueryWithdrawOrder(ctx context.Context, in *QueryWithdrawOrderRequest) (out *QueryWithdrawOrderResponse, err error) {
|
||||
func (s *VirtualPayment) QueryWithdrawOrder(ctx context.Context, in *QueryWithdrawOrderRequest) (out QueryWithdrawOrderResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -319,12 +319,12 @@ func (s *VirtualPayment) QueryWithdrawOrder(ctx context.Context, in *QueryWithdr
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "QueryWithdrawOrder")
|
||||
err = util.DecodeWithError(response, &out, "QueryWithdrawOrder")
|
||||
return
|
||||
}
|
||||
|
||||
// StartUploadGoods 开始上传商品
|
||||
func (s *VirtualPayment) StartUploadGoods(ctx context.Context, in *StartUploadGoodsRequest) (out *StartUploadGoodsResponse, err error) {
|
||||
func (s *VirtualPayment) StartUploadGoods(ctx context.Context, in *StartUploadGoodsRequest) (out StartUploadGoodsResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -348,12 +348,12 @@ func (s *VirtualPayment) StartUploadGoods(ctx context.Context, in *StartUploadGo
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "StartUploadGoods")
|
||||
err = util.DecodeWithError(response, &out, "StartUploadGoods")
|
||||
return
|
||||
}
|
||||
|
||||
// QueryUploadGoods 查询上传商品
|
||||
func (s *VirtualPayment) QueryUploadGoods(ctx context.Context, in *QueryUploadGoodsRequest) (out *QueryUploadGoodsResponse, err error) {
|
||||
func (s *VirtualPayment) QueryUploadGoods(ctx context.Context, in *QueryUploadGoodsRequest) (out QueryUploadGoodsResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -377,12 +377,12 @@ func (s *VirtualPayment) QueryUploadGoods(ctx context.Context, in *QueryUploadGo
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "QueryUploadGoods")
|
||||
err = util.DecodeWithError(response, &out, "QueryUploadGoods")
|
||||
return
|
||||
}
|
||||
|
||||
// StartPublishGoods 开始发布商品
|
||||
func (s *VirtualPayment) StartPublishGoods(ctx context.Context, in *StartPublishGoodsRequest) (out *StartPublishGoodsResponse, err error) {
|
||||
func (s *VirtualPayment) StartPublishGoods(ctx context.Context, in *StartPublishGoodsRequest) (out StartPublishGoodsResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -406,12 +406,12 @@ func (s *VirtualPayment) StartPublishGoods(ctx context.Context, in *StartPublish
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "StartPublishGoods")
|
||||
err = util.DecodeWithError(response, &out, "StartPublishGoods")
|
||||
return
|
||||
}
|
||||
|
||||
// QueryPublishGoods 查询发布商品
|
||||
func (s *VirtualPayment) QueryPublishGoods(ctx context.Context, in *QueryPublishGoodsRequest) (out *QueryPublishGoodsResponse, err error) {
|
||||
func (s *VirtualPayment) QueryPublishGoods(ctx context.Context, in *QueryPublishGoodsRequest) (out QueryPublishGoodsResponse, err error) {
|
||||
var jsonByte []byte
|
||||
if jsonByte, err = json.Marshal(in); err != nil {
|
||||
return
|
||||
@@ -435,7 +435,7 @@ func (s *VirtualPayment) QueryPublishGoods(ctx context.Context, in *QueryPublish
|
||||
}
|
||||
|
||||
// 使用通用方法返回错误
|
||||
err = util.DecodeWithError(response, out, "QueryPublishGoods")
|
||||
err = util.DecodeWithError(response, &out, "QueryPublishGoods")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -479,7 +479,6 @@ func (s *VirtualPayment) requestAddress(params URLParams) (url string, err error
|
||||
case queryUserBalance:
|
||||
case currencyPay:
|
||||
case cancelCurrencyPay:
|
||||
case defaultUnifiedOrderURL:
|
||||
if params.PaySign, params.Signature, err = s.PaySignature(params.Path, params.Content); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// 获取微信服务器IP地址
|
||||
// 获取微信服务器 IP 地址
|
||||
// 文档:https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_the_WeChat_server_IP_address.html
|
||||
getCallbackIPURL = "https://api.weixin.qq.com/cgi-bin/getcallbackip"
|
||||
getAPIDomainIPURL = "https://api.weixin.qq.com/cgi-bin/get_api_domain_ip"
|
||||
@@ -29,13 +29,13 @@ func NewBasic(context *context.Context) *Basic {
|
||||
return basic
|
||||
}
|
||||
|
||||
// IPListRes 获取微信服务器IP地址 返回结果
|
||||
// IPListRes 获取微信服务器 IP 地址 返回结果
|
||||
type IPListRes struct {
|
||||
util.CommonError
|
||||
IPList []string `json:"ip_list"`
|
||||
}
|
||||
|
||||
// GetCallbackIP 获取微信callback IP地址
|
||||
// GetCallbackIP 获取微信 callback IP 地址
|
||||
func (basic *Basic) GetCallbackIP() ([]string, error) {
|
||||
ak, err := basic.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -51,7 +51,7 @@ func (basic *Basic) GetCallbackIP() ([]string, error) {
|
||||
return ipListRes.IPList, err
|
||||
}
|
||||
|
||||
// GetAPIDomainIP 获取微信API接口 IP地址
|
||||
// GetAPIDomainIP 获取微信 API 接口 IP 地址
|
||||
func (basic *Basic) GetAPIDomainIP() ([]string, error) {
|
||||
ak, err := basic.GetAccessToken()
|
||||
if err != nil {
|
||||
|
||||
@@ -34,7 +34,7 @@ type Request struct {
|
||||
} `json:"action_info"`
|
||||
}
|
||||
|
||||
// Ticket 二维码ticket
|
||||
// Ticket 二维码 ticket
|
||||
type Ticket struct {
|
||||
util.CommonError `json:",inline"`
|
||||
Ticket string `json:"ticket"`
|
||||
@@ -70,26 +70,34 @@ func (basic *Basic) GetQRTicket(tq *Request) (t *Ticket, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// ShowQRCode 通过ticket换取二维码
|
||||
// ShowQRCode 通过 ticket 换取二维码
|
||||
func ShowQRCode(tk *Ticket) string {
|
||||
return fmt.Sprintf(getQRImgURL, tk.Ticket)
|
||||
}
|
||||
|
||||
// NewTmpQrRequest 新建临时二维码请求实例
|
||||
func NewTmpQrRequest(exp time.Duration, scene interface{}) *Request {
|
||||
tq := &Request{
|
||||
ExpireSeconds: int64(exp.Seconds()),
|
||||
}
|
||||
var (
|
||||
tq = &Request{
|
||||
ExpireSeconds: int64(exp.Seconds()),
|
||||
}
|
||||
ok bool
|
||||
)
|
||||
switch reflect.ValueOf(scene).Kind() {
|
||||
case reflect.String:
|
||||
tq.ActionName = actionStr
|
||||
tq.ActionInfo.Scene.SceneStr = scene.(string)
|
||||
if tq.ActionInfo.Scene.SceneStr, ok = scene.(string); !ok {
|
||||
panic("scene must be string")
|
||||
}
|
||||
case reflect.Int, reflect.Int8, reflect.Int16,
|
||||
reflect.Int32, reflect.Int64,
|
||||
reflect.Uint, reflect.Uint8, reflect.Uint16,
|
||||
reflect.Uint32, reflect.Uint64:
|
||||
tq.ActionName = actionID
|
||||
tq.ActionInfo.Scene.SceneID = scene.(int)
|
||||
if tq.ActionInfo.Scene.SceneID, ok = scene.(int); !ok {
|
||||
panic("scene must be int")
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
||||
return tq
|
||||
@@ -97,17 +105,25 @@ func NewTmpQrRequest(exp time.Duration, scene interface{}) *Request {
|
||||
|
||||
// NewLimitQrRequest 新建永久二维码请求实例
|
||||
func NewLimitQrRequest(scene interface{}) *Request {
|
||||
tq := &Request{}
|
||||
var (
|
||||
tq = &Request{}
|
||||
ok bool
|
||||
)
|
||||
switch reflect.ValueOf(scene).Kind() {
|
||||
case reflect.String:
|
||||
tq.ActionName = actionLimitStr
|
||||
tq.ActionInfo.Scene.SceneStr = scene.(string)
|
||||
if tq.ActionInfo.Scene.SceneStr, ok = scene.(string); !ok {
|
||||
panic("scene must be string")
|
||||
}
|
||||
case reflect.Int, reflect.Int8, reflect.Int16,
|
||||
reflect.Int32, reflect.Int64,
|
||||
reflect.Uint, reflect.Uint8, reflect.Uint16,
|
||||
reflect.Uint32, reflect.Uint64:
|
||||
tq.ActionName = actionLimitID
|
||||
tq.ActionInfo.Scene.SceneID = scene.(int)
|
||||
if tq.ActionInfo.Scene.SceneID, ok = scene.(int); !ok {
|
||||
panic("scene must be int")
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
||||
return tq
|
||||
|
||||
@@ -44,9 +44,6 @@ func (basic *Basic) Long2ShortURL(longURL string) (shortURL string, err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if err = util.DecodeWithError(responseBytes, resp, long2shortAction); err != nil {
|
||||
return
|
||||
}
|
||||
shortURL = resp.ShortURL
|
||||
return
|
||||
err = util.DecodeWithError(responseBytes, resp, long2shortAction)
|
||||
return resp.ShortURL, err
|
||||
}
|
||||
|
||||
@@ -69,9 +69,9 @@ type SpeedResult struct {
|
||||
|
||||
// sendRequest 发送请求的数据
|
||||
type sendRequest struct {
|
||||
// 根据tag获全部发送
|
||||
// 根据 tag 获全部发送
|
||||
Filter map[string]interface{} `json:"filter,omitempty"`
|
||||
// 根据OpenID发送
|
||||
// 根据 OpenID 发送
|
||||
ToUser interface{} `json:"touser,omitempty"`
|
||||
// 发送文本
|
||||
Text map[string]interface{} `json:"text,omitempty"`
|
||||
@@ -79,6 +79,10 @@ type sendRequest struct {
|
||||
Mpnews map[string]interface{} `json:"mpnews,omitempty"`
|
||||
// 发送语音
|
||||
Voice map[string]interface{} `json:"voice,omitempty"`
|
||||
// 发送视频
|
||||
Mpvideo map[string]interface{} `json:"mpvideo,omitempty"`
|
||||
// 发送图片 - 预览使用
|
||||
Image map[string]interface{} `json:"image,omitempty"`
|
||||
// 发送图片
|
||||
Images *Image `json:"images,omitempty"`
|
||||
// 发送卡券
|
||||
@@ -96,9 +100,9 @@ type Image struct {
|
||||
}
|
||||
|
||||
// SendText 群发文本
|
||||
// user 为nil,表示全员发送
|
||||
// &User{TagID:2} 根据tag发送
|
||||
// &User{OpenID:[]string("xxx","xxx")} 根据openid发送
|
||||
// user 为 nil,表示全员发送
|
||||
// &User{TagID:2} 根据 tag 发送
|
||||
// &User{OpenID:[]string("xxx","xxx")} 根据 openid 发送
|
||||
func (broadcast *Broadcast) SendText(user *User, content string) (*Result, error) {
|
||||
ak, err := broadcast.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -183,7 +187,13 @@ func (broadcast *Broadcast) SendImage(user *User, images *Image) (*Result, error
|
||||
ToUser: nil,
|
||||
MsgType: MsgTypeImage,
|
||||
}
|
||||
req.Images = images
|
||||
if broadcast.preview {
|
||||
req.Image = map[string]interface{}{
|
||||
"media_id": images.MediaIDs[0],
|
||||
}
|
||||
} else {
|
||||
req.Images = images
|
||||
}
|
||||
req, sendURL := broadcast.chooseTagOrOpenID(user, req)
|
||||
url := fmt.Sprintf("%s?access_token=%s", sendURL, ak)
|
||||
data, err := util.PostJSON(url, req)
|
||||
@@ -205,7 +215,7 @@ func (broadcast *Broadcast) SendVideo(user *User, mediaID string, title, descrip
|
||||
ToUser: nil,
|
||||
MsgType: MsgTypeVideo,
|
||||
}
|
||||
req.Voice = map[string]interface{}{
|
||||
req.Mpvideo = map[string]interface{}{
|
||||
"media_id": mediaID,
|
||||
"title": title,
|
||||
"description": description,
|
||||
|
||||
@@ -46,10 +46,10 @@ type KeFuInfo struct {
|
||||
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”
|
||||
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 {
|
||||
@@ -72,11 +72,7 @@ func (csm *Manager) List() (customerServiceList []*KeFuInfo, err error) {
|
||||
}
|
||||
var res resKeFuList
|
||||
err = util.DecodeWithError(response, &res, "ListCustomerService")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
customerServiceList = res.KfList
|
||||
return
|
||||
return res.KfList, err
|
||||
}
|
||||
|
||||
// KeFuOnlineInfo 客服在线信息
|
||||
@@ -107,17 +103,13 @@ func (csm *Manager) OnlineList() (customerServiceOnlineList []*KeFuOnlineInfo, e
|
||||
}
|
||||
var res resKeFuOnlineList
|
||||
err = util.DecodeWithError(response, &res, "ListOnlineCustomerService")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
customerServiceOnlineList = res.KfOnlineList
|
||||
return
|
||||
return res.KfOnlineList, err
|
||||
}
|
||||
|
||||
// Add 添加客服账号
|
||||
func (csm *Manager) Add(kfAccount, nickName string) (err error) {
|
||||
// kfAccount:完整客服帐号,格式为:帐号前缀@公众号微信号,帐号前缀最多10个字符,必须是英文、数字字符或者下划线,后缀为公众号微信号,长度不超过30个字符
|
||||
// nickName:客服昵称,最长16个字
|
||||
// kfAccount:完整客服帐号,格式为:帐号前缀@公众号微信号,帐号前缀最多 10 个字符,必须是英文、数字字符或者下划线,后缀为公众号微信号,长度不超过 30 个字符
|
||||
// nickName:客服昵称,最长 16 个字
|
||||
// 参数此处均不做校验
|
||||
var accessToken string
|
||||
accessToken, err = csm.GetAccessToken()
|
||||
|
||||
@@ -22,7 +22,7 @@ const (
|
||||
SlotIDBizSponsor AdSlot = "SLOT_ID_BIZ_SPONSOR"
|
||||
// SlotIDBizCps 公众号返佣商品
|
||||
SlotIDBizCps AdSlot = "SLOT_ID_BIZ_CPS"
|
||||
// SlotIDWeappBanner 小程序banner
|
||||
// SlotIDWeappBanner 小程序 banner
|
||||
SlotIDWeappBanner AdSlot = "SLOT_ID_WEAPP_BANNER"
|
||||
// SlotIDWeappRewardVideo 小程序激励视频
|
||||
SlotIDWeappRewardVideo AdSlot = "SLOT_ID_WEAPP_REWARD_VIDEO"
|
||||
@@ -183,9 +183,6 @@ func (cube *DataCube) fetchData(params ParamsPublisher) (response []byte, err er
|
||||
uri := fmt.Sprintf("%s?%s", publisherURL, v.Encode())
|
||||
|
||||
response, err = util.HTTPGet(uri)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ const (
|
||||
)
|
||||
|
||||
type reqDeviceAuthorize struct {
|
||||
// 设备id的个数
|
||||
// 设备 id 的个数
|
||||
DeviceNum string `json:"device_num"`
|
||||
// 设备id的列表,json的array格式,其size必须等于device_num
|
||||
// 设备 id 的列表,json 的 array 格式,其 size 必须等于 device_num
|
||||
DeviceList []ReqDevice `json:"device_list"`
|
||||
// 请求操作的类型,限定取值为:0:设备授权(缺省值为0) 1:设备更新(更新已授权设备的各属性值)
|
||||
// 请求操作的类型,限定取值为:0:设备授权(缺省值为 0)1:设备更新(更新已授权设备的各属性值)
|
||||
OpType string `json:"op_type,omitempty"`
|
||||
// 设备的产品编号(由微信硬件平台分配)。可在公众号设备功能管理页面查询。
|
||||
// 当 op_type 为‘0’,product_id 为‘1’时,不要填写 product_id 字段(会引起不必要错误);
|
||||
@@ -33,39 +33,39 @@ type reqDeviceAuthorize struct {
|
||||
type ReqDevice struct {
|
||||
// 设备的 device id
|
||||
ID string `json:"id"`
|
||||
// 设备的mac地址 格式采用16进制串的方式(长度为12字节),
|
||||
// 不需要0X前缀,如: 1234567890AB
|
||||
// 设备的 mac 地址 格式采用 16 进制串的方式(长度为 12 字节),
|
||||
// 不需要 0X 前缀,如:1234567890AB
|
||||
Mac string `json:"mac"`
|
||||
// 支持以下四种连接协议:
|
||||
// android classic bluetooth – 1
|
||||
// ios classic bluetooth – 2
|
||||
// ble – 3
|
||||
// wifi -- 4
|
||||
// 一个设备可以支持多种连接类型,用符号"|"做分割,客户端优先选择靠前的连接方式(优先级按|关系的排序依次降低),举例:
|
||||
// 1:表示设备仅支持andiod classic bluetooth 1|2:表示设备支持android 和ios 两种classic bluetooth,但是客户端优先选择android classic bluetooth 协议,如果android classic bluetooth协议连接失败,再选择ios classic bluetooth协议进行连接
|
||||
// (注:安卓平台不同时支持BLE和classic类型)
|
||||
// 一个设备可以支持多种连接类型,用符号"|"做分割,客户端优先选择靠前的连接方式(优先级按 | 关系的排序依次降低),举例:
|
||||
// 1:表示设备仅支持 andiod classic bluetooth 1|2:表示设备支持 android 和 ios 两种 classic bluetooth,但是客户端优先选择 android classic bluetooth 协议,如果 android classic bluetooth 协议连接失败,再选择 ios classic bluetooth 协议进行连接
|
||||
// (注:安卓平台不同时支持 BLE 和 classic 类型)
|
||||
ConnectProtocol string `json:"connect_protocol"`
|
||||
// auth及通信的加密key,第三方需要将key烧制在设备上(128bit),格式采用16进制串的方式(长度为32字节),不需要0X前缀,如: 1234567890ABCDEF1234567890ABCDEF
|
||||
// auth 及通信的加密 key,第三方需要将 key 烧制在设备上(128bit),格式采用 16 进制串的方式(长度为 32 字节),不需要 0X 前缀,如:1234567890ABCDEF1234567890ABCDEF
|
||||
AuthKey string `json:"auth_key"`
|
||||
// 断开策略,目前支持: 1:退出公众号页面时即断开连接 2:退出公众号之后保持连接不断开
|
||||
// 断开策略,目前支持:1:退出公众号页面时即断开连接 2:退出公众号之后保持连接不断开
|
||||
CloseStrategy string `json:"close_strategy"`
|
||||
// 连接策略,32位整型,按bit位置位,目前仅第1bit和第3bit位有效(bit置0为无效,1为有效;第2bit已被废弃),且bit位可以按或置位(如1|4=5),各bit置位含义说明如下:
|
||||
// 1:(第1bit置位)在公众号对话页面,不停的尝试连接设备
|
||||
// 4:(第3bit置位)处于非公众号页面(如主界面等),微信自动连接。当用户切换微信到前台时,可能尝试去连接设备,连上后一定时间会断开
|
||||
// 连接策略,32 位整型,按 bit 位置位,目前仅第 1bit 和第 3bit 位有效(bit 置 0 为无效,1 为有效;第 2bit 已被废弃),且 bit 位可以按或置位(如 1|4=5),各 bit 置位含义说明如下:
|
||||
// 1:(第 1bit 置位)在公众号对话页面,不停的尝试连接设备
|
||||
// 4:(第 3bit 置位)处于非公众号页面(如主界面等),微信自动连接。当用户切换微信到前台时,可能尝试去连接设备,连上后一定时间会断开
|
||||
ConnStrategy string `json:"conn_strategy"`
|
||||
// auth version,设备和微信进行auth时,会根据该版本号来确认auth buf和auth key的格式(各version对应的auth buf及key的具体格式可以参看“客户端蓝牙外设协议”),该字段目前支持取值:
|
||||
// 0:不加密的version
|
||||
// auth version,设备和微信进行 auth 时,会根据该版本号来确认 auth buf 和 auth key 的格式(各 version 对应的 auth buf 及 key 的具体格式可以参看“客户端蓝牙外设协议”),该字段目前支持取值:
|
||||
// 0:不加密的 version
|
||||
// 1:version 1
|
||||
AuthVer string `json:"auth_ver"`
|
||||
// 表示mac地址在厂商广播manufacture data里含有mac地址的偏移,取值如下:
|
||||
// 表示 mac 地址在厂商广播 manufacture data 里含有 mac 地址的偏移,取值如下:
|
||||
// -1:在尾部、
|
||||
// -2:表示不包含mac地址 其他:非法偏移
|
||||
// -2:表示不包含 mac 地址 其他:非法偏移
|
||||
ManuMacPos string `json:"manu_mac_pos"`
|
||||
// 表示mac地址在厂商serial number里含有mac地址的偏移,取值如下:
|
||||
// 表示 mac 地址在厂商 serial number 里含有 mac 地址的偏移,取值如下:
|
||||
// -1:表示在尾部
|
||||
// -2:表示不包含mac地址 其他:非法偏移
|
||||
// -2:表示不包含 mac 地址 其他:非法偏移
|
||||
SerMacPost string `json:"ser_mac_post"`
|
||||
// 精简协议类型,取值如下:计步设备精简协议:1 (若该字段填1,connect_protocol 必须包括3。非精简协议设备切勿填写该字段)
|
||||
// 精简协议类型,取值如下:计步设备精简协议:1(若该字段填 1,connect_protocol 必须包括 3。非精简协议设备切勿填写该字段)
|
||||
BleSimpleProtocol string `json:"ble_simple_protocol,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
@@ -33,12 +33,12 @@ type Article struct {
|
||||
Title string `json:"title"` // 标题
|
||||
Author string `json:"author"` // 作者
|
||||
Digest string `json:"digest"` // 图文消息的摘要,仅有单图文消息才有摘要,多图文此处为空。
|
||||
Content string `json:"content"` // 图文消息的具体内容,支持HTML标签,必须少于2万字符,小于1M,且去除JS
|
||||
ContentSourceURL string `json:"content_source_url"` // 图文消息的原文地址,即点击“阅读原文”后的URL
|
||||
ThumbMediaID string `json:"thumb_media_id"` // 图文消息的封面图片素材id(必须是永久MediaID)
|
||||
ShowCoverPic uint `json:"show_cover_pic"` // 是否显示封面,0为false,即不显示,1为true,即显示(默认)
|
||||
NeedOpenComment uint `json:"need_open_comment"` // 是否打开评论,0不打开(默认),1打开
|
||||
OnlyFansCanComment uint `json:"only_fans_can_comment"` // 是否粉丝才可评论,0所有人可评论(默认),1粉丝才可评论
|
||||
Content string `json:"content"` // 图文消息的具体内容,支持 HTML 标签,必须少于 2 万字符,小于 1M,且去除 JS
|
||||
ContentSourceURL string `json:"content_source_url"` // 图文消息的原文地址,即点击“阅读原文”后的 URL
|
||||
ThumbMediaID string `json:"thumb_media_id"` // 图文消息的封面图片素材 id(必须是永久 MediaID)
|
||||
ShowCoverPic uint `json:"show_cover_pic"` // 是否显示封面,0 为 false,即不显示,1 为 true,即显示 (默认)
|
||||
NeedOpenComment uint `json:"need_open_comment"` // 是否打开评论,0 不打开 (默认),1 打开
|
||||
OnlyFansCanComment uint `json:"only_fans_can_comment"` // 是否粉丝才可评论,0 所有人可评论 (默认),1 粉丝才可评论
|
||||
}
|
||||
|
||||
// AddDraft 新建草稿
|
||||
@@ -64,11 +64,7 @@ func (draft *Draft) AddDraft(articles []*Article) (mediaID string, err error) {
|
||||
MediaID string `json:"media_id"`
|
||||
}
|
||||
err = util.DecodeWithError(response, &res, "AddDraft")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
mediaID = res.MediaID
|
||||
return
|
||||
return res.MediaID, err
|
||||
}
|
||||
|
||||
// GetDraft 获取草稿
|
||||
@@ -94,12 +90,7 @@ func (draft *Draft) GetDraft(mediaID string) (articles []*Article, err error) {
|
||||
NewsItem []*Article `json:"news_item"`
|
||||
}
|
||||
err = util.DecodeWithError(response, &res, "GetDraft")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
articles = res.NewsItem
|
||||
return
|
||||
return res.NewsItem, err
|
||||
}
|
||||
|
||||
// DeleteDraft 删除草稿
|
||||
@@ -126,7 +117,7 @@ func (draft *Draft) DeleteDraft(mediaID string) (err error) {
|
||||
}
|
||||
|
||||
// UpdateDraft 修改草稿
|
||||
// index 要更新的文章在图文消息中的位置(多图文消息时,此字段才有意义),第一篇为0
|
||||
// index 要更新的文章在图文消息中的位置(多图文消息时,此字段才有意义),第一篇为 0
|
||||
func (draft *Draft) UpdateDraft(article *Article, mediaID string, index uint) (err error) {
|
||||
accessToken, err := draft.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -172,12 +163,7 @@ func (draft *Draft) CountDraft() (total uint, err error) {
|
||||
Total uint `json:"total_count"`
|
||||
}
|
||||
err = util.DecodeWithError(response, &res, "CountDraft")
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
total = res.Total
|
||||
return
|
||||
return res.Total, err
|
||||
}
|
||||
|
||||
// ArticleList 草稿列表
|
||||
@@ -190,7 +176,7 @@ type ArticleList struct {
|
||||
|
||||
// ArticleListItem 用于 ArticleList 的 item 节点
|
||||
type ArticleListItem struct {
|
||||
MediaID string `json:"media_id"` // 图文消息的id
|
||||
MediaID string `json:"media_id"` // 图文消息的 id
|
||||
Content ArticleListContent `json:"content"` // 内容
|
||||
UpdateTime int64 `json:"update_time"` // 这篇图文消息素材的最后更新时间
|
||||
}
|
||||
|
||||
@@ -73,34 +73,29 @@ func (freePublish *FreePublish) Publish(mediaID string) (publishID int64, err er
|
||||
PublishID int64 `json:"publish_id"`
|
||||
}
|
||||
err = util.DecodeWithError(response, &res, "SubmitFreePublish")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
publishID = res.PublishID
|
||||
return
|
||||
return res.PublishID, err
|
||||
}
|
||||
|
||||
// PublishStatusList 发布任务状态列表
|
||||
type PublishStatusList struct {
|
||||
util.CommonError
|
||||
PublishID int64 `json:"publish_id"` // 发布任务id
|
||||
PublishID int64 `json:"publish_id"` // 发布任务 id
|
||||
PublishStatus PublishStatus `json:"publish_status"` // 发布状态
|
||||
ArticleID string `json:"article_id"` // 当发布状态为0时(即成功)时,返回图文的 article_id,可用于“客服消息”场景
|
||||
ArticleID string `json:"article_id"` // 当发布状态为 0 时(即成功)时,返回图文的 article_id,可用于“客服消息”场景
|
||||
ArticleDetail PublishArticleDetail `json:"article_detail"` // 发布任务文章成功状态详情
|
||||
FailIndex []uint `json:"fail_idx"` // 当发布状态为2或4时,返回不通过的文章编号,第一篇为 1;其他发布状态则为空
|
||||
FailIndex []uint `json:"fail_idx"` // 当发布状态为 2 或 4 时,返回不通过的文章编号,第一篇为 1;其他发布状态则为空
|
||||
}
|
||||
|
||||
// PublishArticleDetail 发布任务成功详情
|
||||
type PublishArticleDetail struct {
|
||||
Count uint `json:"count"` // 当发布状态为0时(即成功)时,返回文章数量
|
||||
Count uint `json:"count"` // 当发布状态为 0 时(即成功)时,返回文章数量
|
||||
Items []PublishArticleItem `json:"item"`
|
||||
}
|
||||
|
||||
// PublishArticleItem 发布任务成功的文章内容
|
||||
type PublishArticleItem struct {
|
||||
Index uint `json:"idx"` // 当发布状态为0时(即成功)时,返回文章对应的编号
|
||||
ArticleURL string `json:"article_url"` // 当发布状态为0时(即成功)时,返回图文的永久链接
|
||||
Index uint `json:"idx"` // 当发布状态为 0 时(即成功)时,返回文章对应的编号
|
||||
ArticleURL string `json:"article_url"` // 当发布状态为 0 时(即成功)时,返回图文的永久链接
|
||||
}
|
||||
|
||||
// SelectStatus 发布状态轮询接口
|
||||
@@ -127,8 +122,8 @@ func (freePublish *FreePublish) SelectStatus(publishID int64) (list PublishStatu
|
||||
}
|
||||
|
||||
// Delete 删除发布。
|
||||
// index 要删除的文章在图文消息中的位置,第一篇编号为1,该字段不填或填0会删除全部文章
|
||||
// !!!此操作不可逆,请谨慎操作!!!删除后微信公众号后台仍然会有记录!!!
|
||||
// index 要删除的文章在图文消息中的位置,第一篇编号为 1,该字段不填或填 0 会删除全部文章
|
||||
// !!! 此操作不可逆,请谨慎操作!!! 删除后微信公众号后台仍然会有记录!!!
|
||||
func (freePublish *FreePublish) Delete(articleID string, index uint) (err error) {
|
||||
accessToken, err := freePublish.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -157,13 +152,13 @@ type Article struct {
|
||||
Title string `json:"title"` // 标题
|
||||
Author string `json:"author"` // 作者
|
||||
Digest string `json:"digest"` // 图文消息的摘要,仅有单图文消息才有摘要,多图文此处为空
|
||||
Content string `json:"content"` // 图文消息的具体内容,支持HTML标签,必须少于2万字符,小于1M,且此处会去除JS
|
||||
ContentSourceURL string `json:"content_source_url"` // 图文消息的原文地址,即点击“阅读原文”后的URL
|
||||
ThumbMediaID string `json:"thumb_media_id"` // 图文消息的封面图片素材id(一定是永久MediaID)
|
||||
ShowCoverPic uint `json:"show_cover_pic"` // 是否显示封面,0为false,即不显示,1为true,即显示(默认)
|
||||
NeedOpenComment uint `json:"need_open_comment"` // 是否打开评论,0不打开(默认),1打开
|
||||
OnlyFansCanComment uint `json:"only_fans_can_comment"` // 是否粉丝才可评论,0所有人可评论(默认),1粉丝才可评论
|
||||
URL string `json:"url"` // 图文消息的URL
|
||||
Content string `json:"content"` // 图文消息的具体内容,支持 HTML 标签,必须少于 2 万字符,小于 1M,且此处会去除 JS
|
||||
ContentSourceURL string `json:"content_source_url"` // 图文消息的原文地址,即点击“阅读原文”后的 URL
|
||||
ThumbMediaID string `json:"thumb_media_id"` // 图文消息的封面图片素材 id(一定是永久 MediaID)
|
||||
ShowCoverPic uint `json:"show_cover_pic"` // 是否显示封面,0 为 false,即不显示,1 为 true,即显示 (默认)
|
||||
NeedOpenComment uint `json:"need_open_comment"` // 是否打开评论,0 不打开 (默认),1 打开
|
||||
OnlyFansCanComment uint `json:"only_fans_can_comment"` // 是否粉丝才可评论,0 所有人可评论 (默认),1 粉丝才可评论
|
||||
URL string `json:"url"` // 图文消息的 URL
|
||||
IsDeleted bool `json:"is_deleted"` // 该图文是否被删除
|
||||
}
|
||||
|
||||
@@ -191,12 +186,7 @@ func (freePublish *FreePublish) First(articleID string) (list []Article, err err
|
||||
NewsItem []Article `json:"news_item"`
|
||||
}
|
||||
err = util.DecodeWithError(response, &res, "FirstFreePublish")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
list = res.NewsItem
|
||||
return
|
||||
return res.NewsItem, err
|
||||
}
|
||||
|
||||
// ArticleList 发布列表
|
||||
@@ -209,7 +199,7 @@ type ArticleList struct {
|
||||
|
||||
// ArticleListItem 用于 ArticleList 的 item 节点
|
||||
type ArticleListItem struct {
|
||||
ArticleID string `json:"article_id"` // 成功发布的图文消息id
|
||||
ArticleID string `json:"article_id"` // 成功发布的图文消息 id
|
||||
Content ArticleListContent `json:"content"` // 内容
|
||||
UpdateTime int64 `json:"update_time"` // 这篇图文消息素材的最后更新时间
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ type Js struct {
|
||||
credential.JsTicketHandle
|
||||
}
|
||||
|
||||
// Config 返回给用户jssdk配置信息
|
||||
// Config 返回给用户 jssdk 配置信息
|
||||
type Config struct {
|
||||
AppID string `json:"app_id"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
@@ -31,12 +31,12 @@ func NewJs(context *context.Context) *Js {
|
||||
return js
|
||||
}
|
||||
|
||||
// SetJsTicketHandle 自定义js ticket取值方式
|
||||
// SetJsTicketHandle 自定义 js ticket 取值方式
|
||||
func (js *Js) SetJsTicketHandle(ticketHandle credential.JsTicketHandle) {
|
||||
js.JsTicketHandle = ticketHandle
|
||||
}
|
||||
|
||||
// GetConfig 获取jssdk需要的配置参数
|
||||
// GetConfig 获取 jssdk 需要的配置参数
|
||||
// uri 为当前网页地址
|
||||
func (js *Js) GetConfig(uri string) (config *Config, err error) {
|
||||
config = new(Config)
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
@@ -160,8 +162,8 @@ type resAddMaterial struct {
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// AddMaterial 上传永久性素材(处理视频需要单独上传)
|
||||
func (material *Material) AddMaterial(mediaType MediaType, filename string) (mediaID string, url string, err error) {
|
||||
// AddMaterialFromReader 上传永久性素材(处理视频需要单独上传),从 io.Reader 中读取
|
||||
func (material *Material) AddMaterialFromReader(mediaType MediaType, filename string, reader io.Reader) (mediaID string, url string, err error) {
|
||||
if mediaType == MediaTypeVideo {
|
||||
err = errors.New("永久视频素材上传使用 AddVideo 方法")
|
||||
return
|
||||
@@ -174,7 +176,7 @@ func (material *Material) AddMaterial(mediaType MediaType, filename string) (med
|
||||
|
||||
uri := fmt.Sprintf("%s?access_token=%s&type=%s", addMaterialURL, accessToken, mediaType)
|
||||
var response []byte
|
||||
response, err = util.PostFile("media", filename, uri)
|
||||
response, err = util.PostFileFromReader("media", filename, uri, reader)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -192,13 +194,24 @@ func (material *Material) AddMaterial(mediaType MediaType, filename string) (med
|
||||
return
|
||||
}
|
||||
|
||||
// AddMaterial 上传永久性素材(处理视频需要单独上传)
|
||||
func (material *Material) AddMaterial(mediaType MediaType, filename string) (mediaID string, url string, err error) {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
return material.AddMaterialFromReader(mediaType, filename, f)
|
||||
}
|
||||
|
||||
type reqVideo struct {
|
||||
Title string `json:"title"`
|
||||
Introduction string `json:"introduction"`
|
||||
}
|
||||
|
||||
// AddVideo 永久视频素材文件上传
|
||||
func (material *Material) AddVideo(filename, title, introduction string) (mediaID string, url string, err error) {
|
||||
// AddVideoFromReader 永久视频素材文件上传,从 io.Reader 中读取
|
||||
func (material *Material) AddVideoFromReader(filename, title, introduction string, reader io.Reader) (mediaID string, url string, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = material.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -219,9 +232,10 @@ func (material *Material) AddVideo(filename, title, introduction string) (mediaI
|
||||
|
||||
fields := []util.MultipartFormField{
|
||||
{
|
||||
IsFile: true,
|
||||
Fieldname: "media",
|
||||
Filename: filename,
|
||||
IsFile: true,
|
||||
Fieldname: "media",
|
||||
Filename: filename,
|
||||
FileReader: reader,
|
||||
},
|
||||
{
|
||||
IsFile: false,
|
||||
@@ -250,6 +264,17 @@ func (material *Material) AddVideo(filename, title, introduction string) (mediaI
|
||||
return
|
||||
}
|
||||
|
||||
// AddVideo 永久视频素材文件上传
|
||||
func (material *Material) AddVideo(filename, title, introduction string) (mediaID string, url string, err error) {
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
defer func() { _ = f.Close() }()
|
||||
|
||||
return material.AddVideoFromReader(filename, title, introduction, f)
|
||||
}
|
||||
|
||||
type reqDeleteMaterial struct {
|
||||
MediaID string `json:"media_id"`
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
type MediaType string
|
||||
|
||||
const (
|
||||
// MediaTypeImage 媒体文件:图片
|
||||
// MediaTypeImage 媒体文件:图片
|
||||
MediaTypeImage MediaType = "image"
|
||||
// MediaTypeVoice 媒体文件:声音
|
||||
// MediaTypeVoice 媒体文件:声音
|
||||
MediaTypeVoice MediaType = "voice"
|
||||
// MediaTypeVideo 媒体文件:视频
|
||||
// MediaTypeVideo 媒体文件:视频
|
||||
MediaTypeVideo MediaType = "video"
|
||||
// MediaTypeThumb 媒体文件:缩略图
|
||||
// MediaTypeThumb 媒体文件:缩略图
|
||||
MediaTypeThumb MediaType = "thumb"
|
||||
)
|
||||
|
||||
@@ -63,7 +63,7 @@ func (material *Material) MediaUpload(mediaType MediaType, filename string) (med
|
||||
}
|
||||
|
||||
// GetMediaURL 返回临时素材的下载地址供用户自己处理
|
||||
// NOTICE: URL 不可公开,因为含access_token 需要立即另存文件
|
||||
// NOTICE: URL 不可公开,因为含 access_token 需要立即另存文件
|
||||
func (material *Material) GetMediaURL(mediaID string) (mediaURL string, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = material.GetAccessToken()
|
||||
|
||||
@@ -23,7 +23,7 @@ func (btn *Button) SetSubButton(name string, subButtons []*Button) *Button {
|
||||
return btn
|
||||
}
|
||||
|
||||
// SetClickButton btn 为click类型
|
||||
// SetClickButton btn 为 click 类型
|
||||
func (btn *Button) SetClickButton(name, key string) *Button {
|
||||
btn.Type = "click"
|
||||
btn.Name = name
|
||||
@@ -34,7 +34,7 @@ func (btn *Button) SetClickButton(name, key string) *Button {
|
||||
return btn
|
||||
}
|
||||
|
||||
// SetViewButton view类型
|
||||
// SetViewButton view 类型
|
||||
func (btn *Button) SetViewButton(name, url string) *Button {
|
||||
btn.Type = "view"
|
||||
btn.Name = name
|
||||
@@ -116,7 +116,7 @@ func (btn *Button) SetLocationSelectButton(name, key string) *Button {
|
||||
return btn
|
||||
}
|
||||
|
||||
// SetMediaIDButton 设置 下发消息(除文本消息) 类型按钮
|
||||
// SetMediaIDButton 设置 下发消息 (除文本消息) 类型按钮
|
||||
func (btn *Button) SetMediaIDButton(name, mediaID string) *Button {
|
||||
btn.Type = "media_id"
|
||||
btn.Name = name
|
||||
@@ -128,7 +128,7 @@ func (btn *Button) SetMediaIDButton(name, mediaID string) *Button {
|
||||
return btn
|
||||
}
|
||||
|
||||
// SetViewLimitedButton 设置 跳转图文消息URL 类型按钮
|
||||
// SetViewLimitedButton 设置 跳转图文消息 URL 类型按钮
|
||||
func (btn *Button) SetViewLimitedButton(name, mediaID string) *Button {
|
||||
btn.Type = "view_limited"
|
||||
btn.Name = name
|
||||
@@ -159,12 +159,12 @@ func NewSubButton(name string, subButtons []*Button) *Button {
|
||||
return (&Button{}).SetSubButton(name, subButtons)
|
||||
}
|
||||
|
||||
// NewClickButton btn 为click类型
|
||||
// NewClickButton btn 为 click 类型
|
||||
func NewClickButton(name, key string) *Button {
|
||||
return (&Button{}).SetClickButton(name, key)
|
||||
}
|
||||
|
||||
// NewViewButton view类型
|
||||
// NewViewButton view 类型
|
||||
func NewViewButton(name, url string) *Button {
|
||||
return (&Button{}).SetViewButton(name, url)
|
||||
}
|
||||
@@ -199,12 +199,12 @@ func NewLocationSelectButton(name, key string) *Button {
|
||||
return (&Button{}).SetLocationSelectButton(name, key)
|
||||
}
|
||||
|
||||
// NewMediaIDButton 下发消息(除文本消息) 类型按钮
|
||||
// NewMediaIDButton 下发消息 (除文本消息) 类型按钮
|
||||
func NewMediaIDButton(name, mediaID string) *Button {
|
||||
return (&Button{}).SetMediaIDButton(name, mediaID)
|
||||
}
|
||||
|
||||
// NewViewLimitedButton 跳转图文消息URL 类型按钮
|
||||
// NewViewLimitedButton 跳转图文消息 URL 类型按钮
|
||||
func NewViewLimitedButton(name, mediaID string) *Button {
|
||||
return (&Button{}).SetViewLimitedButton(name, mediaID)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ func NewMessageManager(context *context.Context) *Manager {
|
||||
|
||||
// CustomerMessage 客服消息
|
||||
type CustomerMessage struct {
|
||||
ToUser string `json:"touser"` // 接受者OpenID
|
||||
ToUser string `json:"touser"` // 接受者 OpenID
|
||||
Msgtype MsgType `json:"msgtype"` // 客服消息类型
|
||||
Text *MediaText `json:"text,omitempty"` // 可选
|
||||
Image *MediaResource `json:"image,omitempty"` // 可选
|
||||
@@ -93,12 +93,12 @@ type MediaText struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// MediaResource 消息使用的永久素材id
|
||||
// MediaResource 消息使用的永久素材 id
|
||||
type MediaResource struct {
|
||||
MediaID string `json:"media_id"`
|
||||
}
|
||||
|
||||
// MediaArticle 消息使用的已发布文章id
|
||||
// MediaArticle 消息使用的已发布文章 id
|
||||
type MediaArticle struct {
|
||||
ArticleID string `json:"article_id"`
|
||||
}
|
||||
@@ -146,7 +146,7 @@ type MsgmenuItem struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// MediaWxcard 卡券的id
|
||||
// MediaWxcard 卡券的 id
|
||||
type MediaWxcard struct {
|
||||
CardID string `json:"card_id"`
|
||||
}
|
||||
|
||||
@@ -27,15 +27,15 @@ const (
|
||||
MsgTypeVideo MsgType = "video"
|
||||
// MsgTypeMiniprogrampage 表示小程序卡片消息
|
||||
MsgTypeMiniprogrampage MsgType = "miniprogrampage"
|
||||
// MsgTypeShortVideo 表示短视频消息[限接收]
|
||||
// MsgTypeShortVideo 表示短视频消息 [限接收]
|
||||
MsgTypeShortVideo MsgType = "shortvideo"
|
||||
// MsgTypeLocation 表示坐标消息[限接收]
|
||||
// MsgTypeLocation 表示坐标消息 [限接收]
|
||||
MsgTypeLocation MsgType = "location"
|
||||
// MsgTypeLink 表示链接消息[限接收]
|
||||
// MsgTypeLink 表示链接消息 [限接收]
|
||||
MsgTypeLink MsgType = "link"
|
||||
// MsgTypeMusic 表示音乐消息[限回复]
|
||||
// MsgTypeMusic 表示音乐消息 [限回复]
|
||||
MsgTypeMusic MsgType = "music"
|
||||
// MsgTypeNews 表示图文消息[限回复]
|
||||
// MsgTypeNews 表示图文消息 [限回复]
|
||||
MsgTypeNews MsgType = "news"
|
||||
// MsgTypeTransfer 表示消息消息转发到客服
|
||||
MsgTypeTransfer MsgType = "transfer_customer_service"
|
||||
@@ -91,7 +91,7 @@ const (
|
||||
const (
|
||||
// 微信开放平台需要用到
|
||||
|
||||
// InfoTypeVerifyTicket 返回ticket
|
||||
// InfoTypeVerifyTicket 返回 ticket
|
||||
InfoTypeVerifyTicket InfoType = "component_verify_ticket"
|
||||
// InfoTypeAuthorized 授权
|
||||
InfoTypeAuthorized InfoType = "authorized"
|
||||
@@ -108,8 +108,8 @@ type MixMessage struct {
|
||||
CommonToken
|
||||
|
||||
// 基本消息
|
||||
MsgID int64 `xml:"MsgId"` // 其他消息推送过来是MsgId
|
||||
TemplateMsgID int64 `xml:"MsgID"` // 模板消息推送成功的消息是MsgID
|
||||
MsgID int64 `xml:"MsgId"` // 其他消息推送过来是 MsgId
|
||||
TemplateMsgID int64 `xml:"MsgID"` // 模板消息推送成功的消息是 MsgID
|
||||
Content string `xml:"Content"`
|
||||
Recognition string `xml:"Recognition"`
|
||||
PicURL string `xml:"PicUrl"`
|
||||
@@ -166,17 +166,17 @@ type MixMessage struct {
|
||||
|
||||
// 事件相关:发布能力
|
||||
PublishEventInfo struct {
|
||||
PublishID int64 `xml:"publish_id"` // 发布任务id
|
||||
PublishID int64 `xml:"publish_id"` // 发布任务 id
|
||||
PublishStatus freepublish.PublishStatus `xml:"publish_status"` // 发布状态
|
||||
ArticleID string `xml:"article_id"` // 当发布状态为0时(即成功)时,返回图文的 article_id,可用于“客服消息”场景
|
||||
ArticleID string `xml:"article_id"` // 当发布状态为 0 时(即成功)时,返回图文的 article_id,可用于“客服消息”场景
|
||||
ArticleDetail struct {
|
||||
Count uint `xml:"count"` // 文章数量
|
||||
Item []struct {
|
||||
Index uint `xml:"idx"` // 文章对应的编号
|
||||
ArticleURL string `xml:"article_url"` // 图文的永久链接
|
||||
} `xml:"item"`
|
||||
} `xml:"article_detail"` // 当发布状态为0时(即成功)时,返回内容
|
||||
FailIndex []uint `xml:"fail_idx"` // 当发布状态为2或4时,返回不通过的文章编号,第一篇为 1;其他发布状态则为空
|
||||
} `xml:"article_detail"` // 当发布状态为 0 时(即成功)时,返回内容
|
||||
FailIndex []uint `xml:"fail_idx"` // 当发布状态为 2 或 4 时,返回不通过的文章编号,第一篇为 1;其他发布状态则为空
|
||||
} `xml:"PublishEventInfo"`
|
||||
|
||||
// 第三方平台相关
|
||||
@@ -222,19 +222,19 @@ type MixMessage struct {
|
||||
TraceID string `xml:"trace_id"`
|
||||
StatusCode int `xml:"status_code"`
|
||||
|
||||
//小程序名称审核结果事件推送
|
||||
Ret int32 `xml:"ret"` //审核结果 2:失败,3:成功
|
||||
NickName string `xml:"nickname"` //小程序昵称
|
||||
// 小程序名称审核结果事件推送
|
||||
Ret int32 `xml:"ret"` // 审核结果 2:失败,3:成功
|
||||
NickName string `xml:"nickname"` // 小程序昵称
|
||||
|
||||
// 设备相关
|
||||
device.MsgDevice
|
||||
|
||||
//小程序审核通知
|
||||
SuccTime int `xml:"SuccTime"` //审核成功时的时间戳
|
||||
FailTime int `xml:"FailTime"` //审核不通过的时间戳
|
||||
DelayTime int `xml:"DelayTime"` //审核延后时的时间戳
|
||||
Reason string `xml:"Reason"` //审核不通过的原因
|
||||
ScreenShot string `xml:"ScreenShot"` //审核不通过的截图示例。用 | 分隔的 media_id 的列表,可通过获取永久素材接口拉取截图内容
|
||||
// 小程序审核通知
|
||||
SuccTime int `xml:"SuccTime"` // 审核成功时的时间戳
|
||||
FailTime int `xml:"FailTime"` // 审核不通过的时间戳
|
||||
DelayTime int `xml:"DelayTime"` // 审核延后时的时间戳
|
||||
Reason string `xml:"Reason"` // 审核不通过的原因
|
||||
ScreenShot string `xml:"ScreenShot"` // 审核不通过的截图示例。用 | 分隔的 media_id 的列表,可通过获取永久素材接口拉取截图内容
|
||||
}
|
||||
|
||||
// SubscribeMsgPopupEvent 订阅通知事件推送的消息体
|
||||
@@ -282,7 +282,7 @@ type ResponseEncryptedXMLMsg struct {
|
||||
Nonce string `xml:"Nonce" json:"Nonce"`
|
||||
}
|
||||
|
||||
// CDATA 使用该类型,在序列化为 xml 文本时文本会被解析器忽略
|
||||
// CDATA 使用该类型,在序列化为 xml 文本时文本会被解析器忽略
|
||||
type CDATA string
|
||||
|
||||
// MarshalXML 实现自己的序列化方法
|
||||
|
||||
@@ -31,14 +31,14 @@ func NewSubscribe(context *context.Context) *Subscribe {
|
||||
|
||||
// SubscribeMessage 发送的订阅消息内容
|
||||
type SubscribeMessage struct {
|
||||
ToUser string `json:"touser"` // 必须, 接受者OpenID
|
||||
TemplateID string `json:"template_id"` // 必须, 模版ID
|
||||
Page string `json:"page,omitempty"` // 可选, 跳转网页时填写
|
||||
Data map[string]*SubscribeDataItem `json:"data"` // 必须, 模板数据
|
||||
ToUser string `json:"touser"` // 必须,接受者 OpenID
|
||||
TemplateID string `json:"template_id"` // 必须,模版 ID
|
||||
Page string `json:"page,omitempty"` // 可选,跳转网页时填写
|
||||
Data map[string]*SubscribeDataItem `json:"data"` // 必须,模板数据
|
||||
MiniProgram struct {
|
||||
AppID string `json:"appid"` // 所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系)
|
||||
PagePath string `json:"pagepath"` // 所需跳转到小程序的具体页面路径,支持带参数,(示例index?foo=bar)
|
||||
} `json:"miniprogram"` // 可选,跳转至小程序地址
|
||||
AppID string `json:"appid"` // 所需跳转到的小程序 appid(该小程序 appid 必须与发模板消息的公众号是绑定关联关系)
|
||||
PagePath string `json:"pagepath"` // 所需跳转到小程序的具体页面路径,支持带参数,(示例 index?foo=bar)
|
||||
} `json:"miniprogram"` // 可选,跳转至小程序地址
|
||||
}
|
||||
|
||||
// SubscribeDataItem 模版内某个 .DATA 的值
|
||||
@@ -90,11 +90,7 @@ func (tpl *Subscribe) List() (templateList []*PrivateSubscribeItem, err error) {
|
||||
}
|
||||
var res resPrivateSubscribeList
|
||||
err = util.DecodeWithError(response, &res, "ListSubscribe")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
templateList = res.SubscriptionList
|
||||
return
|
||||
return res.SubscriptionList, err
|
||||
}
|
||||
|
||||
type resSubscribeAdd struct {
|
||||
@@ -123,11 +119,7 @@ func (tpl *Subscribe) Add(ShortID string, kidList []int, sceneDesc string) (temp
|
||||
}
|
||||
var result resSubscribeAdd
|
||||
err = util.DecodeWithError(response, &result, "AddSubscribe")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
templateID = result.TemplateID
|
||||
return
|
||||
return result.TemplateID, err
|
||||
}
|
||||
|
||||
// Delete 删除私有模板
|
||||
@@ -151,7 +143,7 @@ func (tpl *Subscribe) Delete(templateID string) (err error) {
|
||||
|
||||
// PublicTemplateCategory 公众号类目
|
||||
type PublicTemplateCategory struct {
|
||||
ID int `json:"id"` // 类目ID
|
||||
ID int `json:"id"` // 类目 ID
|
||||
Name string `json:"name"` // 类目的中文名
|
||||
}
|
||||
|
||||
@@ -175,11 +167,7 @@ func (tpl *Subscribe) GetCategory() (categoryList []*PublicTemplateCategory, err
|
||||
}
|
||||
var result resSubscribeCategoryList
|
||||
err = util.DecodeWithError(response, &result, "GetCategory")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
categoryList = result.CategoryList
|
||||
return
|
||||
return result.CategoryList, err
|
||||
}
|
||||
|
||||
// PublicTemplateKeyWords 模板中的关键词
|
||||
@@ -210,11 +198,7 @@ func (tpl *Subscribe) GetPubTplKeyWordsByID(titleID string) (keyWordsList []*Pub
|
||||
}
|
||||
var result resPublicTemplateKeyWordsList
|
||||
err = util.DecodeWithError(response, &result, "GetPublicTemplateKeyWords")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
keyWordsList = result.KeyWordsList
|
||||
return
|
||||
return result.KeyWordsList, err
|
||||
}
|
||||
|
||||
// PublicTemplateTitle 类目下的公共模板
|
||||
@@ -246,10 +230,5 @@ func (tpl *Subscribe) GetPublicTemplateTitleList(ids string, start int, limit in
|
||||
}
|
||||
var result resPublicTemplateTitleList
|
||||
err = util.DecodeWithError(response, &result, "GetPublicTemplateTitle")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = result.Count
|
||||
templateTitleList = result.TemplateTitleList
|
||||
return
|
||||
return result.Count, result.TemplateTitleList, err
|
||||
}
|
||||
|
||||
@@ -29,17 +29,17 @@ func NewTemplate(context *context.Context) *Template {
|
||||
|
||||
// TemplateMessage 发送的模板消息内容
|
||||
type TemplateMessage struct {
|
||||
ToUser string `json:"touser"` // 必须, 接受者OpenID
|
||||
TemplateID string `json:"template_id"` // 必须, 模版ID
|
||||
URL string `json:"url,omitempty"` // 可选, 用户点击后跳转的URL, 该URL必须处于开发者在公众平台网站中设置的域中
|
||||
Color string `json:"color,omitempty"` // 可选, 整个消息的颜色, 可以不设置
|
||||
Data map[string]*TemplateDataItem `json:"data"` // 必须, 模板数据
|
||||
ClientMsgID string `json:"client_msg_id,omitempty"` // 可选, 防重入ID
|
||||
ToUser string `json:"touser"` // 必须,接受者 OpenID
|
||||
TemplateID string `json:"template_id"` // 必须,模版 ID
|
||||
URL string `json:"url,omitempty"` // 可选,用户点击后跳转的 URL, 该 URL 必须处于开发者在公众平台网站中设置的域中
|
||||
Color string `json:"color,omitempty"` // 可选,整个消息的颜色,可以不设置
|
||||
Data map[string]*TemplateDataItem `json:"data"` // 必须,模板数据
|
||||
ClientMsgID string `json:"client_msg_id,omitempty"` // 可选,防重入 ID
|
||||
|
||||
MiniProgram struct {
|
||||
AppID string `json:"appid"` // 所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系)
|
||||
PagePath string `json:"pagepath"` // 所需跳转到小程序的具体页面路径,支持带参数,(示例index?foo=bar)
|
||||
} `json:"miniprogram"` // 可选,跳转至小程序地址
|
||||
AppID string `json:"appid"` // 所需跳转到的小程序 appid(该小程序 appid 必须与发模板消息的公众号是绑定关联关系)
|
||||
PagePath string `json:"pagepath"` // 所需跳转到小程序的具体页面路径,支持带参数,(示例 index?foo=bar)
|
||||
} `json:"miniprogram"` // 可选,跳转至小程序地址
|
||||
}
|
||||
|
||||
// TemplateDataItem 模版内某个 .DATA 的值
|
||||
@@ -61,15 +61,15 @@ func (tpl *Template) Send(msg *TemplateMessage) (msgID int64, err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", templateSendURL, accessToken)
|
||||
var response []byte
|
||||
response, err = util.PostJSON(uri, msg)
|
||||
if err != nil {
|
||||
var (
|
||||
uri = fmt.Sprintf("%s?access_token=%s", templateSendURL, accessToken)
|
||||
response []byte
|
||||
)
|
||||
if response, err = util.PostJSON(uri, msg); err != nil {
|
||||
return
|
||||
}
|
||||
var result resTemplateSend
|
||||
err = json.Unmarshal(response, &result)
|
||||
if err != nil {
|
||||
if err = json.Unmarshal(response, &result); err != nil {
|
||||
return
|
||||
}
|
||||
if result.ErrCode != 0 {
|
||||
@@ -80,7 +80,7 @@ func (tpl *Template) Send(msg *TemplateMessage) (msgID int64, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// TemplateItem 模板消息.
|
||||
// TemplateItem 模板消息。
|
||||
type TemplateItem struct {
|
||||
TemplateID string `json:"template_id"`
|
||||
Title string `json:"title"`
|
||||
@@ -103,19 +103,16 @@ func (tpl *Template) List() (templateList []*TemplateItem, err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", templateListURL, accessToken)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(uri)
|
||||
if err != nil {
|
||||
var (
|
||||
uri = fmt.Sprintf("%s?access_token=%s", templateListURL, accessToken)
|
||||
response []byte
|
||||
)
|
||||
if response, err = util.HTTPGet(uri); err != nil {
|
||||
return
|
||||
}
|
||||
var res resTemplateList
|
||||
err = util.DecodeWithError(response, &res, "ListTemplate")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
templateList = res.TemplateList
|
||||
return
|
||||
return res.TemplateList, err
|
||||
}
|
||||
|
||||
type resTemplateAdd struct {
|
||||
@@ -124,47 +121,44 @@ type resTemplateAdd struct {
|
||||
TemplateID string `json:"template_id"`
|
||||
}
|
||||
|
||||
// Add 添加模板.
|
||||
func (tpl *Template) Add(shortID string) (templateID string, err error) {
|
||||
// Add 添加模板。
|
||||
func (tpl *Template) Add(shortID string, keyNameList []string) (templateID string, err error) {
|
||||
var accessToken string
|
||||
accessToken, err = tpl.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var msg = struct {
|
||||
ShortID string `json:"template_id_short"`
|
||||
}{ShortID: shortID}
|
||||
uri := fmt.Sprintf("%s?access_token=%s", templateAddURL, accessToken)
|
||||
var response []byte
|
||||
response, err = util.PostJSON(uri, msg)
|
||||
if err != nil {
|
||||
var (
|
||||
msg = struct {
|
||||
ShortID string `json:"template_id_short"`
|
||||
KeyNameList []string `json:"keyword_name_list"`
|
||||
}{ShortID: shortID, KeyNameList: keyNameList}
|
||||
uri = fmt.Sprintf("%s?access_token=%s", templateAddURL, accessToken)
|
||||
response []byte
|
||||
)
|
||||
if response, err = util.PostJSON(uri, msg); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var result resTemplateAdd
|
||||
err = util.DecodeWithError(response, &result, "AddTemplate")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
templateID = result.TemplateID
|
||||
return
|
||||
return result.TemplateID, err
|
||||
}
|
||||
|
||||
// Delete 删除私有模板.
|
||||
// Delete 删除私有模板。
|
||||
func (tpl *Template) Delete(templateID string) (err error) {
|
||||
var accessToken string
|
||||
accessToken, err = tpl.GetAccessToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var msg = struct {
|
||||
TemplateID string `json:"template_id"`
|
||||
}{TemplateID: templateID}
|
||||
|
||||
uri := fmt.Sprintf("%s?access_token=%s", templateDelURL, accessToken)
|
||||
var response []byte
|
||||
response, err = util.PostJSON(uri, msg)
|
||||
if err != nil {
|
||||
var (
|
||||
msg = struct {
|
||||
TemplateID string `json:"template_id"`
|
||||
}{TemplateID: templateID}
|
||||
uri = fmt.Sprintf("%s?access_token=%s", templateDelURL, accessToken)
|
||||
response []byte
|
||||
)
|
||||
if response, err = util.PostJSON(uri, msg); err != nil {
|
||||
return
|
||||
}
|
||||
return util.DecodeWithCommonError(response, "DeleteTemplate")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
ctx2 "context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@@ -31,14 +32,14 @@ func NewOauth(context *context.Context) *Oauth {
|
||||
return auth
|
||||
}
|
||||
|
||||
// GetRedirectURL 获取跳转的url地址
|
||||
// GetRedirectURL 获取跳转的 url 地址
|
||||
func (oauth *Oauth) GetRedirectURL(redirectURI, scope, state string) (string, error) {
|
||||
// url encode
|
||||
urlStr := url.QueryEscape(redirectURI)
|
||||
return fmt.Sprintf(redirectOauthURL, oauth.AppID, urlStr, scope, state), nil
|
||||
}
|
||||
|
||||
// GetWebAppRedirectURL 获取网页应用跳转的url地址
|
||||
// GetWebAppRedirectURL 获取网页应用跳转的 url 地址
|
||||
func (oauth *Oauth) GetWebAppRedirectURL(redirectURI, scope, state string) (string, error) {
|
||||
urlStr := url.QueryEscape(redirectURI)
|
||||
return fmt.Sprintf(webAppRedirectOauthURL, oauth.AppID, urlStr, scope, state), nil
|
||||
@@ -54,7 +55,7 @@ func (oauth *Oauth) Redirect(writer http.ResponseWriter, req *http.Request, redi
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResAccessToken 获取用户授权access_token的返回结果
|
||||
// ResAccessToken 获取用户授权 access_token 的返回结果
|
||||
type ResAccessToken struct {
|
||||
util.CommonError
|
||||
|
||||
@@ -64,7 +65,7 @@ type ResAccessToken struct {
|
||||
OpenID string `json:"openid"`
|
||||
Scope string `json:"scope"`
|
||||
|
||||
// IsSnapShotUser 是否为快照页模式虚拟账号,只有当用户是快照页模式虚拟账号时返回,值为1
|
||||
// IsSnapShotUser 是否为快照页模式虚拟账号,只有当用户是快照页模式虚拟账号时返回,值为 1
|
||||
// 公众号文档 https://developers.weixin.qq.com/community/minihome/doc/000c2c34068880629ced91a2f56001
|
||||
IsSnapShotUser int `json:"is_snapshotuser"`
|
||||
|
||||
@@ -73,11 +74,28 @@ type ResAccessToken struct {
|
||||
UnionID string `json:"unionid"`
|
||||
}
|
||||
|
||||
// GetUserAccessToken 通过网页授权的code 换取access_token(区别于context中的access_token)
|
||||
// GetUserInfoByCodeContext 通过网页授权的 code 换取用户的信息
|
||||
func (oauth *Oauth) GetUserInfoByCodeContext(ctx ctx2.Context, code string) (result UserInfo, err error) {
|
||||
var (
|
||||
token ResAccessToken
|
||||
)
|
||||
if token, err = oauth.GetUserAccessTokenContext(ctx, code); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return oauth.GetUserInfoContext(ctx, token.AccessToken, token.OpenID, "")
|
||||
}
|
||||
|
||||
// GetUserAccessToken 通过网页授权的 code 换取 access_token(区别于 context 中的 access_token)
|
||||
func (oauth *Oauth) GetUserAccessToken(code string) (result ResAccessToken, err error) {
|
||||
return oauth.GetUserAccessTokenContext(ctx2.Background(), code)
|
||||
}
|
||||
|
||||
// GetUserAccessTokenContext 通过网页授权的 code 换取 access_token(区别于 context 中的 access_token) with context
|
||||
func (oauth *Oauth) GetUserAccessTokenContext(ctx ctx2.Context, code string) (result ResAccessToken, err error) {
|
||||
urlStr := fmt.Sprintf(accessTokenURL, oauth.AppID, oauth.AppSecret, code)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(urlStr)
|
||||
response, err = util.HTTPGetContext(ctx, urlStr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -92,11 +110,16 @@ func (oauth *Oauth) GetUserAccessToken(code string) (result ResAccessToken, err
|
||||
return
|
||||
}
|
||||
|
||||
// RefreshAccessToken 刷新access_token
|
||||
// RefreshAccessToken 刷新 access_token
|
||||
func (oauth *Oauth) RefreshAccessToken(refreshToken string) (result ResAccessToken, err error) {
|
||||
return oauth.RefreshAccessTokenContext(ctx2.Background(), refreshToken)
|
||||
}
|
||||
|
||||
// RefreshAccessTokenContext 刷新 access_token with context
|
||||
func (oauth *Oauth) RefreshAccessTokenContext(ctx ctx2.Context, refreshToken string) (result ResAccessToken, err error) {
|
||||
urlStr := fmt.Sprintf(refreshAccessTokenURL, oauth.AppID, refreshToken)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(urlStr)
|
||||
response, err = util.HTTPGetContext(ctx, urlStr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -111,11 +134,16 @@ func (oauth *Oauth) RefreshAccessToken(refreshToken string) (result ResAccessTok
|
||||
return
|
||||
}
|
||||
|
||||
// CheckAccessToken 检验access_token是否有效
|
||||
// CheckAccessToken 检验 access_token 是否有效
|
||||
func (oauth *Oauth) CheckAccessToken(accessToken, openID string) (b bool, err error) {
|
||||
return oauth.CheckAccessTokenContext(ctx2.Background(), accessToken, openID)
|
||||
}
|
||||
|
||||
// CheckAccessTokenContext 检验 access_token 是否有效 with context
|
||||
func (oauth *Oauth) CheckAccessTokenContext(ctx ctx2.Context, accessToken, openID string) (b bool, err error) {
|
||||
urlStr := fmt.Sprintf(checkAccessTokenURL, accessToken, openID)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(urlStr)
|
||||
response, err = util.HTTPGetContext(ctx, urlStr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -147,14 +175,19 @@ type UserInfo struct {
|
||||
Unionid string `json:"unionid"`
|
||||
}
|
||||
|
||||
// GetUserInfo 如果scope为 snsapi_userinfo 则可以通过此方法获取到用户基本信息
|
||||
// GetUserInfo 如果 scope 为 snsapi_userinfo 则可以通过此方法获取到用户基本信息
|
||||
func (oauth *Oauth) GetUserInfo(accessToken, openID, lang string) (result UserInfo, err error) {
|
||||
return oauth.GetUserInfoContext(ctx2.Background(), accessToken, openID, lang)
|
||||
}
|
||||
|
||||
// GetUserInfoContext 如果 scope 为 snsapi_userinfo 则可以通过此方法获取到用户基本信息 with context
|
||||
func (oauth *Oauth) GetUserInfoContext(ctx ctx2.Context, accessToken, openID, lang string) (result UserInfo, err error) {
|
||||
if lang == "" {
|
||||
lang = "zh_CN"
|
||||
}
|
||||
urlStr := fmt.Sprintf(userInfoURL, accessToken, openID, lang)
|
||||
var response []byte
|
||||
response, err = util.HTTPGet(urlStr)
|
||||
response, err = util.HTTPGetContext(ctx, urlStr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ func NewOCR(c *context.Context) *OCR {
|
||||
return ocr
|
||||
}
|
||||
|
||||
// IDCard 身份证OCR识别接口
|
||||
// IDCard 身份证 OCR 识别接口
|
||||
func (ocr *OCR) IDCard(path string) (resIDCard ResIDCard, err error) {
|
||||
accessToken, err := ocr.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -170,7 +170,7 @@ func (ocr *OCR) IDCard(path string) (resIDCard ResIDCard, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// BankCard 银行卡OCR识别接口
|
||||
// BankCard 银行卡 OCR 识别接口
|
||||
func (ocr *OCR) BankCard(path string) (resBankCard ResBankCard, err error) {
|
||||
accessToken, err := ocr.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -187,7 +187,7 @@ func (ocr *OCR) BankCard(path string) (resBankCard ResBankCard, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Driving 行驶证OCR识别接口
|
||||
// Driving 行驶证 OCR 识别接口
|
||||
func (ocr *OCR) Driving(path string) (resDriving ResDriving, err error) {
|
||||
accessToken, err := ocr.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -204,7 +204,7 @@ func (ocr *OCR) Driving(path string) (resDriving ResDriving, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// DrivingLicense 驾驶证OCR识别接口
|
||||
// DrivingLicense 驾驶证 OCR 识别接口
|
||||
func (ocr *OCR) DrivingLicense(path string) (resDrivingLicense ResDrivingLicense, err error) {
|
||||
accessToken, err := ocr.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -221,7 +221,7 @@ func (ocr *OCR) DrivingLicense(path string) (resDrivingLicense ResDrivingLicense
|
||||
return
|
||||
}
|
||||
|
||||
// BizLicense 营业执照OCR识别接口
|
||||
// BizLicense 营业执照 OCR 识别接口
|
||||
func (ocr *OCR) BizLicense(path string) (resBizLicense ResBizLicense, err error) {
|
||||
accessToken, err := ocr.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -238,7 +238,7 @@ func (ocr *OCR) BizLicense(path string) (resBizLicense ResBizLicense, err error)
|
||||
return
|
||||
}
|
||||
|
||||
// Common 通用印刷体OCR识别接口
|
||||
// Common 通用印刷体 OCR 识别接口
|
||||
func (ocr *OCR) Common(path string) (resCommon ResCommon, err error) {
|
||||
accessToken, err := ocr.GetAccessToken()
|
||||
if err != nil {
|
||||
@@ -255,7 +255,7 @@ func (ocr *OCR) Common(path string) (resCommon ResCommon, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// PlateNumber 车牌OCR识别接口
|
||||
// PlateNumber 车牌 OCR 识别接口
|
||||
func (ocr *OCR) PlateNumber(path string) (resPlateNumber ResPlateNumber, err error) {
|
||||
accessToken, err := ocr.GetAccessToken()
|
||||
if err != nil {
|
||||
|
||||
@@ -4,30 +4,28 @@ import (
|
||||
stdcontext "context"
|
||||
"net/http"
|
||||
|
||||
"github.com/silenceper/wechat/v2/internal/openapi"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/draft"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/freepublish"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/ocr"
|
||||
|
||||
"github.com/silenceper/wechat/v2/officialaccount/datacube"
|
||||
|
||||
"github.com/silenceper/wechat/v2/credential"
|
||||
"github.com/silenceper/wechat/v2/internal/openapi"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/basic"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/broadcast"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/config"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/customerservice"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/datacube"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/device"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/draft"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/freepublish"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/js"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/material"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/menu"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/message"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/oauth"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/ocr"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/server"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/user"
|
||||
)
|
||||
|
||||
// OfficialAccount 微信公众号相关API
|
||||
// OfficialAccount 微信公众号相关 API
|
||||
type OfficialAccount struct {
|
||||
ctx *context.Context
|
||||
basic *basic.Basic
|
||||
@@ -47,7 +45,7 @@ type OfficialAccount struct {
|
||||
subscribeMsg *message.Subscribe
|
||||
}
|
||||
|
||||
// NewOfficialAccount 实例化公众号API
|
||||
// NewOfficialAccount 实例化公众号 API
|
||||
func NewOfficialAccount(cfg *config.Config) *OfficialAccount {
|
||||
defaultAkHandle := credential.NewDefaultAccessToken(cfg.AppID, cfg.AppSecret, credential.CacheKeyOfficialAccountPrefix, cfg.Cache)
|
||||
ctx := &context.Context{
|
||||
@@ -57,7 +55,7 @@ func NewOfficialAccount(cfg *config.Config) *OfficialAccount {
|
||||
return &OfficialAccount{ctx: ctx}
|
||||
}
|
||||
|
||||
// SetAccessTokenHandle 自定义access_token获取方式
|
||||
// SetAccessTokenHandle 自定义 access_token 获取方式
|
||||
func (officialAccount *OfficialAccount) SetAccessTokenHandle(accessTokenHandle credential.AccessTokenHandle) {
|
||||
officialAccount.ctx.AccessTokenHandle = accessTokenHandle
|
||||
}
|
||||
@@ -91,12 +89,12 @@ func (officialAccount *OfficialAccount) GetServer(req *http.Request, writer http
|
||||
return srv
|
||||
}
|
||||
|
||||
// GetAccessToken 获取access_token
|
||||
// GetAccessToken 获取 access_token
|
||||
func (officialAccount *OfficialAccount) GetAccessToken() (string, error) {
|
||||
return officialAccount.ctx.GetAccessToken()
|
||||
}
|
||||
|
||||
// GetAccessTokenContext 获取access_token
|
||||
// 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)
|
||||
@@ -104,7 +102,7 @@ func (officialAccount *OfficialAccount) GetAccessTokenContext(ctx stdcontext.Con
|
||||
return officialAccount.ctx.GetAccessToken()
|
||||
}
|
||||
|
||||
// GetOauth oauth2网页授权
|
||||
// GetOauth oauth2 网页授权
|
||||
func (officialAccount *OfficialAccount) GetOauth() *oauth.Oauth {
|
||||
if officialAccount.oauth == nil {
|
||||
officialAccount.oauth = oauth.NewOauth(officialAccount.ctx)
|
||||
@@ -136,7 +134,7 @@ func (officialAccount *OfficialAccount) GetFreePublish() *freepublish.FreePublis
|
||||
return officialAccount.freepublish
|
||||
}
|
||||
|
||||
// GetJs js-sdk配置
|
||||
// GetJs js-sdk 配置
|
||||
func (officialAccount *OfficialAccount) GetJs() *js.Js {
|
||||
if officialAccount.js == nil {
|
||||
officialAccount.js = js.NewJs(officialAccount.ctx)
|
||||
@@ -193,7 +191,7 @@ func (officialAccount *OfficialAccount) GetDataCube() *datacube.DataCube {
|
||||
return officialAccount.datacube
|
||||
}
|
||||
|
||||
// GetOCR OCR接口
|
||||
// GetOCR OCR 接口
|
||||
func (officialAccount *OfficialAccount) GetOCR() *ocr.OCR {
|
||||
if officialAccount.ocr == nil {
|
||||
officialAccount.ocr = ocr.NewOCR(officialAccount.ctx)
|
||||
@@ -214,7 +212,7 @@ func (officialAccount *OfficialAccount) GetCustomerServiceManager() *customerser
|
||||
return customerservice.NewCustomerServiceManager(officialAccount.ctx)
|
||||
}
|
||||
|
||||
// GetOpenAPI openApi管理接口
|
||||
// GetOpenAPI openApi 管理接口
|
||||
func (officialAccount *OfficialAccount) GetOpenAPI() *openapi.OpenAPI {
|
||||
return openapi.NewOpenAPI(officialAccount.ctx)
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func (srv *Server) Serve() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 非安全模式下,请求处理方法返回为nil则直接回复success给微信服务器
|
||||
// 非安全模式下,请求处理方法返回为 nil 则直接回复 success 给微信服务器
|
||||
if response == nil && !srv.isSafeMode {
|
||||
srv.String("success")
|
||||
return nil
|
||||
@@ -198,7 +198,7 @@ func (srv *Server) parseRequestMessage(rawXMLMsgBytes []byte) (msg *message.MixM
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// nonstandard json, 目前小程序订阅消息返回数据格式不标准,订阅消息模板单个List返回是对象,多个List返回是数组。
|
||||
// nonstandard json, 目前小程序订阅消息返回数据格式不标准,订阅消息模板单个 List 返回是对象,多个 List 返回是数组。
|
||||
if msg.MsgType == message.MsgTypeEvent {
|
||||
listData := gjson.Get(string(rawXMLMsgBytes), "List")
|
||||
if listData.IsObject() {
|
||||
@@ -284,7 +284,7 @@ func (srv *Server) Send() (err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// TODO 如果获取不到timestamp nonce 则自己生成
|
||||
// TODO 如果获取不到 timestamp nonce 则自己生成
|
||||
timestamp := srv.timestamp
|
||||
timestampStr := strconv.FormatInt(timestamp, 10)
|
||||
msgSignature := util.Signature(srv.Token, timestampStr, srv.nonce, string(encryptedMsg))
|
||||
|
||||
@@ -19,11 +19,11 @@ const (
|
||||
)
|
||||
|
||||
// GetBlackList 获取公众号的黑名单列表
|
||||
// 该接口每次调用最多可拉取 1000 个OpenID,当列表数较多时,可以通过多次拉取的方式来满足需求。
|
||||
// 该接口每次调用最多可拉取 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,若需要从头开始拉取列表请留空。")
|
||||
return nil, errors.New("参数 beginOpenid 错误:请传递 1 个 openID,若需要从头开始拉取列表请留空。")
|
||||
}
|
||||
// 获取 AccessToken
|
||||
var accessToken string
|
||||
@@ -62,13 +62,13 @@ func (user *User) GetAllBlackList() (openIDList []string, err error) {
|
||||
)
|
||||
|
||||
for {
|
||||
// 获取列表(每次1k条)
|
||||
// 获取列表(每次 1k 条)
|
||||
if userlist, err = user.GetBlackList(beginOpenid); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
openIDList = append(openIDList, userlist.Data.OpenIDs...) // 存储本次获得的OpenIDs
|
||||
openIDList = append(openIDList, userlist.Data.OpenIDs...) // 存储本次获得的 OpenIDs
|
||||
count += userlist.Count // 记录获得的总数量
|
||||
beginOpenid = userlist.NextOpenID // 记录下次循环的起始openID
|
||||
beginOpenid = userlist.NextOpenID // 记录下次循环的起始 openID
|
||||
if count >= userlist.Total {
|
||||
break // 获得的数量=total,结束循环
|
||||
}
|
||||
@@ -78,13 +78,13 @@ func (user *User) GetAllBlackList() (openIDList []string, err error) {
|
||||
}
|
||||
|
||||
// BatchBlackList 拉黑用户
|
||||
// 参数 openidList:需要拉入黑名单的用户的openid,每次拉黑最多允许20个
|
||||
// 参数 openidList:需要拉入黑名单的用户的 openid,每次拉黑最多允许 20 个
|
||||
func (user *User) BatchBlackList(openidList ...string) (err error) {
|
||||
return user.batch(batchblacklistURL, "BatchBlackList", openidList...)
|
||||
}
|
||||
|
||||
// BatchUnBlackList 取消拉黑用户
|
||||
// 参数 openidList:需要取消拉入黑名单的用户的openid,每次拉黑最多允许20个
|
||||
// 参数 openidList:需要取消拉入黑名单的用户的 openid,每次拉黑最多允许 20 个
|
||||
func (user *User) BatchUnBlackList(openidList ...string) (err error) {
|
||||
return user.batch(batchunblacklistURL, "BatchUnBlackList", openidList...)
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func (user *User) BatchUnBlackList(openidList ...string) (err error) {
|
||||
func (user *User) batch(url, apiName string, openidList ...string) (err error) {
|
||||
// 检查参数
|
||||
if len(openidList) == 0 || len(openidList) > 20 {
|
||||
return errors.New("参数 openidList 错误:每次操作黑名单用户数量为1-20个。")
|
||||
return errors.New("参数 openidList 错误:每次操作黑名单用户数量为 1-20 个。")
|
||||
}
|
||||
|
||||
// 获取 AccessToken
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Package user migrate 用于微信公众号账号迁移,获取openID变化
|
||||
// Package user migrate 用于微信公众号账号迁移,获取 openID 变化
|
||||
// 参考文档:https://kf.qq.com/faq/1901177NrqMr190117nqYJze.html
|
||||
package user
|
||||
|
||||
@@ -13,23 +13,23 @@ const (
|
||||
changeOpenIDURL = "https://api.weixin.qq.com/cgi-bin/changeopenid"
|
||||
)
|
||||
|
||||
// ChangeOpenIDResult OpenID迁移变化
|
||||
// ChangeOpenIDResult OpenID 迁移变化
|
||||
type ChangeOpenIDResult struct {
|
||||
OriOpenID string `json:"ori_openid"`
|
||||
NewOpenID string `json:"new_openid"`
|
||||
ErrMsg string `json:"err_msg,omitempty"`
|
||||
}
|
||||
|
||||
// ChangeOpenIDResultList OpenID迁移变化列表
|
||||
// ChangeOpenIDResultList OpenID 迁移变化列表
|
||||
type ChangeOpenIDResultList struct {
|
||||
util.CommonError
|
||||
List []ChangeOpenIDResult `json:"result_list"`
|
||||
}
|
||||
|
||||
// ListChangeOpenIDs 返回指定OpenID变化列表
|
||||
// fromAppID 为老账号AppID
|
||||
// openIDs 为老账号的openID,openIDs限100个以内
|
||||
// AccessToken 为新账号的AccessToken
|
||||
// ListChangeOpenIDs 返回指定 OpenID 变化列表
|
||||
// fromAppID 为老账号 AppID
|
||||
// openIDs 为老账号的 openID,openIDs 限 100 个以内
|
||||
// AccessToken 为新账号的 AccessToken
|
||||
func (user *User) ListChangeOpenIDs(fromAppID string, openIDs ...string) (list *ChangeOpenIDResultList, err error) {
|
||||
list = &ChangeOpenIDResultList{}
|
||||
// list.List = make([]ChangeOpenIDResult, 0)
|
||||
@@ -62,17 +62,13 @@ func (user *User) ListChangeOpenIDs(fromAppID string, openIDs ...string) (list *
|
||||
}
|
||||
|
||||
err = util.DecodeWithError(resp, list, "ListChangeOpenIDs")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// ListAllChangeOpenIDs 返回所有用户OpenID列表
|
||||
// fromAppID 为老账号AppID
|
||||
// openIDs 为老账号的openID
|
||||
// AccessToken 为新账号的AccessToken
|
||||
// ListAllChangeOpenIDs 返回所有用户 OpenID 列表
|
||||
// fromAppID 为老账号 AppID
|
||||
// openIDs 为老账号的 openID
|
||||
// AccessToken 为新账号的 AccessToken
|
||||
func (user *User) ListAllChangeOpenIDs(fromAppID string, openIDs ...string) (list []ChangeOpenIDResult, err error) {
|
||||
list = make([]ChangeOpenIDResult, 0)
|
||||
chunks := util.SliceChunk(openIDs, 100)
|
||||
|
||||
@@ -126,10 +126,7 @@ func (user *User) GetTag() (tags []*TagInfo, err error) {
|
||||
Tags []*TagInfo `json:"tags"`
|
||||
}
|
||||
err = json.Unmarshal(response, &result)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return result.Tags, nil
|
||||
return result.Tags, err
|
||||
}
|
||||
|
||||
// OpenIDListByTag 获取标签下粉丝列表
|
||||
@@ -154,9 +151,6 @@ func (user *User) OpenIDListByTag(tagID int32, nextOpenID ...string) (userList *
|
||||
}
|
||||
userList = new(TagOpenIDList)
|
||||
err = json.Unmarshal(response, &userList)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ type BatchGetUserInfoParams struct {
|
||||
// BatchGetUserListItem 需要获取基本信息的用户
|
||||
type BatchGetUserListItem struct {
|
||||
OpenID string `json:"openid"` // 用户的标识,对当前公众号唯一
|
||||
Lang string `json:"lang"` // 国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语,默认为zh-CN
|
||||
Lang string `json:"lang"` // 国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语,默认为 zh-CN
|
||||
}
|
||||
|
||||
// InfoList 用户基本信息列表
|
||||
@@ -161,7 +161,10 @@ func (user *User) ListUserOpenIDs(nextOpenid ...string) (*OpenidList, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uri, _ := url.Parse(userListURL)
|
||||
uri, err := url.Parse(userListURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
q := uri.Query()
|
||||
q.Set("access_token", accessToken)
|
||||
if len(nextOpenid) > 0 && nextOpenid[0] != "" {
|
||||
@@ -184,7 +187,7 @@ func (user *User) ListUserOpenIDs(nextOpenid ...string) (*OpenidList, error) {
|
||||
return &userlist, nil
|
||||
}
|
||||
|
||||
// ListAllUserOpenIDs 返回所有用户OpenID列表
|
||||
// ListAllUserOpenIDs 返回所有用户 OpenID 列表
|
||||
func (user *User) ListAllUserOpenIDs() ([]string, error) {
|
||||
nextOpenid := ""
|
||||
openids := make([]string, 0)
|
||||
|
||||
@@ -19,7 +19,7 @@ cfg := &openplatform.Config{
|
||||
|
||||
|
||||
openPlatform := wc.GetOpenPlatform(cfg)
|
||||
// 传入request和responseWriter
|
||||
// 传入 request 和 responseWriter
|
||||
server := openPlatform.GetServer(req, rw)
|
||||
//设置接收消息的处理方法
|
||||
server.SetMessageHandler(func(msg *message.MixMessage) *message.Reply {
|
||||
@@ -57,7 +57,7 @@ server.Send()
|
||||
|
||||
```go
|
||||
|
||||
//授权的第三方公众号的appID
|
||||
//授权的第三方公众号的 appID
|
||||
appID := "xxx"
|
||||
openPlatform := wc.GetOpenPlatform(cfg)
|
||||
openPlatform.GetOfficialAccount(appID)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Package context 开放平台相关context
|
||||
// Package context 开放平台相关 context
|
||||
package context
|
||||
|
||||
import (
|
||||
@@ -48,7 +48,7 @@ func (ctx *Context) GetComponentAccessToken() (string, error) {
|
||||
return ctx.GetComponentAccessTokenContext(context.Background())
|
||||
}
|
||||
|
||||
// SetComponentAccessTokenContext 通过component_verify_ticket 获取 ComponentAccessToken
|
||||
// SetComponentAccessTokenContext 通过 component_verify_ticket 获取 ComponentAccessToken
|
||||
func (ctx *Context) SetComponentAccessTokenContext(stdCtx context.Context, verifyTicket string) (*ComponentAccessToken, error) {
|
||||
body := map[string]string{
|
||||
"component_appid": ctx.AppID,
|
||||
@@ -77,7 +77,7 @@ func (ctx *Context) SetComponentAccessTokenContext(stdCtx context.Context, verif
|
||||
return at, nil
|
||||
}
|
||||
|
||||
// SetComponentAccessToken 通过component_verify_ticket 获取 ComponentAccessToken
|
||||
// SetComponentAccessToken 通过 component_verify_ticket 获取 ComponentAccessToken
|
||||
func (ctx *Context) SetComponentAccessToken(stdCtx context.Context, verifyTicket string) (*ComponentAccessToken, error) {
|
||||
return ctx.SetComponentAccessTokenContext(stdCtx, verifyTicket)
|
||||
}
|
||||
@@ -100,11 +100,8 @@ func (ctx *Context) GetPreCodeContext(stdCtx context.Context) (string, error) {
|
||||
var ret struct {
|
||||
PreCode string `json:"pre_auth_code"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &ret); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return ret.PreCode, nil
|
||||
err = json.Unmarshal(body, &ret)
|
||||
return ret.PreCode, err
|
||||
}
|
||||
|
||||
// GetPreCode 获取预授权码
|
||||
@@ -112,7 +109,7 @@ func (ctx *Context) GetPreCode() (string, error) {
|
||||
return ctx.GetPreCodeContext(context.Background())
|
||||
}
|
||||
|
||||
// GetComponentLoginPageContext 获取第三方公众号授权链接(扫码授权)
|
||||
// GetComponentLoginPageContext 获取第三方公众号授权链接 (扫码授权)
|
||||
func (ctx *Context) GetComponentLoginPageContext(stdCtx context.Context, redirectURI string, authType int, bizAppID string) (string, error) {
|
||||
code, err := ctx.GetPreCodeContext(stdCtx)
|
||||
if err != nil {
|
||||
@@ -121,12 +118,12 @@ func (ctx *Context) GetComponentLoginPageContext(stdCtx context.Context, redirec
|
||||
return fmt.Sprintf(componentLoginURL, ctx.AppID, code, url.QueryEscape(redirectURI), authType, bizAppID), nil
|
||||
}
|
||||
|
||||
// GetComponentLoginPage 获取第三方公众号授权链接(扫码授权)
|
||||
// GetComponentLoginPage 获取第三方公众号授权链接 (扫码授权)
|
||||
func (ctx *Context) GetComponentLoginPage(redirectURI string, authType int, bizAppID string) (string, error) {
|
||||
return ctx.GetComponentLoginPageContext(context.Background(), redirectURI, authType, bizAppID)
|
||||
}
|
||||
|
||||
// GetBindComponentURLContext 获取第三方公众号授权链接(链接跳转,适用移动端)
|
||||
// GetBindComponentURLContext 获取第三方公众号授权链接 (链接跳转,适用移动端)
|
||||
func (ctx *Context) GetBindComponentURLContext(stdCtx context.Context, redirectURI string, authType int, bizAppID string) (string, error) {
|
||||
code, err := ctx.GetPreCodeContext(stdCtx)
|
||||
if err != nil {
|
||||
@@ -135,7 +132,7 @@ func (ctx *Context) GetBindComponentURLContext(stdCtx context.Context, redirectU
|
||||
return fmt.Sprintf(bindComponentURL, authType, ctx.AppID, code, url.QueryEscape(redirectURI), bizAppID), nil
|
||||
}
|
||||
|
||||
// GetBindComponentURL 获取第三方公众号授权链接(链接跳转,适用移动端)
|
||||
// GetBindComponentURL 获取第三方公众号授权链接 (链接跳转,适用移动端)
|
||||
func (ctx *Context) GetBindComponentURL(redirectURI string, authType int, bizAppID string) (string, error) {
|
||||
return ctx.GetBindComponentURLContext(context.Background(), redirectURI, authType, bizAppID)
|
||||
}
|
||||
@@ -156,7 +153,7 @@ type AuthFuncInfo struct {
|
||||
FuncscopeCategory ID `json:"funcscope_category"`
|
||||
}
|
||||
|
||||
// AuthrAccessToken 授权方AccessToken
|
||||
// AuthrAccessToken 授权方 AccessToken
|
||||
type AuthrAccessToken struct {
|
||||
Appid string `json:"authorizer_appid"`
|
||||
AccessToken string `json:"authorizer_access_token"`
|
||||
@@ -236,7 +233,7 @@ func (ctx *Context) RefreshAuthrToken(appid, refreshToken string) (*AuthrAccessT
|
||||
return ctx.RefreshAuthrTokenContext(context.Background(), appid, refreshToken)
|
||||
}
|
||||
|
||||
// GetAuthrAccessTokenContext 获取授权方AccessToken
|
||||
// GetAuthrAccessTokenContext 获取授权方 AccessToken
|
||||
func (ctx *Context) GetAuthrAccessTokenContext(stdCtx context.Context, appid string) (string, error) {
|
||||
authrTokenKey := "authorizer_access_token_" + appid
|
||||
val := cache.GetContext(stdCtx, ctx.Cache, authrTokenKey)
|
||||
@@ -246,7 +243,7 @@ func (ctx *Context) GetAuthrAccessTokenContext(stdCtx context.Context, appid str
|
||||
return val.(string), nil
|
||||
}
|
||||
|
||||
// GetAuthrAccessToken 获取授权方AccessToken
|
||||
// GetAuthrAccessToken 获取授权方 AccessToken
|
||||
func (ctx *Context) GetAuthrAccessToken(appid string) (string, error) {
|
||||
return ctx.GetAuthrAccessTokenContext(context.Background(), appid)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,12 @@ import (
|
||||
|
||||
const (
|
||||
getAccountBasicInfoURL = "https://api.weixin.qq.com/cgi-bin/account/getaccountbasicinfo"
|
||||
checkNickNameURL = "https://api.weixin.qq.com/cgi-bin/wxverify/checkwxverifynickname"
|
||||
setNickNameURL = "https://api.weixin.qq.com/wxa/setnickname"
|
||||
setSignatureURL = "https://api.weixin.qq.com/cgi-bin/account/modifysignature"
|
||||
setHeadImageURL = "https://api.weixin.qq.com/cgi-bin/account/modifyheadimage"
|
||||
getSearchStatusURL = "https://api.weixin.qq.com/wxa/getwxasearchstatus"
|
||||
setSearchStatusURL = "https://api.weixin.qq.com/wxa/changewxasearchstatus"
|
||||
)
|
||||
|
||||
// Basic 基础信息设置
|
||||
@@ -47,7 +53,185 @@ func (basic *Basic) GetAccountBasicInfo() (*AccountBasicInfo, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// modify_domain设置服务器域名
|
||||
// modify_domain 设置服务器域名
|
||||
// TODO
|
||||
// func (encryptor *Basic) modifyDomain() {
|
||||
// }
|
||||
|
||||
// CheckNickNameResp 小程序名称检测结果
|
||||
type CheckNickNameResp struct {
|
||||
util.CommonError
|
||||
HitCondition bool `json:"hit_condition"` // 是否命中关键字策略。若命中,可以选填关键字材料
|
||||
Wording string `json:"wording"` // 命中关键字的说明描述
|
||||
}
|
||||
|
||||
// CheckNickName 检测微信认证的名称是否符合规则
|
||||
// ref: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/basic-info-management/checkNickName.html
|
||||
func (basic *Basic) CheckNickName(nickname string) (*CheckNickNameResp, error) {
|
||||
ak, err := basic.GetAuthrAccessToken(basic.AppID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
url := fmt.Sprintf("%s?access_token=%s", checkNickNameURL, ak)
|
||||
data, err := util.PostJSON(url, map[string]string{
|
||||
"nick_name": nickname,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := &CheckNickNameResp{}
|
||||
err = util.DecodeWithError(data, res, "CheckNickName")
|
||||
return res, err
|
||||
}
|
||||
|
||||
// SetNickNameResp 设置小程序名称结果
|
||||
type SetNickNameResp struct {
|
||||
util.CommonError
|
||||
AuditID int64 `json:"audit_id"` // 审核单 Id,通过用于查询改名审核状态
|
||||
Wording string `json:"wording"` // 材料说明
|
||||
}
|
||||
|
||||
// SetNickNameParam 设置小程序名称参数
|
||||
type SetNickNameParam struct {
|
||||
NickName string `json:"nick_name"` // 昵称,不支持包含“小程序”关键字的昵称
|
||||
IDCard string `json:"id_card,omitempty"` // 身份证照片 mediaid,个人号必填
|
||||
License string `json:"license,omitempty"` // 组织机构代码证或营业执照 mediaid,组织号必填
|
||||
NameingOtherStuff1 string `json:"naming_other_stuff_1,omitempty"` // 其他证明材料 mediaid,选填
|
||||
NameingOtherStuff2 string `json:"naming_other_stuff_2,omitempty"` // 其他证明材料 mediaid,选填
|
||||
NameingOtherStuff3 string `json:"naming_other_stuff_3,omitempty"` // 其他证明材料 mediaid,选填
|
||||
NameingOtherStuff4 string `json:"naming_other_stuff_4,omitempty"` // 其他证明材料 mediaid,选填
|
||||
NameingOtherStuff5 string `json:"naming_other_stuff_5,omitempty"` // 其他证明材料 mediaid,选填
|
||||
}
|
||||
|
||||
// SetNickName 设置小程序名称
|
||||
func (basic *Basic) SetNickName(nickname string) (*SetNickNameResp, error) {
|
||||
return basic.SetNickNameFull(&SetNickNameParam{
|
||||
NickName: nickname,
|
||||
})
|
||||
}
|
||||
|
||||
// SetNickNameFull 设置小程序名称
|
||||
// ref: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/basic-info-management/setNickName.html
|
||||
func (basic *Basic) SetNickNameFull(param *SetNickNameParam) (*SetNickNameResp, error) {
|
||||
ak, err := basic.GetAuthrAccessToken(basic.AppID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
url := fmt.Sprintf("%s?access_token=%s", setNickNameURL, ak)
|
||||
data, err := util.PostJSON(url, param)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := &SetNickNameResp{}
|
||||
err = util.DecodeWithError(data, res, "SetNickName")
|
||||
return res, err
|
||||
}
|
||||
|
||||
// SetSignatureResp 小程序功能介绍修改结果
|
||||
type SetSignatureResp struct {
|
||||
util.CommonError
|
||||
}
|
||||
|
||||
// SetSignature 小程序修改功能介绍
|
||||
// ref: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/basic-info-management/setSignature.html
|
||||
func (basic *Basic) SetSignature(signature string) error {
|
||||
ak, err := basic.GetAuthrAccessToken(basic.AppID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
url := fmt.Sprintf("%s?access_token=%s", setSignatureURL, ak)
|
||||
data, err := util.PostJSON(url, map[string]string{
|
||||
"signature": signature,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithError(data, &SetSignatureResp{}, "SetSignature")
|
||||
}
|
||||
|
||||
// GetSearchStatusResp 查询小程序当前是否可被搜索
|
||||
type GetSearchStatusResp struct {
|
||||
util.CommonError
|
||||
Status int `json:"status"` // 1 表示不可搜索,0 表示可搜索
|
||||
}
|
||||
|
||||
// GetSearchStatus 查询小程序当前是否可被搜索
|
||||
// ref: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/basic-info-management/getSearchStatus.html
|
||||
func (basic *Basic) GetSearchStatus(signature string) (*GetSearchStatusResp, error) {
|
||||
ak, err := basic.GetAuthrAccessToken(basic.AppID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
url := fmt.Sprintf("%s?access_token=%s", getSearchStatusURL, ak)
|
||||
data, err := util.HTTPGet(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := &GetSearchStatusResp{}
|
||||
err = util.DecodeWithError(data, res, "GetSearchStatus")
|
||||
return res, err
|
||||
}
|
||||
|
||||
// SetSearchStatusResp 小程序是否可被搜索修改结果
|
||||
type SetSearchStatusResp struct {
|
||||
util.CommonError
|
||||
}
|
||||
|
||||
// SetSearchStatus 修改小程序是否可被搜索
|
||||
// status: 1 表示不可搜索,0 表示可搜索
|
||||
// ref: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/basic-info-management/setSearchStatus.html
|
||||
func (basic *Basic) SetSearchStatus(status int) error {
|
||||
ak, err := basic.GetAuthrAccessToken(basic.AppID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
url := fmt.Sprintf("%s?access_token=%s", setSearchStatusURL, ak)
|
||||
data, err := util.PostJSON(url, map[string]int{
|
||||
"status": status,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithError(data, &SetSearchStatusResp{}, "SetSearchStatus")
|
||||
}
|
||||
|
||||
// SetHeadImageResp 小程序头像修改结果
|
||||
type SetHeadImageResp struct {
|
||||
util.CommonError
|
||||
}
|
||||
|
||||
// SetHeadImageParam 小程序头像修改参数
|
||||
type SetHeadImageParam struct {
|
||||
HeadImageMediaID string `json:"head_img_media_id"` // 头像素材 media_id
|
||||
X1 string `json:"x1"` // 裁剪框左上角 x 坐标(取值范围:[0, 1])
|
||||
Y1 string `json:"y1"` // 裁剪框左上角 y 坐标(取值范围:[0, 1])
|
||||
X2 string `json:"x2"` // 裁剪框右下角 x 坐标(取值范围:[0, 1])
|
||||
Y2 string `json:"y2"` // 裁剪框右下角 y 坐标(取值范围:[0, 1])
|
||||
}
|
||||
|
||||
// SetHeadImage 修改小程序头像
|
||||
func (basic *Basic) SetHeadImage(imgMediaID string) error {
|
||||
return basic.SetHeadImageFull(&SetHeadImageParam{
|
||||
HeadImageMediaID: imgMediaID,
|
||||
X1: "0",
|
||||
Y1: "0",
|
||||
X2: "1",
|
||||
Y2: "1",
|
||||
})
|
||||
}
|
||||
|
||||
// SetHeadImageFull 修改小程序头像
|
||||
// 新增临时素材:https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html
|
||||
// ref: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/basic-info-management/setHeadImage.html
|
||||
func (basic *Basic) SetHeadImageFull(param *SetHeadImageParam) error {
|
||||
ak, err := basic.GetAuthrAccessToken(basic.AppID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
url := fmt.Sprintf("%s?access_token=%s", setHeadImageURL, ak)
|
||||
data, err := util.PostJSON(url, param)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return util.DecodeWithError(data, &SetHeadImageResp{}, "account/setheadimage")
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func NewComponent(opContext *openContext.Context) *Component {
|
||||
type RegisterMiniProgramParam struct {
|
||||
Name string `json:"name"` // 企业名
|
||||
Code string `json:"code"` // 企业代码
|
||||
CodeType string `json:"code_type"` // 企业代码类型 1:统一社会信用代码(18 位) 2:组织机构代码(9 位 xxxxxxxx-x) 3:营业执照注册号(15 位)
|
||||
CodeType string `json:"code_type"` // 企业代码类型 1:统一社会信用代码(18 位)2:组织机构代码(9 位 xxxxxxxx-x)3:营业执照注册号 (15 位)
|
||||
LegalPersonaWechat string `json:"legal_persona_wechat"` // 法人微信号
|
||||
LegalPersonaName string `json:"legal_persona_name"` // 法人姓名(绑定银行卡)
|
||||
ComponentPhone string `json:"component_phone"` // 第三方联系电话(方便法人与第三方联系)
|
||||
@@ -54,7 +54,7 @@ type GetRegistrationStatusParam struct {
|
||||
|
||||
}
|
||||
|
||||
// GetRegistrationStatus 查询创建任务状态.
|
||||
// GetRegistrationStatus 查询创建任务状态。
|
||||
func (component *Component) GetRegistrationStatus(param *GetRegistrationStatusParam) error {
|
||||
componentAK, err := component.GetComponentAccessToken()
|
||||
if err != nil {
|
||||
|
||||
@@ -21,7 +21,7 @@ type MiniProgram struct {
|
||||
authorizerRefreshToken string
|
||||
}
|
||||
|
||||
// GetAccessToken 获取ak
|
||||
// GetAccessToken 获取 ak
|
||||
func (miniProgram *MiniProgram) GetAccessToken() (string, error) {
|
||||
ak, akErr := miniProgram.openContext.GetAuthrAccessToken(miniProgram.AppID)
|
||||
if akErr == nil {
|
||||
@@ -37,7 +37,7 @@ func (miniProgram *MiniProgram) GetAccessToken() (string, error) {
|
||||
return akRes.AccessToken, nil
|
||||
}
|
||||
|
||||
// SetAuthorizerRefreshToken 设置代执操作业务授权账号authorizer_refresh_token
|
||||
// SetAuthorizerRefreshToken 设置代执操作业务授权账号 authorizer_refresh_token
|
||||
func (miniProgram *MiniProgram) SetAuthorizerRefreshToken(authorizerRefreshToken string) *MiniProgram {
|
||||
miniProgram.authorizerRefreshToken = authorizerRefreshToken
|
||||
return miniProgram
|
||||
@@ -49,7 +49,7 @@ func NewMiniProgram(opCtx *openContext.Context, appID string) *MiniProgram {
|
||||
AppID: opCtx.AppID,
|
||||
Cache: opCtx.Cache,
|
||||
})
|
||||
// 设置获取access_token的函数
|
||||
// 设置获取 access_token 的函数
|
||||
miniProgram.SetAccessTokenHandle(NewDefaultAuthrAccessToken(opCtx, appID))
|
||||
return &MiniProgram{AppID: appID, MiniProgram: miniProgram, openContext: opCtx}
|
||||
}
|
||||
@@ -65,20 +65,20 @@ func (miniProgram *MiniProgram) GetBasic() *basic.Basic {
|
||||
return basic.NewBasic(miniProgram.openContext, miniProgram.AppID)
|
||||
}
|
||||
|
||||
// GetURLLink 小程序URL Link接口 调用前需确认已调用 SetAuthorizerRefreshToken 避免由于缓存中 authorizer_access_token 过期执行中断
|
||||
// GetURLLink 小程序 URL Link 接口 调用前需确认已调用 SetAuthorizerRefreshToken 避免由于缓存中 authorizer_access_token 过期执行中断
|
||||
func (miniProgram *MiniProgram) GetURLLink() *urllink.URLLink {
|
||||
return urllink.NewURLLink(&miniContext.Context{
|
||||
AccessTokenHandle: miniProgram,
|
||||
})
|
||||
}
|
||||
|
||||
// DefaultAuthrAccessToken 默认获取授权ak的方法
|
||||
// DefaultAuthrAccessToken 默认获取授权 ak 的方法
|
||||
type DefaultAuthrAccessToken struct {
|
||||
opCtx *openContext.Context
|
||||
appID string
|
||||
}
|
||||
|
||||
// NewDefaultAuthrAccessToken 设置access_token
|
||||
// NewDefaultAuthrAccessToken 设置 access_token
|
||||
func NewDefaultAuthrAccessToken(opCtx *openContext.Context, appID string) credential.AccessTokenHandle {
|
||||
return &DefaultAuthrAccessToken{
|
||||
opCtx: opCtx,
|
||||
@@ -86,7 +86,7 @@ func NewDefaultAuthrAccessToken(opCtx *openContext.Context, appID string) creden
|
||||
}
|
||||
}
|
||||
|
||||
// GetAccessToken 获取ak
|
||||
// GetAccessToken 获取 ak
|
||||
func (ak *DefaultAuthrAccessToken) GetAccessToken() (string, error) {
|
||||
return ak.opCtx.GetAuthrAccessToken(ak.appID)
|
||||
}
|
||||
|
||||
@@ -24,12 +24,12 @@ func NewJs(context *context.Context, appID string) *Js {
|
||||
return js
|
||||
}
|
||||
|
||||
// SetJsTicketHandle 自定义js ticket取值方式
|
||||
// SetJsTicketHandle 自定义 js ticket 取值方式
|
||||
func (js *Js) SetJsTicketHandle(ticketHandle credential.JsTicketHandle) {
|
||||
js.JsTicketHandle = ticketHandle
|
||||
}
|
||||
|
||||
// GetConfig 第三方平台 - 获取jssdk需要的配置参数
|
||||
// GetConfig 第三方平台 - 获取 jssdk 需要的配置参数
|
||||
// uri 为当前网页地址
|
||||
func (js *Js) GetConfig(uri, appid string) (config *officialJs.Config, err error) {
|
||||
config = new(officialJs.Config)
|
||||
|
||||
@@ -16,19 +16,19 @@ const (
|
||||
platformAccessTokenURL = "https://api.weixin.qq.com/sns/oauth2/component/access_token?appid=%s&code=%s&grant_type=authorization_code&component_appid=%s&component_access_token=%s"
|
||||
)
|
||||
|
||||
// Oauth 平台代发起oauth2网页授权
|
||||
// Oauth 平台代发起 oauth2 网页授权
|
||||
type Oauth struct {
|
||||
*context.Context
|
||||
}
|
||||
|
||||
// NewOauth 实例化平台代发起oauth2网页授权
|
||||
// NewOauth 实例化平台代发起 oauth2 网页授权
|
||||
func NewOauth(context *context.Context) *Oauth {
|
||||
auth := new(Oauth)
|
||||
auth.Context = context
|
||||
return auth
|
||||
}
|
||||
|
||||
// GetRedirectURL 第三方平台 - 获取跳转的url地址
|
||||
// GetRedirectURL 第三方平台 - 获取跳转的 url 地址
|
||||
func (oauth *Oauth) GetRedirectURL(redirectURI, scope, state, appID string) (string, error) {
|
||||
// url encode
|
||||
urlStr := url.QueryEscape(redirectURI)
|
||||
@@ -45,7 +45,7 @@ func (oauth *Oauth) Redirect(writer http.ResponseWriter, req *http.Request, redi
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUserAccessToken 第三方平台 - 通过网页授权的code 换取access_token(区别于context中的access_token)
|
||||
// GetUserAccessToken 第三方平台 - 通过网页授权的 code 换取 access_token(区别于 context 中的 access_token)
|
||||
func (oauth *Oauth) GetUserAccessToken(code, appID, componentAccessToken string) (result officialOauth.ResAccessToken, err error) {
|
||||
urlStr := fmt.Sprintf(platformAccessTokenURL, appID, code, oauth.AppID, componentAccessToken)
|
||||
var response []byte
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
// OfficialAccount 代公众号实现业务
|
||||
type OfficialAccount struct {
|
||||
// 授权的公众号的appID
|
||||
// 授权的公众号的 appID
|
||||
appID string
|
||||
*officialaccount.OfficialAccount
|
||||
}
|
||||
@@ -25,22 +25,22 @@ func NewOfficialAccount(opCtx *opContext.Context, appID string) *OfficialAccount
|
||||
Token: opCtx.Token,
|
||||
Cache: opCtx.Cache,
|
||||
})
|
||||
// 设置获取access_token的函数
|
||||
// 设置获取 access_token 的函数
|
||||
officialAccount.SetAccessTokenHandle(NewDefaultAuthrAccessToken(opCtx, appID))
|
||||
return &OfficialAccount{appID: appID, OfficialAccount: officialAccount}
|
||||
}
|
||||
|
||||
// PlatformOauth 平台代发起oauth2网页授权
|
||||
// PlatformOauth 平台代发起 oauth2 网页授权
|
||||
func (officialAccount *OfficialAccount) PlatformOauth() *oauth.Oauth {
|
||||
return oauth.NewOauth(officialAccount.GetContext())
|
||||
}
|
||||
|
||||
// PlatformJs 平台代获取js-sdk配置
|
||||
// PlatformJs 平台代获取 js-sdk 配置
|
||||
func (officialAccount *OfficialAccount) PlatformJs() *js.Js {
|
||||
return js.NewJs(officialAccount.GetContext(), officialAccount.appID)
|
||||
}
|
||||
|
||||
// DefaultAuthrAccessToken 默认获取授权ak的方法
|
||||
// DefaultAuthrAccessToken 默认获取授权 ak 的方法
|
||||
type DefaultAuthrAccessToken struct {
|
||||
opCtx *opContext.Context
|
||||
appID string
|
||||
@@ -54,7 +54,7 @@ func NewDefaultAuthrAccessToken(opCtx *opContext.Context, appID string) credenti
|
||||
}
|
||||
}
|
||||
|
||||
// GetAccessToken 获取ak
|
||||
// GetAccessToken 获取 ak
|
||||
func (ak *DefaultAuthrAccessToken) GetAccessToken() (string, error) {
|
||||
return ak.opCtx.GetAuthrAccessToken(ak.appID)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/silenceper/wechat/v2/openplatform/officialaccount"
|
||||
)
|
||||
|
||||
// OpenPlatform 微信开放平台相关api
|
||||
// OpenPlatform 微信开放平台相关 api
|
||||
type OpenPlatform struct {
|
||||
*context.Context
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func (notify *Notify) PaidVerifySign(notifyRes PaidResult) bool {
|
||||
}
|
||||
sort.Strings(sortedKeys)
|
||||
|
||||
// STEP2, 对key=value的键值对用&连接起来,略过空值 & sign
|
||||
// STEP2, 对 key=value 的键值对用&连接起来,略过空值 & sign
|
||||
var signStrings string
|
||||
for _, k := range sortedKeys {
|
||||
value := fmt.Sprintf("%v", cast.ToString(resMap[k]))
|
||||
@@ -84,10 +84,10 @@ func (notify *Notify) PaidVerifySign(notifyRes PaidResult) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// STEP3, 在键值对的最后加上key=API_KEY
|
||||
// STEP3, 在键值对的最后加上 key=API_KEY
|
||||
signStrings = signStrings + "key=" + notify.Key
|
||||
|
||||
// STEP4, 根据SignType计算出签名
|
||||
// STEP4, 根据 SignType 计算出签名
|
||||
var signType string
|
||||
if notifyRes.SignType != nil {
|
||||
signType = *notifyRes.SignType
|
||||
|
||||
@@ -18,7 +18,7 @@ type CloseParams struct {
|
||||
|
||||
// closeRequest 接口请求参数
|
||||
type closeRequest struct {
|
||||
AppID string `xml:"appid"` // 公众账号ID
|
||||
AppID string `xml:"appid"` // 公众账号 ID
|
||||
MchID string `xml:"mch_id"` // 商户号
|
||||
NonceStr string `xml:"nonce_str"` // 随机字符串
|
||||
Sign string `xml:"sign"` // 签名
|
||||
|
||||
@@ -35,7 +35,7 @@ type Params struct {
|
||||
CreateIP string
|
||||
Body string
|
||||
OutTradeNo string
|
||||
TimeExpire string // 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。
|
||||
TimeExpire string // 订单失效时间,格式为 yyyyMMddHHmmss,如 2009 年 12 月 27 日 9 点 10 分 10 秒表示为 20091227091010。
|
||||
OpenID string
|
||||
TradeType string
|
||||
SignType string
|
||||
@@ -85,7 +85,7 @@ type PreOrder struct {
|
||||
|
||||
// payRequest 接口请求参数
|
||||
type payRequest struct {
|
||||
AppID string `xml:"appid"` // 公众账号ID
|
||||
AppID string `xml:"appid"` // 公众账号 ID
|
||||
MchID string `xml:"mch_id"` // 商户号
|
||||
DeviceInfo string `xml:"device_info,omitempty"` // 设备号
|
||||
NonceStr string `xml:"nonce_str"` // 随机字符串
|
||||
@@ -97,13 +97,13 @@ type payRequest struct {
|
||||
OutTradeNo string `xml:"out_trade_no"` // 商户订单号
|
||||
FeeType string `xml:"fee_type,omitempty"` // 标价币种
|
||||
TotalFee string `xml:"total_fee"` // 标价金额
|
||||
SpbillCreateIP string `xml:"spbill_create_ip"` // 终端IP
|
||||
SpbillCreateIP string `xml:"spbill_create_ip"` // 终端 IP
|
||||
TimeStart string `xml:"time_start,omitempty"` // 交易起始时间
|
||||
TimeExpire string `xml:"time_expire,omitempty"` // 交易结束时间
|
||||
GoodsTag string `xml:"goods_tag,omitempty"` // 订单优惠标记
|
||||
NotifyURL string `xml:"notify_url"` // 通知地址
|
||||
TradeType string `xml:"trade_type"` // 交易类型
|
||||
ProductID string `xml:"product_id,omitempty"` // 商品ID
|
||||
ProductID string `xml:"product_id,omitempty"` // 商品 ID
|
||||
LimitPay string `xml:"limit_pay,omitempty"` // 指定支付方式
|
||||
OpenID string `xml:"openid,omitempty"` // 用户标识
|
||||
SceneInfo string `xml:"scene_info,omitempty"` // 场景信息
|
||||
@@ -213,7 +213,7 @@ func (o *Order) PrePayOrder(p *Params) (payOrder PreOrder, err error) {
|
||||
|
||||
// 通知地址
|
||||
if len(p.NotifyURL) == 0 {
|
||||
p.NotifyURL = o.NotifyURL // 默认使用order.NotifyURL
|
||||
p.NotifyURL = o.NotifyURL // 默认使用 order.NotifyURL
|
||||
}
|
||||
|
||||
// 签名类型
|
||||
|
||||
@@ -19,7 +19,7 @@ type QueryParams struct {
|
||||
|
||||
// queryRequest 接口请求参数
|
||||
type queryRequest struct {
|
||||
AppID string `xml:"appid"` // 公众账号ID
|
||||
AppID string `xml:"appid"` // 公众账号 ID
|
||||
MchID string `xml:"mch_id"` // 商户号
|
||||
NonceStr string `xml:"nonce_str"` // 随机字符串
|
||||
Sign string `xml:"sign"` // 签名
|
||||
|
||||
10
pay/pay.go
10
pay/pay.go
@@ -4,16 +4,17 @@ import (
|
||||
"github.com/silenceper/wechat/v2/pay/config"
|
||||
"github.com/silenceper/wechat/v2/pay/notify"
|
||||
"github.com/silenceper/wechat/v2/pay/order"
|
||||
"github.com/silenceper/wechat/v2/pay/redpacket"
|
||||
"github.com/silenceper/wechat/v2/pay/refund"
|
||||
"github.com/silenceper/wechat/v2/pay/transfer"
|
||||
)
|
||||
|
||||
// Pay 微信支付相关API
|
||||
// Pay 微信支付相关 API
|
||||
type Pay struct {
|
||||
cfg *config.Config
|
||||
}
|
||||
|
||||
// NewPay 实例化微信支付相关API
|
||||
// NewPay 实例化微信支付相关 API
|
||||
func NewPay(cfg *config.Config) *Pay {
|
||||
return &Pay{cfg}
|
||||
}
|
||||
@@ -37,3 +38,8 @@ func (pay *Pay) GetRefund() *refund.Refund {
|
||||
func (pay *Pay) GetTransfer() *transfer.Transfer {
|
||||
return transfer.NewTransfer(pay.cfg)
|
||||
}
|
||||
|
||||
// GetRedpacket 红包
|
||||
func (pay *Pay) GetRedpacket() *redpacket.Redpacket {
|
||||
return redpacket.NewRedpacket(pay.cfg)
|
||||
}
|
||||
|
||||
131
pay/redpacket/redpacket.go
Normal file
131
pay/redpacket/redpacket.go
Normal file
@@ -0,0 +1,131 @@
|
||||
package redpacket
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/silenceper/wechat/v2/pay/config"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
// redpacketGateway 发放红包接口
|
||||
// https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
|
||||
var redpacketGateway = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"
|
||||
|
||||
// Redpacket struct extends context
|
||||
type Redpacket struct {
|
||||
*config.Config
|
||||
}
|
||||
|
||||
// NewRedpacket return an instance of Redpacket package
|
||||
func NewRedpacket(cfg *config.Config) *Redpacket {
|
||||
return &Redpacket{cfg}
|
||||
}
|
||||
|
||||
// Params 调用参数
|
||||
type Params struct {
|
||||
MchBillno string // 商户订单号
|
||||
SendName string // 商户名称
|
||||
ReOpenID string
|
||||
TotalAmount int
|
||||
TotalNum int
|
||||
Wishing string
|
||||
ClientIP string
|
||||
ActName string
|
||||
Remark string
|
||||
|
||||
RootCa string // ca 证书
|
||||
}
|
||||
|
||||
// request 接口请求参数
|
||||
type request struct {
|
||||
NonceStr string `xml:"nonce_str"`
|
||||
Sign string `xml:"sign"`
|
||||
MchID string `xml:"mch_id"`
|
||||
MchBillno string `xml:"mch_billno"`
|
||||
Wxappid string `xml:"wxappid"`
|
||||
SendName string `xml:"send_name"`
|
||||
ReOpenID string `xml:"re_openid"`
|
||||
TotalAmount int `xml:"total_amount"`
|
||||
TotalNum int `xml:"total_num"`
|
||||
Wishing string `xml:"wishing"`
|
||||
ClientIP string `xml:"client_ip"`
|
||||
ActName string `xml:"act_name"`
|
||||
Remark string `xml:"remark"`
|
||||
}
|
||||
|
||||
// Response 接口返回
|
||||
type Response struct {
|
||||
ReturnCode string `xml:"return_code"`
|
||||
ReturnMsg string `xml:"return_msg"`
|
||||
ResultCode string `xml:"result_code,omitempty"`
|
||||
ErrCode string `xml:"err_code,omitempty"`
|
||||
ErrCodeDes string `xml:"err_code_des,omitempty"`
|
||||
MchBillno string `xml:"mch_billno,omitempty"`
|
||||
MchID string `xml:"mch_id,omitempty"`
|
||||
Wxappid string `xml:"wxappid"`
|
||||
ReOpenID string `xml:"re_openid"`
|
||||
TotalAmount int `xml:"total_amount"`
|
||||
SendListid string `xml:"send_listid"`
|
||||
}
|
||||
|
||||
// SendRedpacket 发放红包
|
||||
func (redpacket *Redpacket) SendRedpacket(p *Params) (rsp *Response, err error) {
|
||||
nonceStr := util.RandomStr(32)
|
||||
param := make(map[string]string)
|
||||
|
||||
param["nonce_str"] = nonceStr
|
||||
param["mch_id"] = redpacket.MchID
|
||||
param["wxappid"] = redpacket.AppID
|
||||
param["mch_billno"] = p.MchBillno
|
||||
param["send_name"] = p.SendName
|
||||
param["re_openid"] = p.ReOpenID
|
||||
param["total_amount"] = strconv.Itoa(p.TotalAmount)
|
||||
param["total_num"] = strconv.Itoa(p.TotalNum)
|
||||
param["wishing"] = p.Wishing
|
||||
param["client_ip"] = p.ClientIP
|
||||
param["act_name"] = p.ActName
|
||||
param["remark"] = p.Remark
|
||||
//param["scene_id"] = "PRODUCT_2"
|
||||
|
||||
sign, err := util.ParamSign(param, redpacket.Key)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
req := request{
|
||||
NonceStr: nonceStr,
|
||||
Sign: sign,
|
||||
MchID: redpacket.MchID,
|
||||
Wxappid: redpacket.AppID,
|
||||
MchBillno: p.MchBillno,
|
||||
SendName: p.SendName,
|
||||
ReOpenID: p.ReOpenID,
|
||||
TotalAmount: p.TotalAmount,
|
||||
TotalNum: p.TotalNum,
|
||||
Wishing: p.Wishing,
|
||||
ClientIP: p.ClientIP,
|
||||
ActName: p.ActName,
|
||||
Remark: p.Remark,
|
||||
}
|
||||
|
||||
rawRet, err := util.PostXMLWithTLS(redpacketGateway, req, p.RootCa, redpacket.MchID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = xml.Unmarshal(rawRet, &rsp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if rsp.ReturnCode == "SUCCESS" {
|
||||
if rsp.ResultCode == "SUCCESS" {
|
||||
err = nil
|
||||
return
|
||||
}
|
||||
err = fmt.Errorf("send redpacket error, errcode=%s,errmsg=%s", rsp.ErrCode, rsp.ErrCodeDes)
|
||||
return
|
||||
}
|
||||
err = fmt.Errorf("[msg : xmlUnmarshalError] [rawReturn : %s] [sign : %s]", string(rawRet), sign)
|
||||
return
|
||||
}
|
||||
@@ -29,7 +29,7 @@ type Params struct {
|
||||
TotalFee string
|
||||
RefundFee string
|
||||
RefundDesc string
|
||||
RootCa string // ca证书
|
||||
RootCa string // ca 证书
|
||||
NotifyURL string
|
||||
SignType string
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ type Params struct {
|
||||
Amount int
|
||||
Desc string
|
||||
SpbillCreateIP string
|
||||
RootCa string // ca证书
|
||||
RootCa string // ca 证书
|
||||
}
|
||||
|
||||
// request 接口请求参数
|
||||
|
||||
@@ -44,7 +44,7 @@ func EncryptMsg(random, rawXMLMsg []byte, appID, aesKey string) (encrtptMsg []by
|
||||
func AESEncryptMsg(random, rawXMLMsg []byte, appID string, aesKey []byte) (ciphertext []byte) {
|
||||
const (
|
||||
BlockSize = 32 // PKCS#7
|
||||
BlockMask = BlockSize - 1 // BLOCK_SIZE 为 2^n 时, 可以用 mask 获取针对 BLOCK_SIZE 的余数
|
||||
BlockMask = BlockSize - 1 // BLOCK_SIZE 为 2^n 时,可以用 mask 获取针对 BLOCK_SIZE 的余数
|
||||
)
|
||||
|
||||
appIDOffset := 20 + len(rawXMLMsg)
|
||||
@@ -100,7 +100,7 @@ func DecryptMsg(appID, encryptedMsg, aesKey string) (random, rawMsgXMLBytes []by
|
||||
return
|
||||
}
|
||||
if appID != string(getAppIDBytes) {
|
||||
err = fmt.Errorf("消息解密校验APPID失败")
|
||||
err = fmt.Errorf("消息解密校验 APPID 失败")
|
||||
return
|
||||
}
|
||||
return
|
||||
@@ -127,7 +127,7 @@ func aesKeyDecode(encodedAESKey string) (key []byte, err error) {
|
||||
func AESDecryptMsg(ciphertext []byte, aesKey []byte) (random, rawXMLMsg, appID []byte, err error) {
|
||||
const (
|
||||
BlockSize = 32 // PKCS#7
|
||||
BlockMask = BlockSize - 1 // BLOCK_SIZE 为 2^n 时, 可以用 mask 获取针对 BLOCK_SIZE 的余数
|
||||
BlockMask = BlockSize - 1 // BLOCK_SIZE 为 2^n 时,可以用 mask 获取针对 BLOCK_SIZE 的余数
|
||||
)
|
||||
|
||||
if len(ciphertext) < BlockSize {
|
||||
|
||||
100
util/http.go
100
util/http.go
@@ -17,6 +17,19 @@ import (
|
||||
"golang.org/x/crypto/pkcs12"
|
||||
)
|
||||
|
||||
// URIModifier URI 修改器
|
||||
type URIModifier func(uri string) string
|
||||
|
||||
var uriModifier URIModifier
|
||||
|
||||
// DefaultHTTPClient 默认 httpClient
|
||||
var DefaultHTTPClient = http.DefaultClient
|
||||
|
||||
// SetURIModifier 设置 URI 修改器
|
||||
func SetURIModifier(fn URIModifier) {
|
||||
uriModifier = fn
|
||||
}
|
||||
|
||||
// HTTPGet get 请求
|
||||
func HTTPGet(uri string) ([]byte, error) {
|
||||
return HTTPGetContext(context.Background(), uri)
|
||||
@@ -24,11 +37,14 @@ func HTTPGet(uri string) ([]byte, error) {
|
||||
|
||||
// HTTPGetContext get 请求
|
||||
func HTTPGetContext(ctx context.Context, uri string) ([]byte, error) {
|
||||
if uriModifier != nil {
|
||||
uri = uriModifier(uri)
|
||||
}
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response, err := http.DefaultClient.Do(request)
|
||||
response, err := DefaultHTTPClient.Do(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -47,6 +63,9 @@ func HTTPPost(uri string, data string) ([]byte, error) {
|
||||
|
||||
// HTTPPostContext post 请求
|
||||
func HTTPPostContext(ctx context.Context, uri string, data []byte, header map[string]string) ([]byte, error) {
|
||||
if uriModifier != nil {
|
||||
uri = uriModifier(uri)
|
||||
}
|
||||
body := bytes.NewBuffer(data)
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, body)
|
||||
if err != nil {
|
||||
@@ -57,7 +76,7 @@ func HTTPPostContext(ctx context.Context, uri string, data []byte, header map[st
|
||||
request.Header.Set(key, value)
|
||||
}
|
||||
|
||||
response, err := http.DefaultClient.Do(request)
|
||||
response, err := DefaultHTTPClient.Do(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -71,6 +90,9 @@ func HTTPPostContext(ctx context.Context, uri string, data []byte, header map[st
|
||||
|
||||
// PostJSONContext post json 数据请求
|
||||
func PostJSONContext(ctx context.Context, uri string, obj interface{}) ([]byte, error) {
|
||||
if uriModifier != nil {
|
||||
uri = uriModifier(uri)
|
||||
}
|
||||
jsonBuf := new(bytes.Buffer)
|
||||
enc := json.NewEncoder(jsonBuf)
|
||||
enc.SetEscapeHTML(false)
|
||||
@@ -83,7 +105,7 @@ func PostJSONContext(ctx context.Context, uri string, obj interface{}) ([]byte,
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json;charset=utf-8")
|
||||
response, err := http.DefaultClient.Do(req)
|
||||
response, err := DefaultHTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -110,7 +132,7 @@ func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, e
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
response, err := http.Post(uri, "application/json;charset=utf-8", jsonBuf)
|
||||
response, err := DefaultHTTPClient.Post(uri, "application/json;charset=utf-8", jsonBuf)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -136,16 +158,33 @@ func PostFile(fieldName, filename, uri string) ([]byte, error) {
|
||||
return PostMultipartForm(fields, uri)
|
||||
}
|
||||
|
||||
// PostFileFromReader 上传文件,从 io.Reader 中读取
|
||||
func PostFileFromReader(filedName, fileName, uri string, reader io.Reader) ([]byte, error) {
|
||||
fields := []MultipartFormField{
|
||||
{
|
||||
IsFile: true,
|
||||
Fieldname: filedName,
|
||||
Filename: fileName,
|
||||
FileReader: reader,
|
||||
},
|
||||
}
|
||||
return PostMultipartForm(fields, uri)
|
||||
}
|
||||
|
||||
// MultipartFormField 保存文件或其他字段信息
|
||||
type MultipartFormField struct {
|
||||
IsFile bool
|
||||
Fieldname string
|
||||
Value []byte
|
||||
Filename string
|
||||
IsFile bool
|
||||
Fieldname string
|
||||
Value []byte
|
||||
Filename string
|
||||
FileReader io.Reader
|
||||
}
|
||||
|
||||
// PostMultipartForm 上传文件或其他多个字段
|
||||
func PostMultipartForm(fields []MultipartFormField, uri string) (respBody []byte, err error) {
|
||||
if uriModifier != nil {
|
||||
uri = uriModifier(uri)
|
||||
}
|
||||
bodyBuf := &bytes.Buffer{}
|
||||
bodyWriter := multipart.NewWriter(bodyBuf)
|
||||
|
||||
@@ -157,15 +196,21 @@ func PostMultipartForm(fields []MultipartFormField, uri string) (respBody []byte
|
||||
return
|
||||
}
|
||||
|
||||
fh, e := os.Open(field.Filename)
|
||||
if e != nil {
|
||||
err = fmt.Errorf("error opening file , err=%v", e)
|
||||
return
|
||||
}
|
||||
defer fh.Close()
|
||||
|
||||
if _, err = io.Copy(fileWriter, fh); err != nil {
|
||||
return
|
||||
if field.FileReader == nil {
|
||||
fh, e := os.Open(field.Filename)
|
||||
if e != nil {
|
||||
err = fmt.Errorf("error opening file , err=%v", e)
|
||||
return
|
||||
}
|
||||
_, err = io.Copy(fileWriter, fh)
|
||||
_ = fh.Close()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if _, err = io.Copy(fileWriter, field.FileReader); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
} else {
|
||||
partWriter, e := bodyWriter.CreateFormField(field.Fieldname)
|
||||
@@ -183,14 +228,14 @@ func PostMultipartForm(fields []MultipartFormField, uri string) (respBody []byte
|
||||
contentType := bodyWriter.FormDataContentType()
|
||||
bodyWriter.Close()
|
||||
|
||||
resp, e := http.Post(uri, contentType, bodyBuf)
|
||||
resp, e := DefaultHTTPClient.Post(uri, contentType, bodyBuf)
|
||||
if e != nil {
|
||||
err = e
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("http code error : uri=%v , statusCode=%v", uri, resp.StatusCode)
|
||||
}
|
||||
respBody, err = io.ReadAll(resp.Body)
|
||||
return
|
||||
@@ -198,13 +243,16 @@ func PostMultipartForm(fields []MultipartFormField, uri string) (respBody []byte
|
||||
|
||||
// PostXML perform a HTTP/POST request with XML body
|
||||
func PostXML(uri string, obj interface{}) ([]byte, error) {
|
||||
if uriModifier != nil {
|
||||
uri = uriModifier(uri)
|
||||
}
|
||||
xmlData, err := xml.Marshal(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
body := bytes.NewBuffer(xmlData)
|
||||
response, err := http.Post(uri, "application/xml;charset=utf-8", body)
|
||||
response, err := DefaultHTTPClient.Post(uri, "application/xml;charset=utf-8", body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -227,11 +275,10 @@ func httpWithTLS(rootCa, key string) (*http.Client, error) {
|
||||
config := &tls.Config{
|
||||
Certificates: []tls.Certificate{cert},
|
||||
}
|
||||
tr := &http.Transport{
|
||||
TLSClientConfig: config,
|
||||
DisableCompression: true,
|
||||
}
|
||||
client = &http.Client{Transport: tr}
|
||||
trans := (DefaultHTTPClient.Transport.(*http.Transport)).Clone()
|
||||
trans.TLSClientConfig = config
|
||||
trans.DisableCompression = true
|
||||
client = &http.Client{Transport: trans}
|
||||
return client, nil
|
||||
}
|
||||
|
||||
@@ -259,6 +306,9 @@ func pkcs12ToPem(p12 []byte, password string) tls.Certificate {
|
||||
|
||||
// PostXMLWithTLS perform a HTTP/POST request with XML body and TLS
|
||||
func PostXMLWithTLS(uri string, obj interface{}, ca, key string) ([]byte, error) {
|
||||
if uriModifier != nil {
|
||||
uri = uriModifier(uri)
|
||||
}
|
||||
xmlData, err := xml.Marshal(obj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Query 将Map序列化为Query参数
|
||||
// Query 将 Map 序列化为 Query 参数
|
||||
func Query(params map[string]interface{}) string {
|
||||
finalString := make([]string, 0)
|
||||
for key, value := range params {
|
||||
|
||||
@@ -12,8 +12,8 @@ func TestQuery(t *testing.T) {
|
||||
"cat": "Peter",
|
||||
})
|
||||
if result == "" {
|
||||
// 由于hash是乱序 所以没法很好的预测输出的字符串
|
||||
// 将会输出符合Query规则的字符串 "age=12&name=Alan&cat=Peter"
|
||||
// 由于 hash 是乱序 所以没法很好的预测输出的字符串
|
||||
// 将会输出符合 Query 规则的字符串 "age=12&name=Alan&cat=Peter"
|
||||
t.Error("NOT PASS")
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user