审查视图

pkg/domain/qrcode.go 1.5 KB
1 2 3
package domain

import (
yangfu authored
4
	"encoding/base64"
5
	"fmt"
yangfu authored
6
	"github.com/forgoer/openssl"
yangfu authored
7
	"github.com/google/uuid"
yangfu authored
8
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
yangfu authored
9 10
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
	"strings"
11 12 13
)

const (
yangfu authored
14
	QrcodeCodeExpire int64 = 60 * 5 //5分钟过期
15 16
)
yangfu authored
17 18 19 20
var (
	aecSecret = []byte("mmm.qrcode.ecb.1")
	qrcodeLogin = "/v1/auth/login/qrcode?key="
)
yangfu authored
21
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
type QrcodeMessage struct {
	Id      string `json:"id"`
	Token   string `json:"token"`
	IsLogin bool   `json:"isLogin"`
	//用户id
	UserId     int64 `json:"userId"`
	UserBaseId int64 `json:"userBaseId"`
	// 账号
	Account string `json:"account"`
	// 公司id
	CompanyId int64 `json:"companyId"`
	// 组织id
	OrgId int64 `json:"orgId"`
}
yangfu authored
37 38
func (qrmsg *QrcodeMessage) Init() ([]byte, error) {
	str := strings.Replace(uuid.New().String(), "-", "", -1)
yangfu authored
39
	key := constant.ALLIED_CREATION_GATEWAY_HOST + qrcodeLogin + str
yangfu authored
40
	log.Logger.Debug("key:" + key)
yangfu authored
41 42 43 44
	encryptedData, err := openssl.AesECBEncrypt([]byte(key), aecSecret, openssl.PKCS7_PADDING)
	if err != nil {
		return nil, err
	}
yangfu authored
45
	qrmsg.Id = str
yangfu authored
46
	qrmsg.Token = base64.StdEncoding.EncodeToString(encryptedData)
47
	qrmsg.IsLogin = false
yangfu authored
48
	return encryptedData, err
49 50
}
yangfu authored
51 52 53 54 55 56 57 58 59 60 61 62
func (qrmsg *QrcodeMessage) BindUser(operator Operator) error {
	if qrmsg.IsLogin {
		return fmt.Errorf("登录中")
	}
	qrmsg.UserId = operator.UserId
	qrmsg.OrgId = operator.OrgId
	qrmsg.CompanyId = operator.CompanyId
	qrmsg.UserBaseId = operator.UserBaseId
	qrmsg.Account = operator.Phone
	qrmsg.IsLogin = true
	return nil
}