作者 yangfu

扫码登录修改

... ... @@ -103,6 +103,8 @@ spec:
value: "false"
- name: HTTP_PORT
value: "8082"
- name: ALLIED_CREATION_GATEWAY_HOST
value: "https://allied-creation-gateway-dev.fjmaimaimai.com"
- name: ALLIED_CREATION_USER_HOST
value: "http://allied-creation-user-dev.fjmaimaimai.com"
- name: ALLIED_CREATION_COOPERATION_HOST
... ...
... ... @@ -107,6 +107,8 @@ spec:
value: "false"
- name: HTTP_PORT
value: "8082"
- name: ALLIED_CREATION_GATEWAY_HOST
value: "https://allied-creation-gateway-test.fjmaimaimai.com"
- name: ALLIED_CREATION_USER_HOST
value: "https://allied-creation-user-test.fjmaimaimai.com"
- name: ALLIED_CREATION_COOPERATION_HOST
... ...
... ... @@ -6,6 +6,7 @@ require (
github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2
github.com/beego/beego/v2 v2.0.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/forgoer/openssl v0.0.0-20210828150411-6c5378b5b719 // indirect
github.com/go-pg/pg/v10 v10.10.1
github.com/go-redis/redis v6.14.2+incompatible
github.com/google/uuid v1.1.1
... ...
... ... @@ -54,6 +54,8 @@ github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3C
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/forgoer/openssl v0.0.0-20210828150411-6c5378b5b719 h1:sBIoJbXC+QBD9kL00aAxi7dfJJ70YHhiKzSN9yeTjbU=
github.com/forgoer/openssl v0.0.0-20210828150411-6c5378b5b719/go.mod h1:NMVFOzYeLVR7UiGTxsa+A21nrERTZ3Rv2JHDPcJpDyI=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/frankban/quicktest v1.4.1 h1:Wv2VwvNn73pAdFIVUQRXYDFp31lXKbqblIXo/Q5GPSg=
... ...
... ... @@ -8,12 +8,13 @@ import (
const SERVICE_NAME = "allied-creation-gateway"
var LOG_LEVEL = "debug"
var LOG_TYPE = "console"// file, console, es
var LOG_TYPE = "console" // file, console, es
var LOG_FRAMEWORK = "beego" // beego logrus
var LOG_FILE = "app.log"
var LOG_PREFIX = "[allied-creation-gateway]"
var HTTP_PORT int = 8083
var ALLIED_CREATION_GATEWAY_HOST = "https://allied-creation-gateway-dev.fjmaimaimai.com"
//天联共创基础模块
var ALLIED_CREATION_BASIC_HOST = "http://localhost:8080" //"http://allied-creation-basic-dev.fjmaimaimai.com"
... ... @@ -37,6 +38,9 @@ func init() {
if os.Getenv("LOG_TYPE") != "" {
LOG_TYPE = os.Getenv("LOG_TYPE")
}
if os.Getenv("ALLIED_CREATION_GATEWAY_HOST") != "" {
ALLIED_CREATION_GATEWAY_HOST = os.Getenv("ALLIED_CREATION_GATEWAY_HOST")
}
if os.Getenv("ALLIED_CREATION_BASIC_HOST") != "" {
ALLIED_CREATION_BASIC_HOST = os.Getenv("ALLIED_CREATION_BASIC_HOST")
}
... ...
... ... @@ -3,8 +3,8 @@ package domain
import (
"encoding/base64"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/util"
"log"
"github.com/forgoer/openssl"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
"time"
jwt "github.com/dgrijalva/jwt-go"
... ... @@ -15,8 +15,8 @@ const (
qrcodeCodeExpire int64 = 60 * 30 //15分钟过期
)
var aecSecret = []byte("mmm.qrcode.(%^&)")
var loginHost = "https://api.fjmaimaimai.com/app/auth/login/qrcode?key="
var aecSecret = []byte("mmm.qrcode.ecb.1")
var qrcodeLogin = "/v1/auth/login/qrcode?key="
type QrcodeMessage struct {
jwt.StandardClaims
... ... @@ -48,34 +48,13 @@ func (qrmsg *QrcodeMessage) GenerateImageBase64() ([]byte, error) {
if err != nil {
return nil, err
}
key := loginHost + str
encryptedData, err := util.AesEncrypt([]byte(key), aecSecret)
key := constant.ALLIED_CREATION_GATEWAY_HOST + qrcodeLogin + str
encryptedData, err := openssl.AesECBEncrypt([]byte(key), aecSecret, openssl.PKCS7_PADDING)
if err != nil {
return nil, err
}
qrmsg.Token = base64.StdEncoding.EncodeToString(encryptedData)
//初始化数据
//qrmsg.Token = string(encryptedData)
qrmsg.IsLogin = false
// 输入日志
decrypted, _ := util.AesDecrypt(encryptedData, aecSecret)
if string(decrypted) == key {
log.Println("token:", str, "\n encrypt:", key, "\n decrypt:", string(decrypted))
}
//qrCode, err := qr.Encode(str, qr.M, qr.Auto)
//if err != nil {
// return nil, err
//}
//qrCode, err = barcode.Scale(qrCode, 200, 200)
//if err != nil {
// return nil, err
//}
//var buf bytes.Buffer
//err = png.Encode(&buf, qrCode)
//if err != nil {
// return nil, err
//}
//var result []byte
//base64.StdEncoding.Encode(result, buf.Bytes())
return encryptedData, err
}
... ...
... ... @@ -93,3 +93,30 @@ func AesDecrypt(crypted, key []byte) ([]byte, error) {
origData = PKCS7UnPadding(origData, blockSize)
return origData, nil
}
func ECBEncrypt(block cipher.Block, src, key []byte) ([]byte, error) {
blockSize := block.BlockSize()
encryptData := make([]byte, len(src))
tmpData := make([]byte, blockSize)
for index := 0; index < len(src); index += blockSize {
block.Encrypt(tmpData, src[index:index+blockSize])
copy(encryptData, tmpData)
}
return encryptData, nil
}
func ECBDecrypt(block cipher.Block, src, key []byte) ([]byte, error) {
dst := make([]byte, len(src))
blockSize := block.BlockSize()
tmpData := make([]byte, blockSize)
for index := 0; index < len(src); index += blockSize {
block.Decrypt(tmpData, src[index:index+blockSize])
copy(dst, tmpData)
}
return dst, nil
}
... ...
... ... @@ -3,28 +3,34 @@ package util
import (
"encoding/base64"
"fmt"
"github.com/forgoer/openssl"
"testing"
)
func Test_Aes(t *testing.T) {
//key的长度必须是16、24或者32字节,分别用于选择AES-128, AES-192, or AES-256
var aeskey = []byte("mmm.qrcode.(%^&)")
pass := []byte("vdncloud123456")
pass := []byte("https://www.baidu.com/")
xpass, err := AesEncrypt(pass, aeskey)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("base64 加密前:%v\n", string(xpass))
pass64 := base64.StdEncoding.EncodeToString(xpass)
fmt.Printf("加密后:%v\n", pass64)
fmt.Printf("base64 加密:%v\n", pass64)
//pass64 ="qYy8JqxzYGkhmDCZ6581/Fg9LfcGGqlAVjCWHpSayNs="
bytesPass, err := base64.StdEncoding.DecodeString(pass64)
fmt.Printf("base64 解密:%v\n", string(bytesPass))
if err != nil {
fmt.Println(err)
return
}
//bytesPass:=xpass
//fmt.Println(string(bytesPass))
tpass, err := AesDecrypt(bytesPass, aeskey)
if err != nil {
fmt.Println(err)
... ... @@ -32,3 +38,38 @@ func Test_Aes(t *testing.T) {
}
fmt.Printf("解密后:%s\n", tpass)
}
func Test_Base64(t *testing.T) {
xpass := []byte("123") //123
fmt.Printf("base64 加密前:%v\n", string(xpass))
pass64 := base64.StdEncoding.EncodeToString(xpass)
fmt.Printf("base64 加密:%v\n", pass64)
bytesPass, err := base64.StdEncoding.DecodeString(pass64)
fmt.Printf("base64 解密:%v\n", string(bytesPass))
if err != nil {
fmt.Println(err)
return
}
}
func Test_AES_ECB(t *testing.T) {
src := []byte("123456")
key := []byte("mmm.qrcode.ecb.1")
dst, _ := openssl.AesECBEncrypt(src, key, openssl.PKCS7_PADDING)
fmt.Println(base64.StdEncoding.EncodeToString(dst)) // 1jdzWuniG6UMtoa3T6uNLA==
dst, _ = openssl.AesECBDecrypt(dst, key, openssl.PKCS7_PADDING)
fmt.Println(string(dst)) // 123456
}
func Test_AES_CBC(t *testing.T) {
src := []byte("123456")
key := []byte("mmm.qrcode.ecb.1")
iv := []byte("mmm.qrcode.ecb.1")
dst, _ := openssl.AesCBCEncrypt(src, key, iv, openssl.PKCS7_PADDING)
fmt.Println(base64.StdEncoding.EncodeToString(dst)) // 1jdzWuniG6UMtoa3T6uNLA==
dst, _ = openssl.AesCBCDecrypt(dst, key, iv, openssl.PKCS7_PADDING)
fmt.Println(string(dst)) // 123456
}
... ...