package models

import (
	"wechat-conf/models/model"
	"wechat-conf/utils"
)

// InitWechat 初始化微信
func InitWechat() {
	var wxconfs []model.SysWechatConf
	err := DBEngine.Where("status=1").Find(&wxconfs)
	if err != nil {
		utils.LogError("初始化微信失败:", err)
		return
	}
	for _, conf := range wxconfs {
		var cert = map[string]string{
			"authorizer_access_token":  conf.Token,
			"authorizer_refresh_token": conf.RefreshToken,
			"authorization_code":       conf.AuthorizationCode,
			"appid":                    conf.Appid,
		}
		client := utils.WechatInit(cert)
		utils.AppendWxClient(client)
	}
}