wechat.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package wechat
  2. import (
  3. "os"
  4. "github.com/silenceper/wechat/v2/miniprogram"
  5. miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
  6. "github.com/silenceper/wechat/v2/officialaccount"
  7. offConfig "github.com/silenceper/wechat/v2/officialaccount/config"
  8. "github.com/silenceper/wechat/v2/pay"
  9. payConfig "github.com/silenceper/wechat/v2/pay/config"
  10. log "github.com/sirupsen/logrus"
  11. )
  12. func init() {
  13. // Log as JSON instead of the default ASCII formatter.
  14. log.SetFormatter(&log.TextFormatter{})
  15. // Output to stdout instead of the default stderr
  16. // Can be any io.Writer, see below for File example
  17. log.SetOutput(os.Stdout)
  18. // Only log the warning severity or above.
  19. log.SetLevel(log.DebugLevel)
  20. }
  21. // Wechat struct
  22. type Wechat struct {
  23. }
  24. // Config for user
  25. type Config struct {
  26. PayMchID string //支付 - 商户 ID
  27. PayNotifyURL string //支付 - 接受微信支付结果通知的接口地址
  28. PayKey string //支付 - 商户后台设置的支付 key
  29. }
  30. // NewWechat init
  31. func NewWechat() *Wechat {
  32. return &Wechat{}
  33. }
  34. //GetOfficialAccount 获取微信公众号实例
  35. func (wc *Wechat) GetOfficialAccount(cfg *offConfig.Config) *officialaccount.OfficialAccount {
  36. return officialaccount.NewOfficialAccount(cfg)
  37. }
  38. // GetMiniProgram 获取小程序的实例
  39. func (wc *Wechat) GetMiniProgram(cfg *miniConfig.Config) *miniprogram.MiniProgram {
  40. return miniprogram.NewMiniProgram(cfg)
  41. }
  42. // GetPay 获取微信支付的实例
  43. func (wc *Wechat) GetPay(cfg *payConfig.Config) *pay.Pay {
  44. return pay.NewPay(cfg)
  45. }