package hdl import ( "applet/app/e" "applet/app/svc" "applet/app/utils" "fmt" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" ) func ImgUpload(c *gin.Context) { file, err := c.FormFile("file") if err != nil { e.OutErr(c, 400, e.NewErr(400, "上传图片失败")) return } fileStr := "./static/img/" + file.Filename c.SaveUploadedFile(file, fileStr) res := map[string]string{ "fileName": "http://ywym.jiaxiandingding.top/serverStatic/img/" + file.Filename, "saveName": "serverStatic/img/" + file.Filename, } token, err := svc.GetWechatToken() if err != nil { e.OutErr(c, 400, err.Error()) return } fmt.Println(token) uri := "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=" + token + "&type=image" postFile, err := utils.PostFile("media", fileStr, uri) fmt.Println(string(postFile)) fmt.Println(err) res["mediaId"] = gjson.Get(string(postFile), "media_id").String() e.OutSuc(c, res, nil) return }