config.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package utils
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/beego/beego/v2/core/logs"
  7. "github.com/beego/beego/v2/server/web"
  8. "github.com/go-redis/redis/v8"
  9. "strconv"
  10. "strings"
  11. )
  12. var (
  13. RunMode string //运行模式
  14. MYSQL_URL string //数据库连接
  15. MYSQL_URL_RDDP string //数据库连接
  16. MYSQL_URL_EDB string
  17. REDIS_CACHE string //缓存地址
  18. Redis *redis.Client //redis链接
  19. )
  20. var (
  21. STATIC_DIR string
  22. )
  23. //微信配置信息
  24. var (
  25. WxId string //微信原始ID
  26. WxAppId string
  27. WxAppSecret string
  28. TemplateIdByProduct string //产品运行报告通知-模板ID
  29. TemplateRedirectUrl string //模板消息跳转地址
  30. WxPlatform int //用户来源,需要入库,用来保存该用户来自哪个平台,默认是:1
  31. EsEnglishReportIndexName string //研报ES索引
  32. )
  33. //pc端微信配置信息
  34. var (
  35. PcWxId string //微信原始ID
  36. PcWxAppId string
  37. PcWxAppSecret string
  38. PcTemplateIdByProduct string //产品运行报告通知-模板ID
  39. PcTemplateRedirectUrl string //模板消息跳转地址
  40. WxPcPlatform int //用户来源,需要入库,用来保存该用户来自哪个平台,默认是:3
  41. )
  42. var (
  43. ClassifyArr []string
  44. ReportNameArr []string
  45. )
  46. func init() {
  47. tmpRunMode, err := web.AppConfig.String("run_mode")
  48. if err != nil {
  49. panic("配置文件读取run_mode错误 " + err.Error())
  50. }
  51. RunMode = tmpRunMode
  52. if RunMode == "" {
  53. localIp, err := GetLocalIP()
  54. fmt.Println("localIp:", localIp)
  55. if localIp == "10.0.0.123" {
  56. RunMode = "debug"
  57. } else {
  58. RunMode = "release"
  59. }
  60. fmt.Println("RunMode:", RunMode)
  61. configPath := `/home/code/config/hongze_api/conf/app.conf`
  62. fmt.Println("configPath:", configPath)
  63. err = web.LoadAppConfig("ini", configPath)
  64. if err != nil {
  65. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  66. }
  67. //RunMode = "release"
  68. //configPath := `/home/code/config/hongze_api/conf/app.conf`
  69. //err := web.LoadAppConfig("ini", configPath)
  70. //if err != nil {
  71. // fmt.Println("web.LoadAppConfig Err:" + err.Error())
  72. //}
  73. }
  74. config, err := web.AppConfig.GetSection(RunMode)
  75. if err != nil {
  76. panic("配置文件读取错误 " + err.Error())
  77. }
  78. logs.Info(RunMode + " 模式")
  79. MYSQL_URL = config["mysql_url"]
  80. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  81. MYSQL_URL_EDB = config["mysql_url_edb"]
  82. if RunMode == "release" {
  83. WxAppId = "wx4a844c734d8c8e56"
  84. WxAppSecret = "26c586e7ccb3c575433f0f37797b3eeb"
  85. WxId = "gh_b67e0049fb8c"
  86. TemplateIdByProduct = "Cp2wF8gvBtxyWV4DeYuI172oqwyYXVRSm3AyJO42d84"
  87. TemplateRedirectUrl = "https://ficc.hzinsights.com/reportdtl?id="
  88. WxPlatform = 1
  89. WxPcPlatform = 3
  90. PcWxAppId = "wx615472d6874eeb7f"
  91. PcWxAppSecret = "97fe374fb0cc90ef58c4b49d431366f1"
  92. STATIC_DIR = "/home/static/imgs/"
  93. EsEnglishReportIndexName = "english_report_v1"
  94. } else {
  95. WxAppId = "wx9b5d7291e581233a"
  96. WxAppSecret = "f4d52e34021eee262dce9682b31f8861"
  97. WxId = "gh_5dc508325c6f"
  98. TemplateIdByProduct = "-YjuPOB7Fqd-S3ilabYa6wvjDY9aXmeEfPN6DCiy-EY"
  99. TemplateRedirectUrl = "http://rddpweb.brilliantstart.cn/reportdtl?id="
  100. WxPlatform = 1
  101. WxPcPlatform = 3
  102. PcWxAppId = "wx7c8084f6e5b1d85a"
  103. PcWxAppSecret = "9e4210cd5a363aa1f316b7c4b8898418"
  104. STATIC_DIR = "/home/static/imgs/"
  105. EsEnglishReportIndexName = "test_english_report_v1"
  106. }
  107. // 初始化redis缓存
  108. initRedis(config)
  109. initAutoReply()
  110. }
  111. // initRedis 初始化redis配置
  112. func initRedis(config map[string]string) {
  113. REDIS_CACHE = config["beego_cache"]
  114. if len(REDIS_CACHE) <= 0 {
  115. panic("redis链接参数没有配置")
  116. }
  117. var redisConf map[string]string
  118. err := json.Unmarshal([]byte(REDIS_CACHE), &redisConf)
  119. if err != nil {
  120. panic("redis 配置异常失败:" + err.Error())
  121. }
  122. redisDb := 0 //默认使用redis的0库
  123. if dbStr, ok := redisConf["db"]; ok {
  124. redisDb, err = strconv.Atoi(dbStr)
  125. if err != nil {
  126. panic("redis 操作db库配置异常,db:" + dbStr)
  127. }
  128. }
  129. client := redis.NewClient(&redis.Options{
  130. Addr: redisConf["conn"],
  131. Password: redisConf["password"],
  132. DB: redisDb,
  133. //PoolSize: 10, //连接池最大socket连接数,默认为10倍CPU数, 10 * runtime.NumCPU(暂不配置)
  134. })
  135. _, err = client.Ping(context.TODO()).Result()
  136. if err != nil {
  137. panic("redis 链接失败:" + err.Error())
  138. }
  139. //全局赋值redis链接
  140. Redis = client
  141. }
  142. //自动回复
  143. func initAutoReply() {
  144. keyWord := `宏观经济、利率债、原油、PTA、MEG、织造终端、甲醇、聚烯烃、沥青、苯乙烯、聚酯、钢材、铁矿、玻璃纯碱、PVC、双焦、铜/铝、镍/不锈钢、锌、钴锂、策略`
  145. ClassifyArr = strings.Split(keyWord, "、")
  146. reportNameStr := `比如晨报、周报、宏观报告、从宏观看商品、大宗商品、数据点评、知白守黑日评、有声有色日评、化里化外日评、股债日评、草根调研`
  147. ReportNameArr = strings.Split(reportNameStr, "、")
  148. }
  149. //http://webapi.brilliantstart.cn/api/
  150. //http://webapi.brilliantstart.cn/swagger/
  151. //http://139.196.122.219:8603/swagger/