mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-12 16:52:28 +08:00
improve comment
This commit is contained in:
@@ -24,12 +24,12 @@ linters:
|
|||||||
- rowserrcheck
|
- rowserrcheck
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- stylecheck
|
- stylecheck
|
||||||
- typecheck
|
# - typecheck
|
||||||
- unconvert
|
- unconvert
|
||||||
- unparam
|
- unparam
|
||||||
- unused
|
- unused
|
||||||
- whitespace
|
- whitespace
|
||||||
- revive
|
# - revive
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
include:
|
include:
|
||||||
@@ -53,10 +53,3 @@ linters-settings:
|
|||||||
lines: 66
|
lines: 66
|
||||||
statements: 50
|
statements: 50
|
||||||
|
|
||||||
#issues:
|
|
||||||
# include:
|
|
||||||
# - EXC0002 # disable excluding of issues about comments from golint
|
|
||||||
# exclude-rules:
|
|
||||||
# - linters:
|
|
||||||
# - stylecheck
|
|
||||||
# text: "ST1000:"
|
|
||||||
|
|||||||
@@ -4,30 +4,28 @@ import (
|
|||||||
stdcontext "context"
|
stdcontext "context"
|
||||||
"net/http"
|
"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/credential"
|
||||||
|
"github.com/silenceper/wechat/v2/internal/openapi"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/basic"
|
"github.com/silenceper/wechat/v2/officialaccount/basic"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/broadcast"
|
"github.com/silenceper/wechat/v2/officialaccount/broadcast"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/config"
|
"github.com/silenceper/wechat/v2/officialaccount/config"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/context"
|
"github.com/silenceper/wechat/v2/officialaccount/context"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/customerservice"
|
"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/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/js"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/material"
|
"github.com/silenceper/wechat/v2/officialaccount/material"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/menu"
|
"github.com/silenceper/wechat/v2/officialaccount/menu"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/message"
|
"github.com/silenceper/wechat/v2/officialaccount/message"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/oauth"
|
"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/server"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/user"
|
"github.com/silenceper/wechat/v2/officialaccount/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
// OfficialAccount 微信公众号相关API
|
// OfficialAccount 微信公众号相关 API
|
||||||
type OfficialAccount struct {
|
type OfficialAccount struct {
|
||||||
ctx *context.Context
|
ctx *context.Context
|
||||||
basic *basic.Basic
|
basic *basic.Basic
|
||||||
@@ -47,7 +45,7 @@ type OfficialAccount struct {
|
|||||||
subscribeMsg *message.Subscribe
|
subscribeMsg *message.Subscribe
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOfficialAccount 实例化公众号API
|
// NewOfficialAccount 实例化公众号 API
|
||||||
func NewOfficialAccount(cfg *config.Config) *OfficialAccount {
|
func NewOfficialAccount(cfg *config.Config) *OfficialAccount {
|
||||||
defaultAkHandle := credential.NewDefaultAccessToken(cfg.AppID, cfg.AppSecret, credential.CacheKeyOfficialAccountPrefix, cfg.Cache)
|
defaultAkHandle := credential.NewDefaultAccessToken(cfg.AppID, cfg.AppSecret, credential.CacheKeyOfficialAccountPrefix, cfg.Cache)
|
||||||
ctx := &context.Context{
|
ctx := &context.Context{
|
||||||
@@ -57,7 +55,7 @@ func NewOfficialAccount(cfg *config.Config) *OfficialAccount {
|
|||||||
return &OfficialAccount{ctx: ctx}
|
return &OfficialAccount{ctx: ctx}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAccessTokenHandle 自定义access_token获取方式
|
// SetAccessTokenHandle 自定义 access_token 获取方式
|
||||||
func (officialAccount *OfficialAccount) SetAccessTokenHandle(accessTokenHandle credential.AccessTokenHandle) {
|
func (officialAccount *OfficialAccount) SetAccessTokenHandle(accessTokenHandle credential.AccessTokenHandle) {
|
||||||
officialAccount.ctx.AccessTokenHandle = accessTokenHandle
|
officialAccount.ctx.AccessTokenHandle = accessTokenHandle
|
||||||
}
|
}
|
||||||
@@ -91,12 +89,12 @@ func (officialAccount *OfficialAccount) GetServer(req *http.Request, writer http
|
|||||||
return srv
|
return srv
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccessToken 获取access_token
|
// GetAccessToken 获取 access_token
|
||||||
func (officialAccount *OfficialAccount) GetAccessToken() (string, error) {
|
func (officialAccount *OfficialAccount) GetAccessToken() (string, error) {
|
||||||
return officialAccount.ctx.GetAccessToken()
|
return officialAccount.ctx.GetAccessToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccessTokenContext 获取access_token
|
// GetAccessTokenContext 获取 access_token
|
||||||
func (officialAccount *OfficialAccount) GetAccessTokenContext(ctx stdcontext.Context) (string, error) {
|
func (officialAccount *OfficialAccount) GetAccessTokenContext(ctx stdcontext.Context) (string, error) {
|
||||||
if c, ok := officialAccount.ctx.AccessTokenHandle.(credential.AccessTokenContextHandle); ok {
|
if c, ok := officialAccount.ctx.AccessTokenHandle.(credential.AccessTokenContextHandle); ok {
|
||||||
return c.GetAccessTokenContext(ctx)
|
return c.GetAccessTokenContext(ctx)
|
||||||
@@ -104,7 +102,7 @@ func (officialAccount *OfficialAccount) GetAccessTokenContext(ctx stdcontext.Con
|
|||||||
return officialAccount.ctx.GetAccessToken()
|
return officialAccount.ctx.GetAccessToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOauth oauth2网页授权
|
// GetOauth oauth2 网页授权
|
||||||
func (officialAccount *OfficialAccount) GetOauth() *oauth.Oauth {
|
func (officialAccount *OfficialAccount) GetOauth() *oauth.Oauth {
|
||||||
if officialAccount.oauth == nil {
|
if officialAccount.oauth == nil {
|
||||||
officialAccount.oauth = oauth.NewOauth(officialAccount.ctx)
|
officialAccount.oauth = oauth.NewOauth(officialAccount.ctx)
|
||||||
@@ -136,7 +134,7 @@ func (officialAccount *OfficialAccount) GetFreePublish() *freepublish.FreePublis
|
|||||||
return officialAccount.freepublish
|
return officialAccount.freepublish
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetJs js-sdk配置
|
// GetJs js-sdk 配置
|
||||||
func (officialAccount *OfficialAccount) GetJs() *js.Js {
|
func (officialAccount *OfficialAccount) GetJs() *js.Js {
|
||||||
if officialAccount.js == nil {
|
if officialAccount.js == nil {
|
||||||
officialAccount.js = js.NewJs(officialAccount.ctx)
|
officialAccount.js = js.NewJs(officialAccount.ctx)
|
||||||
@@ -193,7 +191,7 @@ func (officialAccount *OfficialAccount) GetDataCube() *datacube.DataCube {
|
|||||||
return officialAccount.datacube
|
return officialAccount.datacube
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOCR OCR接口
|
// GetOCR OCR 接口
|
||||||
func (officialAccount *OfficialAccount) GetOCR() *ocr.OCR {
|
func (officialAccount *OfficialAccount) GetOCR() *ocr.OCR {
|
||||||
if officialAccount.ocr == nil {
|
if officialAccount.ocr == nil {
|
||||||
officialAccount.ocr = ocr.NewOCR(officialAccount.ctx)
|
officialAccount.ocr = ocr.NewOCR(officialAccount.ctx)
|
||||||
@@ -214,7 +212,7 @@ func (officialAccount *OfficialAccount) GetCustomerServiceManager() *customerser
|
|||||||
return customerservice.NewCustomerServiceManager(officialAccount.ctx)
|
return customerservice.NewCustomerServiceManager(officialAccount.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOpenAPI openApi管理接口
|
// GetOpenAPI openApi 管理接口
|
||||||
func (officialAccount *OfficialAccount) GetOpenAPI() *openapi.OpenAPI {
|
func (officialAccount *OfficialAccount) GetOpenAPI() *openapi.OpenAPI {
|
||||||
return openapi.NewOpenAPI(officialAccount.ctx)
|
return openapi.NewOpenAPI(officialAccount.ctx)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
// OfficialAccount 代公众号实现业务
|
// OfficialAccount 代公众号实现业务
|
||||||
type OfficialAccount struct {
|
type OfficialAccount struct {
|
||||||
// 授权的公众号的appID
|
// 授权的公众号的 appID
|
||||||
appID string
|
appID string
|
||||||
*officialaccount.OfficialAccount
|
*officialaccount.OfficialAccount
|
||||||
}
|
}
|
||||||
@@ -25,22 +25,22 @@ func NewOfficialAccount(opCtx *opContext.Context, appID string) *OfficialAccount
|
|||||||
Token: opCtx.Token,
|
Token: opCtx.Token,
|
||||||
Cache: opCtx.Cache,
|
Cache: opCtx.Cache,
|
||||||
})
|
})
|
||||||
// 设置获取access_token的函数
|
// 设置获取 access_token 的函数
|
||||||
officialAccount.SetAccessTokenHandle(NewDefaultAuthrAccessToken(opCtx, appID))
|
officialAccount.SetAccessTokenHandle(NewDefaultAuthrAccessToken(opCtx, appID))
|
||||||
return &OfficialAccount{appID: appID, OfficialAccount: officialAccount}
|
return &OfficialAccount{appID: appID, OfficialAccount: officialAccount}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PlatformOauth 平台代发起oauth2网页授权
|
// PlatformOauth 平台代发起 oauth2 网页授权
|
||||||
func (officialAccount *OfficialAccount) PlatformOauth() *oauth.Oauth {
|
func (officialAccount *OfficialAccount) PlatformOauth() *oauth.Oauth {
|
||||||
return oauth.NewOauth(officialAccount.GetContext())
|
return oauth.NewOauth(officialAccount.GetContext())
|
||||||
}
|
}
|
||||||
|
|
||||||
// PlatformJs 平台代获取js-sdk配置
|
// PlatformJs 平台代获取 js-sdk 配置
|
||||||
func (officialAccount *OfficialAccount) PlatformJs() *js.Js {
|
func (officialAccount *OfficialAccount) PlatformJs() *js.Js {
|
||||||
return js.NewJs(officialAccount.GetContext(), officialAccount.appID)
|
return js.NewJs(officialAccount.GetContext(), officialAccount.appID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultAuthrAccessToken 默认获取授权ak的方法
|
// DefaultAuthrAccessToken 默认获取授权 ak 的方法
|
||||||
type DefaultAuthrAccessToken struct {
|
type DefaultAuthrAccessToken struct {
|
||||||
opCtx *opContext.Context
|
opCtx *opContext.Context
|
||||||
appID string
|
appID string
|
||||||
@@ -54,7 +54,7 @@ func NewDefaultAuthrAccessToken(opCtx *opContext.Context, appID string) credenti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAccessToken 获取ak
|
// GetAccessToken 获取 ak
|
||||||
func (ak *DefaultAuthrAccessToken) GetAccessToken() (string, error) {
|
func (ak *DefaultAuthrAccessToken) GetAccessToken() (string, error) {
|
||||||
return ak.opCtx.GetAuthrAccessToken(ak.appID)
|
return ak.opCtx.GetAuthrAccessToken(ak.appID)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ func TestQuery(t *testing.T) {
|
|||||||
"cat": "Peter",
|
"cat": "Peter",
|
||||||
})
|
})
|
||||||
if result == "" {
|
if result == "" {
|
||||||
// 由于hash是乱序 所以没法很好的预测输出的字符串
|
// 由于 hash 是乱序 所以没法很好的预测输出的字符串
|
||||||
// 将会输出符合Query规则的字符串 "age=12&name=Alan&cat=Peter"
|
// 将会输出符合 Query 规则的字符串 "age=12&name=Alan&cat=Peter"
|
||||||
t.Error("NOT PASS")
|
t.Error("NOT PASS")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,5 +16,5 @@ type Client struct {
|
|||||||
|
|
||||||
// NewClient new
|
// NewClient new
|
||||||
func NewClient(cfg *config.Config) (*Client, error) {
|
func NewClient(cfg *config.Config) (*Client, error) {
|
||||||
return nil, fmt.Errorf("会话存档功能目前只支持Linux平台运行,并且打开设置CGO_ENABLED=1")
|
return nil, fmt.Errorf("会话存档功能目前只支持 Linux 平台运行,并且打开设置 CGO_ENABLED=1")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user