first commit
This commit is contained in:
437
api/controller/loginController.go
Normal file
437
api/controller/loginController.go
Normal file
@@ -0,0 +1,437 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
"xiawan/wx/api/req"
|
||||
"xiawan/wx/api/service"
|
||||
"xiawan/wx/api/vo"
|
||||
"xiawan/wx/clientsdk/baseutils"
|
||||
"xiawan/wx/db"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gogf/guuid"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
// 检查请求参数 key 对应的 license 是否可用
|
||||
func checkLicense(ctx *gin.Context) (string, error) {
|
||||
queryKey, isExist := ctx.GetQuery("key")
|
||||
errMsg := fmt.Sprintf("%s 该 key 无效! 请 检查正确性 或 联系管理员生成", queryKey)
|
||||
if !isExist || len(strings.TrimSpace(queryKey)) == 0 {
|
||||
// 请求参数中没有携带 license 或者 license 为空
|
||||
return "", errors.New(errMsg)
|
||||
}
|
||||
has, err := db.HasLicense(queryKey)
|
||||
if has == nil || err != nil {
|
||||
// MySQL 数据库没有该 license
|
||||
return "", errors.New(errMsg)
|
||||
}
|
||||
if db.CheckExpiry(has.ExpiryDate, has.Type) {
|
||||
// MySQL 数据库中的该 license 已过期
|
||||
return "", errors.New(fmt.Sprintf("%s 该 key 已过期!", queryKey))
|
||||
}
|
||||
|
||||
// license 可用
|
||||
return queryKey, nil
|
||||
}
|
||||
|
||||
// GetLoginQrCodeTempShow HTML展示登录二维码
|
||||
func GetLoginQrCodeTempShow(ctx *gin.Context) {
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
//获取二维码
|
||||
qrcodeResponse, dto := service.GetLoginQrCodeShow(queryKey)
|
||||
|
||||
// 二维码写入到文件
|
||||
baseutils.WriteToFile(qrcodeResponse.GetQrcode().GetSrc(), "static/qrcode/"+qrcodeResponse.GetUuid()+".png")
|
||||
// 延时删除图片
|
||||
go func() {
|
||||
time.Sleep(time.Second * 10)
|
||||
err := os.Remove("static/qrcode/" + qrcodeResponse.GetUuid() + ".png")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
if dto.Code == vo.SUCCESS {
|
||||
ctx.HTML(http.StatusOK, "login.tmpl", gin.H{"img": qrcodeResponse.GetUuid()})
|
||||
} else {
|
||||
ctx.HTML(http.StatusOK, "err.tmpl", gin.H{"showlog": dto})
|
||||
}
|
||||
}
|
||||
|
||||
// GetLoginQrCodeNewApi 获取登录二维码-iPad(异地IP必须用代理! socks5://username:password@ipv4:port)
|
||||
func GetLoginQrCodeNewApi(ctx *gin.Context) {
|
||||
reqModel := new(req.GetLoginQrCodeModel)
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
result := service.GetLoginQrCodeNewService(queryKey, *reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// GetLoginQrCodeNewApi 获取登录二维码-直登(异地IP必须用代理! socks5://username:password@ipv4:port)
|
||||
func GetLoginQrCodeNewApiDirect(ctx *gin.Context) {
|
||||
reqModel := new(req.GetLoginQrCodeModel)
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
result := service.GetLoginQrCodeNewServiceDirect(queryKey, *reqModel, reqModel.IpadOrmac)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// WxBindOpMobileForRegApi 获取验证码
|
||||
func WxBindOpMobileForRegApi(ctx *gin.Context) {
|
||||
reqModel := new(req.WxBindOpMobileForModel)
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
result := service.WxBindOpMobileForRegService(queryKey, *reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// Get62DataApi 提取62数据
|
||||
func Get62DataApi(ctx *gin.Context) {
|
||||
queryKey, isExist := ctx.GetQuery("key")
|
||||
if !isExist {
|
||||
queryKey = guuid.New().String()
|
||||
}
|
||||
result := service.Get62DataService(queryKey)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// PhoneDeviceLoginApi 辅助新手机登录
|
||||
func PhoneDeviceLoginApi(ctx *gin.Context) {
|
||||
reqModel := new(req.PhoneLoginModel)
|
||||
queryKey, isExist := ctx.GetQuery("key")
|
||||
if !isExist || strings.Trim(queryKey, "") == "" || strings.Trim(queryKey, "") == "null" {
|
||||
//确保每次都有Key
|
||||
ctx.JSON(http.StatusOK, vo.NewFailUUId(""))
|
||||
return
|
||||
}
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
result := service.PhoneDeviceLoginService(queryKey, *reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// DeviceIdLoginApi 62账号密码登录
|
||||
func DeviceIdLoginApi(ctx *gin.Context) {
|
||||
reqModel := new(req.DeviceIdLoginModel)
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
result := service.DeviceIdLoginService(queryKey, *reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// SmsLoginApi 短信登录
|
||||
func SmsLoginApi(ctx *gin.Context) {
|
||||
reqModel := new(req.DeviceIdLoginModel)
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
reqModel.Password = "strdm@," + reqModel.Password
|
||||
result := service.SmsLoginService(queryKey, *reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// A16LoginApi A16数据登录
|
||||
func A16LoginApi(ctx *gin.Context) {
|
||||
reqModel := new(req.DeviceIdLoginModel)
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
result := service.A16LoginService(queryKey, *reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// LoginNewApi 62LoginNew新疆号登录
|
||||
func LoginNewApi(ctx *gin.Context) {
|
||||
reqModel := new(req.DeviceIdLoginModel)
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
reqModel.Type = 1
|
||||
result := service.A16LoginService(queryKey, *reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// CheckLoginStatusApi 检测扫码状态
|
||||
func CheckLoginStatusApi(ctx *gin.Context) {
|
||||
queryKey, isExist := ctx.GetQuery("key")
|
||||
if !isExist || strings.Trim(queryKey, "") == "" || strings.Trim(queryKey, "") == "null" {
|
||||
//确保每次都有Key
|
||||
ctx.JSON(http.StatusOK, vo.NewFailUUId(""))
|
||||
return
|
||||
}
|
||||
|
||||
result := service.CheckLoginQrCodeStatusService(queryKey)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// GetInItStatusApi 初始化状态
|
||||
func GetInItStatusApi(ctx *gin.Context) {
|
||||
queryKey, isExist := ctx.GetQuery("key")
|
||||
if !isExist || strings.Trim(queryKey, "") == "" || strings.Trim(queryKey, "") == "null" {
|
||||
//确保每次都有Key
|
||||
ctx.JSON(http.StatusOK, vo.NewFailUUId(""))
|
||||
return
|
||||
}
|
||||
result := service.GetInItStatusService(queryKey)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// WakeUpLoginApi 唤醒登录(只限扫码登录)
|
||||
func WakeUpLoginApi(ctx *gin.Context) {
|
||||
reqModel := new(req.GetLoginQrCodeModel)
|
||||
queryKey, isExist := ctx.GetQuery("key")
|
||||
if !isExist || strings.Trim(queryKey, "") == "" || strings.Trim(queryKey, "") == "null" {
|
||||
//确保每次都有Key
|
||||
ctx.JSON(http.StatusOK, vo.NewFailUUId(""))
|
||||
return
|
||||
}
|
||||
result := service.WakeUpLoginService(queryKey, reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// GetLoginStatusApi 获取在线状态
|
||||
func GetLoginStatusApi(ctx *gin.Context) {
|
||||
autoLogin := true
|
||||
queryKey, isExist := ctx.GetQuery("key")
|
||||
if !isExist || strings.Trim(queryKey, "") == "" || strings.Trim(queryKey, "") == "null" {
|
||||
//确保每次都有Key
|
||||
ctx.JSON(http.StatusOK, vo.NewFailUUId(""))
|
||||
return
|
||||
}
|
||||
isAutoLogin, isExist := ctx.GetQuery("autoLogin")
|
||||
if isExist {
|
||||
if strings.Contains(isAutoLogin, "false") {
|
||||
autoLogin = false
|
||||
}
|
||||
}
|
||||
|
||||
result := service.GetLoginStatusService(queryKey, false, autoLogin)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// GetSafetyInfoApi 获取安全设备列表
|
||||
func GetSafetyInfoApi(ctx *gin.Context) {
|
||||
queryKey, _ := ctx.GetQuery("key")
|
||||
result := service.GetSafetyInfoService(queryKey)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// DelSafeDeviceApi 删除安全设备
|
||||
func DelSafeDeviceApi(ctx *gin.Context) {
|
||||
reqModel := new(req.DelSafeDeviceModel)
|
||||
queryKey, _ := ctx.GetQuery("key")
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
result := service.DelSafeDeviceService(queryKey, *reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// GetBoundHardDevice 获取硬件设备情况
|
||||
func GetBoundHardDevice(ctx *gin.Context) {
|
||||
queryKey, _ := ctx.GetQuery("key")
|
||||
result := service.GetBoundHardDeviceService(queryKey)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// CheckCanSetAliasApi 检测微信登录环境
|
||||
func CheckCanSetAliasApi(ctx *gin.Context) {
|
||||
queryKey, _ := ctx.GetQuery("key")
|
||||
result := service.CheckCanSetAliasService(queryKey)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// IWXConnectMgrApi 打印链接数量
|
||||
func IWXConnectMgrApi(ctx *gin.Context) {
|
||||
result := service.IWXConnectMgrService()
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// GetConnectInfo 打印链接信息
|
||||
func GetConnectInfo(ctx *gin.Context) {
|
||||
result := service.GetConnectInfo()
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// LogOutRequestApi 退出登录
|
||||
func LogOutRequestApi(ctx *gin.Context) {
|
||||
|
||||
queryKey, isExist := ctx.GetQuery("key")
|
||||
if !isExist || strings.Trim(queryKey, "") == "" || strings.Trim(queryKey, "") == "null" {
|
||||
//确保每次都有Key
|
||||
ctx.JSON(http.StatusOK, vo.NewFailUUId(""))
|
||||
return
|
||||
}
|
||||
|
||||
result := service.LogOutService(queryKey)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// MacLoginApi 获取Mac登录二维码 (异地IP必须用代理 socks5://username:password@ipv4:port)
|
||||
func MacLoginApi(ctx *gin.Context) {
|
||||
reqModel := new(req.GetLoginQrCodeModel)
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
result := service.MacLoginService(queryKey, *reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// AndroidPadLoginApi 获取安卓平板登录二维码 (异地IP必须用代理 socks5://username:password@ipv4:port)
|
||||
func AndroidPadLoginApi(ctx *gin.Context) {
|
||||
reqModel := new(req.GetLoginQrCodeModel)
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
result := service.AndroidPadLoginService(queryKey, *reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// CarLoginApi 获取车载登录二维码 (异地IP必须用代理 socks5://username:password@ipv4:port)
|
||||
func CarLoginApi(ctx *gin.Context) {
|
||||
reqModel := new(req.GetLoginQrCodeModel)
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
result := service.CarLoginService(queryKey, *reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// VerifyCodeApi 验证码验证(输入iPad登录验证码)
|
||||
func VerifyCodeApi(ctx *gin.Context) {
|
||||
reqModel := new(req.VerifyCodeModel)
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
|
||||
param := req.VerifyCodeModel{
|
||||
Code: reqModel.Code,
|
||||
Data62: reqModel.Data62,
|
||||
Ticket: reqModel.Ticket,
|
||||
}
|
||||
result := service.Verificationcode2(param, queryKey)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// VerifyCodeSlideApi 过mac滑块验证
|
||||
func VerifyCodeApiSlide(ctx *gin.Context) {
|
||||
reqModel := new(req.SlideTicketModel)
|
||||
queryKey, _ := ctx.GetQuery("key")
|
||||
if queryKey != "1234520" {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail("key错误"))
|
||||
return
|
||||
}
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
param := req.SlideTicketModel{
|
||||
Data62: reqModel.Data62,
|
||||
Ticket: reqModel.Ticket,
|
||||
RandStr: reqModel.RandStr,
|
||||
SlideTicket: reqModel.SlideTicket,
|
||||
}
|
||||
result := service.VerificationcodeSlide(param)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
|
||||
// WinLoginService win登录
|
||||
func WinLoginService(ctx *gin.Context) {
|
||||
reqModel := new(req.GetLoginQrCodeModel)
|
||||
queryKey, err := checkLicense(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, vo.NewFail(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if !validateData(ctx, &reqModel) {
|
||||
return
|
||||
}
|
||||
result := service.WinLoginService(queryKey, *reqModel)
|
||||
ctx.JSON(http.StatusOK, result)
|
||||
}
|
||||
Reference in New Issue
Block a user