diff --git a/README.md b/README.md index 311446d..ecff105 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/accesstoken.go b/accesstoken.go index de641bd..8f2c2a3 100644 --- a/accesstoken.go +++ b/accesstoken.go @@ -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 diff --git a/server.go b/server.go index d918f31..022bae5 100644 --- a/server.go +++ b/server.go @@ -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]) @@ -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{