作者 tangxuhui

Merge branch 'test' of http://gitlab.fjmaimaimai.com/allied-creation/allied-crea…

…tion-gateway into test
... ... @@ -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,10 @@ spec:
value: "false"
- name: HTTP_PORT
value: "8082"
- name: SUPLUS_ADMIN_BASE_HOST
value: "http://suplus-admin-base-test.fjmaimaimai.com"
- 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=
... ...
... ... @@ -369,7 +369,7 @@ func (svr AuthService) OrgSwitch(switchOrgCommand *command.SwitchOrgCommand) (in
loginToken := domain.LoginToken{}
err := loginToken.ParseToken(switchOrgCommand.Operator.Token)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "accessToken 不可用,"+err.Error())
return nil, domain.NewApplicationError(domain.InvalidAccessToken)
}
loginToken.OrgId = switchOrgCommand.OrgId
token, err := svr.getToken(loginToken)
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"net/http"
)
type GetLatestVersionQuery struct {
//操作人
//操作人
//Operator domain.Operator `json:"-"`
DeviceType string `json:"-"`
VersionNo int `json:"versionNo"`
Channel int `json:"channel"`
Request *http.Request `json:"-"`
}
func (departmentsUsersQuery *GetLatestVersionQuery) Valid(validation *validation.Validation) {
}
func (departmentsUsersQuery *GetLatestVersionQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(departmentsUsersQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -4,6 +4,9 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/query"
)
const IOSPage = "http://fir.fjmaimaimai.com/pdvn"
const ANDPage = "http://fir.fjmaimaimai.com/ben1"
type CommonService struct {
}
... ... @@ -67,22 +70,48 @@ func (srv *CommonService) GetDictionaryByCode(getDictionaryQuery *query.GetDicti
}
//LatestVersionInfo 版本升级
func (srv *CommonService) LatestVersionInfo() (interface{}, error) {
func (srv *CommonService) LatestVersionInfo(q *query.GetLatestVersionQuery) (interface{}, error) {
page := IOSPage
if q.DeviceType == "1" { // 安卓
page = ANDPage
}
return map[string]interface{}{
"version": map[string]interface{}{
"downloadPage": "www.baidu.com",
"downloadFile": "test.iso",
"downloadPage": page,
"downloadFile": "",
"updateType": 0,
},
}, nil
//vs:= version_server.NewHttpLibVersionServer()
//data,err:= vs.GetLatestVersion(q.Request,version_server.ReqLatestVersion{
// VersionNo: q.VersionNo,
// Channel: q.Channel,
//})
//if err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
//}
//return data, nil
}
//AppSharing 获取分享链接地址
func (srv *CommonService) AppSharing() (interface{}, error) {
func (srv *CommonService) AppSharing(q *query.GetLatestVersionQuery) (interface{}, error) {
page := IOSPage
if q.DeviceType == "1" { // 安卓
page = ANDPage
}
return map[string]interface{}{
"version": map[string]interface{}{
"downloadPage": "www.baidu.com",
"downloadFile": "test.iso",
"downloadPage": page,
"downloadFile": "",
},
}, nil
//vs:= version_server.NewHttpLibVersionServer()
//data,err:= vs.GetLatestVersion(q.Request,version_server.ReqLatestVersion{
// VersionNo: q.VersionNo,
// Channel: q.Channel,
//})
//if err != nil {
// return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
//}
//return data, nil
}
... ...
... ... @@ -139,7 +139,7 @@ func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPer
// 分红支出
DividendsIncome float64 `json:"dividendsIncome"`
// 企业信息
Company domain.CompanyData `json:"company"`
Company domain.Company `json:"company"`
}
var cooperationCompanyStatisticsResponses []cooperationCompanyStatisticsResponse
if err := json.UnmarshalFromString(json.MarshalToString(result), &cooperationCompanyStatisticsResponses); err != nil {
... ... @@ -152,10 +152,10 @@ func (srv PersonStatisticsService) CompanyStatistics(cmd *command.CooperationPer
var values = make([]interface{}, 0)
for i := range users.Users {
user := users.Users[i]
cooperationCompanyStatisticsResponses[i].Company = domain.CompanyData{
cooperationCompanyStatisticsResponses[i].Company = domain.Company{
CompanyID: user.Org.OrgId,
CompanyName: user.Org.OrgName,
CompanyLogo: user.Company.Logo,
Logo: user.Company.Logo,
}
values = append(values, cooperationCompanyStatisticsResponses[i])
}
... ...
... ... @@ -117,8 +117,8 @@ func (srv UserService) UpdateUserBaseInfo(updateUserInfoCommand *command.UpdateU
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
user, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
UserId: int(updateUserInfoCommand.Operator.UserId),
user, err := creationUserGateway.AuthUserBaseInfo(allied_creation_user.ReqAuthUserBase{
Account: updateUserInfoCommand.Operator.Phone,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "用户不存在")
... ... @@ -143,11 +143,11 @@ func (srv UserService) UpdateUserBaseInfo(updateUserInfoCommand *command.UpdateU
}
}
_, err = creationUserGateway.UserUpdateBaseInfo(allied_creation_user.ReqUserUpdateBaseInfo{
UserId: int64(user.UserId),
UserName: updateUserInfoCommand.UserName,
Avatar: updateUserInfoCommand.Avatar,
Phone: updateUserInfoCommand.Phone,
Email: updateUserInfoCommand.Email,
UserBaseId: int64(user.UserBaseID),
UserName: updateUserInfoCommand.UserName,
Avatar: updateUserInfoCommand.Avatar,
Phone: updateUserInfoCommand.Phone,
Email: updateUserInfoCommand.Email,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -70,12 +70,12 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
resultApplication, err := creationCooperationGateway.CooperationApplicationsSearch(allied_creation_cooperation.ReqCooperationApplicationSearch{
CooperationProjectNumber: resultProject.CooperationProject.CooperationProjectNumber,
PageNumber: 0,
PageSize: 0,
CompanyId: resultProject.Company.CompanyId,
OrgId: int64(resultProject.Org.OrgId),
CooperationApplicationStatus: 2, //审核通过的
CooperationProjectNumber: resultProject.CooperationProject.CooperationProjectNumber,
PageNumber: 0,
PageSize: 0,
CompanyId: resultProject.Company.CompanyId,
OrgId: int64(resultProject.Org.OrgId),
//CooperationApplicationStatus: 2, //审核通过的
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -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"
... ... @@ -24,6 +25,9 @@ var ALLIED_CREATION_USER_HOST = "http://localhost:8081" //"http://allied-creatio
//天联共创业务模块
var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" // "http://allied-creation-cooperation-dev.fjmaimaimai.com"
// 版本更新模块
var SUPLUS_ADMIN_BASE_HOST = "http://suplus-admin-base-test.fjmaimaimai.com"
//通用模块短信服务
var SMS_SERVE_HOST = "https://sms.fjmaimaimai.com:9897"
... ... @@ -37,6 +41,12 @@ func init() {
if os.Getenv("LOG_TYPE") != "" {
LOG_TYPE = os.Getenv("LOG_TYPE")
}
if os.Getenv("SUPLUS_ADMIN_BASE_HOST") != "" {
ALLIED_CREATION_GATEWAY_HOST = os.Getenv("SUPLUS_ADMIN_BASE_HOST")
}
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")
}
... ...
... ... @@ -6,3 +6,9 @@ type CompanyData struct {
CompanyLogo string `json:"companyLogo"`
CompanyName string `json:"companyName"`
}
type Company struct {
CompanyID int `json:"companyId"`
Logo string `json:"logo"`
CompanyName string `json:"companyName"`
}
... ...
... ... @@ -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
}
... ...
... ... @@ -303,6 +303,8 @@ type (
type (
ReqUserUpdateBaseInfo struct {
UserId int64 `json:"userId"`
// 用户基础Id 用户唯一标识
UserBaseId int64 `cname:"用户Id 用户唯一标识" json:"userBaseId" valid:"Required"`
// 用户姓名
UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
// 头像
... ...
package version_server
import (
"encoding/json"
"fmt"
"net/http"
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
)
//公共短信服务模块
type HttpLibVersionServer struct {
service_gateway.BaseServiceGateway
baseUrL string
}
func NewHttpLibVersionServer() *HttpLibVersionServer {
return &HttpLibVersionServer{
BaseServiceGateway: service_gateway.BaseServiceGateway{
ConnectTimeout: 100 * time.Second,
ReadWriteTimeout: 30 * time.Second,
},
baseUrL: constant.SUPLUS_ADMIN_BASE_HOST,
}
}
//SendSms 公共短信验证码服务 发送验证码
func (gateway HttpLibVersionServer) GetLatestVersion(rc *http.Request, param ReqLatestVersion) (*DataLatestVersion, error) {
url := gateway.baseUrL + "/version/getLatestVersionInfo"
method := "post"
req := gateway.CreateRequest(url, method)
//TODO traceID
log.Logger.Debug("向版本管理请求数据:搜索用户列表。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("搜索版本失败:%w", err)
}
for k, vs := range rc.Header {
for i := range vs {
req.Header(k, vs[i])
}
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取版本失败:%w", err)
}
fmt.Println(string(byteResult))
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析版本:%w", err)
}
var data DataLatestVersion
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
package version_server
type (
ReqLatestVersion struct {
VersionNo int `json:"versionNo"`
Channel int `json:"channel"`
}
DataLatestVersion map[string]interface{}
)
... ...
... ... @@ -2,9 +2,6 @@ package controllers
import (
"fmt"
"io"
"path/filepath"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/json"
"github.com/linmadan/egglib-go/web/beego"
... ... @@ -12,6 +9,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/middleware"
"io"
"path/filepath"
)
type BaseController struct {
... ...
... ... @@ -3,13 +3,13 @@ package controllers
import (
"io/ioutil"
"github.com/linmadan/egglib-go/web/beego"
//"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/common/service"
)
type CommonController struct {
beego.BaseController
BaseController
}
func (controller *CommonController) GetDictionaryByCode() {
... ... @@ -22,17 +22,21 @@ func (controller *CommonController) GetDictionaryByCode() {
func (controller *CommonController) LatestVersionInfo() {
commonService := service.NewCommonService(nil)
queryParam := &query.GetDictionaryByCodeQuery{}
queryParam := &query.GetLatestVersionQuery{}
_ = controller.Unmarshal(queryParam)
data, err := commonService.LatestVersionInfo()
queryParam.Request = controller.Ctx.Request
queryParam.DeviceType = controller.GetDeviceType()
data, err := commonService.LatestVersionInfo(queryParam)
controller.Response(data, err)
}
func (controller *CommonController) AppSharing() {
commonService := service.NewCommonService(nil)
queryParam := &query.GetDictionaryByCodeQuery{}
queryParam := &query.GetLatestVersionQuery{}
_ = controller.Unmarshal(queryParam)
data, err := commonService.AppSharing()
queryParam.Request = controller.Ctx.Request
queryParam.DeviceType = controller.GetDeviceType()
data, err := commonService.AppSharing(queryParam)
controller.Response(data, 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
}
... ...