package wechat import ( "go.ipao.vip/atom/container" "go.ipao.vip/atom/opt" ) const DefaultPrefix = "WeChat" func DefaultProvider() container.ProviderContainer { return container.ProviderContainer{ Provider: Provide, Options: []opt.Option{ opt.Prefix(DefaultPrefix), }, } } 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() (*Config, *Client, error) { httpClient := DefaultClient if config.DevMode { httpClient = httpClient.DevMode() } return &config, New( WithAppID(config.AppID), WithAppSecret(config.AppSecret), WithAESKey(config.EncodingAESKey), WithToken(config.Token), WithClient(httpClient), ), nil }, o.DiOptions()...) } type Config struct { AppID string AppSecret string Token string EncodingAESKey string DevMode bool Pay *Pay } type Pay struct { MchID string SerialNo string MechName string NotifyURL string ApiV3Key string PrivateKey string }