|
123456789101112131415161718192021222324252627282930313233343536 |
- 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 := "./public/img/" + file.Filename
- c.SaveUploadedFile(file, fileStr)
- res := map[string]string{
- "fileName": "http://ywym.jiaxiandingding.top/public/img/" + file.Filename,
- "saveName": "public/img/" + file.Filename,
- }
- token, err := svc.GetWechatToken()
- if err != nil {
- e.OutErr(c, 400, err.Error())
- return
- }
- uri := "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token" + token + "&type=image"
- postFile, err := utils.PostFile("media", res["fileName"], uri)
- fmt.Println(postFile)
- fmt.Println(err)
- res["media_id"] = gjson.Get(string(postFile), "media_id").String()
- e.OutSuc(c, res, nil)
- return
- }
|