作者 yangfu

二维码

... ... @@ -18,6 +18,10 @@ service Core {
@handler commonSmsCode
post /common/sms/code (CommonSmsCodeRequest) returns (CommonSmsCodeResposne)
@doc "微信二维码"
@handler miniQrcodeInvite
post /mini/qrcode (MiniQrCodeRequest)
@doc "日志查询"
@handler commonGetLog
get /log/:module
... ... @@ -35,4 +39,12 @@ type(
CommonSmsCodeResposne{
}
)
type(
MiniQrCodeRequest{
Page string `json:"page"` // 微信页面入口
Path string `json:"path"` //
Scene string `json:"scene"` // 参数
}
)
\ No newline at end of file
... ...
package common
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/common"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniQrcodeInviteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniQrCodeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := common.NewMiniQrcodeInviteLogic(r.Context(), svcCtx)
resp, err := l.MiniQrcodeInvite(&req)
if err != nil {
result.HttpResult(r, w, resp, err)
}
w.Header().Set("Content-Disposition", "attachment; filename="+"qrcode.png")
w.Header().Set("Content-Type", "application/octet-stream")
w.Write(resp)
}
}
... ...
... ... @@ -27,6 +27,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: common.CommonSmsCodeHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/qrcode",
Handler: common.MiniQrcodeInviteHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/log/:module",
Handler: common.CommonGetLogHandler(serverCtx),
... ...
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
}
... ...
package svc
import (
"github.com/silenceper/wechat/v2"
minicache "github.com/silenceper/wechat/v2/cache"
"github.com/silenceper/wechat/v2/miniprogram"
miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
"github.com/zeromicro/go-zero/core/stores/redis"
"github.com/zeromicro/go-zero/rest"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/config"
... ... @@ -44,6 +48,8 @@ type ServiceContext struct {
ApiAuthService authlib.ApiAuthService
SmsService smslib.SMSService
MiniProgram *miniprogram.MiniProgram
LoginStatusCheck rest.Middleware
LogRequest rest.Middleware
}
... ... @@ -57,6 +63,11 @@ func NewServiceContext(c config.Config) *ServiceContext {
apiAuth := authlib.ApiAuthService{
Service: gateway.NewService(c.ApiAuth.Name, c.ApiAuth.Host, c.ApiAuth.Timeout),
}
miniProgram := wechat.NewWechat().GetMiniProgram(&miniConfig.Config{
AppID: c.Wechat.AppID,
AppSecret: c.Wechat.AppSecret,
Cache: minicache.NewMemory(),
})
return &ServiceContext{
Config: c,
DB: db,
... ... @@ -65,6 +76,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
SmsService: smslib.SMSService{Service: gateway.NewService("短信服务", "https://sms.fjmaimaimai.com:9897", time.Second*5)},
LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle,
LogRequest: middleware.NewLogRequestMiddleware(c.LogRequest).Handle,
MiniProgram: miniProgram,
ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)),
ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)),
... ...
... ... @@ -8,6 +8,11 @@ type CommonSmsCodeRequest struct {
type CommonSmsCodeResposne struct {
}
type MiniQrCodeRequest struct {
Page string `json:"page"` // 微信页面入口
Scene string `json:"scene"` // 参数
}
type CommentAuthor struct {
Id int64 `json:"id"` // 人员id
Name string `json:"name"` // 人员的名字
... ...