附近小店
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

87 行
2.9 KiB

  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. scheme := "http"
  26. if c.Request.TLS != nil {
  27. scheme = "https"
  28. }
  29. // 拼装回调地址
  30. callbackUrl := scheme + "://" + c.Request.Host + "/api/v1/file/img/callback?master_id=" + c.GetString("mid")
  31. utils.FilePutContents("qiniuyun", callbackUrl)
  32. //fmt.Println(callbackUrl)
  33. // callbackUrl = "http://120.55.83.222/raw.php"
  34. res, err := svc.ImgReqUpload(c, uid, args.Dir, args.FileName, callbackUrl, args.FileSize)
  35. if err != nil {
  36. e.OutErr(c, 400, err)
  37. return
  38. }
  39. my := utils.SerializeStr(res)
  40. var my1 map[string]interface{}
  41. utils.Unserialize([]byte(my), &my1)
  42. 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 {
  43. my1["host"] = "https://api.zhiyingos.com/api/v1/proxy/upload" //官方页面才有白名单
  44. }
  45. e.OutSuc(c, my1, nil)
  46. }
  47. // 请求上传图片
  48. func ImgReqUploadNoUser(c *gin.Context) {
  49. // 文件名名称
  50. var args struct {
  51. Dir string `json:"dir"`
  52. FileName string `json:"file_name"`
  53. FileSize int64 `json:"file_size"` // 文件大小, 单位byte
  54. }
  55. if err := c.ShouldBindJSON(&args); err != nil || args.FileSize < 1 || args.FileName == "" {
  56. logx.Warn(err)
  57. e.OutErr(c, e.ERR_INVALID_ARGS)
  58. return
  59. }
  60. scheme := "http"
  61. if c.Request.TLS != nil {
  62. scheme = "https"
  63. }
  64. // 拼装回调地址
  65. callbackUrl := scheme + "://" + c.Request.Host + "/api/v1/file/img/callback?master_id=" + c.GetString("mid")
  66. utils.FilePutContents("qny", callbackUrl)
  67. //fmt.Println(callbackUrl)
  68. // callbackUrl = "http://120.55.83.222/raw.php"
  69. res, err := svc.ImgReqUpload(c, "", args.Dir, args.FileName, callbackUrl, args.FileSize)
  70. if err != nil {
  71. e.OutErr(c, 400, err)
  72. return
  73. }
  74. my := utils.SerializeStr(res)
  75. var my1 map[string]interface{}
  76. utils.Unserialize([]byte(my), &my1)
  77. domainApiBase := svc.GetWebSiteDomainInfoOfficial(c, "api")
  78. 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 {
  79. my1["host"] = domainApiBase + "/api/v1/proxy/upload"
  80. }
  81. e.OutSuc(c, my1, nil)
  82. }