Skip to content

Commit

Permalink
New和Set参数保持一致
Browse files Browse the repository at this point in the history
  • Loading branch information
TomLiu-GitHub committed Jun 5, 2019
1 parent 51d347c commit b675a14
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ func WxHandler(w http.ResponseWriter, r *http.Request) {

* 创建其他实例,密文模式
```go
// 创建公众号实例(服务号/订阅号/小程序) 不带aesKey则为明文模式
app := wechat.New("token", "appId", "secret")

// 创建公众号实例(服务号/订阅号/小程序)
app := wechat.New("token", "appId", "secret", "aesKey")

// 创建企业号实例
app := wechat.New("token", "appId", "secret", "aesKey", "agentId")
app := wechat.NewEnt("token", "appId", "secret", "aesKey", "agentId")

// 实例化后其他业务操作
ctx := app.VerifyURL(w, r)
Expand Down
1 change: 1 addition & 0 deletions accesstoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (s *Server) getAccessToken() (err error) {
} else {
Printf("使用本地机制获取token")
url := fmt.Sprintf(s.TokenUrl, s.AppId, s.Secret)
Printf(url)
at := new(AccessToken)
if err = util.GetJson(url, at); err != nil {
return
Expand Down
8 changes: 7 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type Server struct {
}

// New 微信服务容器,根据agentId判断是企业号或服务号
func New(token, appid, secret, key string, agentId ...int) (s *Server) {
func NewEnt(token, appid, secret, key string, agentId ...int) (s *Server) {
s = NewServer(nil)
if len(agentId) > 0 {
s.SetEnt(token, appid, secret, key, agentId[0])
Expand All @@ -77,6 +77,12 @@ func New(token, appid, secret, key string, agentId ...int) (s *Server) {
return s
}

// New 微信服务容器
func New(token, appid, secret string, key ...string) (s *Server) {
s = NewServer(nil)
s.Set(token, appid, secret, key...)
return s
}
// NewServer 空容器
func NewServer(f func(appId string) *AccessToken) *Server {
s := &Server{
Expand Down

0 comments on commit b675a14

Please sign in to comment.