12345678910111213141516171819202122232425262728293031323334353637
  1. package utils
  2. import (
  3. "github.com/astaxie/beego"
  4. "github.com/zjxpcyc/wechat/wx"
  5. )
  6. var client *wx.Client
  7. // WxClientSingleton 初始化
  8. func WxClientSingleton(cert map[string]string) {
  9. client = wx.NewClient(cert)
  10. }
  11. // WxClient 微信实例
  12. func WxClient() *wx.Client {
  13. return client
  14. }
  15. // 初始化微信
  16. func InitWechat() {
  17. appRoot := GetAppRoot()
  18. wechatConf, _ := GetConfiger(appRoot + "/conf/wechat.conf")
  19. if wechatConf == nil {
  20. return
  21. }
  22. cert := map[string]string{
  23. "appid": wechatConf.String("appid"),
  24. "secret": wechatConf.String("secret"),
  25. "token": wechatConf.String("token"),
  26. "aeskey": "",
  27. "wxid": wechatConf.String("wxid"),
  28. }
  29. beego.Error(cert)
  30. WxClientSingleton(cert)
  31. }