蛋蛋星球 后台端

svc_comm.go 2.8 KiB

há 2 semanas
há 2 semanas
há 4 semanas
há 2 semanas
há 2 semanas
há 2 semanas
há 1 mês
há 1 mês
há 1 mês
há 2 semanas
há 1 mês
há 2 semanas
há 2 semanas
há 4 semanas
há 2 semanas
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/svc/sys_cfg"
  5. "applet/app/utils"
  6. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  7. openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  8. ram20150501 "github.com/alibabacloud-go/ram-20150501/v2/client"
  9. sts20150401 "github.com/alibabacloud-go/sts-20150401/v2/client"
  10. util2 "github.com/alibabacloud-go/tea-utils/v2/service"
  11. "github.com/alibabacloud-go/tea/tea"
  12. "github.com/gin-gonic/gin"
  13. "strings"
  14. "time"
  15. )
  16. func GetOssUrl(img string) string {
  17. sysCfgDb := sys_cfg.NewSysCfgDb(db.Db)
  18. sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme")
  19. if strings.Contains(img, "http") == false && img != "" {
  20. http := sysCfg["oss_bucket_scheme"]
  21. img = http + "://" + sysCfg["oss_domain"] + "/" + img
  22. }
  23. return img
  24. }
  25. func GetOssDomain() string {
  26. sysCfgDb := sys_cfg.NewSysCfgDb(db.Db)
  27. sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme")
  28. http := sysCfg["oss_bucket_scheme"]
  29. return http + "://" + sysCfg["oss_domain"] + "/"
  30. }
  31. func GetSysCfgStr(key string) string {
  32. return sys_cfg.NewSysCfgDb(db.Db).SysCfgGetWithDb(key)
  33. }
  34. func SetSysCfgStr(key, val string) bool {
  35. cfgDb := sys_cfg.NewSysCfgDb(db.Db)
  36. var bools bool
  37. if val != "" {
  38. data, _ := cfgDb.SysCfgGetOne(key)
  39. if data == nil {
  40. bools = cfgDb.SysCfgInsert(key, val, "")
  41. } else {
  42. bools = cfgDb.SysCfgUpdate(key, val)
  43. }
  44. }
  45. return bools
  46. }
  47. func CreateSTSClient(accessKeyId *string, accessKeySecret *string, stsEndpoint *string) (*sts20150401.Client, error) {
  48. config := &openapi.Config{
  49. AccessKeyId: accessKeyId,
  50. AccessKeySecret: accessKeySecret,
  51. // Endpoint 请参考 https://api.aliyun.com/product/Sts
  52. Endpoint: stsEndpoint,
  53. }
  54. return sts20150401.NewClient(config)
  55. }
  56. func AssumeRole(client *sts20150401.Client, roleArn *string, roleSessionName *string, durationSeconds int64) (*sts20150401.AssumeRoleResponse, error) {
  57. assumeRoleRequest := &sts20150401.AssumeRoleRequest{
  58. DurationSeconds: &durationSeconds,
  59. RoleArn: roleArn,
  60. RoleSessionName: roleSessionName,
  61. }
  62. return client.AssumeRoleWithOptions(assumeRoleRequest, &util2.RuntimeOptions{})
  63. }
  64. func CreateGetRoleClient(accessKeyId, accessKeySecret *string) (_result *ram20150501.Client, _err error) {
  65. config := &openapi.Config{
  66. AccessKeyId: accessKeyId,
  67. AccessKeySecret: accessKeySecret,
  68. }
  69. // Endpoint 请参考 https://api.aliyun.com/product/Ram
  70. config.Endpoint = tea.String("ram.aliyuncs.com")
  71. _result = &ram20150501.Client{}
  72. _result, _err = ram20150501.NewClient(config)
  73. return _result, _err
  74. }
  75. // 操作日志
  76. func AddAdminLog(c *gin.Context, adminId int, types, memo, ext string) {
  77. var tmp = model.AdminLog{
  78. Type: types,
  79. AdminId: adminId,
  80. Memo: memo,
  81. Time: time.Now(),
  82. Ip: utils.GetIP(c.Request),
  83. Data: ext,
  84. }
  85. db.Db.Insert(&tmp)
  86. }