mini_qrcode_invite_logic.go 1.1 KB
package common

import (
	"context"
	"github.com/samber/lo"
	"github.com/silenceper/wechat/v2/miniprogram/qrcode"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"

	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MiniQrcodeInviteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMiniQrcodeInviteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniQrcodeInviteLogic {
	return &MiniQrcodeInviteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MiniQrcodeInviteLogic) MiniQrcodeInvite(req *types.MiniQrCodeRequest) (resp []byte, err error) {
	q := l.svcCtx.MiniProgram.GetQRCode()
	var data []byte
	data, err = q.GetWXACodeUnlimit(qrcode.QRCoder{
		Page:       req.Page,
		Path:       req.Page,
		Scene:      req.Scene,
		CheckPath:  lo.ToPtr(false),
		EnvVersion: "release",
	})
	if err != nil {
		return nil, xerr.NewErr(err)
	}
	return data, nil
}