master
huanghai 5 years ago
parent ce4f9cdd57
commit 4840fea102

@ -21,9 +21,12 @@ import (
"fmt"
"github.com/dchest/captcha"
"github.com/gin-gonic/gin"
"github.com/opesun/goquery"
"github.com/tidwall/gjson"
"io"
"io/ioutil"
"net/http"
"os"
"strconv"
"strings"
"time"
@ -52,6 +55,8 @@ func Routers(r *gin.RouterGroup) {
r.GET("/checkOpenId", checkOpenId)
//绑定用户
r.POST("/bindWxUser", bindWxUser)
//显示微信二维码
r.GET("/wxShowImg", wxShowImg)
return
}
@ -705,3 +710,40 @@ func bindWxUser(context *gin.Context) {
return
}
}
// @Summary 微信显示二维码
// @Description 微信显示二维码
// @Tags 登录验证类
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Success 200 {string} string
// @Router /oauth2/wxShowImg [get]
// http://10.10.14.187/oauth2/wxShowImg
func wxShowImg(context *gin.Context) {
url := `https://open.weixin.qq.com/connect/qrconnect?appid=wx3e0449144386938a&redirect_uri=http://fort.edusoa.com:7777/sso/static/jumpWx.html&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect`
//获取http代码
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
//下载文件到本地临时目录中
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)
}
}

Loading…
Cancel
Save