mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 12:52:27 +08:00
50
.github/workflows/go.yml
vendored
Normal file
50
.github/workflows/go.yml
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
name: Go
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master,release-* ]
|
||||
pull_request:
|
||||
branches: [ master,release-* ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
redis:
|
||||
image: redis
|
||||
ports:
|
||||
- 6379:6379
|
||||
options: --entrypoint redis-server
|
||||
memcached:
|
||||
image: memcached
|
||||
ports:
|
||||
- 11211:11211
|
||||
steps:
|
||||
|
||||
- name: Set up Go 1.x
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ^1.13
|
||||
id: go
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Get dependencies
|
||||
run: |
|
||||
go get -v -t -d ./...
|
||||
if [ -f Gopkg.toml ]; then
|
||||
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
|
||||
dep ensure
|
||||
fi
|
||||
|
||||
- name: Lint Go Code
|
||||
run: |
|
||||
export PATH=$PATH:$(go env GOPATH)/bin # temporary fix. See https://github.com/actions/setup-go/issues/14
|
||||
go get -u golang.org/x/lint/golint
|
||||
go vet ./...
|
||||
golint -set_exit_status $(go list ./...)
|
||||
|
||||
- name: Test
|
||||
run: go test -v -race ./...
|
||||
11
README.md
11
README.md
@@ -1,5 +1,5 @@
|
||||
# WeChat SDK for Go
|
||||
[](https://travis-ci.org/silenceper/wechat)
|
||||
[](https://travis-ci.org/silenceper/wechat)
|
||||
[](https://goreportcard.com/report/github.com/silenceper/wechat)
|
||||
[](http://godoc.org/github.com/silenceper/wechat)
|
||||
|
||||
@@ -44,10 +44,11 @@ server.Send()
|
||||
|
||||
```
|
||||
|
||||
## 文档
|
||||
[Wechat SDK 2.0 文档](http://silenceper.com/wechat)
|
||||
|
||||
## 参与贡献
|
||||
|
||||
### 目录说明
|
||||
## 目录说明
|
||||
- officialaccount: 微信公众号API
|
||||
- miniprogram: 小程序API
|
||||
- minigame:小游戏API
|
||||
@@ -56,6 +57,10 @@ server.Send()
|
||||
- work:企业微信
|
||||
- aispeech:智能对话
|
||||
|
||||
## 如何贡献
|
||||
- 提交issue,描述需要贡献的内容
|
||||
- 完成更改后,提交PR
|
||||
|
||||
|
||||
## License
|
||||
|
||||
|
||||
10
go.mod
10
go.mod
@@ -1,9 +1,11 @@
|
||||
module github.com/silenceper/wechat
|
||||
module github.com/silenceper/wechat/v2
|
||||
|
||||
go 1.13
|
||||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
|
||||
github.com/gomodule/redigo v2.0.0+incompatible
|
||||
golang.org/x/crypto v0.0.0-20200117160349-530e935923ad
|
||||
github.com/gomodule/redigo v1.8.1
|
||||
github.com/sirupsen/logrus v1.6.0
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
|
||||
)
|
||||
|
||||
34
go.sum
34
go.sum
@@ -1,13 +1,39 @@
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0=
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0=
|
||||
github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gomodule/redigo v1.8.1 h1:Abmo0bI7Xf0IhdIPc7HZQzZcShdnmxeoVuDDtIQp8N8=
|
||||
github.com/gomodule/redigo v1.8.1/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
|
||||
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||
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=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200117160349-530e935923ad h1:Jh8cai0fqIK+f6nG0UgPW5wFk8wmiMhM3AyciDBdtQg=
|
||||
golang.org/x/crypto v0.0.0-20200117160349-530e935923ad/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
|
||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
||||
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/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
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-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 h1:EBZoQjiKKPaLbPrbpssUfuHtwM6KV/vb4U85g/cigFY=
|
||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
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/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/miniprogram/context"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/miniprogram/context"
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package basic
|
||||
|
||||
import "github.com/silenceper/wechat/miniprogram/context"
|
||||
import "github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
|
||||
//Basic struct
|
||||
type Basic struct {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/cache"
|
||||
"github.com/silenceper/wechat/v2/cache"
|
||||
)
|
||||
|
||||
//Config config for 小程序
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -3,7 +3,7 @@ package context
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/silenceper/wechat/miniprogram/config"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/config"
|
||||
)
|
||||
|
||||
// Context struct
|
||||
|
||||
@@ -3,13 +3,13 @@ package miniprogram
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/silenceper/wechat/miniprogram/analysis"
|
||||
"github.com/silenceper/wechat/miniprogram/auth"
|
||||
"github.com/silenceper/wechat/miniprogram/basic"
|
||||
"github.com/silenceper/wechat/miniprogram/config"
|
||||
"github.com/silenceper/wechat/miniprogram/context"
|
||||
"github.com/silenceper/wechat/miniprogram/qrcode"
|
||||
"github.com/silenceper/wechat/miniprogram/tcb"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/analysis"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/auth"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/basic"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/config"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/qrcode"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/tcb"
|
||||
)
|
||||
|
||||
//MiniProgram 微信小程序相关API
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/silenceper/wechat/miniprogram/context"
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -29,4 +29,4 @@ if err != nil {
|
||||
}
|
||||
```
|
||||
|
||||
更多使用方法参考[GODOC](https://godoc.org/github.com/silenceper/wechat/tcb)
|
||||
更多使用方法参考[GODOC](https://godoc.org/github.com/silenceper/wechat/v2/tcb)
|
||||
@@ -3,7 +3,7 @@ package tcb
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -3,7 +3,7 @@ package tcb
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -3,7 +3,7 @@ package tcb
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package tcb
|
||||
|
||||
import "github.com/silenceper/wechat/miniprogram/context"
|
||||
import "github.com/silenceper/wechat/v2/miniprogram/context"
|
||||
|
||||
//Tcb Tencent Cloud Base
|
||||
type Tcb struct {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package basic
|
||||
|
||||
import "github.com/silenceper/wechat/officialaccount/context"
|
||||
import "github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
|
||||
//Basic struct
|
||||
type Basic struct {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/cache"
|
||||
"github.com/silenceper/wechat/v2/cache"
|
||||
)
|
||||
|
||||
//Config config for 微信公众号
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -3,7 +3,7 @@ package context
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount/config"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/config"
|
||||
)
|
||||
|
||||
// Context struct
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
// ReqBind 设备绑定解绑共通实体
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount/context"
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
//ResCreateQRCode 获取二维码的返回实体
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount/context"
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const getTicketURL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi"
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount/context"
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
//MediaType 媒体文件类型
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount/context"
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount/context"
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -3,7 +3,7 @@ package message
|
||||
import (
|
||||
"encoding/xml"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount/device"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/device"
|
||||
)
|
||||
|
||||
// MsgType 基本消息类型
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount/context"
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount/context"
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -4,17 +4,17 @@ import (
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount/basic"
|
||||
"github.com/silenceper/wechat/officialaccount/config"
|
||||
"github.com/silenceper/wechat/officialaccount/context"
|
||||
"github.com/silenceper/wechat/officialaccount/device"
|
||||
"github.com/silenceper/wechat/officialaccount/js"
|
||||
"github.com/silenceper/wechat/officialaccount/material"
|
||||
"github.com/silenceper/wechat/officialaccount/menu"
|
||||
"github.com/silenceper/wechat/officialaccount/message"
|
||||
"github.com/silenceper/wechat/officialaccount/oauth"
|
||||
"github.com/silenceper/wechat/officialaccount/server"
|
||||
"github.com/silenceper/wechat/officialaccount/user"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/basic"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/config"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/device"
|
||||
"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/server"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/user"
|
||||
)
|
||||
|
||||
//OfficialAccount 微信公众号相关API
|
||||
@@ -25,7 +25,7 @@ type OfficialAccount struct {
|
||||
//NewOfficialAccount 实例化公众号API
|
||||
func NewOfficialAccount(cfg *config.Config) *OfficialAccount {
|
||||
if cfg.Cache == nil {
|
||||
panic("cache未设置")
|
||||
panic("cache 未设置")
|
||||
}
|
||||
ctx := &context.Context{
|
||||
Config: cfg,
|
||||
|
||||
@@ -10,10 +10,11 @@ import (
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount/context"
|
||||
"github.com/silenceper/wechat/officialaccount/message"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/message"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
//Server struct
|
||||
@@ -22,7 +23,7 @@ type Server struct {
|
||||
Writer http.ResponseWriter
|
||||
Request *http.Request
|
||||
|
||||
debug bool
|
||||
skipValidate bool
|
||||
|
||||
openID string
|
||||
|
||||
@@ -46,14 +47,15 @@ func NewServer(context *context.Context) *Server {
|
||||
return srv
|
||||
}
|
||||
|
||||
// SetDebug set debug field
|
||||
func (srv *Server) SetDebug(debug bool) {
|
||||
srv.debug = debug
|
||||
// SkipValidate set skip validate
|
||||
func (srv *Server) SkipValidate(skip bool) {
|
||||
srv.skipValidate = skip
|
||||
}
|
||||
|
||||
//Serve 处理微信的请求消息
|
||||
func (srv *Server) Serve() error {
|
||||
if !srv.Validate() {
|
||||
log.Error("Validate Signature Failed.")
|
||||
return fmt.Errorf("请求校验失败")
|
||||
}
|
||||
|
||||
@@ -68,22 +70,21 @@ func (srv *Server) Serve() error {
|
||||
return err
|
||||
}
|
||||
|
||||
//debug
|
||||
if srv.debug {
|
||||
fmt.Println("request msg = ", string(srv.requestRawXMLMsg))
|
||||
}
|
||||
//debug print request msg
|
||||
log.Debugf("request msg =%s", string(srv.requestRawXMLMsg))
|
||||
|
||||
return srv.buildResponse(response)
|
||||
}
|
||||
|
||||
//Validate 校验请求是否合法
|
||||
func (srv *Server) Validate() bool {
|
||||
if srv.debug {
|
||||
if srv.skipValidate {
|
||||
return true
|
||||
}
|
||||
timestamp := srv.Query("timestamp")
|
||||
nonce := srv.Query("nonce")
|
||||
signature := srv.Query("signature")
|
||||
log.Debugf("validate signature, timestamp=%s, nonce=%s", timestamp, nonce)
|
||||
return signature == util.Signature(srv.Token, timestamp, nonce)
|
||||
}
|
||||
|
||||
@@ -223,6 +224,7 @@ func (srv *Server) buildResponse(reply *message.Reply) (err error) {
|
||||
//Send 将自定义的消息发送
|
||||
func (srv *Server) Send() (err error) {
|
||||
replyMsg := srv.responseMsg
|
||||
log.Debugf("response msg =%+v", replyMsg)
|
||||
if srv.isSafeMode {
|
||||
//安全模式下对消息进行加密
|
||||
var encryptedMsg []byte
|
||||
|
||||
@@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount/context"
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package notify
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/pay/config"
|
||||
"github.com/silenceper/wechat/v2/pay/config"
|
||||
)
|
||||
|
||||
//Notify 回调
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
// Base 公用参数
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/silenceper/wechat/pay/config"
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/pay/config"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
//https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/pay/config"
|
||||
"github.com/silenceper/wechat/pay/notify"
|
||||
"github.com/silenceper/wechat/pay/order"
|
||||
"github.com/silenceper/wechat/v2/pay/config"
|
||||
"github.com/silenceper/wechat/v2/pay/notify"
|
||||
"github.com/silenceper/wechat/v2/pay/order"
|
||||
)
|
||||
|
||||
//Pay 微信支付相关API
|
||||
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/pay/config"
|
||||
"github.com/silenceper/wechat/util"
|
||||
"github.com/silenceper/wechat/v2/pay/config"
|
||||
"github.com/silenceper/wechat/v2/util"
|
||||
)
|
||||
|
||||
var refundGateway = "https://api.mch.weixin.qq.com/secapi/pay/refund"
|
||||
|
||||
28
wechat.go
28
wechat.go
@@ -1,15 +1,31 @@
|
||||
package wechat
|
||||
|
||||
import (
|
||||
"github.com/silenceper/wechat/miniprogram"
|
||||
miniConfig "github.com/silenceper/wechat/miniprogram/config"
|
||||
payConfig "github.com/silenceper/wechat/pay/config"
|
||||
"os"
|
||||
|
||||
"github.com/silenceper/wechat/officialaccount"
|
||||
offConfig "github.com/silenceper/wechat/officialaccount/config"
|
||||
"github.com/silenceper/wechat/pay"
|
||||
"github.com/silenceper/wechat/v2/miniprogram"
|
||||
miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
|
||||
"github.com/silenceper/wechat/v2/officialaccount"
|
||||
offConfig "github.com/silenceper/wechat/v2/officialaccount/config"
|
||||
"github.com/silenceper/wechat/v2/pay"
|
||||
payConfig "github.com/silenceper/wechat/v2/pay/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
// Log as JSON instead of the default ASCII formatter.
|
||||
log.SetFormatter(&log.TextFormatter{})
|
||||
|
||||
// Output to stdout instead of the default stderr
|
||||
// Can be any io.Writer, see below for File example
|
||||
log.SetOutput(os.Stdout)
|
||||
|
||||
// Only log the warning severity or above.
|
||||
log.SetLevel(log.DebugLevel)
|
||||
|
||||
}
|
||||
|
||||
// Wechat struct
|
||||
type Wechat struct {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user