44 lines
866 B
Go
44 lines
866 B
Go
package wechat
|
|
|
|
import (
|
|
"git.ipao.vip/rogeecn/atom/container"
|
|
"git.ipao.vip/rogeecn/atom/utils/opt"
|
|
)
|
|
|
|
func DefaultProvider() container.ProviderContainer {
|
|
return container.ProviderContainer{
|
|
Provider: Provide,
|
|
Options: []opt.Option{},
|
|
}
|
|
}
|
|
|
|
type Config struct {
|
|
AppID string
|
|
AppSecret string
|
|
Token string
|
|
AesKey string
|
|
DevMode bool
|
|
}
|
|
|
|
func Provide(opts ...opt.Option) error {
|
|
o := opt.New(opts...)
|
|
var config Config
|
|
if err := o.UnmarshalConfig(&config); err != nil {
|
|
return err
|
|
}
|
|
|
|
return container.Container.Provide(func() (*Client, error) {
|
|
httpClient := DefaultClient
|
|
if config.DevMode {
|
|
httpClient = httpClient.DevMode()
|
|
}
|
|
return New(
|
|
WithAppID(config.AppID),
|
|
WithAppSecret(config.AppSecret),
|
|
WithAESKey(config.AesKey),
|
|
WithToken(config.Token),
|
|
WithClient(httpClient),
|
|
), nil
|
|
}, o.DiOptions()...)
|
|
}
|