123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- package utils
- import (
- "context"
- "encoding/json"
- "fmt"
- "github.com/beego/beego/v2/core/logs"
- "github.com/beego/beego/v2/server/web"
- "github.com/go-redis/redis/v8"
- "strconv"
- "strings"
- )
- var (
- RunMode string //运行模式
- MYSQL_URL string //数据库连接
- MYSQL_URL_RDDP string //数据库连接
- MYSQL_URL_ETA string
- //MYSQL_URL_EDB string
- MYSQL_URL_RDDP_TRIAL string // ETA试用rddp库
- REDIS_CACHE string //缓存地址
- Redis *redis.Client //redis链接
- )
- var (
- STATIC_DIR string
- )
- // 微信配置信息
- var (
- WxId string //微信原始ID
- WxAppId string
- WxAppSecret string
- TemplateIdByProduct string //产品运行报告通知-模板ID
- TemplateRedirectUrl string //模板消息跳转地址
- WxPlatform int //用户来源,需要入库,用来保存该用户来自哪个平台,默认是:1
- EsEnglishReportIndexName string //研报ES索引
- )
- // pc端微信配置信息
- var (
- PcWxId string //微信原始ID
- PcWxAppId string
- PcWxAppSecret string
- PcTemplateIdByProduct string //产品运行报告通知-模板ID
- PcTemplateRedirectUrl string //模板消息跳转地址
- WxPcPlatform int //用户来源,需要入库,用来保存该用户来自哪个平台,默认是:3
- )
- var (
- ClassifyArr []string
- ReportNameArr []string
- )
- // 公共api内部服务调用
- var (
- // EtaPubUrl 模板消息推送
- EtaPubUrl string
- // EtaPubAuthorization 模板推送秘钥
- EtaPubAuthorization string
- // AlarmMsgUrl 报警服务地址
- AlarmMsgUrl string
- )
- func init() {
- tmpRunMode, err := web.AppConfig.String("run_mode")
- if err != nil {
- panic("配置文件读取run_mode错误 " + err.Error())
- }
- RunMode = tmpRunMode
- if RunMode == "" {
- localIp, err := GetLocalIP()
- fmt.Println("localIp:", localIp)
- if localIp == "10.0.0.123" {
- RunMode = "debug"
- } else {
- RunMode = "release"
- }
- fmt.Println("RunMode:", RunMode)
- configPath := `/home/code/config/hongze_api/conf/app.conf`
- fmt.Println("configPath:", configPath)
- err = web.LoadAppConfig("ini", configPath)
- if err != nil {
- fmt.Println("web.LoadAppConfig Err:" + err.Error())
- }
- //RunMode = "release"
- //configPath := `/home/code/config/hongze_api/conf/app.conf`
- //err := web.LoadAppConfig("ini", configPath)
- //if err != nil {
- // fmt.Println("web.LoadAppConfig Err:" + err.Error())
- //}
- }
- config, err := web.AppConfig.GetSection(RunMode)
- if err != nil {
- panic("配置文件读取错误 " + err.Error())
- }
- logs.Info(RunMode + " 模式")
- MYSQL_URL = config["mysql_url"]
- MYSQL_URL_RDDP = config["mysql_url_rddp"]
- MYSQL_URL_ETA = config["mysql_url_eta"]
- //MYSQL_URL_EDB = config["mysql_url_edb"]
- MYSQL_URL_RDDP_TRIAL = config["mysql_url_rddp_trial"]
- if RunMode == "release" {
- WxAppId = "wx4a844c734d8c8e56"
- WxAppSecret = "26c586e7ccb3c575433f0f37797b3eeb"
- WxId = "gh_b67e0049fb8c"
- TemplateIdByProduct = "Cp2wF8gvBtxyWV4DeYuI172oqwyYXVRSm3AyJO42d84"
- TemplateRedirectUrl = "https://ficc.hzinsights.com/reportdtl?id="
- WxPlatform = 1
- WxPcPlatform = 3
- PcWxAppId = "wx615472d6874eeb7f"
- PcWxAppSecret = "97fe374fb0cc90ef58c4b49d431366f1"
- STATIC_DIR = "/home/static/imgs/"
- EsEnglishReportIndexName = "english_report_v1"
- } else {
- WxAppId = "wx9b5d7291e581233a"
- WxAppSecret = "f4d52e34021eee262dce9682b31f8861"
- WxId = "gh_5dc508325c6f"
- TemplateIdByProduct = "-YjuPOB7Fqd-S3ilabYa6wvjDY9aXmeEfPN6DCiy-EY"
- TemplateRedirectUrl = "http://rddpweb.brilliantstart.cn/reportdtl?id="
- WxPlatform = 1
- WxPcPlatform = 3
- PcWxAppId = "wx7c8084f6e5b1d85a"
- PcWxAppSecret = "9e4210cd5a363aa1f316b7c4b8898418"
- STATIC_DIR = "/home/static/imgs/"
- EsEnglishReportIndexName = "test_english_report_v1"
- }
- // 系统内部服务地址
- {
- // 发送微信模板消息地址
- EtaPubUrl = config["eta_pub_url"]
- // 发送微信模板消息地址
- EtaPubAuthorization = config["eta_pub_authorization"]
- // 报警服务地址
- AlarmMsgUrl = config["alarm_msg_url"]
- }
- // 初始化redis缓存
- initRedis(config)
- initAutoReply()
- }
- // initRedis 初始化redis配置
- func initRedis(config map[string]string) {
- REDIS_CACHE = config["beego_cache"]
- if len(REDIS_CACHE) <= 0 {
- panic("redis链接参数没有配置")
- }
- var redisConf map[string]string
- err := json.Unmarshal([]byte(REDIS_CACHE), &redisConf)
- if err != nil {
- panic("redis 配置异常失败:" + err.Error())
- }
- redisDb := 0 //默认使用redis的0库
- if dbStr, ok := redisConf["db"]; ok {
- redisDb, err = strconv.Atoi(dbStr)
- if err != nil {
- panic("redis 操作db库配置异常,db:" + dbStr)
- }
- }
- client := redis.NewClient(&redis.Options{
- Addr: redisConf["conn"],
- Password: redisConf["password"],
- DB: redisDb,
- //PoolSize: 10, //连接池最大socket连接数,默认为10倍CPU数, 10 * runtime.NumCPU(暂不配置)
- })
- _, err = client.Ping(context.TODO()).Result()
- if err != nil {
- panic("redis 链接失败:" + err.Error())
- }
- //全局赋值redis链接
- Redis = client
- }
- // 自动回复
- func initAutoReply() {
- keyWord := `宏观经济、利率债、原油、PTA、MEG、织造终端、甲醇、聚烯烃、沥青、苯乙烯、聚酯、钢材、铁矿、玻璃纯碱、PVC、双焦、铜/铝、镍/不锈钢、锌、钴锂、策略`
- ClassifyArr = strings.Split(keyWord, "、")
- reportNameStr := `比如晨报、周报、宏观报告、从宏观看商品、大宗商品、数据点评、知白守黑日评、有声有色日评、化里化外日评、股债日评、草根调研`
- ReportNameArr = strings.Split(reportNameStr, "、")
- }
- //http://webapi.brilliantstart.cn/api/
- //http://webapi.brilliantstart.cn/swagger/
- //http://139.196.122.219:8603/swagger/
|