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

hdl_file_img_req_upload.go 3.0 KiB

2 달 전
2 달 전
2 달 전
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package hdl
  2. import (
  3. "applet/app/e"
  4. "applet/app/md"
  5. "applet/app/svc"
  6. "applet/app/utils"
  7. "applet/app/utils/logx"
  8. "github.com/gin-gonic/gin"
  9. )
  10. // 请求上传图片
  11. func ImgReqUpload(c *gin.Context) {
  12. user := svc.GetUser(c)
  13. uid := utils.IntToStr(user.Info.Uid)
  14. // 文件名名称
  15. var args struct {
  16. Dir string `json:"dir"`
  17. FileName string `json:"file_name"`
  18. FileSize int64 `json:"file_size"` // 文件大小, 单位byte
  19. }
  20. if err := c.ShouldBindJSON(&args); err != nil || args.FileSize < 1 || args.FileName == "" {
  21. logx.Warn(err)
  22. e.OutErr(c, e.ERR_INVALID_ARGS)
  23. return
  24. }
  25. //// 限制用户上传目录
  26. //if _, ok := md.FileUserDir[args.Dir]; !ok {
  27. // e.OutErr(c, e.ERR_FORBIDEN)
  28. // return
  29. //}
  30. scheme := "http"
  31. if c.Request.TLS != nil {
  32. scheme = "https"
  33. }
  34. // 拼装回调地址
  35. callbackUrl := scheme + "://" + c.Request.Host + "/api/v1/communityTeam/agent/file/img/callback?master_id=" + c.GetString("mid")
  36. utils.FilePutContents("qiniuyun", callbackUrl)
  37. //fmt.Println(callbackUrl)
  38. // callbackUrl = "http://120.55.83.222/raw.php"
  39. res, err := svc.ImgReqUpload(c, uid, args.Dir, args.FileName, callbackUrl, args.FileSize)
  40. if err != nil {
  41. e.OutErr(c, 400, err)
  42. return
  43. }
  44. my := utils.SerializeStr(res)
  45. var my1 map[string]interface{}
  46. utils.Unserialize([]byte(my), &my1)
  47. if c.GetHeader("Platform") == md.PLATFORM_WX_APPLET || c.GetHeader("Platform") == md.PLATFORM_TIKTOK_APPLET || c.GetHeader("Platform") == md.PLATFORM_TOUTIAO_APPLET || c.GetHeader("Platform") == md.PLATFORM_BAIDU_APPLET || c.GetHeader("Platform") == md.PLATFORM_ALIPAY_APPLET {
  48. my1["host"] = "https://api.zhiyingos.com/api/v1/proxy/upload" //官方页面才有白名单
  49. }
  50. e.OutSuc(c, my1, nil)
  51. }
  52. // 请求上传图片
  53. func ImgReqUploadNoUser(c *gin.Context) {
  54. // 文件名名称
  55. var args struct {
  56. Dir string `json:"dir"`
  57. FileName string `json:"file_name"`
  58. FileSize int64 `json:"file_size"` // 文件大小, 单位byte
  59. }
  60. if err := c.ShouldBindJSON(&args); err != nil || args.FileSize < 1 || args.FileName == "" {
  61. logx.Warn(err)
  62. e.OutErr(c, e.ERR_INVALID_ARGS)
  63. return
  64. }
  65. scheme := "http"
  66. if c.Request.TLS != nil {
  67. scheme = "https"
  68. }
  69. // 拼装回调地址
  70. callbackUrl := scheme + "://" + c.Request.Host + "/api/v1/file/img/callback?master_id=" + c.GetString("mid")
  71. utils.FilePutContents("qny", callbackUrl)
  72. //fmt.Println(callbackUrl)
  73. // callbackUrl = "http://120.55.83.222/raw.php"
  74. res, err := svc.ImgReqUpload(c, "", args.Dir, args.FileName, callbackUrl, args.FileSize)
  75. if err != nil {
  76. e.OutErr(c, 400, err)
  77. return
  78. }
  79. my := utils.SerializeStr(res)
  80. var my1 map[string]interface{}
  81. utils.Unserialize([]byte(my), &my1)
  82. domainApiBase := svc.GetWebSiteDomainInfoOfficial(c, "api")
  83. if c.GetHeader("Platform") == md.PLATFORM_WX_APPLET || c.GetHeader("Platform") == md.PLATFORM_TIKTOK_APPLET || c.GetHeader("Platform") == md.PLATFORM_TOUTIAO_APPLET || c.GetHeader("Platform") == md.PLATFORM_BAIDU_APPLET || c.GetHeader("Platform") == md.PLATFORM_ALIPAY_APPLET {
  84. my1["host"] = domainApiBase + "/api/v1/proxy/upload"
  85. }
  86. e.OutSuc(c, my1, nil)
  87. }