67 lines
2.0 KiB
Go
67 lines
2.0 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"fusenapi/model/gmodel"
|
|
"fusenapi/server/data-transfer/internal/svc"
|
|
"fusenapi/server/data-transfer/internal/types"
|
|
"fusenapi/utils/auth"
|
|
"fusenapi/utils/basic"
|
|
"fusenapi/utils/qrcode"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"strings"
|
|
)
|
|
|
|
type UploadQrcodeLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewUploadQrcodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadQrcodeLogic {
|
|
return &UploadQrcodeLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
// 生成base64二维码
|
|
func (l *UploadQrcodeLogic) UploadQrcode(req *types.UploadQrcodeReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "please login first")
|
|
}
|
|
if req.Url == "" {
|
|
resp.SetStatus(basic.CodeApiErr, "param url is empty")
|
|
}
|
|
if req.QRcodeType <= 0 {
|
|
resp.SetStatus(basic.CodeApiErr, "param QRcodeType must large than 0")
|
|
}
|
|
//获取二维码模板信息
|
|
qrCodeModel := gmodel.NewFsQrcodeSetModel(l.svcCtx.MysqlConn)
|
|
qrCodeSet, err := qrCodeModel.FindOne(l.ctx, req.QRcodeType)
|
|
if err != nil {
|
|
logx.Error(err)
|
|
resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get qrcode setting")
|
|
}
|
|
if qrCodeSet.Id == 0 {
|
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "qrcode setting is not exists")
|
|
}
|
|
qrType := *qrCodeSet.SvgWebsite
|
|
if strings.Contains(req.Url, "www.instagram.com") {
|
|
qrType = *qrCodeSet.SvgInstagram
|
|
} else if strings.Contains(req.Url, "www.facebook.com") {
|
|
qrType = *qrCodeSet.SvgFacebook
|
|
}
|
|
//生成二维码
|
|
imgBase64, err := qrcode.CreateQrCodeBs64WithLogo(req.Url, "", "", 512, int(*qrCodeSet.IndexX), int(*qrCodeSet.IndexY), true)
|
|
if err != nil {
|
|
logx.Error(err)
|
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to generate qrcode")
|
|
}
|
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.UploadQrcodeRsp{
|
|
Link: "",
|
|
Data: qrType + " " + imgBase64,
|
|
})
|
|
}
|