正在显示
6 个修改的文件
包含
107 行增加
和
0 行删除
| @@ -18,6 +18,10 @@ service Core { | @@ -18,6 +18,10 @@ service Core { | ||
| 18 | @handler commonSmsCode | 18 | @handler commonSmsCode |
| 19 | post /common/sms/code (CommonSmsCodeRequest) returns (CommonSmsCodeResposne) | 19 | post /common/sms/code (CommonSmsCodeRequest) returns (CommonSmsCodeResposne) |
| 20 | 20 | ||
| 21 | + @doc "微信二维码" | ||
| 22 | + @handler miniQrcodeInvite | ||
| 23 | + post /mini/qrcode (MiniQrCodeRequest) | ||
| 24 | + | ||
| 21 | @doc "日志查询" | 25 | @doc "日志查询" |
| 22 | @handler commonGetLog | 26 | @handler commonGetLog |
| 23 | get /log/:module | 27 | get /log/:module |
| @@ -36,3 +40,11 @@ type( | @@ -36,3 +40,11 @@ type( | ||
| 36 | 40 | ||
| 37 | } | 41 | } |
| 38 | ) | 42 | ) |
| 43 | + | ||
| 44 | +type( | ||
| 45 | + MiniQrCodeRequest{ | ||
| 46 | + Page string `json:"page"` // 微信页面入口 | ||
| 47 | + Path string `json:"path"` // | ||
| 48 | + Scene string `json:"scene"` // 参数 | ||
| 49 | + } | ||
| 50 | +) |
| 1 | +package common | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
| 5 | + "net/http" | ||
| 6 | + | ||
| 7 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/common" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +func MiniQrcodeInviteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 14 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 15 | + var req types.MiniQrCodeRequest | ||
| 16 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 17 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 18 | + return | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + l := common.NewMiniQrcodeInviteLogic(r.Context(), svcCtx) | ||
| 22 | + resp, err := l.MiniQrcodeInvite(&req) | ||
| 23 | + if err != nil { | ||
| 24 | + result.HttpResult(r, w, resp, err) | ||
| 25 | + } | ||
| 26 | + w.Header().Set("Content-Disposition", "attachment; filename="+"qrcode.png") | ||
| 27 | + w.Header().Set("Content-Type", "application/octet-stream") | ||
| 28 | + w.Write(resp) | ||
| 29 | + } | ||
| 30 | +} |
| @@ -27,6 +27,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -27,6 +27,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 27 | Handler: common.CommonSmsCodeHandler(serverCtx), | 27 | Handler: common.CommonSmsCodeHandler(serverCtx), |
| 28 | }, | 28 | }, |
| 29 | { | 29 | { |
| 30 | + Method: http.MethodPost, | ||
| 31 | + Path: "/mini/qrcode", | ||
| 32 | + Handler: common.MiniQrcodeInviteHandler(serverCtx), | ||
| 33 | + }, | ||
| 34 | + { | ||
| 30 | Method: http.MethodGet, | 35 | Method: http.MethodGet, |
| 31 | Path: "/log/:module", | 36 | Path: "/log/:module", |
| 32 | Handler: common.CommonGetLogHandler(serverCtx), | 37 | Handler: common.CommonGetLogHandler(serverCtx), |
| 1 | +package common | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "context" | ||
| 5 | + "github.com/samber/lo" | ||
| 6 | + "github.com/silenceper/wechat/v2/miniprogram/qrcode" | ||
| 7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
| 8 | + | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
| 10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
| 11 | + | ||
| 12 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +type MiniQrcodeInviteLogic struct { | ||
| 16 | + logx.Logger | ||
| 17 | + ctx context.Context | ||
| 18 | + svcCtx *svc.ServiceContext | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +func NewMiniQrcodeInviteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniQrcodeInviteLogic { | ||
| 22 | + return &MiniQrcodeInviteLogic{ | ||
| 23 | + Logger: logx.WithContext(ctx), | ||
| 24 | + ctx: ctx, | ||
| 25 | + svcCtx: svcCtx, | ||
| 26 | + } | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +func (l *MiniQrcodeInviteLogic) MiniQrcodeInvite(req *types.MiniQrCodeRequest) (resp []byte, err error) { | ||
| 30 | + q := l.svcCtx.MiniProgram.GetQRCode() | ||
| 31 | + var data []byte | ||
| 32 | + data, err = q.GetWXACodeUnlimit(qrcode.QRCoder{ | ||
| 33 | + Page: req.Page, | ||
| 34 | + Path: req.Page, | ||
| 35 | + Scene: req.Scene, | ||
| 36 | + CheckPath: lo.ToPtr(false), | ||
| 37 | + EnvVersion: "release", | ||
| 38 | + }) | ||
| 39 | + if err != nil { | ||
| 40 | + return nil, xerr.NewErr(err) | ||
| 41 | + } | ||
| 42 | + return data, nil | ||
| 43 | +} |
| 1 | package svc | 1 | package svc |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "github.com/silenceper/wechat/v2" | ||
| 5 | + minicache "github.com/silenceper/wechat/v2/cache" | ||
| 6 | + "github.com/silenceper/wechat/v2/miniprogram" | ||
| 7 | + miniConfig "github.com/silenceper/wechat/v2/miniprogram/config" | ||
| 4 | "github.com/zeromicro/go-zero/core/stores/redis" | 8 | "github.com/zeromicro/go-zero/core/stores/redis" |
| 5 | "github.com/zeromicro/go-zero/rest" | 9 | "github.com/zeromicro/go-zero/rest" |
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/config" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/config" |
| @@ -44,6 +48,8 @@ type ServiceContext struct { | @@ -44,6 +48,8 @@ type ServiceContext struct { | ||
| 44 | ApiAuthService authlib.ApiAuthService | 48 | ApiAuthService authlib.ApiAuthService |
| 45 | SmsService smslib.SMSService | 49 | SmsService smslib.SMSService |
| 46 | 50 | ||
| 51 | + MiniProgram *miniprogram.MiniProgram | ||
| 52 | + | ||
| 47 | LoginStatusCheck rest.Middleware | 53 | LoginStatusCheck rest.Middleware |
| 48 | LogRequest rest.Middleware | 54 | LogRequest rest.Middleware |
| 49 | } | 55 | } |
| @@ -57,6 +63,11 @@ func NewServiceContext(c config.Config) *ServiceContext { | @@ -57,6 +63,11 @@ func NewServiceContext(c config.Config) *ServiceContext { | ||
| 57 | apiAuth := authlib.ApiAuthService{ | 63 | apiAuth := authlib.ApiAuthService{ |
| 58 | Service: gateway.NewService(c.ApiAuth.Name, c.ApiAuth.Host, c.ApiAuth.Timeout), | 64 | Service: gateway.NewService(c.ApiAuth.Name, c.ApiAuth.Host, c.ApiAuth.Timeout), |
| 59 | } | 65 | } |
| 66 | + miniProgram := wechat.NewWechat().GetMiniProgram(&miniConfig.Config{ | ||
| 67 | + AppID: c.Wechat.AppID, | ||
| 68 | + AppSecret: c.Wechat.AppSecret, | ||
| 69 | + Cache: minicache.NewMemory(), | ||
| 70 | + }) | ||
| 60 | return &ServiceContext{ | 71 | return &ServiceContext{ |
| 61 | Config: c, | 72 | Config: c, |
| 62 | DB: db, | 73 | DB: db, |
| @@ -65,6 +76,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | @@ -65,6 +76,7 @@ func NewServiceContext(c config.Config) *ServiceContext { | ||
| 65 | SmsService: smslib.SMSService{Service: gateway.NewService("短信服务", "https://sms.fjmaimaimai.com:9897", time.Second*5)}, | 76 | SmsService: smslib.SMSService{Service: gateway.NewService("短信服务", "https://sms.fjmaimaimai.com:9897", time.Second*5)}, |
| 66 | LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle, | 77 | LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle, |
| 67 | LogRequest: middleware.NewLogRequestMiddleware(c.LogRequest).Handle, | 78 | LogRequest: middleware.NewLogRequestMiddleware(c.LogRequest).Handle, |
| 79 | + MiniProgram: miniProgram, | ||
| 68 | 80 | ||
| 69 | ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)), | 81 | ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)), |
| 70 | ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)), | 82 | ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)), |
| @@ -8,6 +8,11 @@ type CommonSmsCodeRequest struct { | @@ -8,6 +8,11 @@ type CommonSmsCodeRequest struct { | ||
| 8 | type CommonSmsCodeResposne struct { | 8 | type CommonSmsCodeResposne struct { |
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | +type MiniQrCodeRequest struct { | ||
| 12 | + Page string `json:"page"` // 微信页面入口 | ||
| 13 | + Scene string `json:"scene"` // 参数 | ||
| 14 | +} | ||
| 15 | + | ||
| 11 | type CommentAuthor struct { | 16 | type CommentAuthor struct { |
| 12 | Id int64 `json:"id"` // 人员id | 17 | Id int64 `json:"id"` // 人员id |
| 13 | Name string `json:"name"` // 人员的名字 | 18 | Name string `json:"name"` // 人员的名字 |
-
请 注册 或 登录 后发表评论