附近小店
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

82 líneas
2.6 KiB

  1. package svc
  2. import (
  3. "applet/app/utils"
  4. "fmt"
  5. "github.com/syyongx/php2go"
  6. "strings"
  7. "github.com/gin-gonic/gin"
  8. )
  9. // ImageFormat is 格式化 图片
  10. func ImageFormat(c *gin.Context, name string) string {
  11. if strings.Contains(name, "https:") || strings.Contains(name, "http:") {
  12. return name
  13. }
  14. scheme := SysCfgGet(c, "file_bucket_scheme")
  15. domain := SysCfgGet(c, "file_bucket_host")
  16. name, _ = php2go.URLDecode(name)
  17. name = php2go.URLEncode(name)
  18. return fmt.Sprintf("%s://%s/%s", scheme, domain, name)
  19. }
  20. // OffImageFormat is 格式化官方 图片
  21. func OffImageFormat(c *gin.Context, name string) string {
  22. if strings.Contains(name, "https:") || strings.Contains(name, "http:") {
  23. return name
  24. }
  25. name, _ = php2go.URLDecode(name)
  26. name = php2go.URLEncode(name)
  27. return fmt.Sprintf("%s://%s/%s", "http", "ossn.izhim.net", name)
  28. }
  29. // ImageBucket is 获取域名
  30. func ImageBucket(c *gin.Context) (string, string) {
  31. return SysCfgGet(c, "file_bucket_scheme"), SysCfgGet(c, "file_bucket_host")
  32. }
  33. // ImageFormatWithBucket is 格式化成oss 域名
  34. func ImageFormatWithBucket(scheme, domain, name string) string {
  35. if strings.Contains(name, "http") || name == "" {
  36. return name
  37. }
  38. name, _ = php2go.URLDecode(name)
  39. name = php2go.URLEncode(name)
  40. return fmt.Sprintf("%s://%s/%s", scheme, domain, name)
  41. }
  42. // ImageBucketNew is 获取域名
  43. func ImageBucketNew(c *gin.Context) (string, string, string, map[string]string) {
  44. var list = make(map[string]string, 0)
  45. for i := 1; i < 10; i++ {
  46. keys := "file_bucket_sub_host" + utils.IntToStr(i)
  47. list[keys] = SysCfgGet(c, keys)
  48. }
  49. return SysCfgGet(c, "file_bucket_scheme"), SysCfgGet(c, "file_bucket_host"), SysCfgGet(c, "file_bucket_sub_host"), list
  50. }
  51. // ImageFormatWithBucket is 格式化成oss 域名
  52. func ImageFormatWithBucketNew(scheme, domain, subDomain string, moreSubDomain map[string]string, name string) string {
  53. if strings.Contains(name, "http") {
  54. return name
  55. }
  56. if strings.Contains(name, "{{subhost}}") && subDomain != "" { //读副域名 有可能是其他平台的
  57. domain = subDomain
  58. }
  59. //为了兼容一些客户自营商城导到不同系统 并且七牛云不一样
  60. for i := 1; i < 10; i++ {
  61. keys := "file_bucket_sub_host" + utils.IntToStr(i)
  62. if strings.Contains(name, "{{subhost"+utils.IntToStr(i)+"}}") && moreSubDomain[keys] != "" {
  63. domain = moreSubDomain[keys]
  64. }
  65. name = strings.ReplaceAll(name, "{{subhost"+utils.IntToStr(i)+"}}", "")
  66. }
  67. name = strings.ReplaceAll(name, "{{host}}", "")
  68. name = strings.ReplaceAll(name, "{{subhost}}", "")
  69. name, _ = php2go.URLDecode(name)
  70. name = php2go.URLEncode(name)
  71. return fmt.Sprintf("%s://%s/%s", scheme, domain, name)
  72. }