蛋蛋星球 后台端
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

128 satır
3.8 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/utils"
  5. "applet/app/utils/cache"
  6. "applet/app/utils/logx"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/dao"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  10. openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  11. ram20150501 "github.com/alibabacloud-go/ram-20150501/v2/client"
  12. sts20150401 "github.com/alibabacloud-go/sts-20150401/v2/client"
  13. util2 "github.com/alibabacloud-go/tea-utils/v2/service"
  14. "github.com/alibabacloud-go/tea/tea"
  15. "github.com/gin-gonic/gin"
  16. "strings"
  17. "time"
  18. )
  19. func GetOssUrl(img string) string {
  20. redisConn := cache.GetPool().Get()
  21. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  22. defer func(sysCfgDb dao.SysCfgDao) {
  23. err := sysCfgDb.Close()
  24. if err != nil {
  25. logx.Error("redis close err:" + err.Error()) // 记录错误信息
  26. }
  27. }(sysCfgDb)
  28. sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme")
  29. if strings.Contains(img, "http") == false && img != "" {
  30. http := sysCfg["oss_bucket_scheme"]
  31. img = http + "://" + sysCfg["oss_domain"] + "/" + img
  32. }
  33. return img
  34. }
  35. func GetOssDomain() string {
  36. redisConn := cache.GetPool().Get()
  37. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  38. defer func(sysCfgDb dao.SysCfgDao) {
  39. err := sysCfgDb.Close()
  40. if err != nil {
  41. logx.Error("redis close err:" + err.Error()) // 记录错误信息
  42. }
  43. }(sysCfgDb)
  44. sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme")
  45. http := sysCfg["oss_bucket_scheme"]
  46. return http + "://" + sysCfg["oss_domain"] + "/"
  47. }
  48. func GetSysCfgStr(key string) string {
  49. redisConn := cache.GetPool().Get()
  50. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  51. defer func(sysCfgDb dao.SysCfgDao) {
  52. err := sysCfgDb.Close()
  53. if err != nil {
  54. logx.Error("redis close err:" + err.Error()) // 记录错误信息
  55. }
  56. }(sysCfgDb)
  57. return sysCfgDb.SysCfgGetWithDb(key)
  58. }
  59. func SetSysCfgStr(key, val string) bool {
  60. redisConn := cache.GetPool().Get()
  61. cfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  62. defer func(cfgDb dao.SysCfgDao) {
  63. err := cfgDb.Close()
  64. if err != nil {
  65. logx.Error("redis close err:" + err.Error()) // 记录错误信息
  66. }
  67. }(cfgDb)
  68. var bools bool
  69. if val != "" {
  70. data, _ := cfgDb.SysCfgGetOne(key)
  71. if data == nil {
  72. bools = cfgDb.SysCfgInsert(key, val, "")
  73. } else {
  74. bools = cfgDb.SysCfgUpdate(key, val)
  75. }
  76. }
  77. return bools
  78. }
  79. func CreateSTSClient(accessKeyId *string, accessKeySecret *string, stsEndpoint *string) (*sts20150401.Client, error) {
  80. config := &openapi.Config{
  81. AccessKeyId: accessKeyId,
  82. AccessKeySecret: accessKeySecret,
  83. // Endpoint 请参考 https://api.aliyun.com/product/Sts
  84. Endpoint: stsEndpoint,
  85. }
  86. return sts20150401.NewClient(config)
  87. }
  88. func AssumeRole(client *sts20150401.Client, roleArn *string, roleSessionName *string, durationSeconds int64) (*sts20150401.AssumeRoleResponse, error) {
  89. assumeRoleRequest := &sts20150401.AssumeRoleRequest{
  90. DurationSeconds: &durationSeconds,
  91. RoleArn: roleArn,
  92. RoleSessionName: roleSessionName,
  93. }
  94. return client.AssumeRoleWithOptions(assumeRoleRequest, &util2.RuntimeOptions{})
  95. }
  96. func CreateGetRoleClient(accessKeyId, accessKeySecret *string) (_result *ram20150501.Client, _err error) {
  97. config := &openapi.Config{
  98. AccessKeyId: accessKeyId,
  99. AccessKeySecret: accessKeySecret,
  100. }
  101. // Endpoint 请参考 https://api.aliyun.com/product/Ram
  102. config.Endpoint = tea.String("ram.aliyuncs.com")
  103. _result = &ram20150501.Client{}
  104. _result, _err = ram20150501.NewClient(config)
  105. return _result, _err
  106. }
  107. // 操作日志
  108. func AddAdminLog(c *gin.Context, adminId int, types, memo, ext string) {
  109. var tmp = model.AdminLog{
  110. Type: types,
  111. AdminId: adminId,
  112. Memo: memo,
  113. Time: time.Now(),
  114. Ip: utils.GetIP(c.Request),
  115. Data: ext,
  116. }
  117. db.Db.Insert(&tmp)
  118. }