一物一码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

37 lines
930 B

  1. package hdl
  2. import (
  3. "applet/app/e"
  4. "applet/app/svc"
  5. "applet/app/utils"
  6. "fmt"
  7. "github.com/gin-gonic/gin"
  8. "github.com/tidwall/gjson"
  9. )
  10. func ImgUpload(c *gin.Context) {
  11. file, err := c.FormFile("file")
  12. if err != nil {
  13. e.OutErr(c, 400, e.NewErr(400, "上传图片失败"))
  14. return
  15. }
  16. fileStr := "./public/img/" + file.Filename
  17. c.SaveUploadedFile(file, fileStr)
  18. res := map[string]string{
  19. "fileName": "http://ywym.jiaxiandingding.top/public/img/" + file.Filename,
  20. "saveName": "public/img/" + file.Filename,
  21. }
  22. token, err := svc.GetWechatToken()
  23. if err != nil {
  24. e.OutErr(c, 400, err.Error())
  25. return
  26. }
  27. uri := "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token" + token + "&type=image"
  28. postFile, err := utils.PostFile("media", res["fileName"], uri)
  29. fmt.Println(postFile)
  30. fmt.Println(err)
  31. res["media_id"] = gjson.Get(string(postFile), "media_id").String()
  32. e.OutSuc(c, res, nil)
  33. return
  34. }