|
|
|
@ -21,12 +21,9 @@ 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"
|
|
|
|
@ -51,8 +48,6 @@ func Routers(r *gin.RouterGroup) {
|
|
|
|
|
r.GET("/resetRemainCount", resetRemainCount)
|
|
|
|
|
//微信登录
|
|
|
|
|
r.POST("/wxLogin", wxLogin)
|
|
|
|
|
//微信二维码
|
|
|
|
|
r.GET("/wxShowImg", wxShowImg)
|
|
|
|
|
//检查OpenId
|
|
|
|
|
r.GET("/checkOpenId", checkOpenId)
|
|
|
|
|
//绑定用户
|
|
|
|
@ -116,6 +111,16 @@ func getCaptchaPng(c *gin.Context) {
|
|
|
|
|
ControllerRecaptcha.ServeHTTP(c.Writer, c.Request)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//写Cookie
|
|
|
|
|
func WriteCookie(context *gin.Context, identityId string, personId string, deviceId string) {
|
|
|
|
|
//1、生成加密串
|
|
|
|
|
r, _ := AesUtil.Encrypt([]byte(identityId + "_" + personId + "_" + deviceId + "_" + ConvertUtil.Int64ToString(CommonUtil.GetCurrentTimestamp())))
|
|
|
|
|
//2、转base64
|
|
|
|
|
encodeString := base64.RawURLEncoding.EncodeToString([]byte(r))
|
|
|
|
|
//3、写cookie
|
|
|
|
|
context.SetCookie(ConfigUtil.AccessToken, encodeString, 0, "/", "", false, true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
功能:产生授权码
|
|
|
|
|
作者:黄海
|
|
|
|
@ -128,12 +133,8 @@ func generateAuthCode(context *gin.Context, identityId string, personId string,
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
//1、生成加密串
|
|
|
|
|
r, _ := AesUtil.Encrypt([]byte(identityId + "_" + personId + "_" + deviceId + "_" + ConvertUtil.Int64ToString(CommonUtil.GetCurrentTimestamp())))
|
|
|
|
|
//2、转base64
|
|
|
|
|
encodeString := base64.RawURLEncoding.EncodeToString([]byte(r))
|
|
|
|
|
//3、写cookie
|
|
|
|
|
context.SetCookie(ConfigUtil.AccessToken, encodeString, 0, "/", "", false, true)
|
|
|
|
|
//写cookie
|
|
|
|
|
WriteCookie(context, identityId, personId, deviceId)
|
|
|
|
|
//如果是统一认证管理员登录
|
|
|
|
|
if identityId == "0" && personId == "0" {
|
|
|
|
|
context.JSON(http.StatusOK, Model.Res{
|
|
|
|
@ -597,48 +598,6 @@ func wxLogin(context *gin.Context) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Summary 微信显示二维码
|
|
|
|
|
// @Description 微信显示二维码
|
|
|
|
|
// @Tags 登录验证类
|
|
|
|
|
// @Accept application/x-www-form-urlencoded
|
|
|
|
|
// @Produce json
|
|
|
|
|
// @Success 200 {string} string
|
|
|
|
|
// @Router /oauth2/wxShowImg [get]
|
|
|
|
|
func wxShowImg(context *gin.Context) {
|
|
|
|
|
//异常处理
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
fmt.Printf("%s\n", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Summary 检查OPENID的是否已经绑定
|
|
|
|
|
// @Description 检查OPENID的是否已经绑定
|
|
|
|
|
// @Tags 登录验证类
|
|
|
|
@ -662,12 +621,8 @@ func checkOpenId(context *gin.Context) {
|
|
|
|
|
}
|
|
|
|
|
//1、此OpenId已经存在挂接关系,那么写入相应的登录标识,并跳转到指定的页面
|
|
|
|
|
if found {
|
|
|
|
|
//1、生成加密串
|
|
|
|
|
r, _ := AesUtil.Encrypt([]byte(CommonUtil.ConvertInt64ToString(identityId) + "_" + personId + "_1_" + ConvertUtil.Int64ToString(CommonUtil.GetCurrentTimestamp())))
|
|
|
|
|
//2、转base64
|
|
|
|
|
encodeString := base64.RawURLEncoding.EncodeToString([]byte(r))
|
|
|
|
|
//3、写cookie
|
|
|
|
|
context.SetCookie(ConfigUtil.AccessToken, encodeString, 0, "/", "", false, true)
|
|
|
|
|
//写cookie
|
|
|
|
|
WriteCookie(context, CommonUtil.ConvertInt64ToString(identityId), personId, "1")
|
|
|
|
|
//4、跳转到XXX页面,比如集成页,或者管理员的首页
|
|
|
|
|
context.JSON(http.StatusOK, map[string]interface{}{"success": true, "openId": openId})
|
|
|
|
|
} else {
|
|
|
|
@ -735,12 +690,8 @@ func bindWxUser(context *gin.Context) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
//输出正确了~
|
|
|
|
|
//1、生成加密串
|
|
|
|
|
r, _ := AesUtil.Encrypt([]byte(identityId + "_" + personId + "_1_" + ConvertUtil.Int64ToString(CommonUtil.GetCurrentTimestamp())))
|
|
|
|
|
//2、转base64
|
|
|
|
|
encodeString := base64.RawURLEncoding.EncodeToString([]byte(r))
|
|
|
|
|
//3、写cookie
|
|
|
|
|
context.SetCookie(ConfigUtil.AccessToken, encodeString, 0, "/", "", false, true)
|
|
|
|
|
//写cookie
|
|
|
|
|
WriteCookie(context, identityId, personId, "1")
|
|
|
|
|
context.JSON(http.StatusOK, Model.Res{
|
|
|
|
|
Code: http.StatusOK,
|
|
|
|
|
Msg: "绑定成功!",
|
|
|
|
|