Files
full/module/finance/wallet/internal/config/config.go

90 lines
3.6 KiB
Go
Raw Normal View History

package config
import (
"net"
"git.apinb.com/bsm-sdk/core/conf"
"git.apinb.com/bsm-sdk/core/crypto/encipher"
"git.apinb.com/bsm-sdk/core/env"
)
var (
Spec SrvConfig // 全局配置实例
)
// SrvConfig 服务配置结构体
type SrvConfig struct {
conf.Base `yaml:",inline"` // 基础配置
Databases *conf.DBConf `yaml:"Databases"` // 数据库配置
MicroService *conf.MicroServiceConf `yaml:"MicroService"` // 微服务配置
Rpc map[string]conf.RpcConf `yaml:"Rpc"` // RPC配置
Gateway *conf.GatewayConf `yaml:"Gateway"` // 网关配置
Apm *conf.ApmConf `yaml:"APM"` // APM监控配置
Etcd *conf.EtcdConf `yaml:"Etcd"` // Etcd配置
WeChat *WeChatConf `yaml:"WeChat"` // 微信支付配置
Alipay *AlipayConf `yaml:"Alipay"` // 支付宝配置
Wallet *WalletConfig `yaml:"Wallet"` // 钱包配置
QrCodeSavePath string `yaml:"QrCodeSavePath"` // 二维码保存路径
}
// WeChatConf 微信支付配置
type WeChatConf struct {
AppID string `yaml:"AppID"` // 微信应用ID
AppSecret string `yaml:"AppSecret"` // 微信应用密钥
SerialNo string `yaml:"SerialNo"` // 证书序列号
APIV3Key string `yaml:"APIV3Key"` // APIv3密钥
PrivateKey string `yaml:"PrivateKey"` // 私钥
NotifyURL string `yaml:"NotifyURL"` // 回调通知地址
Currency string `yaml:"Currency"` // 货币类型
MchID string `yaml:"MchID"` // 商户号
SubMchID string `yaml:"SubMchID"` // 子商户号
OpenID string `yaml:"OpenID"` // 用户OpenID
}
// AlipayConf 支付宝配置
type AlipayConf struct {
AppID string `yaml:"AppID"` // 支付宝应用ID
AppSecret string `yaml:"AppSecret"` // 应用密钥
PrivateKey string `yaml:"PrivateKey"` // 应用私钥
IsProd bool `yaml:"IsProd"` // 是否生产环境
NotifyURL string `yaml:"NotifyURL"` // 异步通知地址
ReturnURL string `yaml:"ReturnURL"` // 同步跳转地址
QuitURL string `yaml:"QuitURL"` // 退出地址
PublicKeyRsa2Byte string `yaml:"PublicKeyRsa2Byte"` // 支付宝公钥
CertPublicKey string `yaml:"CertPublicKey"` // 应用公钥证书
CertRoot string `yaml:"CertRoot"` // 根证书
CertPublicKeyRsa2 string `yaml:"CertPublicKeyRsa2"` // 应用公钥证书RSA2
}
// WalletConfig 钱包配置
type WalletConfig struct {
Name string `yaml:"Name"` // 钱包名称
URL string `yaml:"URL"` // 钱包URL
PublicKey string `yaml:"PublicKey"` // 公钥
YMDHMS string `yaml:"YMDHMS"` // 时间格式
YMD string `yaml:"YMD"` // 日期格式
AlipyIsOpen bool `yaml:"AlipyIsOpen"` // 支付宝是否开启
WalletIsOpen bool `yaml:"WalletIsOpen"` // 钱包是否开启
WechatpayIsOpen bool `yaml:"WechatpayIsOpen"` // 微信支付是否开启
}
// New 初始化配置
func New(srvKey string) {
// 初始化配置,创建一个新的配置实例
conf.New(srvKey, &Spec)
// 配置校验服务IP和端口
Spec.Port = conf.CheckPort(Spec.Port)
Spec.BindIP = conf.CheckIP(Spec.BindIP)
Spec.Addr = net.JoinHostPort(Spec.BindIP, Spec.Port)
// 配置校验 服务名称地址及监听地址不能为空
conf.NotNil(Spec.Service, Spec.Cache)
// 初始化加密SecretKey
encipher.New(env.Runtime.JwtSecretKey)
conf.PrintInfo(Spec.Addr)
}