蛋蛋星球 后台端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 lines
2.3 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/utils/cache"
  5. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  6. openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
  7. ram20150501 "github.com/alibabacloud-go/ram-20150501/v2/client"
  8. sts20150401 "github.com/alibabacloud-go/sts-20150401/v2/client"
  9. util2 "github.com/alibabacloud-go/tea-utils/v2/service"
  10. "github.com/alibabacloud-go/tea/tea"
  11. "strings"
  12. )
  13. func GetOssUrl(img string) string {
  14. redisConn := cache.GetPool().Get()
  15. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  16. sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme")
  17. if strings.Contains(img, "http") == false && img != "" {
  18. http := sysCfg["oss_bucket_scheme"]
  19. img = http + "://" + sysCfg["oss_domain"] + "/" + img
  20. }
  21. return img
  22. }
  23. func GetOssDomain() string {
  24. redisConn := cache.GetPool().Get()
  25. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  26. sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain", "oss_bucket_scheme")
  27. http := sysCfg["oss_bucket_scheme"]
  28. return http + "://" + sysCfg["oss_domain"] + "/"
  29. }
  30. func GetSysCfgStr(key string) string {
  31. redisConn := cache.GetPool().Get()
  32. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  33. return sysCfgDb.SysCfgGetWithDb(key)
  34. }
  35. func CreateSTSClient(accessKeyId *string, accessKeySecret *string, stsEndpoint *string) (*sts20150401.Client, error) {
  36. config := &openapi.Config{
  37. AccessKeyId: accessKeyId,
  38. AccessKeySecret: accessKeySecret,
  39. // Endpoint 请参考 https://api.aliyun.com/product/Sts
  40. Endpoint: stsEndpoint,
  41. }
  42. return sts20150401.NewClient(config)
  43. }
  44. func AssumeRole(client *sts20150401.Client, roleArn *string, roleSessionName *string, durationSeconds int64) (*sts20150401.AssumeRoleResponse, error) {
  45. assumeRoleRequest := &sts20150401.AssumeRoleRequest{
  46. DurationSeconds: &durationSeconds,
  47. RoleArn: roleArn,
  48. RoleSessionName: roleSessionName,
  49. }
  50. return client.AssumeRoleWithOptions(assumeRoleRequest, &util2.RuntimeOptions{})
  51. }
  52. func CreateGetRoleClient(accessKeyId, accessKeySecret *string) (_result *ram20150501.Client, _err error) {
  53. config := &openapi.Config{
  54. AccessKeyId: accessKeyId,
  55. AccessKeySecret: accessKeySecret,
  56. }
  57. // Endpoint 请参考 https://api.aliyun.com/product/Ram
  58. config.Endpoint = tea.String("ram.aliyuncs.com")
  59. _result = &ram20150501.Client{}
  60. _result, _err = ram20150501.NewClient(config)
  61. return _result, _err
  62. }