From 83d2801735b9ec4a5f671776cdde81eef5fcb15c Mon Sep 17 00:00:00 2001 From: huanghai <10402852@qq.com> Date: Thu, 30 Jul 2020 17:20:46 +0800 Subject: [PATCH] 'commit' --- .../ControllerOauth2/ControllerOauth2.go | 20 ++++++++++++++++++- dsSso/Utils/CommonUtil/CommonUtil.go | 12 ++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/dsSso/Controller/ControllerOauth2/ControllerOauth2.go b/dsSso/Controller/ControllerOauth2/ControllerOauth2.go index 2e5706cb..6d9444de 100644 --- a/dsSso/Controller/ControllerOauth2/ControllerOauth2.go +++ b/dsSso/Controller/ControllerOauth2/ControllerOauth2.go @@ -23,8 +23,10 @@ import ( "github.com/gin-gonic/gin" "github.com/opesun/goquery" "github.com/tidwall/gjson" + "io" "io/ioutil" "net/http" + "os" "strconv" "strings" "time" @@ -542,9 +544,25 @@ func wxShowImg(context *gin.Context) { p, err := goquery.ParseUrl(url) if err != nil { context.JSON(http.StatusOK, map[string]interface{}{"success": false, "imgSrc": "", "message": "获取微信图片发生异常!"}) + return } else { imgSrc := p.Find("img").Attr("src") imgSrc = `https://open.weixin.qq.com` + imgSrc - context.JSON(http.StatusOK, map[string]interface{}{"success": true, "imgSrc": imgSrc}) + //下载文件到本地临时目录中 + res, err := http.Get(imgSrc) + if err != nil { + context.JSON(http.StatusOK, map[string]interface{}{"success": false, "imgSrc": "", "message": "获取微信图片发生异常!"}) + return + } + //图片 + pngFile := "/usr/local/dsMin/dsSso/Logs/" + CommonUtil.GetUUID() + ".png" + f, err := os.Create(pngFile) + if err != nil { + context.JSON(http.StatusOK, map[string]interface{}{"success": false, "imgSrc": "", "message": "获取微信图片发生异常!"}) + return + } + io.Copy(f, res.Body) + //提供图片 + context.File(pngFile) } } diff --git a/dsSso/Utils/CommonUtil/CommonUtil.go b/dsSso/Utils/CommonUtil/CommonUtil.go index f3bf5ef4..58b218e8 100644 --- a/dsSso/Utils/CommonUtil/CommonUtil.go +++ b/dsSso/Utils/CommonUtil/CommonUtil.go @@ -6,6 +6,7 @@ import ( "dsSso/Utils/IdCardUtil" "errors" "fmt" + uuid "github.com/satori/go.uuid" "log" "net" "net/http" @@ -290,4 +291,13 @@ func CheckPasswordLevel(ps string) error { return fmt.Errorf("password need symbol :%v", err) } return nil -} \ No newline at end of file +} +/** +功能:获取UUID +作者:黄海 +时间:2020-02-03 +*/ +func GetUUID() string { + u2 := strings.ToUpper(uuid.NewV4().String()) + return u2 +}